Explorar o código

修改订单完成才生成骑手、商家账单

qmj hai 1 mes
pai
achega
e03d8865c2

+ 4 - 149
ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderController.java

@@ -140,6 +140,8 @@ public class PosOrderController extends BaseController {
     @Autowired
     private UserService userService;
     @Autowired
+    private OrderService orderService;
+    @Autowired
     private PosOrderShOprateController shOprateController;
     @Autowired
     private OrderLogHelper orderLogHelper;
@@ -467,8 +469,8 @@ public class PosOrderController extends BaseController {
 
             UserBilling billing = userBillingService.getOne(wrapper);
             if (billing == null) {
-                setSanghuBilling(order);
-                setQishouBilling(order);
+                orderService.setSanghuBilling(order);
+                orderService.setQishouBilling(order);
             }
             return success(MessageUtils.message("no.modify.success"), posOrder.getId());
         } else {
@@ -589,153 +591,6 @@ public class PosOrderController extends BaseController {
     }
 
 
-    //执行商户分成
-    public void setSanghuBilling(@NotNull PosOrder posOrder) {
-        long count = userBillingService.count(new LambdaQueryWrapper<UserBilling>().eq(UserBilling::getUserId, posOrder.getShId()).eq(UserBilling::getType, "0").eq(UserBilling::getDdId, posOrder.getDdId()));
-        if (count <= 0) {
-            UserBilling billing = new UserBilling();
-            DecimalFormat df = new DecimalFormat("#.00");
-
-            // 判断是否为摊位订单
-            PosStore store = posStoreService.getById(posOrder.getMdId());
-            boolean isStall = store != null && store.getIsStall() != null && store.getIsStall() == 1 && store.getNightMarketId() != null;
-
-            InfoUser user;
-            if (isStall) {
-                // 摊位订单:使用夜市用户的分成比例
-                user = infoUserService.getById(store.getNightMarketId());
-            } else {
-                // 普通订单:使用商家用户的分成比例
-                user = infoUserService.getById(posOrder.getShId());
-            }
-            Double fcbili = user.getCommission() == null ? 0.00 : user.getCommission();
-            fcbili = getShCommissionRate(fcbili, user.getUserId());
-            JSONArray list = JSONArray.parseArray(posOrder.getFood());
-            int fenc = 0;
-            for (int i = 0; i < list.size(); i++) {
-                JSONObject foods = list.getJSONObject(i);
-                //20250612修改,商品金额等于价格乘以数量;未修改前金额直接为商品价格
-                int price = foods.getInteger("price");
-                int otherPrice = foods.getInteger("otherPrice"); //规格价格
-                int num = foods.getInteger("number");
-                int age = (price + otherPrice) * num; //价格=商品价格+规格价格
-                fenc += age;
-            }
-            String remark = "";
-            //商家分成总金额,减去商家优惠金额,减去商家活动金额(type=1 为平台指定商家优惠券,由平台承担)
-            if (posOrder.getMdYhId() != null && posOrder.getMdDiscountAmount() != null) {
-                VipUserQuanyi userQuanyi = userQuanyiService.getById(posOrder.getMdYhId());
-                if (userQuanyi != null && "1".equals(userQuanyi.getType())) {
-                    fenc = fenc - posOrder.getMdDiscountAmount();
-                    String yhmcMessage = MessageUtils.message("no.posorder.md.yh.mc.messag");
-                    yhmcMessage = StrUtil.format(yhmcMessage, posOrder.getMdYhName());
-                    remark += yhmcMessage;
-                    String yhAmount = MessageUtils.message("no.posorder.md.yh.jiner.messag");
-                    yhAmount = StrUtil.format(yhAmount, posOrder.getMdDiscountAmount());
-                    remark += yhAmount;
-                }
-
-            }
-            if (posOrder.getMdSalesName() != null && posOrder.getMdSalesReduction() != null) {
-                fenc = fenc - posOrder.getMdSalesReduction();
-                String cxNameMessage = MessageUtils.message("no.posorder.md.cx.mc.messag");
-                cxNameMessage = StrUtil.format(cxNameMessage, posOrder.getMdSalesName());
-                remark += cxNameMessage;
-                String cxAmount = MessageUtils.message("no.posorder.md.cx.jiner.messag");
-                cxAmount = StrUtil.format(cxAmount, posOrder.getMdSalesReduction());
-                remark += cxAmount;
-            }
-            billing.setIllustrate(remark);
-            Double chouc = fenc * fcbili;
-            Double shfc = fenc - chouc;
-            billing.setUserId(posOrder.getShId());
-            billing.setDdId(String.valueOf(posOrder.getDdId()));
-            billing.setType("0");
-            billing.setAmount(Double.valueOf(df.format(shfc)));
-            billing.setDivvy(Double.valueOf(df.format(chouc)));
-            billing.setState("0");
-            billing.setMdId(posOrder.getMdId());
-            billing.setUserType("1");
-            billing.setDivvyRate(fcbili);
-            if (isStall) {
-                // 摊位订单:更新摊位钱包
-                billing.setStoreId(Long.valueOf(store.getId()));
-                walletService.addStallBalance(Long.valueOf(store.getId()), BigDecimal.valueOf(billing.getAmount()), billing);
-            } else {
-                // 普通订单:更新用户钱包
-                walletService.addBalance(billing.getUserId(), BigDecimal.valueOf(billing.getAmount()), billing);
-            }
-//            int reg = userBillingService.insertUserBilling(billing);
-//            if (reg == 1) {
-//
-//                System.out.println("商户分成成功,订单号:" + posOrder.getDdId() + ",分成金额:" + shfc + ",抽成:" + chouc);
-//
-//            } else {
-//                System.out.println("订单:" + posOrder.getDdId() + "分成失败");
-//            }
-        }
-    }
-
-    /**
-     * 获取商家分成比例
-     * 委托给 Service 层处理
-     *
-     * @param rate     默认分成比例
-     * @param shUserId 商家用户ID
-     * @return 分成比例
-     */
-    public Double getShCommissionRate(Double rate, Long shUserId) {
-        return rate;
-        // 委托给 Service 层处理
-//        return commissionRatesService.getShCommissionRate(rate, shUserId);
-    }
-
-    //执行骑手分成
-    public void setQishouBilling(@NotNull PosOrder posOrder) {
-        long count = userBillingService.count(new LambdaQueryWrapper<UserBilling>().eq(UserBilling::getUserId, posOrder.getQsId()).eq(UserBilling::getType, "0").eq(UserBilling::getDdId, posOrder.getDdId()));
-        if (count <= 0) {
-            UserBilling billing = new UserBilling();
-            DecimalFormat df = new DecimalFormat("#.00");
-            InfoUser user = infoUserService.getById(posOrder.getQsId());
-            if (user == null) {
-                System.out.println("订单无骑手");
-            } else {
-                Double fcbili = user.getCommission() == null ? 0.00 : user.getCommission();
-                Double fenc = posOrder.getFreight();
-                Double chouc = fenc * fcbili;
-                Double shfc = fenc - chouc;
-                List<SysDictData> taxBl = DictUtils.getDictCache("sys_qs_freight_bl");
-                if (taxBl != null && taxBl.get(0) != null) {
-                    Double tax = shfc * Double.parseDouble(taxBl.get(0).getDictValue());
-                    billing.setTax(BigDecimal.valueOf(tax));
-                    billing.setTaxRate(taxBl.get(0).getDictValue());
-                    shfc = shfc - tax;
-                }
-                billing.setUserId(posOrder.getQsId());
-                billing.setDdId(String.valueOf(posOrder.getDdId()));
-                billing.setType("0");
-                billing.setAmount(Double.valueOf(df.format(shfc)));
-                billing.setDivvy(Double.valueOf(df.format(chouc)));
-                billing.setState("0");
-                billing.setMdId(posOrder.getMdId());
-                billing.setUserType("2");
-                billing.setDivvyRate(user.getCommission());
-                //货到付款设置代收金额
-                if ("1".equals(posOrder.getCollectPayment())) {
-                    billing.setBehalfAmount(Double.valueOf(posOrder.getAmount()));
-                }
-                walletService.addBalance(billing.getUserId(), BigDecimal.valueOf(billing.getAmount()), billing);
-//                int reg = userBillingService.insertUserBilling(billing);
-//                if (reg == 1) {
-//                    System.out.println("骑手分成成功,订单号:" + posOrder.getDdId() + ",分成金额:" + shfc + ",抽成:" + chouc);
-//                } else {
-//                    System.out.println("订单:" + posOrder.getDdId() + "分成失败");
-//                }
-            }
-        }
-
-    }
-
 
     //后台查询详情
     @GetMapping("/getorderhout")

+ 1 - 2
ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderQsOprateController.java

@@ -125,7 +125,7 @@ public class PosOrderQsOprateController extends BaseController {
     }
 
     /**
-     * 骑手送达:设置 deliveryStatus=3,同时设置 state=3
+     * 骑手送达:设置 deliveryStatus=3
      */
     @Anonymous
     @Auth
@@ -143,7 +143,6 @@ public class PosOrderQsOprateController extends BaseController {
         posOrder.setId(order.getId());
         posOrder.setQsImg(input.getQsImg());
         posOrder.setDeliveryStatus(3L);
-        posOrder.setState(3L);
         posOrder.setSdTime(new Date());
 
         InfoUser qsUser = infoUserService.getOne(new LambdaQueryWrapper<InfoUser>().eq(InfoUser::getUserId, Long.valueOf(qsId)));

+ 5 - 0
ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderShOprateController.java

@@ -54,6 +54,8 @@ public class PosOrderShOprateController extends BaseController {
     private IOperatingHoursService operatingHoursService;
     @Autowired
     private IOrderParentService orderParentService;
+    @Autowired
+    private OrderService orderService;
 
     /**
      * 商家端下单
@@ -272,6 +274,9 @@ public class PosOrderShOprateController extends BaseController {
         InfoUser shUser = infoUserService.getOne(new LambdaQueryWrapper<InfoUser>().eq(InfoUser::getUserId, Long.valueOf(new JwtUtil().getusid(token))));
         String shName = shUser != null ? shUser.getNickName() : "";
         orderLogHelper.log(String.valueOf(order.getDdId()), 2, Long.valueOf(new JwtUtil().getusid(token)), shName, "商家" + shName + "已完成订单");
+        // 商家完成订单时生成商家账单
+        PosOrder fullOrder = posOrderService.getById(order.getId());
+        orderService.setSanghuBilling(fullOrder);
         return AjaxResult.success();
     }
 

+ 4 - 2
ruoyi-admin/src/main/java/com/ruoyi/app/order/TestTask.java

@@ -50,6 +50,8 @@ public class TestTask {
     private ZaloPay zaloPay;
     @Autowired
     private OrderLogHelper orderLogHelper;
+    @Autowired
+    private OrderService orderService;
 
 
     private static Logger logger = LoggerFactory.getLogger(TestTask.class);
@@ -145,8 +147,8 @@ public class TestTask {
             posOrderService.saveOrUpdate(pos);
             orderLogHelper.logSync(String.valueOf(ordlist.get(i).getDdId()), 0, null, "系统", "系统自动完成超时订单");
             PosOrder order = posOrderService.getById(ordlist.get(i).getId());
-            posorder.setSanghuBilling(order);
-            posorder.setQishouBilling(order);
+            orderService.setSanghuBilling(order);
+            orderService.setQishouBilling(order);
         }
     }
 

+ 40 - 0
ruoyi-admin/src/main/java/com/ruoyi/app/order/UserOrderController.java

@@ -453,6 +453,46 @@ public class UserOrderController extends BaseController {
         return success("确认取餐成功");
     }
 
+    /**
+     * 用户确认完成外送订单(骑手已送达后,state=2 → state=3)
+     */
+    @GetMapping("/confirmDelivery")
+    @Auth
+    @Anonymous
+    public AjaxResult confirmDelivery(@RequestHeader String token, @RequestParam Long id) {
+        JwtUtil jwtUtil = new JwtUtil();
+        String userId = jwtUtil.getusid(token);
+
+        PosOrder order = posOrderService.getOne(
+            new LambdaQueryWrapper<PosOrder>()
+                .eq(PosOrder::getId, id)
+                .eq(PosOrder::getUserId, Long.valueOf(userId))
+        );
+        if (order == null) {
+            return error("订单不存在");
+        }
+        if (order.getState() == null || order.getState() != 2L) {
+            return error("当前订单状态不可确认完成");
+        }
+        if (order.getDeliveryStatus() == null || order.getDeliveryStatus() != 3L) {
+            return error("骑手尚未送达,不可确认完成");
+        }
+        if (order.getAfterSaleStatus() != null && order.getAfterSaleStatus() > 0) {
+            return error("订单存在售后处理中,不可确认完成");
+        }
+        PosOrder update = new PosOrder();
+        update.setId(order.getId());
+        update.setState(3L);
+        posOrderService.updateById(update);
+
+        // 用户确认完成,添加操作日志
+        InfoUser uUser = infoUserService.getOne(new LambdaQueryWrapper<InfoUser>().eq(InfoUser::getUserId, Long.valueOf(userId)));
+        String uName = uUser != null ? uUser.getNickName() : "";
+        orderLogHelper.log(String.valueOf(order.getDdId()), 4, Long.valueOf(userId), uName, "用户" + uName + "确认完成订单");
+
+        return success("确认完成成功");
+    }
+
     /**
      * 取消订单(未接单前,state=0 → state=4)
      */