zhaoyun 1 week geleden
bovenliggende
commit
e403c3cf54

+ 1 - 1
ydd_mer_java/crmeb-front/src/main/java/com/zbkj/front/controller/PayCallbackController.java

@@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletRequest;
  */
 @Slf4j
 @RestController
-@RequestMapping("api/publicly/payment/callback")
+@RequestMapping("api/front/payment/callback")
 @Api(tags = "支付回调控制器")
 @CustomResponseAnnotation
 public class PayCallbackController {

+ 26 - 11
ydd_mer_java/crmeb-front/src/main/java/com/zbkj/front/service/impl/FrontOrderServiceImpl.java

@@ -249,7 +249,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
 
             preOrderInfoVo.setSvipDiscountPrice(preOrderInfoVo.getProTotalFee().subtract(svipTotalPrice));
         }
-        preOrderInfoVo.setPayFee(preOrderInfoVo.getProTotalFee().add(preOrderInfoVo.getFreightFee()).add(preOrderInfoVo.getPickingFee()).subtract(preOrderInfoVo.getSvipDiscountPrice()));
+        preOrderInfoVo.setPayFee(preOrderInfoVo.getProTotalFee().add(preOrderInfoVo.getFreightFee()).add(preOrderInfoVo.getPickingFee()).subtract(preOrderInfoVo.getSvipDiscountPrice()).subtract(preOrderInfoVo.getFirstDeduc()));
         preOrderInfoVo.setUserIntegral(user.getIntegral());
         preOrderInfoVo.setUserBalance(user.getNowMoney());
         preOrderInfoVo.setIntegralDeductionSwitch(false);
@@ -266,7 +266,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
             preOrderSetCouponPrice(preOrderInfoVo, orderInfoList, user);
         }
         BigDecimal proPayFee = preOrderInfoVo.getProTotalFee().subtract(preOrderInfoVo.getCouponFee()).subtract(preOrderInfoVo.getSvipDiscountPrice());
