Parcourir la source

订单支付时新增活动id参数,用于用户自定义选择参与活动

codingliang il y a 1 an
Parent
commit
f065d4a348

+ 2 - 1
src/main/java/com/sqx/modules/order/service/AppOrderService.java

@@ -99,9 +99,10 @@ public interface AppOrderService extends IService<TbOrder> {
      * @param orderParentId 父订单id 一般为订单id
      * @param orderType 订单类别 为2时表示外卖订单、1表示上门
      * @param addressId 地址id
+     * @param activityId 活动id 新增,可以为空
      * @return 订单信息
      */
-    TbOrder prepareOrder(Long userId, Long orderParentId, Integer orderType, Long addressId);
+    TbOrder prepareOrder(Long userId, Long orderParentId, Integer orderType, Long addressId, Long activityId);
 
     /**
      * 根据订单扣减库存

+ 21 - 5
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -383,7 +383,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
 
     @Transactional(propagation = Propagation.SUPPORTS)
     @Override
-    public TbOrder prepareOrder(Long userId, Long orderParentId, Integer orderType, Long addressId) {
+    public TbOrder prepareOrder(Long userId, Long orderParentId, Integer orderType, Long addressId, Long activityId) {
         // 获取订单信息
         TbOrder parentOrder = appOrderDao.selectById(orderParentId);
         if (parentOrder == null) {
@@ -407,7 +407,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         checkAddress(parentOrder, addressId, goodsShop);
 
         // 检查活动优惠信息
-        checkActivity(parentOrder);
+        checkActivity(activityId, parentOrder);
 
         // 校验优惠券信息
         checkCoupon(parentOrder, userId);
@@ -418,9 +418,25 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         return parentOrder;
     }
 
-    private void checkActivity(TbOrder parentOrder) {
-        // 获取当前订单最优惠的活动
-        OrderSuitActivityVO orderBestActivity = activityService.getOrderBestActivity(parentOrder.getOrderId());
+    /**
+     * 检查活动信息
+     * @param activityId 活动id
+     * @param parentOrder 订单信息
+     */
+    private void checkActivity(Long activityId, TbOrder parentOrder) {
+        OrderSuitActivityVO orderBestActivity = null;
+
+        // 获取当前订单适用的活动列表
+        List<OrderSuitActivityVO> suitActivityList = activityService.getOrderSuitActivity(parentOrder.getOrderId());
+
+        if (ObjectUtil.isNotNull(activityId)) {
+            orderBestActivity = suitActivityList.stream().filter(e -> e.getActivityId().equals(activityId)).findFirst().orElseThrow(() -> new SqxException("订单不适用当前活动"));
+        } else {
+            if (CollUtil.isNotEmpty(suitActivityList)) {
+                orderBestActivity = suitActivityList.get(0);
+            }
+        }
+
         if (ObjectUtil.isNotNull(orderBestActivity)) {
             // 支付金额减去活动优惠金额
             parentOrder.setPayMoney(parentOrder.getPayMoney().subtract(new BigDecimal(orderBestActivity.getDiscountAmount())));

+ 4 - 4
src/main/java/com/sqx/modules/pay/controller/app/ApiWeiXinPayController.java

@@ -46,16 +46,16 @@ public class ApiWeiXinPayController {
     @Login
     @ApiOperation("微信支付宝支付订单")
     @PostMapping("/wxPayJsApiOrder")
-    public Result wxPayJsApiOrder(@RequestAttribute("userId") Long userId, Long parentId, Integer type, Long addressId, Integer orderType) throws Exception {
-        return wxService.payOrder(userId,parentId,type, addressId, orderType);
+    public Result wxPayJsApiOrder(@RequestAttribute("userId") Long userId, Long parentId, Integer type, Long addressId, Integer orderType, Long activityId) throws Exception {
+        return wxService.payOrder(userId,parentId,type, addressId, orderType, activityId);
     }
 
     @Login
     @ApiOperation("余额支付订单")
     @PostMapping(value = "balanceOrder")
-    public Result balanceOrder(@RequestAttribute Long userId, Long parentId, Integer orderType, Long addressId){
+    public Result balanceOrder(@RequestAttribute Long userId, Long parentId, Integer orderType, Long addressId, Long activityId){
 
-        return wxService.balanceOrder(userId, parentId, orderType, addressId);
+        return wxService.balanceOrder(userId, parentId, orderType, addressId, activityId);
     }
 
     @Login

+ 21 - 2
src/main/java/com/sqx/modules/pay/service/WxService.java

@@ -14,7 +14,17 @@ public interface WxService {
 
     Result payMoney(Long userId, BigDecimal money, Integer type) throws Exception;
 
-    Result payOrder(Long userId, Long parentId, Integer type, Long addressId, Integer orderType) throws Exception;
+    /**
+     * 订单支付
+     * @param userId 用户id
+     * @param parentId 订单id
+     * @param type 支付方式 1表示微信支付、4或5表示支付宝支付
+     * @param addressId 地址id
+     * @param orderType 订单类型 1到店、2外卖
+     * @param activityId 活动id(新增,可以为空)
+     * @throws Exception
+     */
+    Result payOrder(Long userId, Long parentId, Integer type, Long addressId, Integer orderType, Long activityId) throws Exception;
 
     String payBack(String resXml,Integer type);;
 
@@ -22,7 +32,16 @@ public interface WxService {
 
     boolean wxRefund(PayDetails payDetails);
 
-    Result balanceOrder(Long userId,Long parentId, Integer orderType, Long addressId);
+    /**
+     * 余额支付订单
+     * @param userId 用户id
+     * @param parentId 订单id
+     * @param orderType 订单类型 1到店、2外卖
+     * @param addressId 地址id
+     * @param activityId 活动id(新增,可以为空)
+     * @return
+     */
+    Result balanceOrder(Long userId,Long parentId, Integer orderType, Long addressId, Long activityId);
 
     Result shopCashDeposit(Long userId, Double money, String openId,Integer type) throws Exception;
 

+ 8 - 6
src/main/java/com/sqx/modules/pay/service/impl/WxServiceImpl.java

@@ -132,10 +132,10 @@ public class WxServiceImpl implements WxService {
     private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     @Override
-    public Result balanceOrder(Long userId, Long parentId, Integer orderType, Long addressId) {
+    public Result balanceOrder(Long userId, Long parentId, Integer orderType, Long addressId, Long activityId) {
         reentrantReadWriteLock.writeLock().lock();
         try{
-            return balanceOrders(userId,parentId,orderType,addressId);
+            return balanceOrders(userId, parentId, orderType, addressId, activityId);
         }catch (Exception e){
             e.printStackTrace();
             log.error("下单异常:"+e.getMessage(),e);
@@ -151,12 +151,13 @@ public class WxServiceImpl implements WxService {
      * @param parentId
      * @param orderType
      * @param addressId
+     * @param activityId 活动id
      * @return
      */
     @Transactional
-    public Result balanceOrders(Long userId, Long parentId, Integer orderType, Long addressId){
+    public Result balanceOrders(Long userId, Long parentId, Integer orderType, Long addressId, Long activityId){
         // 获取订单信息
-        TbOrder tbOrder = appOrderService.prepareOrder(userId, parentId, orderType, addressId);
+        TbOrder tbOrder = appOrderService.prepareOrder(userId, parentId, orderType, addressId, activityId);
 
         // 扣除用户余额
         BigDecimal payMoney = tbOrder.getPayMoney();
@@ -259,10 +260,11 @@ public class WxServiceImpl implements WxService {
      * @param type 支付方式
      * @param addressId 用户地址id
      * @param orderType 订单类型 1到店、2外卖
+     * @param activityId 活动id
      */
     @Override
-    public Result payOrder(Long userId, Long parentId, Integer type, Long addressId, Integer orderType) throws Exception {
-        TbOrder tbOrder = appOrderService.prepareOrder(userId, parentId, orderType, addressId);
+    public Result payOrder(Long userId, Long parentId, Integer type, Long addressId, Integer orderType, Long activityId) throws Exception {
+        TbOrder tbOrder = appOrderService.prepareOrder(userId, parentId, orderType, addressId, activityId);
 
         // 设置支付方式 1表示微信支付、4或5表示支付宝支付
         tbOrder.setPayType(1);