1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

小程序(及后端)订单详情页完成;后端获取用户订单列表接口完成

This commit is contained in:
程序员小墨 2023-03-20 00:24:19 +08:00
parent 90a17c926e
commit 960280b11e
29 changed files with 838 additions and 53 deletions

View File

@ -1,19 +1,34 @@
package com.cxyxiaomo.epp.common.enums;
import java.util.Arrays;
import java.util.Optional;
public enum OrderStatus {
PENDING("Pending"),
PROCESSING("Processing"),
SHIPPED("Shipped"),
DELIVERED("Delivered"),
CANCELLED("Cancelled");
PENDING("Pending", "等待确认"),
PROCESSING("Processing", "已支付,正在处理"),
SHIPPED("Shipped", "已发货,等待确认收货"),
DELIVERED("Delivered", "已送达"),
CANCELLED("Cancelled", "已取消");
private final String value;
private final String description;
private OrderStatus(String value) {
private OrderStatus(String value, String description) {
this.value = value;
this.description = description;
}
public static OrderStatus get(String code) {
Optional<OrderStatus> first = Arrays.stream(OrderStatus.values()).filter(e -> e.getValue().equals(code)).findFirst();
OrderStatus orderStatus = first.orElse(null);
return orderStatus;
}
public String getValue() {
return value;
}
public String toString() {
return description;
}
}

View File

@ -1,6 +1,5 @@
package com.cxyxiaomo.epp.common.pojo;
import com.cxyxiaomo.epp.common.enums.OrderStatus;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@ -14,5 +13,5 @@ public class Order {
private Long id;
private Integer userId;
private LocalDateTime orderDate;
private OrderStatus orderStatus;
private String orderStatus;
}

View File

@ -17,7 +17,7 @@ import java.util.stream.Collectors;
@Accessors(chain = true) // 链式写法
// 微服务必须要实现Serializable
public class GoodVO implements Serializable {
Long id;
String id;
String goodsName;
Integer categoryId;
String brand;
@ -38,6 +38,7 @@ public class GoodVO implements Serializable {
}
GoodVO goodVO = new GoodVO();
BeanUtils.copyProperties(good, goodVO);
goodVO.setId(String.valueOf(good.getId()));
return goodVO;
}

View File

@ -4,6 +4,7 @@ import com.cxyxiaomo.epp.common.pojo.OrderDetail;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.util.List;
@ -17,8 +18,8 @@ import java.util.stream.Collectors;
// 微服务必须要实现Serializable
public class OrderDetailVO implements Serializable {
private Long id;
private Long orderId;
private Long goodId;
private String orderId;
private String goodId;
private Integer goodCount;
private Double unitPrice;
@ -27,7 +28,9 @@ public class OrderDetailVO implements Serializable {
return null;
}
OrderDetailVO orderDetailVO = new OrderDetailVO();
// BeanUtils.copyProperties(orderDetail, orderDetailVO);
BeanUtils.copyProperties(orderDetail, orderDetailVO);
orderDetailVO.setOrderId(String.valueOf(orderDetail.getOrderId()));
orderDetailVO.setGoodId(String.valueOf(orderDetail.getGoodId()));
return orderDetailVO;
}

View File

@ -8,7 +8,6 @@ import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@ -20,10 +19,10 @@ import java.util.stream.Collectors;
@Accessors(chain = true) // 链式写法
// 微服务必须要实现Serializable
public class OrderVO implements Serializable {
private Long id;
private String id;
private Integer userId;
private LocalDateTime orderDate;
private OrderStatus orderStatus;
private String orderStatus;
public static OrderVO convertFrom(Order order) {
if (order == null) {
@ -31,6 +30,10 @@ public class OrderVO implements Serializable {
}
OrderVO orderVO = new OrderVO();
BeanUtils.copyProperties(order, orderVO);
orderVO.setId(String.valueOf(order.getId())); // 转成字符串 避免前端丢失精度
OrderStatus orderStatus = OrderStatus.get(order.getOrderStatus());
orderVO.setOrderStatus(orderStatus.toString());
return orderVO;
}

View File

@ -109,6 +109,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- 热部署 -->
<!--<dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!--</dependency>-->
</dependencies>
<build>

View File

@ -2,14 +2,22 @@ package com.cxyxiaomo.epp.shop.controller;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.cxyxiaomo.epp.common.pojo.Order;
import com.cxyxiaomo.epp.common.pojo.OrderDetail;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import com.cxyxiaomo.epp.common.vo.OrderDetailVO;
import com.cxyxiaomo.epp.common.vo.OrderVO;
import com.cxyxiaomo.epp.shop.service.GoodsService;
import com.cxyxiaomo.epp.shop.service.OrderService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/shop/order")
@ -18,12 +26,14 @@ public class OrderController {
@Resource
OrderService orderService;
@Resource
GoodsService goodsService;
/**
* 小程序端创建订单
*
* @param userId 下单用户
* @param orderList 下单商品 [ { goodId, count }, ... ]
* @param orderList 下单商品 [ { goodId, count }, ... ]
* @return
*/
@PostMapping("/miniprogram/createOrder")
@ -58,7 +68,7 @@ public class OrderController {
try {
long orderId = orderService.createOrder(userId, orderDetailList);
return Res.success(orderId);
return Res.success(String.valueOf(orderId)); // 转为 String 避免前端丢失精度
} catch (Exception e) {
String message = e.getMessage();
if (message.contains("Exception")) {
@ -69,4 +79,63 @@ public class OrderController {
}
}
}
/**
* 获取指定订单的详情
*
* @param orderId
* @return
*/
@GetMapping("/miniprogram/orderDetail")
@ResponseBody
public Res orderDetail(@RequestParam Long orderId) {
if (orderId == null) {
return Res.error("订单不存在");
}
try {
OrderVO orderVO = orderService.getOrderById(orderId);
if (orderVO == null) {
return Res.error("订单不存在");
}
List<OrderDetailVO> orderDetailVOList = orderService.getOrderDetailById(orderId);
List<Long> goodIdList = orderDetailVOList.stream().map(orderDetailVO -> {
String goodId = orderDetailVO.getGoodId();
return Long.parseLong(goodId);
}).collect(Collectors.toList());
List<GoodVO> goodVOList = goodsService.listByIds(goodIdList);
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("order", orderVO);
resultMap.put("orderItem", orderDetailVOList);
resultMap.put("goods", goodVOList);
return Res.success(resultMap);
} catch (Exception e) {
String message = e.getMessage();
if (message.contains("Exception")) {
// 内部异常不打印出去
return Res.error("查询订单失败,请重试");
} else {
return Res.error(message);
}
}
}
/**
* 获取用户的订单列表
*
* @param userId
* @return
*/
@GetMapping("/miniprogram/listUserOrder")
@ResponseBody
public Res listUserOrder(@RequestParam Integer userId) {
if (userId == null) {
return Res.error("参数错误");
}
List<Order> orders = orderService.listUserOrder(userId);
List<OrderVO> orderVOS = OrderVO.convertFrom(orders);
return Res.success(orderVOS);
}
}

View File

@ -17,6 +17,8 @@ public interface GoodsDao {
Good selectById(Long id);
List<Good> listByIds(List<Long> id);
Integer insert(Good good);
Integer update(Good good);

View File

@ -18,7 +18,15 @@ public interface OrderDao {
* @param orderId
* @return
*/
Order getOrderById(Integer orderId);
Order getOrderById(Long orderId);
/**
* 根据订单 ID 查询订单详情
*
* @param orderId
* @return
*/
List<OrderDetail> getOrderDetailById(Long orderId);
/**
* 根据用户 ID 查询订单列表
@ -26,7 +34,7 @@ public interface OrderDao {
* @param userId
* @return
*/
List<Order> listOrdersByUserId(Integer userId);
List<Order> listOrderByUserId(Integer userId);
/**
* 创建订单
@ -48,5 +56,5 @@ public interface OrderDao {
int updateOrderStatus(@Param("orderId") Integer orderId, @Param("status") String status);
// 根据订单 ID 删除订单信息及订单详情信息
int deleteOrderById(Integer orderId);
int deleteOrderById(Long orderId);
}

View File

@ -9,6 +9,7 @@ import com.cxyxiaomo.epp.shop.dao.GoodsDao;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
@ -37,4 +38,13 @@ public class GoodsService {
List<GoodCategoryVO> goodCategoryVOList = GoodCategoryVO.convertFrom(list);
return goodCategoryVOList;
}
public List<GoodVO> listByIds(List<Long> goodIdList) {
if (goodIdList == null || goodIdList.size() == 0) {
return new ArrayList<>();
}
List<Good> list = goodsDao.listByIds(goodIdList);
List<GoodVO> goodVOList = GoodVO.convertFrom(list);
return goodVOList;
}
}

View File

@ -5,6 +5,8 @@ import com.cxyxiaomo.epp.common.pojo.Good;
import com.cxyxiaomo.epp.common.pojo.Order;
import com.cxyxiaomo.epp.common.pojo.OrderDetail;
import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
import com.cxyxiaomo.epp.common.vo.OrderDetailVO;
import com.cxyxiaomo.epp.common.vo.OrderVO;
import com.cxyxiaomo.epp.shop.dao.GoodsDao;
import com.cxyxiaomo.epp.shop.dao.OrderDao;
import org.springframework.stereotype.Service;
@ -43,7 +45,7 @@ public class OrderService {
order.setId(orderId);
order.setUserId(userId);
order.setOrderDate(LocalDateTime.now());
order.setOrderStatus(OrderStatus.PENDING);
order.setOrderStatus(OrderStatus.PENDING.getValue());
orderDao.insertOrder(order);
// 创建订单详情
@ -68,4 +70,43 @@ public class OrderService {
orderDao.batchInsertOrderDetail(orderItemList);
return orderId;
}
/**
* 获取订单
*
* @param orderId
*/
public OrderVO getOrderById(Long orderId) {
Order order = orderDao.getOrderById(orderId);
if (order == null) {
return null;
}
OrderVO orderVO = OrderVO.convertFrom(order);
return orderVO;
}
/**
* 获取订单详情
*
* @param orderId
*/
public List<OrderDetailVO> getOrderDetailById(Long orderId) {
List<OrderDetail> orderDetails = orderDao.getOrderDetailById(orderId);
if (orderDetails == null) {
return null;
}
List<OrderDetailVO> orderDetailVOS = OrderDetailVO.convertFrom(orderDetails);
return orderDetailVOS;
}
/**
* 通过用户 id 获取用户订单列表
*
* @param userId
* @return
*/
public List<Order> listUserOrder(Integer userId) {
List<Order> orders = orderDao.listOrderByUserId(userId);
return orders;
}
}

View File

@ -50,6 +50,20 @@
WHERE id = #{id}
</select>
<select id="listByIds" parameterType="java.util.List" resultType="com.cxyxiaomo.epp.common.pojo.Good">
SELECT *
FROM goods
<where>
<if test="list != null and list.size > 0">
AND id IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
AND deleted = 0
</where>
</select>
<!--<select id="selectByCategoryId" resultMap="GoodsResultMap">-->
<!-- SELECT *-->
<!-- FROM goods-->

View File

@ -11,29 +11,40 @@
<result column="order_status" property="orderStatus"/>
</resultMap>
<resultMap id="OrderDetailResultMap" type="com.cxyxiaomo.epp.common.pojo.OrderDetail">
<id property="id" column="id" />
<result property="orderId" column="order_id" />
<result property="goodId" column="good_id" />
<result property="goodCount" column="good_count" />
<result property="unitPrice" column="unit_price" />
<id property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="goodId" column="good_id"/>
<result property="goodCount" column="good_count"/>
<result property="unitPrice" column="unit_price"/>
</resultMap>
<!-- 根据订单 ID 查询订单信息 -->
<select id="getOrderById" resultMap="OrderResultMap">
SELECT * FROM order WHERE order_id=#{orderId}
SELECT *
FROM `order`
WHERE id = #{orderId}
</select>
<!-- 根据订单 ID 查询订单详情 -->
<select id="getOrderDetailById" resultMap="OrderDetailResultMap">
SELECT *
FROM `order_detail`
WHERE order_id = #{orderId}
</select>
<!-- 根据用户 ID 查询订单列表 -->
<select id="listOrdersByUserId" resultType="com.cxyxiaomo.epp.common.pojo.Order">
<select id="listOrderByUserId" resultType="com.cxyxiaomo.epp.common.pojo.Order">
SELECT *
FROM order
FROM `order`
WHERE user_id = #{userId}
order by order_date desc
</select>
<!-- 创建订单 -->
<insert id="insertOrder" parameterType="com.cxyxiaomo.epp.common.pojo.Order" useGeneratedKeys="true" keyProperty="orderId">
INSERT INTO `order` (id, user_id, order_date, order_status) VALUES
(#{id}, #{userId}, #{orderDate,javaType=java.time.LocalDateTime,jdbcType=TIMESTAMP}, #{orderStatus})
<insert id="insertOrder" parameterType="com.cxyxiaomo.epp.common.pojo.Order" useGeneratedKeys="true"
keyProperty="orderId">
INSERT INTO `order` (id, user_id, order_date, order_status)
VALUES (#{id}, #{userId}, #{orderDate,javaType=java.time.LocalDateTime,jdbcType=TIMESTAMP}, #{orderStatus})
</insert>
<!-- 批量插入订单详情 -->
@ -51,12 +62,18 @@
</insert>
<update id="updateOrderStatus" parameterType="com.cxyxiaomo.epp.common.pojo.Order">
UPDATE order SET order_status=#{orderStatus} WHERE order_id=#{orderId}
UPDATE order
SET order_status=#{orderStatus}
WHERE order_id = #{orderId}
</update>
<!-- 根据订单 ID 删除订单信息及订单详情信息 -->
<delete id="deleteOrderById" parameterType="java.lang.Integer">
DELETE FROM order WHERE order_id = #{orderId};
DELETE FROM goods_order_details WHERE order_id = #{orderId};
DELETE
FROM order
WHERE order_id = #{orderId};
DELETE
FROM goods_order_details
WHERE order_id = #{orderId};
</delete>
</mapper>

View File

@ -207,6 +207,13 @@
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.7.5</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -11,7 +11,7 @@
Target Server Version : 80012
File Encoding : 65001
Date: 19/03/2023 17:36:14
Date: 20/03/2023 00:21:56
*/
SET NAMES utf8mb4;
@ -264,6 +264,16 @@ CREATE TABLE `order` (
-- ----------------------------
-- Records of order
-- ----------------------------
INSERT INTO `order` VALUES (1748800678865801225, 1, '2023-03-19 21:29:33', 'Pending');
INSERT INTO `order` VALUES (1748880836628975622, 1, '2023-03-19 23:48:04', 'Pending');
INSERT INTO `order` VALUES (1748881003193176069, 1, '2023-03-19 23:48:44', 'Pending');
INSERT INTO `order` VALUES (1748881359935508481, 1, '2023-03-19 23:50:09', 'Pending');
INSERT INTO `order` VALUES (1748881582816628736, 1, '2023-03-19 23:51:02', 'Pending');
INSERT INTO `order` VALUES (1748881775876247556, 1, '2023-03-19 23:51:48', 'Pending');
INSERT INTO `order` VALUES (1748883439144275978, 1, '2023-03-19 23:58:25', 'Pending');
INSERT INTO `order` VALUES (1748883587555528711, 1, '2023-03-19 23:59:00', 'Pending');
INSERT INTO `order` VALUES (1748884264885293061, 1, '2023-03-20 00:01:41', 'Pending');
INSERT INTO `order` VALUES (1748884523443163146, 1, '2023-03-20 00:02:43', 'Pending');
-- ----------------------------
-- Table structure for order_detail
@ -285,6 +295,18 @@ CREATE TABLE `order_detail` (
-- ----------------------------
-- Records of order_detail
-- ----------------------------
INSERT INTO `order_detail` VALUES (15, 1748800678865801225, 27, 1, 15.99);
INSERT INTO `order_detail` VALUES (16, 1748800678865801225, 12, 1, 5.99);
INSERT INTO `order_detail` VALUES (17, 1748800678865801225, 13, 1, 5.99);
INSERT INTO `order_detail` VALUES (18, 1748880836628975622, 16, 1, 5.99);
INSERT INTO `order_detail` VALUES (19, 1748881003193176069, 16, 1, 5.99);
INSERT INTO `order_detail` VALUES (20, 1748881359935508481, 16, 1, 5.99);
INSERT INTO `order_detail` VALUES (21, 1748881582816628736, 16, 1, 5.99);
INSERT INTO `order_detail` VALUES (22, 1748881775876247556, 64, 1, 18.00);
INSERT INTO `order_detail` VALUES (23, 1748883439144275978, 16, 1, 5.99);
INSERT INTO `order_detail` VALUES (24, 1748883587555528711, 16, 1, 5.99);
INSERT INTO `order_detail` VALUES (25, 1748884264885293061, 16, 1, 5.99);
INSERT INTO `order_detail` VALUES (26, 1748884523443163146, 57, 1, 2.00);
-- ----------------------------
-- Table structure for report

View File

@ -267,7 +267,7 @@
"method": "GET",
"header": [],
"url": {
"raw": "https://epp.only4.work/shop/good/miniprogram/detail?id=1",
"raw": "https://epp.only4.work/shop/good/miniprogram/detail?id=2",
"protocol": "https",
"host": [
"epp",
@ -283,7 +283,7 @@
"query": [
{
"key": "id",
"value": "1"
"value": "2"
}
]
}
@ -312,6 +312,164 @@
}
},
"response": []
},
{
"name": "[线上] 小程序端下单",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"userId\": 1,\r\n \"orderList\": [\r\n {\r\n \"goodId\": 2,\r\n \"count\": 3\r\n },\r\n {\r\n \"goodId\": 3,\r\n \"count\": 1\r\n }\r\n ]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://epp.only4.work/shop/order/miniprogram/createOrder",
"protocol": "https",
"host": [
"epp",
"only4",
"work"
],
"path": [
"shop",
"order",
"miniprogram",
"createOrder"
]
}
},
"response": []
},
{
"name": "[微服务] 小程序端下单",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"userId\": 1,\r\n \"orderList\": [\r\n {\r\n \"goodId\": 2,\r\n \"count\": 3\r\n },\r\n {\r\n \"goodId\": 3,\r\n \"count\": 1\r\n }\r\n ]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8003/shop/order/miniprogram/createOrder",
"protocol": "http",
"host": [
"localhost"
],
"port": "8003",
"path": [
"shop",
"order",
"miniprogram",
"createOrder"
]
}
},
"response": []
},
{
"name": "[线上] 小程序订单详情",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://epp.only4.work/shop/order/miniprogram/orderDetail?orderId=1",
"protocol": "https",
"host": [
"epp",
"only4",
"work"
],
"path": [
"shop",
"order",
"miniprogram",
"orderDetail"
],
"query": [
{
"key": "orderId",
"value": "1"
}
]
}
},
"response": []
},
{
"name": "[微服务] 小程序订单详情",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8003/shop/order/miniprogram/orderDetail?orderId=1748800678865801225",
"protocol": "http",
"host": [
"localhost"
],
"port": "8003",
"path": [
"shop",
"order",
"miniprogram",
"orderDetail"
],
"query": [
{
"key": "orderId",
"value": "1",
"disabled": true
},
{
"key": "orderId",
"value": "1748800678865801225"
}
]
}
},
"response": []
},
{
"name": "[微服务] 小程序用户订单列表",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8003/shop/order/miniprogram/listUserOrder?userId=1",
"protocol": "http",
"host": [
"localhost"
],
"port": "8003",
"path": [
"shop",
"order",
"miniprogram",
"listUserOrder"
],
"query": [
{
"key": "orderId",
"value": "1",
"disabled": true
},
{
"key": "userId",
"value": "1"
}
]
}
},
"response": []
}
]
}

