Browse Source

团购拼团和超期取消

beaver383 6 years ago
parent
commit
69f9daefa9

+ 59 - 18
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/job/OrderJob.java

@@ -3,11 +3,8 @@ package org.linlinjava.litemall.admin.job;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
 import org.linlinjava.litemall.core.system.SystemConfig;
 import org.linlinjava.litemall.core.system.SystemConfig;
-import org.linlinjava.litemall.db.domain.LitemallOrder;
-import org.linlinjava.litemall.db.domain.LitemallOrderGoods;
-import org.linlinjava.litemall.db.service.LitemallGoodsProductService;
-import org.linlinjava.litemall.db.service.LitemallOrderGoodsService;
-import org.linlinjava.litemall.db.service.LitemallOrderService;
+import org.linlinjava.litemall.db.domain.*;
+import org.linlinjava.litemall.db.service.*;
 import org.linlinjava.litemall.db.util.OrderUtil;
 import org.linlinjava.litemall.db.util.OrderUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -30,6 +27,10 @@ public class OrderJob {
     private LitemallOrderService orderService;
     private LitemallOrderService orderService;
     @Autowired
     @Autowired
     private LitemallGoodsProductService productService;
     private LitemallGoodsProductService productService;
+    @Autowired
+    private LitemallGrouponService grouponService;
+    @Autowired
+    private LitemallGrouponRulesService rulesService;
 
 
     /**
     /**
      * 自动取消订单
      * 自动取消订单
@@ -50,20 +51,9 @@ public class OrderJob {
             // 设置订单已取消状态
             // 设置订单已取消状态
             order.setOrderStatus(OrderUtil.STATUS_AUTO_CANCEL);
             order.setOrderStatus(OrderUtil.STATUS_AUTO_CANCEL);
             order.setEndTime(LocalDateTime.now());
             order.setEndTime(LocalDateTime.now());
-            if (orderService.updateWithOptimisticLocker(order) == 0) {
-                throw new RuntimeException("更新数据已失效");
-            }
 
 
-            // 商品货品数量增加
-            Integer orderId = order.getId();
-            List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
-            for (LitemallOrderGoods orderGoods : orderGoodsList) {
-                Integer productId = orderGoods.getProductId();
-                Short number = orderGoods.getNumber();
-                if (productService.addStock(productId, number) == 0) {
-                    throw new RuntimeException("商品货品库存增加失败");
-                }
-            }
+            cancelOrderScope(order);
+
             logger.info("订单 ID" + order.getId() + " 已经超期自动取消订单");
             logger.info("订单 ID" + order.getId() + " 已经超期自动取消订单");
         }
         }
     }
     }
@@ -120,4 +110,55 @@ public class OrderJob {
             }
             }
         }
         }
     }
     }
+
+    /**
+     * 团购订单拼团超期自动取消
+     */
+    @Scheduled(initialDelay = 5000, fixedDelay = 10 * 60 * 1000)
+    @Transactional(rollbackFor = Exception.class)
+    public void checkGrouponOrderTimeout() {
+        logger.info("系统开启任务检查团购订单是否已经拼团超期自动取消订单");
+
+        List<LitemallGroupon> grouponList = grouponService.queryJoinRecord(0);
+        for (LitemallGroupon groupon : grouponList) {
+            LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId());
+            if (rulesService.isExpired(rules)) {
+                List<LitemallGroupon> subGrouponList = grouponService.queryJoinRecord(groupon.getId());
+                for (LitemallGroupon subGroupon : subGrouponList) {
+                    cancelGrouponScope(subGroupon);
+                }
+
+                cancelGrouponScope(groupon);
+            }
+        }
+    }
+
+    private void cancelGrouponScope(LitemallGroupon groupon) {
+        LitemallOrder order = orderService.findById(groupon.getOrderId());
+        if (order.getOrderStatus().equals(OrderUtil.STATUS_PAY_GROUPON)) {
+            order.setOrderStatus(OrderUtil.STATUS_TIMEOUT_GROUPON);
+            order.setEndTime(LocalDateTime.now());
+
+            cancelOrderScope(order);
+
+            logger.info("团购订单 ID" + order.getId() + " 已经拼团超期自动取消订单");
+        }
+    }
+
+    private void cancelOrderScope(LitemallOrder order) {
+        if (orderService.updateWithOptimisticLocker(order) == 0) {
+            throw new RuntimeException("更新数据已失效");
+        }
+
+        // 商品货品数量增加
+        Integer orderId = order.getId();
+        List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
+        for (LitemallOrderGoods orderGoods : orderGoodsList) {
+            Integer productId = orderGoods.getProductId();
+            Short number = orderGoods.getNumber();
+            if (productService.addStock(productId, number) == 0) {
+                throw new RuntimeException("商品货品库存增加失败");
+            }
+        }
+    }
 }
 }

+ 3 - 1
litemall-admin/src/views/mall/order.vue

@@ -39,7 +39,7 @@
         <template slot-scope="scope">
         <template slot-scope="scope">
           <el-button v-permission="['GET /admin/order/detail']" type="primary" size="mini" @click="handleDetail(scope.row)">详情</el-button>
           <el-button v-permission="['GET /admin/order/detail']" type="primary" size="mini" @click="handleDetail(scope.row)">详情</el-button>
           <el-button v-permission="['POST /admin/order/ship']" v-if="scope.row.orderStatus==201" type="primary" size="mini" @click="handleShip(scope.row)">发货</el-button>
           <el-button v-permission="['POST /admin/order/ship']" v-if="scope.row.orderStatus==201" type="primary" size="mini" @click="handleShip(scope.row)">发货</el-button>