-        preOrderInfoVo.setPayFee(proPayFee.add(preOrderInfoVo.getFreightFee()).add(preOrderInfoVo.getPickingFee()));
+        preOrderInfoVo.setPayFee(proPayFee.add(preOrderInfoVo.getFreightFee()).add(preOrderInfoVo.getPickingFee()).subtract(preOrderInfoVo.getFirstDeduc()));
         String integralDeductionSwitch = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_KEY_INTEGRAL_DEDUCTION_SWITCH);
         String integralDeductionStartMoney = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_KEY_INTEGRAL_DEDUCTION_START_MONEY);
         if ("true".equals(integralDeductionSwitch) && proPayFee.compareTo(new BigDecimal(integralDeductionStartMoney)) >= 0) {
@@ -1235,11 +1235,12 @@ public class FrontOrderServiceImpl implements FrontOrderService {
         order.setTotalPostage(orderInfoVo.getFreightFee());
         order.setPackingFee(orderInfoVo.getPickingFee());
         order.setSvipDiscountPrice(orderInfoVo.getSvipDiscountPrice());
+        order.setFirstDeducPrice(orderInfoVo.getFirstDeduc());
         order.setTotalPrice(order.getProTotalPrice().add(order.getTotalPostage()).add(order.getPackingFee()));
         order.setCouponPrice(orderInfoVo.getCouponFee());
         order.setUseIntegral(merchantOrderVoList.stream().mapToInt(PreMerchantOrderVo::getUseIntegral).sum());
         order.setIntegralPrice(merchantOrderVoList.stream().map(PreMerchantOrderVo::getIntegralPrice).reduce(BigDecimal.ZERO, BigDecimal::add));
-        order.setPayPrice(order.getTotalPrice().subtract(order.getSvipDiscountPrice()).subtract(order.getCouponPrice()).subtract(order.getIntegralPrice()));
+        order.setPayPrice(order.getTotalPrice().subtract(order.getSvipDiscountPrice()).subtract(order.getCouponPrice()).subtract(order.getIntegralPrice()).subtract(orderInfoVo.getFirstDeduc()));
         order.setPayPostage(order.getTotalPostage());
         order.setPaid(false);
         order.setCancelStatus(OrderConstants.ORDER_CANCEL_STATUS_NORMAL);
@@ -1297,6 +1298,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
             merchantOrder.setTotalNum(merchantOrderVo.getProTotalNum());
             merchantOrder.setProTotalPrice(merchantOrderVo.getProTotalFee());
             merchantOrder.setTotalPostage(merchantOrderVo.getFreightFee());
+            merchantOrder.setFirstDeducPrice(merchantOrderVo.getFirstDeduc());
             merchantOrder.setTotalPrice(merchantOrder.getProTotalPrice().add(merchantOrder.getTotalPostage()).add(merchantOrder.getTotalPackingFee()));
             merchantOrder.setPayPostage(merchantOrder.getTotalPostage());
             merchantOrder.setPayPackingFee(merchantOrder.getTotalPackingFee());
@@ -1313,7 +1315,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
             BigDecimal platCouponPrice = detailVoList.stream().map(PreOrderInfoDetailVo::getPlatCouponPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
             merchantOrder.setPlatCouponPrice(platCouponPrice);
             merchantOrder.setCouponPrice(merchantOrder.getMerCouponPrice().add(merchantOrder.getPlatCouponPrice()));
-            merchantOrder.setPayPrice(merchantOrder.getTotalPrice().subtract(merchantOrder.getSvipDiscountPrice()).subtract(merchantOrder.getCouponPrice()).subtract(merchantOrder.getIntegralPrice()));
+            merchantOrder.setPayPrice(merchantOrder.getTotalPrice().subtract(merchantOrder.getSvipDiscountPrice()).subtract(merchantOrder.getCouponPrice()).subtract(merchantOrder.getIntegralPrice()).subtract(merchantOrderVo.getFirstDeduc()));
             merchantOrder.setGainIntegral(0);
             merchantOrder.setType(order.getType());
             merchantOrder.setSecondType(order.getSecondType());
@@ -2563,6 +2565,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
     public void getFreightFee_V_1_8(PreOrderInfoVo orderInfoVo, UserAddress userAddress, Boolean userIsPaidMember) {
         BigDecimal freightFee = BigDecimal.ZERO;
 
+
         List<PreMerchantOrderVo> merchantOrderVoList = orderInfoVo.getMerchantOrderVoList();
         for (PreMerchantOrderVo merchantOrderVo : merchantOrderVoList) {
             if (orderInfoVo.getSecondType().equals(OrderConstants.ORDER_SECOND_TYPE_CLOUD)
@@ -2574,7 +2577,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
                 continue;
             }
             BigDecimal storePostage = BigDecimal.ZERO;
-            if (merchantOrderVo.getShippingType().equals(OrderConstants.ORDER_SHIPPING_TYPE_PICK_UP)) {
+            if (merchantOrderVo.getShippingType().equals(OrderConstants.ORDER_SHIPPING_TYPE_PICK_UP)||merchantOrderVo.getIsFreeDeliveFee().equals(1)) {
                 merchantOrderVo.setFreightFee(storePostage);
                 merchantOrderVo.getOrderInfoList().forEach(info -> info.setFreightFee(BigDecimal.ZERO));
                 continue;
@@ -2846,6 +2849,12 @@ public class FrontOrderServiceImpl implements FrontOrderService {
                 merchantOrderVoList.add(preMerchantOrderVoP);
                 break;
         }
+        BigDecimal firstDeduc = merchantOrderVoList.stream()
+                .map(e -> {
+                    return ObjectUtil.isNull(e.getFirstDeduc())?BigDecimal.ZERO:e.getFirstDeduc();
+                })
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        preOrderInfoVo.setFirstDeduc(firstDeduc);
         preOrderInfoVo.setMerchantOrderVoList(merchantOrderVoList);
         return preOrderInfoVo;
     }
@@ -2923,12 +2932,14 @@ public class FrontOrderServiceImpl implements FrontOrderService {
             merchantOrderVo.setTakeTheirSwitch(merchant.getIsTakeTheir());
             merchantOrderVo.setIsSelf(merchant.getIsSelf());
         }
+        merchantOrderVo.setIsFreeDeliveFee(merchant.getIsFreeDeliveFee());
         merchantOrderVo.setType(OrderConstants.ORDER_TYPE_BASE);
         merchantOrderVo.setSecondType(product.getType());
         merchantOrderVo.setFreightFee(BigDecimal.ZERO);
         merchantOrderVo.setCouponFee(BigDecimal.ZERO);
         merchantOrderVo.setUserCouponId(0);
         merchantOrderVo.setDeliveryMethodMer(product.getDeliveryMethod());
+        merchantOrderVo.setFirstDeduc(getFirstReduc(merchant.getId(), userService.getInfo().getId()));
         PreOrderInfoDetailVo detailVo = new PreOrderInfoDetailVo();
         detailVo.setProductId(product.getId());
         detailVo.setProductName(product.getName());
@@ -3430,7 +3441,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
             merOrderResponse.setSvipDiscountPrice(vo.getSvipDiscountPrice());
             // 查询适用的用户优惠券
             List<Integer> merProIdList = vo.getOrderInfoList().stream().map(PreOrderInfoDetailVo::getProductId).distinct().collect(Collectors.toList());
-            BigDecimal merPrice = vo.getProTotalFee().subtract(vo.getSvipDiscountPrice());
+            BigDecimal merPrice = vo.getProTotalFee().subtract(vo.getSvipDiscountPrice()).subtract(vo.getFirstDeduc());
             BigDecimal merRemainingAmount = merPrice.subtract(orderInfoVo.getPlatCouponFee());
             List<CouponUser> merCouponUserList = couponUserService.findManyByUidAndMerIdAndMoneyAndProList(userId, vo.getMerId(), merProIdList, merPrice);
             for (int i = 0; i < merCouponUserList.size(); ) {
@@ -4084,7 +4095,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
                 continue;
             }
         }
-        orderInfoVo.setPickingFee(payPackingFee);
+        orderInfoVo.setPickingFee(payPackingFee.setScale(2,BigDecimal.ROUND_HALF_UP));
     }
 
     /**
@@ -4094,10 +4105,14 @@ public class FrontOrderServiceImpl implements FrontOrderService {
         String platDeliveryFee=systemConfigService.getValueByKey(SysConfigConstants.CONFIG_RIDER_DELIVERY_FEE);
         return StrUtil.isEmpty(platDeliveryFee)?BigDecimal.ZERO:new BigDecimal(platDeliveryFee);
     }
-    /**
-     * 获取优惠金额
-     */
-    private void getCouponFee(PreOrderInfoVo orderInfoVo){
 
+    private BigDecimal getFirstReduc(Integer merId,Integer uid){
+        Integer buycount=orderService.countBuy(merId,uid);
+        BigDecimal firstReduc=BigDecimal.ZERO;
+        if(buycount==0){
+            Merchant merchant=merchantService.getById(merId);
+            firstReduc= ObjectUtil.isNull(merchant.getFirstReduc())?BigDecimal.ZERO:merchant.getFirstReduc();
+        }
+        return firstReduc;
     }
 }

+ 29 - 44
ydd_mer_java/crmeb-service/src/main/java/com/zbkj/service/service/impl/MerchantServiceImpl.java

@@ -1023,7 +1023,7 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantDao, Merchant> impl
             asyncService.merchantDetailStatistics(merchant.getId(), userId);
         }
         //配送费
-        response.setRiderDeliveryFee(merchantPreferenMeasureService.calcDeliveryFee(merchant.getId()));
+        response.setRiderDeliveryFee(ObjectUtil.isNotNull(merchant.getIsFreeDeliveFee())&&merchant.getIsFreeDeliveFee()>0?BigDecimal.ZERO:merchantPreferenMeasureService.calcDeliveryFee(merchant.getId()));
         response.setMerDeliveryFee(merchantInfo.getDeliveryFee());
         return response;
     }
@@ -1186,31 +1186,18 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantDao, Merchant> impl
             params.put("productType",request.getCateId());
         }
         if (StrUtil.isNotBlank(request.getQueryLabels())) {
-            List<Integer> conditionList=CollUtil.newArrayList();
+            //List<Integer> conditionList=CollUtil.newArrayList();
             List<Integer> condition = CrmebUtil.stringToArray(request.getQueryLabels());
-             condition.stream().forEach(con->{
-                if(!(con.equals(0)||con==0)){
-                    conditionList.add(con);
-                }else{
-                    params.put("orderBySales",1);
-                }
-            });
-            params.put("condition",conditionList);
+            params.put("bySales", condition.contains(0));//按销量排行
+            params.put("byMeasure", condition.contains(1));//按销优惠措施
+            params.put("byFreeDeliverCost", condition.contains(2));//免配送费
+            params.put("byFirstSub", condition.contains(3));//首单立减
         }
         params.put("frontLimit",recomdProdsNum);
         List<MerchantVo> merchantList = dao.selectMerchantList(params);
-       // List<MerchantVo>  merchantList= dao.selectMerchantList(siteSearchRequest.getLatitude(),siteSearchRequest.getLongitude(),siteSearchRequest.getCateId(),null,recomdProdsNum);
-        //redisUtil.addSet(StrUtil.format(RedisConstants.FRONT_USER_TOKEN_SET_KEY, user.getId()), userTokenKey);
-        //redisUtil.set(userTokenKey, loginFrontUserVo, Constants.TOKEN_EXPRESS_MINUTES, TimeUnit.MINUTES);
         return merchantList.stream().map(mer -> {
             IndexMerchantResponse response = new IndexMerchantResponse();
             BeanUtils.copyProperties(mer, response);
-            // 根据商户再获取1条商户对应的1条推荐商品 适用于DIY样式
-            //response.setProList(productService.getRecommendedProductsByMerId(mer.getId(), 1));
-            // 店铺关注人数
-            //response.setFollowerNum(userMerchantCollectService.getCountByMerId(mer.getId()));
-            //if(indexMerchantSearch.getLatitude()!=null && indexMerchantSearch.getLongitude()!=null) {
-               // Double distance = GeoUtils.haversineDistance(indexMerchantSearch.getLatitude(), indexMerchantSearch.getLongitude(), Double.parseDouble(mer.getLatitude()), Double.parseDouble(mer.getLongitude()));
                 response.setDistance(mer.getDistance() + "km");//距离
                 if(ObjectUtil.isNotNull(mer.getDistance()))
                     response.setDeliverTime(DistanceCalculator.distanceToTimeInMinutes(mer.getDistance(), DistanceCalculator.AVERAGE_SPEED));//时间
@@ -1233,14 +1220,15 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantDao, Merchant> impl
             response.setSalesVolume(orderService.selectSaleNumByMerId(mer.getId()));//销售量
             response.setSalesAllNum(orderService.countBuy(mer.getId(),null));//总销量
             List<String> discountLabel =new ArrayList<>();
-            List<MerchantPreferenMeasure> measureList=merchantPreferenMeasureService.selectPreferenMeasureByMerId(mer.getId());
-            measureList.stream().forEach(measure->{
-//                if("减配送费".equals(measure.getMeasureName().trim())&&measure.getIsSetting()){
-//                    response.setIsFreeDeliverFee(true);
-//                    response.setFreeDeliverFee(measure.getMeasureValue());
-//                }
-                discountLabel.add(measure.getMeasureName());
-            });
+            if(ObjectUtil.isNotNull(mer.getHasMeasure())&&mer.getHasMeasure()>0){
+                discountLabel.add("满减大促");
+            }
+            if(ObjectUtil.isNotNull(mer.getIsFreeDeliveFee())&&mer.getIsFreeDeliveFee()>0){
+                discountLabel.add("减配送费");
+            }
+            if(ObjectUtil.isNotNull(mer.getFirstReduc())&&mer.getFirstReduc().compareTo(BigDecimal.ZERO)>0){
+                discountLabel.add("首单立减");
+            }
             if(!response.getIsFreeDeliverFee()){
                 String deliveryFee= systemConfigService.getValueByKey(SysConfigConstants.CONFIG_RIDER_DELIVERY_FEE);
                 response.setDistCosts(StrUtil.isNotBlank(deliveryFee)?new BigDecimal(deliveryFee):null);
@@ -1501,16 +1489,12 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantDao, Merchant> impl
             params.put("productType",request.getProductType());
         }
         if (StrUtil.isNotBlank(request.getQueryLabels())) {
-            List<Integer> conditionList=CollUtil.newArrayList();
+            //List<Integer> conditionList=CollUtil.newArrayList();
             List<Integer> condition = CrmebUtil.stringToArray(request.getQueryLabels());
-            condition.stream().forEach(con->{
-                if(!(con.equals(0)||con==0)){
-                    conditionList.add(con);
-                }else{
-                    params.put("orderBySales",1);
-                }
-            });
-            params.put("condition",conditionList);
+            params.put("bySales", condition.contains(0));//按销量排行
+            params.put("byMeasure", condition.contains(1));//按销优惠措施
+            params.put("byFreeDeliverCost", condition.contains(2));//免配送费
+            params.put("byFirstSub", condition.contains(3));//首单立减
         }
         List<MerchantVo> merchantList = dao.selectMerchantList(params);
         if (CollUtil.isEmpty(merchantList)) {
@@ -1540,14 +1524,15 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantDao, Merchant> impl
             response.setSalesAllNum(orderService.countBuy(mer.getId(),null));//总销量
             List<String> discountLabel =new ArrayList<>();//优惠标签
 //
-            List<MerchantPreferenMeasure> measureList=merchantPreferenMeasureService.selectPreferenMeasureByMerId(mer.getId());
-            measureList.stream().forEach(measure->{
-//                if("减配送费".equals(measure.getMeasureName().trim())&&measure.getIsSetting()){
-//                    response.setIsFreeDeliverFee(true);
-//                    response.setFreeDeliverFee(measure.getMeasureValue());
-//                }
-                discountLabel.add(measure.getMeasureName());
-            });
+            if(ObjectUtil.isNotNull(mer.getHasMeasure())&&mer.getHasMeasure()>0){
+                discountLabel.add("满减大促");
+            }
+            if(ObjectUtil.isNotNull(mer.getIsFreeDeliveFee())&&mer.getIsFreeDeliveFee()>0){
+                discountLabel.add("减配送费");
+            }
+            if(ObjectUtil.isNotNull(mer.getFirstReduc())&&mer.getFirstReduc().compareTo(BigDecimal.ZERO)>0){
+                discountLabel.add("首单立减");
+            }
             if(!response.getIsFreeDeliverFee()){
                 String deliveryFee= systemConfigService.getValueByKey(SysConfigConstants.CONFIG_RIDER_DELIVERY_FEE);
                 response.setDistCosts(StrUtil.isNotBlank(deliveryFee)?new BigDecimal(deliveryFee):null);

+ 41 - 21
ydd_mer_java/crmeb-service/src/main/java/com/zbkj/service/service/impl/PayServiceImpl.java

@@ -379,7 +379,7 @@ public class PayServiceImpl implements PayService {
         }
         asyncService.orderPaySuccessSplit(order.getOrderNo());
         // 添加支付成功task
-//        redisUtil.lPush(TaskConstants.ORDER_TASK_PAY_SUCCESS_AFTER, orderNo);
+        //redisUtil.lPush(TaskConstants.ORDER_TASK_PAY_SUCCESS_AFTER, orderNo);
         return Boolean.TRUE;
     }
 
@@ -527,6 +527,7 @@ public class PayServiceImpl implements PayService {
             logger.error("OrderTaskServiceImpl.orderPaySuccessAfter | 商户订单信息不存在,orderNo: {}", orderNo);
             throw new CrmebException("商户订单信息不存在,orderNo: " + orderNo);
         }
+
         List<UserIntegralRecord> integralList = CollUtil.newArrayList();
         List<UserBrokerageRecord> brokerageRecordList = CollUtil.newArrayList();
         List<OrderProfitSharing> profitSharingList = CollUtil.newArrayList();
@@ -557,10 +558,11 @@ public class PayServiceImpl implements PayService {
                 merchantOrderList.add(merchantOrder);
                 orderDetailList.addAll(merOrderDetailList);
             }
+            Merchant merchant = merchantService.getByIdException(merchantOrder.getMerId());
             // 商户帐单流水、分账
             if (!order.getSecondType().equals(OrderConstants.ORDER_SECOND_TYPE_INTEGRAL)) {// 积分订单不参与账单
-                OrderProfitSharing orderProfitSharing = initOrderProfitSharing(merchantOrder);
-                MerchantBill merchantBill = initPayMerchantBill(merchantOrder, orderProfitSharing.getProfitSharingMerPrice());
+                OrderProfitSharing orderProfitSharing = initOrderProfitSharing(merchantOrder,merchant);
+                MerchantBill merchantBill = initPayMerchantBill(merchantOrder,orderProfitSharing.getProfitSharingMerPrice());
                 List<Bill> platBillList = initPlatformBill(order, merchantOrder, orderProfitSharing);
                 profitSharingList.add(orderProfitSharing);
                 merchantBillList.add(merchantBill);
@@ -575,7 +577,8 @@ public class PayServiceImpl implements PayService {
             merchantBalanceRecord.setLinkNo(sharing.getOrderNo());
             merchantBalanceRecord.setLinkType("order");
             merchantBalanceRecord.setType(1);
-            merchantBalanceRecord.setAmount(sharing.getProfitSharingMerPrice().add(sharing.getFreightFee()));
+            //merchantBalanceRecord.setAmount(sharing.getProfitSharingMerPrice().add(sharing.getFreightFee()));
+            merchantBalanceRecord.setAmount(sharing.getProfitSharingMerPrice());
             merchantBalanceRecord.setTitle(StrUtil.format("订单支付,商户预计分账金额{}元", merchantBalanceRecord.getAmount()));
             merchantBalanceRecord.setBalance(BigDecimal.ZERO);
             merchantBalanceRecord.setStatus(1);
@@ -1047,29 +1050,39 @@ public class PayServiceImpl implements PayService {
      * @param merchantOrder 商户部分订单
      * @return 分账记录
      */
-    private OrderProfitSharing initOrderProfitSharing(MerchantOrder merchantOrder) {
-        // 获取商户信息
-        Merchant merchant = merchantService.getByIdException(merchantOrder.getMerId());
+    private OrderProfitSharing initOrderProfitSharing(MerchantOrder merchantOrder, Merchant merchant) {
         // 分账计算
-        // 商户收入 = 订单应付 - 商户优惠 -平台手续费 - 佣金
-        BigDecimal orderPrice = merchantOrder.getPayPrice().add(merchantOrder.getIntegralPrice()).add(merchantOrder.getPlatCouponPrice()).subtract(merchantOrder.getPayPostage()).subtract(merchantOrder.getPayPackingFee());
-        // 平台手续费
-        BigDecimal platFee = orderPrice.multiply(new BigDecimal(merchant.getHandlingFee())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_UP);
+        // 商户收入 = 订单应付 - 商户优惠 -平台(手续费+打包费) - 佣金-打包费-骑手配送费
+        BigDecimal orderPrice = merchantOrder.getPayPrice().add(merchantOrder.getIntegralPrice()).add(merchantOrder.getPlatCouponPrice());
+        // 平台手续费加打包费
+        BigDecimal platFee = orderPrice.multiply(new BigDecimal(merchant.getHandlingFee())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_UP).add(merchantOrder.getPayPackingFee());
         // 商户收入金额
         BigDecimal merchantFee = orderPrice.subtract(platFee).subtract(merchantOrder.getFirstBrokerage()).subtract(merchantOrder.getSecondBrokerage());
+        //免配送费,商家承担
+        BigDecimal freightFee=BigDecimal.ZERO;
+        if(merchant.getIsFreeDeliveFee()==1 &&  merchantOrder.getPayPostage().compareTo(BigDecimal.ZERO)==0){
+            String deliveryFee = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_RIDER_DELIVERY_FEE);
+            BigDecimal riderFee=new BigDecimal(StrUtil.isNotEmpty(deliveryFee)?deliveryFee:"0");
+            merchantFee=merchantFee.subtract(riderFee);
+            freightFee=riderFee;
+        }else{
+            merchantFee=merchantFee.subtract(merchantOrder.getPayPostage());
+            freightFee=merchantOrder.getPayPostage();
+        }
         OrderProfitSharing orderProfitSharing = new OrderProfitSharing();
         orderProfitSharing.setOrderNo(merchantOrder.getOrderNo());
         orderProfitSharing.setMerId(merchantOrder.getMerId());
         orderProfitSharing.setOrderPrice(merchantOrder.getPayPrice());
         orderProfitSharing.setIntegralNum(merchantOrder.getUseIntegral());
         orderProfitSharing.setIntegralPrice(merchantOrder.getIntegralPrice());
-        orderProfitSharing.setProfitSharingPlatPrice(platFee.add(merchantOrder.getPayPackingFee()));//手续费加打包费
+        orderProfitSharing.setProfitSharingPlatPrice(platFee);//手续费加打包费
         orderProfitSharing.setPackingFee(merchantOrder.getPayPackingFee());//打包费
-        orderProfitSharing.setProfitSharingMerPrice(merchantFee);
+        orderProfitSharing.setProfitSharingMerPrice(merchantFee.compareTo(BigDecimal.ZERO)<0?BigDecimal.ZERO:merchantFee);
         orderProfitSharing.setFirstBrokerageFee(merchantOrder.getFirstBrokerage());
         orderProfitSharing.setSecondBrokerageFee(merchantOrder.getSecondBrokerage());
         orderProfitSharing.setPlatCouponPrice(merchantOrder.getPlatCouponPrice());
-        orderProfitSharing.setFreightFee(merchantOrder.getPayPostage());
+        orderProfitSharing.setFreightFee(freightFee);//免配送费商家承担骑手配送费
+        //orderProfitSharing.setProfitSharingRiderPrice(freightFee);
         return orderProfitSharing;
     }
 
@@ -1080,16 +1093,17 @@ public class PayServiceImpl implements PayService {
      * @param merchantFee   商户分账金额
      */
     private MerchantBill initPayMerchantBill(MerchantOrder merchantOrder, BigDecimal merchantFee) {
+        String deliveryFee = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_RIDER_DELIVERY_FEE);
+        BigDecimal riderFee=new BigDecimal(StrUtil.isNotEmpty(deliveryFee)?deliveryFee:"0");
         MerchantBill merchantBill = new MerchantBill();
         merchantBill.setMerId(merchantOrder.getMerId());
         merchantBill.setType(BillConstants.BILL_TYPE_PAY_ORDER);
         merchantBill.setOrderNo(merchantOrder.getOrderNo());
         merchantBill.setUid(merchantOrder.getUid());
         merchantBill.setPm(BillConstants.BILL_PM_ADD);
-        //BigDecimal merFee = merchantOrder.getPayPostage().add(merchantFee);
-        BigDecimal merFee = merchantFee;
-        merchantBill.setAmount(merFee);
-        merchantBill.setMark(StrUtil.format("订单{}支付{}元,商户收入{}元", merchantOrder.getOrderNo(), merchantOrder.getPayPrice(), merFee));
+       // BigDecimal merFee = merchantFee;
+        merchantBill.setAmount(merchantFee);
+        merchantBill.setMark(StrUtil.format("订单{}支付{}元,商户收入{}元", merchantOrder.getOrderNo(), merchantOrder.getPayPrice(), merchantFee));
         return merchantBill;
     }
 
@@ -1122,14 +1136,20 @@ public class PayServiceImpl implements PayService {
         Bill collectBill = new Bill();
         collectBill.setMerId(merchantOrder.getMerId());
         collectBill.setOrderNo(order.getOrderNo());
-        collectBill.setAmount(orderProfitSharing.getProfitSharingMerPrice().add(merchantOrder.getPayPostage()));
+        collectBill.setAmount(orderProfitSharing.getProfitSharingMerPrice());
         collectBill.setPm(BillConstants.BILL_PM_SUB);
         collectBill.setType(BillConstants.BILL_TYPE_MERCHANT_COLLECT);
-//        collectBill.setMark(StrUtil.format("订单支付成功,商户分账{}元", orderProfitSharing.getProfitSharingMerPrice().add(merchantOrder.getPayPostage())));
         collectBill.setMark(StrUtil.format("订单支付成功,商户分账{}元", orderProfitSharing.getProfitSharingMerPrice()));
-
         billList.add(collectBill);
 
+        Bill riderBill = new Bill();
+        riderBill.setOrderNo(order.getOrderNo());
+        riderBill.setAmount(orderProfitSharing.getFreightFee());
+        riderBill.setPm(BillConstants.BILL_PM_SUB);
+        riderBill.setType(BillConstants.BILL_TYPE_RIDER_COLLECT);
+        riderBill.setMark(StrUtil.format("订单支付成功,骑手分账{}元", orderProfitSharing.getFreightFee()));
+        billList.add(riderBill);
+
         Bill platBill = new Bill();
         platBill.setOrderNo(order.getOrderNo());
         platBill.setAmount(orderProfitSharing.getProfitSharingPlatPrice());

+ 8 - 20
ydd_mer_java/crmeb-service/src/main/java/com/zbkj/service/service/impl/RiderOrderServiceImpl.java

@@ -12,10 +12,7 @@ import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.zbkj.common.config.CrmebConfig;
-import com.zbkj.common.constants.DateConstants;
-import com.zbkj.common.constants.OrderConstants;
-import com.zbkj.common.constants.OrderStatusConstants;
-import com.zbkj.common.constants.UserConstants;
+import com.zbkj.common.constants.*;
 import com.zbkj.common.exception.CrmebException;
 import com.zbkj.common.model.express.ExpressOrder;
 import com.zbkj.common.model.order.MerchantOrder;
@@ -83,6 +80,8 @@ public class RiderOrderServiceImpl extends ServiceImpl<RiderOrderDao, RiderOrder
 
     @Autowired
     private CrmebConfig crmebConfig;
+    @Autowired
+    private SystemConfigService systemConfigService;
 
     @Override
     public PageInfo<RiderOrderResponse> getAllPageList(RiderOrderSearchRequest request) {
@@ -144,22 +143,11 @@ public class RiderOrderServiceImpl extends ServiceImpl<RiderOrderDao, RiderOrder
         }
         map.put("status", request.getStatus());
         List<RiderOrderResponse> responseList = request.getStatus().equals("await")?dao.getH5AwaitPageList(map):dao.getH5PageList(map);
-//        RiderFeeConfig riderFeeConfig=riderService.getRiderFeeConfigDetail();//获取骑手配送费配置
-//        if(ObjectUtil.isNull(riderFeeConfig) || ObjectUtil.isNull(riderFeeConfig.getBasicFee())){
-//             throw new CrmebException("未配置骑手配送费,请联系平台处理");
-//        }
-//        responseList.forEach(response -> {
-//            BigDecimal deliveCharge=riderFeeConfig.getBasicFee();
-//            if(ObjectUtil.isNotNull(response.getDistance()) && response.getDistance().compareTo(riderFeeConfig.getDistanceInKm())>0){ //超过设置距离
-//                try {
-//                    Double distanceOut = response.getDistance() - riderFeeConfig.getDistanceInKm();
-//                    deliveCharge = deliveCharge.add(new BigDecimal(distanceOut).multiply(new BigDecimal(riderFeeConfig.getFeePerKm())));
-//                }catch(Exception e){
-//                    e.printStackTrace();
-//                }
-//            }
-//            response.setDeliveCharge( deliveCharge.setScale(2,BigDecimal.ROUND_HALF_UP));
-//        });
+        String deliveryFee = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_RIDER_DELIVERY_FEE);
+        BigDecimal riderFee=new BigDecimal(StrUtil.isNotEmpty(deliveryFee)?deliveryFee:"0");
+        responseList.forEach(response -> {
+            response.setDeliveCharge(response.getDeliveCharge().compareTo(BigDecimal.ZERO)==0?riderFee:response.getDeliveCharge());
+        });
         return CommonPage.copyPageInfo(page, responseList);
     }
 

+ 7 - 1
ydd_mer_java/crmeb-service/src/main/java/com/zbkj/service/service/impl/StatisticsTaskServiceImpl.java

@@ -32,7 +32,9 @@ import org.springframework.transaction.support.TransactionTemplate;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -954,12 +956,16 @@ public class StatisticsTaskServiceImpl implements StatisticsTaskService {
             return statement;
         }).collect(Collectors.toList());
         return transactionTemplate.execute(e -> {
+            Map<String,Object> params=new HashMap<String,Object>();
+            params.put("data_date",platformDailyStatement.getDataDate());
+            platformDailyStatementService.removeByMap(params);
             boolean save = platformDailyStatementService.save(platformDailyStatement);
             if (!save) {
                 e.setRollbackOnly();
                 return Boolean.FALSE;
             }
-            save = merchantDailyStatementService.saveBatch(merchantDailyStatementList, 100);
+            merchantDailyStatementService.removeByMap(params);
+            save = merchantDailyStatementService.saveBatch(merchantDailyStatementList,100);
             if (!save) {
                 e.setRollbackOnly();
                 return Boolean.FALSE;

+ 21 - 10
ydd_mer_java/crmeb-service/src/main/resources/mapper/merchant/MerchantMapper.xml

@@ -22,6 +22,7 @@
         <result column="is_recommend" property="isRecommend"></result>
         <result column="is_free_delive_fee" property="isFreeDeliveFee"></result>
         <result column="first_reduc" property="firstReduc"></result>
+        <result column="has_measure" property="hasMeasure"></result>
         <result column="is_switch" property="isSwitch"></result>
         <result column="product_switch" property="productSwitch"></result>
         <result column="is_take_their" property="isTakeTheir"></result>
@@ -49,7 +50,8 @@
         * cos(radians(longitude) - radians(#{longitude}))
         + sin(radians(#{latitude}))
         * sin(radians(latitude)))),2)AS distance,
-        (select sum(sales) from eb_product product where product.mer_id=m.id ) as sales
+        (select sum(sales) from eb_product product where product.mer_id=m.id ) as sales,
+        (select 1 from eb_coupon cc where cc.mer_id=m.id and cc.is_del=0 and cc.status = 1) as has_measure
         FROM eb_merchant m
         <where>
             is_switch=1 and is_del=0
@@ -98,22 +100,31 @@
                     #{categoryId}
                 </foreach>
             </if>
-            <if test="condition != null and condition.size()>0">
-                and exists(
-                select 1 from eb_merchant_prefern_measure p where p.measure_id in
-                <foreach collection="condition" item="conditionId" index="index" open="(" separator="," close=")">
-                    #{conditionId}
-                </foreach> and p.mer_id=m.id
-                )
+            <if test="byMeasure != null and byMeasure==true">
+                and exists(select 1 from eb_coupon cc where cc.mer_id=m.id and cc.is_del=0 and cc.status = 1)
+            </if>
+            <if test="byFreeDeliverCost != null and byFreeDeliverCost==true">
+                and m.is_free_delive_fee=1
+            </if>
+            <if test="byFirstSub != null and byFirstSub==true">
+                and m.first_reduc &gt;0
             </if>
+<!--            <if test="condition != null and condition.size()>0">-->
+<!--                and exists(-->
+<!--                select 1 from eb_merchant_prefern_measure p where p.measure_id in-->
+<!--                <foreach collection="condition" item="conditionId" index="index" open="(" separator="," close=")">-->
+<!--                    #{conditionId}-->
+<!--                </foreach> and p.mer_id=m.id-->
+<!--                )-->
+<!--            </if>-->
         </where>
         <if test="frontLimit!=null and frontLimit >0 ">
             LIMIT #{frontLimit}
         </if>
         ) a
         <choose>
-            <when test="orderBySales != null and orderBySales==1">
-                ORDER BY sales desc
+            <when test="bySales != null and bySales==true">
+                ORDER BY sales desc,distance asc
             </when>
             <otherwise>
                 ORDER BY distance asc, is_recommend DESC,sort desc,id desc