View File

@ -7,6 +7,7 @@
"pages/residents/reportHistory",
"pages/shop/shop",
"pages/shop/goodDetail",
"pages/shop/orderConfirm",
"pages/scan/entrance",
"pages/person/person"
],

View File

@ -55,16 +55,16 @@ Page({
}
}
// 开发模式下自动跳转到指定页面,节省开发时间
console.log("app.globalData", app.globalData)
if (app.globalData.debugMode) {
wx.switchTab({
// url: '/pages/residents/report'
// url: '/pages/person/person'
url: '/pages/shop/shop'
})
return
}
// // 开发模式下自动跳转到指定页面,节省开发时间
// console.log("app.globalData", app.globalData)
// if (app.globalData.debugMode) {
// wx.switchTab({
// // url: '/pages/residents/report'
// // url: '/pages/person/person'
// url: '/pages/shop/shop'
// })
// return
// }
}
},
@ -170,7 +170,8 @@ Page({
magicButton() {
wx.navigateTo({
url: "/pages/scan/entrance"
// url: "/pages/scan/entrance?a=1"
url: "/pages/shop/orderConfirm?orderId=1748800678865801225"
})
}
})

View File

@ -5,14 +5,17 @@ Page({
* 页面的初始数据
*/
data: {
options: {},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options)
this.setData({
options: JSON.stringify(options),
})
},
/**

View File

@ -1,4 +1,5 @@
<!--pages/scan/entrance.wxml-->
<view>
您将要进入社区:未知
{{ options }}
</view>

View File

@ -1,6 +1,7 @@
// pages/shop/goodDetail.js
const goodService = require("../../services/good")
const orderService = require("../../services/order")
Page({
@ -73,6 +74,25 @@ Page({
},
// 立即下单
btnBuyTap() {
(async () => {
// 创建订单
let orderList = [{
goodId: this.data.goodId,
count: 1,
}]
let orderId = await orderService.createOrder(orderList)
console.log("orderId", orderId)
// 跳转订单查看页面(携带订单号)
wx.navigateTo({
// url: "/pages/scan/entrance?a=1"
url: "/pages/shop/orderConfirm?orderId=" + orderId
})
})();
},
loadPageData() {
(async () => {
let goodDetail = await goodService.getGoodDetail(this.data.goodId)

View File

@ -39,6 +39,6 @@
<!-- 屏幕底部 -->
<view class="bottom-buttons">
<view class="btn" id="btn-addcart">加入购物车</view>
<view class="btn" id="btn-buy">立即下单</view>
<view class="btn" id="btn-buy" bindtap="btnBuyTap">立即下单</view>
</view>
</view>

View File

@ -0,0 +1,153 @@
// pages/shop/orderConfirm.js
const orderService = require("../../services/order")
Page({
/**
* 页面的初始数据
*/
data: {
orderId: '',
order: {},
// goods: [],
// orderItem: [],
orderGoodList: [],
orderTime: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options)
if (!options || !options.orderId) {
wx.showModal({
title: '订单查询失败',
content: '请刷新页面后重试',
showCancel: false,
complete: (res) => {
wx.navigateBack()
}
})
}
this.setData({
orderId: options.orderId,
})
this.loadPageData()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
confirmPayment() {
// 点击确认支付按钮
wx.showModal({
title: '拉起支付',
content: '点击确认完成支付,点击取消放弃支付',
complete: (res) => {
if (res.cancel) {
wx.showToast({
title: '用户取消支付',
icon: 'error',
})
}
if (res.confirm) {
wx.showToast({
title: '支付成功',
icon: 'success',
})
}
}
})
},
loadPageData() {
(async () => {
console.log("orderId", this.data.orderId)
let orderDetail = await orderService.getOrderDetail(this.data.orderId)
console.log("orderDetail", orderDetail)
if (!orderDetail) {
wx.showModal({
title: '订单查询失败',
content: '',
showCancel: false,
complete: (res) => {
wx.navigateBack()
}
})
return
}
let orderGoodList = []
for (let item of orderDetail.orderItem) {
orderGoodList.push({
wxid: item.goodId, // 用于列表渲染
good: orderDetail.goods.find(good => good.id == item.goodId),
goodCount: item.goodCount,
unitPrice: item.unitPrice,
})
}
console.log("orderGoodList", orderGoodList)
this.setData({
order: orderDetail.order,
// goods: orderDetail.goods,
// orderItem: orderDetail.orderItem,
orderGoodList: orderGoodList,
orderTime: orderDetail.order.orderDate.replace("T", " ")
})
})();
}
})