-          <el-button v-permission="['POST /admin/order/refund']" v-if="scope.row.orderStatus==202" type="primary" size="mini" @click="handleRefund(scope.row)">退款</el-button>
+          <el-button v-permission="['POST /admin/order/refund']" v-if="scope.row.orderStatus==202||scope.row.orderStatus==204" type="primary" size="mini" @click="handleRefund(scope.row)">退款</el-button>
         </template>
         </template>
       </el-table-column>
       </el-table-column>
     </el-table>
     </el-table>
@@ -151,9 +151,11 @@ const statusMap = {
   101: '未付款',
   101: '未付款',
   102: '用户取消',
   102: '用户取消',
   103: '系统取消',
   103: '系统取消',
+  200: '已付款团购',
   201: '已付款',
   201: '已付款',
   202: '申请退款',
   202: '申请退款',
   203: '已退款',
   203: '已退款',
+  204: '已超时团购',
   301: '已发货',
   301: '已发货',
   401: '用户收货',
   401: '用户收货',
   402: '系统收货'
   402: '系统收货'

+ 12 - 2
litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderUtil.java

@@ -30,6 +30,8 @@ public class OrderUtil {
     public static final Short STATUS_REFUND = 202;
     public static final Short STATUS_REFUND = 202;
     public static final Short STATUS_REFUND_CONFIRM = 203;
     public static final Short STATUS_REFUND_CONFIRM = 203;
     public static final Short STATUS_AUTO_CONFIRM = 402;
     public static final Short STATUS_AUTO_CONFIRM = 402;
+    public static final Short STATUS_PAY_GROUPON = 200;
+    public static final Short STATUS_TIMEOUT_GROUPON = 204;
 
 
 
 
     public static String orderStatusText(LitemallOrder order) {
     public static String orderStatusText(LitemallOrder order) {
@@ -47,6 +49,10 @@ public class OrderUtil {
             return "已取消(系统)";
             return "已取消(系统)";
         }
         }
 
 
+        if (status == 200) {
+            return "已付款团购";
+        }
+
         if (status == 201) {
         if (status == 201) {
             return "已付款";
             return "已付款";
         }
         }
@@ -59,6 +65,10 @@ public class OrderUtil {
             return "已退款";
             return "已退款";
         }
         }
 
 
+        if (status == 204) {
+            return "已超时团购";
+        }
+
         if (status == 301) {
         if (status == 301) {
             return "已发货";
             return "已发货";
         }
         }
@@ -86,10 +96,10 @@ public class OrderUtil {
         } else if (status == 102 || status == 103) {
         } else if (status == 102 || status == 103) {
             // 如果订单已经取消或是已完成,则可删除
             // 如果订单已经取消或是已完成,则可删除
             handleOption.setDelete(true);
             handleOption.setDelete(true);
-        } else if (status == 201) {
+        } else if (status == 200 || status == 201) {
             // 如果订单已付款,没有发货,则可退款
             // 如果订单已付款,没有发货,则可退款
             handleOption.setRefund(true);
             handleOption.setRefund(true);
-        } else if (status == 202) {
+        } else if (status == 202 || status == 204) {
             // 如果订单申请退款中,没有相关操作
             // 如果订单申请退款中,没有相关操作
         } else if (status == 203) {
         } else if (status == 203) {
             // 如果订单已经退款,则可删除
             // 如果订单已经退款,则可删除

+ 31 - 0
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java

@@ -660,6 +660,37 @@ public class WxOrderService {
             if (grouponService.updateById(groupon) == 0) {
             if (grouponService.updateById(groupon) == 0) {
                 return WxPayNotifyResponse.fail("更新数据已失效");
                 return WxPayNotifyResponse.fail("更新数据已失效");
             }
             }
+
+            // 团购已达成,更新关联订单支付状态
+            if (groupon.getGrouponId() > 0) {
+                List<LitemallGroupon> grouponList = grouponService.queryJoinRecord(groupon.getGrouponId());
+                if (grouponList.size() >= grouponRules.getDiscountMember() - 1) {
+                    for (LitemallGroupon grouponActivity : grouponList) {
+                        if (grouponActivity.getOrderId().equals(order.getId())) {
+                            //当前订单
+                            continue;
+                        }
+
+                        LitemallOrder grouponOrder = orderService.findById(grouponActivity.getOrderId());
+                        if (grouponOrder.getOrderStatus().equals(OrderUtil.STATUS_PAY_GROUPON)) {
+                            grouponOrder.setOrderStatus(OrderUtil.STATUS_PAY);
+                            orderService.updateWithOptimisticLocker(grouponOrder);
+                        }
+                    }
+
+                    LitemallGroupon grouponSource = grouponService.queryById(groupon.getGrouponId());
+                    LitemallOrder grouponOrder = orderService.findById(grouponSource.getOrderId());
+                    if (grouponOrder.getOrderStatus().equals(OrderUtil.STATUS_PAY_GROUPON)) {
+                        grouponOrder.setOrderStatus(OrderUtil.STATUS_PAY);
+                        orderService.updateWithOptimisticLocker(grouponOrder);
+                    }
+                }
+
+            } else {
+                order = orderService.findBySn(orderSn);
+                order.setOrderStatus(OrderUtil.STATUS_PAY_GROUPON);
+                orderService.updateWithOptimisticLocker(order);
+            }
         }
         }
 
 
         //TODO 发送邮件和短信通知,这里采用异步发送
         //TODO 发送邮件和短信通知,这里采用异步发送