商品下单
This commit is contained in:
@@ -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>
|
||||
|
Reference in New Issue
Block a user