View File

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "确认订单"
}

View File

@ -0,0 +1,50 @@
<!--pages/shop/orderConfirm.wxml-->
<view class="page-title-container">
<view class="page-title-emoji">🎉</view>
<view class="page-title">
订单已创建,快去支付吧
</view>
</view>
<view class="order-info">
<view>订单号:{{order.id}}</view>
<view>订单创建时间:{{orderTime}}</view>
<view>订单状态:{{order.orderStatus}}</view>
</view>
<view class="good-list-title">商品列表</view>
<view class="good-card-container" wx:for="{{orderGoodList}}" wx:for-item="item" wx:key="wxid" goodinfo="{{item}}">
<!-- 商品图片 -->
<view class="good-card-image" style="background-image: {{ 'url(' + item.good.picUrl + ');'}};">
</view>
<!-- 商品标题 -->
<view class="good-card-info good-title-container">
<text class="good-title line-wrap">{{ item.good.brief }}</text>
</view>
<!-- 下单时刻商品单价 -->
<view class="good-card-info">
<view class="good-price good-price-counter">
<view class="good-price-symbol">¥</view>
<view class="good-price-number">{{ item.unitPrice }}</view>
</view>
</view>
<!-- 商品个数 -->
<view class="good-card-info">
<view>x{{ item.goodCount }}</view>
</view>
</view>
<view style="height: 110px;">
<!-- 占位用 -->
</view>
<view class="bottom-controlbox">
<!-- 屏幕底部 -->
<view class="bottom-buttons">
<view class="btn" id="btn-confirm-payment" bindtap="confirmPayment">确认支付</view>
</view>
</view>

