商品下单
This commit is contained in:
parent
0e83116550
commit
b71d4381d7
@ -5,7 +5,7 @@ import java.util.Optional;
|
||||
|
||||
public enum OrderStatus {
|
||||
PENDING("Pending", "等待确认"),
|
||||
PROCESSING("Processing", "已支付,正在处理"),
|
||||
PROCESSING("Processing", "已支付,等待发货中"),
|
||||
SHIPPED("Shipped", "已发货,等待确认收货"),
|
||||
DELIVERED("Delivered", "已送达"),
|
||||
CANCELLED("Cancelled", "已取消");
|
||||
|
@ -92,8 +92,8 @@ public class OrderController {
|
||||
}
|
||||
|
||||
try {
|
||||
OrderVO orderVO = orderService.getOrderById(orderId);
|
||||
if (orderVO == null) {
|
||||
Order order = orderService.getOrderById(orderId);
|
||||
if (order == null) {
|
||||
return Res.error("订单不存在");
|
||||
}
|
||||
List<OrderDetailVO> orderDetailVOList = orderService.getOrderDetailById(orderId);
|
||||
@ -105,7 +105,7 @@ public class OrderController {
|
||||
|
||||
List<GoodVO> goodVOList = goodsService.listByIds(goodIdList);
|
||||
HashMap<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("order", orderVO);
|
||||
resultMap.put("order", OrderVO.convertFrom(order));
|
||||
resultMap.put("orderItem", orderDetailVOList);
|
||||
resultMap.put("goods", goodVOList);
|
||||
return Res.success(resultMap);
|
||||
@ -149,4 +149,40 @@ public class OrderController {
|
||||
map.put("orders", orderVOS);
|
||||
return Res.success(map);
|
||||
}
|
||||
|
||||
@PostMapping("/miniprogram/payOrder")
|
||||
@ResponseBody
|
||||
public Res payOrder(@RequestBody JSONObject params) {
|
||||
Long orderId = params.getLong("orderId");
|
||||
if (orderId == null) {
|
||||
return Res.error("参数错误");
|
||||
}
|
||||
|
||||
// 查询订单详情
|
||||
Order order = orderService.getOrderById(orderId);
|
||||
if (order == null) {
|
||||
return Res.error("订单不存在");
|
||||
}
|
||||
|
||||
//判断是否可以支付
|
||||
OrderStatus orderStatus = OrderStatus.get(order.getOrderStatus());
|
||||
if (orderStatus != OrderStatus.PENDING) {
|
||||
}
|
||||
switch (orderStatus) {
|
||||
case PENDING:
|
||||
// 可以支付
|
||||
break;
|
||||
case PROCESSING:
|
||||
return Res.error("订单已支付,无需重复支付");
|
||||
case CANCELLED:
|
||||
return Res.error("订单已取消,无需重复支付");
|
||||
default:
|
||||
return Res.error("当前订单状态无法支付");
|
||||
}
|
||||
|
||||
// 更新支付信息
|
||||
Boolean success = orderService.updateOrderStatus(orderId, OrderStatus.PROCESSING);
|
||||
|
||||
return Res.success(success ? "支付成功" : "支付失败");
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,14 @@ public interface OrderDao {
|
||||
*/
|
||||
int batchInsertOrderDetail(List<OrderDetail> details);
|
||||
|
||||
// 更新订单状态
|
||||
int updateOrderStatus(@Param("orderId") Integer orderId, @Param("status") String status);
|
||||
/**
|
||||
* 更新订单状态
|
||||
*
|
||||
* @param orderId
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
int updateOrderStatus(@Param("orderId") Long orderId, @Param("orderStatus") String orderStatus);
|
||||
|
||||
// 根据订单 ID 删除订单信息及订单详情信息
|
||||
int deleteOrderById(Long orderId);
|
||||
|
@ -6,7 +6,6 @@ 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;
|
||||
@ -89,13 +88,12 @@ public class OrderService {
|
||||
*
|
||||
* @param orderId
|
||||
*/
|
||||
public OrderVO getOrderById(Long orderId) {
|
||||
public Order getOrderById(Long orderId) {
|
||||
Order order = orderDao.getOrderById(orderId);
|
||||
if (order == null) {
|
||||
return null;
|
||||
}
|
||||
OrderVO orderVO = OrderVO.convertFrom(order);
|
||||
return orderVO;
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,4 +120,16 @@ public class OrderService {
|
||||
List<Order> orders = orderDao.listOrderByUserId(userId, orderStatus);
|
||||
return orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
*
|
||||
* @param orderId
|
||||
* @param orderStatus
|
||||
* @return
|
||||
*/
|
||||
public Boolean updateOrderStatus(Long orderId, OrderStatus orderStatus) {
|
||||
int affectRows = orderDao.updateOrderStatus(orderId, orderStatus.getValue());
|
||||
return affectRows > 0;
|
||||
}
|
||||
}
|
||||
|
@ -47,12 +47,13 @@
|
||||
<insert id="insertOrder" parameterType="com.cxyxiaomo.epp.common.pojo.Order" useGeneratedKeys="true"
|
||||
keyProperty="orderId">
|
||||
INSERT INTO `order` (id, user_id, order_date, order_status, order_price)
|
||||
VALUES (#{id}, #{userId}, #{orderDate,javaType=java.time.LocalDateTime,jdbcType=TIMESTAMP}, #{orderStatus}, #{orderPrice})
|
||||
VALUES (#{id}, #{userId}, #{orderDate,javaType=java.time.LocalDateTime,jdbcType=TIMESTAMP}, #{orderStatus},
|
||||
#{orderPrice})
|
||||
</insert>
|
||||
|
||||
<!-- 批量插入订单详情 -->
|
||||
<insert id="batchInsertOrderDetail" parameterType="java.util.List">
|
||||
INSERT INTO order_detail (order_id, good_id, good_count, unit_price)
|
||||
INSERT INTO `order_detail` (order_id, good_id, good_count, unit_price)
|
||||
VALUES
|
||||
<if test="list != null and list.size() > 0">
|
||||
<foreach collection="list" item="detail" separator=",">
|
||||
@ -65,18 +66,19 @@
|
||||
</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 id = #{orderId} LIMIT 1
|
||||
</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};
|
||||
FROM `order`
|
||||
WHERE id = #{orderId};
|
||||
-- 级联删除,无需手动删除订单详情
|
||||
-- DELETE
|
||||
-- FROM goods_order_details
|
||||
-- WHERE order_id = #{orderId};
|
||||
</delete>
|
||||
</mapper>
|
||||
|
@ -470,6 +470,43 @@
|
||||
}
|
||||
},
|
||||
"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/payOrder?orderId=1749496012575215624",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8003",
|
||||
"path": [
|
||||
"shop",
|
||||
"order",
|
||||
"miniprogram",
|
||||
"payOrder"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "orderId",
|
||||
"value": "1749496012575215624"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
// pages/shop/myOrder.js
|
||||
|
||||
const goodService = require("../../services/good")
|
||||
const orderService = require("../../services/order")
|
||||
|
||||
Page({
|
||||
|
@ -112,10 +112,23 @@ Page({
|
||||
}
|
||||
|
||||
if (res.confirm) {
|
||||
wx.showToast({
|
||||
title: '支付成功',
|
||||
icon: 'success',
|
||||
(async () => {
|
||||
let payResult = await orderService.payOrder(this.data.orderId)
|
||||
console.log("payResult", payResult)
|
||||
wx.showModal({
|
||||
title: '支付结果',
|
||||
content: payResult,
|
||||
showCancel: false,
|
||||
complete: (res) => {
|
||||
wx.navigateBack({
|
||||
delta: getCurrentPages().length - 1
|
||||
})
|
||||
wx.navigateTo({
|
||||
url: "/pages/shop/orderDetail?orderId=" + this.data.orderId,
|
||||
})
|
||||
}
|
||||
})
|
||||
})();
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -39,3 +39,14 @@ export function listUserOrder(filter) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 订单支付 */
|
||||
export function payOrder(orderId) {
|
||||
return send_request({
|
||||
url: '/shop/order/miniprogram/payOrder',
|
||||
method: "POST",
|
||||
data: {
|
||||
"orderId": orderId,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user