View File

@ -0,0 +1,144 @@
/* pages/shop/orderConfirm.wxss */
.page-title-container {
margin-top: 16px;
text-align: center;
}
.page-title-emoji {
font-size: 72px;
}
.page-title {
/* border: 2px dashed black; */
display: inline-block;
padding: 15px 20px;
font-size: 20px;
}
.order-info {
background-color: tomato;
padding: 10px 18px;
margin: 10px;
border-radius: 10px;
color: #fff3f1;
font-weight: 500;
line-height: 1.8em;
}
.good-list-title {
text-align: center;
margin-top: 20px;
margin-bottom: 20px;
font-weight: 500;
font-size: 18px;
}
/* 商品列表样式 */
.good-card-container {
/* border: 1px solid grey; */
border-radius: 12px;
box-shadow: 0 2px 10px 0 rgba(0, 0, 0, .2);
margin: 0 14px;
padding: 15px 20px;
display: grid;
grid-template-columns: 120px 1fr 50px;
grid-template-rows: 4fr 3fr;
place-items: center;
gap: 0 8px;
margin-bottom: 10px;
}
.good-card-image {
width: 88px;
height: 88px;
background-color: teal;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
border: 1px solid grey;
border-radius: 5px;
grid-row-start: 1;
grid-row-end: 3;
}
.good-card-info {
width: 100%;
}
/* 商品标题 */
.good-title-container {
grid-column-start: 2;
grid-column-end: 4;
}
.good-title {
font-size: 30rpx;
color: #333;
font-weight: 400;
display: -webkit-box;
height: 72rpx;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
word-break: break-word;
line-height: 36rpx;
margin: 4rpx 0;
}
/* 商品价格 */
.good-price {
white-space: nowrap;
font-weight: 700;
margin: 0;
display: inline;
position: relative;
}
.good-price-counter {
color: #fa4126;
font-size: 36rpx;
}
.good-price .good-price-symbol {
font-size: 24rpx;
display: inline;
}
.good-price .good-price-number {
display: inline;
}
/* 屏幕底部 确认支付按钮 */
.bottom-controlbox {
background-color: white;
position: fixed;
z-index: 999;
bottom: 0;
left: 0;
right: 0;
width: 100%;
padding-top: 6px;
padding-bottom: 12px;
border-top: 1px solid grey;
text-align: center;
}
.bottom-buttons {
height: 100%;
display: inline-block;
}
.btn {
width: 254rpx;
height: 80rpx;
display: inline-grid;
align-items: center;
justify-content: center;
color: white;
}
#btn-confirm-payment {
background-color: #fa4126;
color: #fff;
border-radius: 40rpx;
}

View File

@ -39,6 +39,9 @@
/* border-bottom: 1px solid rgb(121, 121, 121); */
height: 100%;
display: table;
/* iOS下要设置一下 width */
width: 100%;
}
.sidebar-item:last-child {
@ -56,6 +59,7 @@
font-weight: bold;
color: #FF764E;
border-left: 4px solid #FF764E;
box-sizing: border-box;
}
.tabbar {

View File

@ -37,7 +37,8 @@
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"ignoreUploadUnusedFiles": false
},
"compileType": "miniprogram",
"libVersion": "2.19.4",

View File

@ -0,0 +1,28 @@
/* eslint-disable no-param-reassign */
const send_request = require('../utils/sendRequest')
/** 商品下单 */
export function createOrder(orderList) {
let userInfo = wx.getStorageSync("userInfo")
// orderList 结构为 [ { goodId, count }, ... ]
return send_request({
url: '/shop/order/miniprogram/createOrder',
method: "POST",
data: {
"userId": userInfo.id,
"orderList": orderList
}
})
}
/** 商品下单 */
export function getOrderDetail(orderId) {
return send_request({
url: '/shop/order/miniprogram/orderDetail',
method: "GET",
data: {
"orderId": orderId
}
})
}