Browse Source

私账订单利润转第三方

zhijiezhao 1 year ago
parent
commit
5fda3bb410

+ 6 - 0
src/main/java/com/caimei365/order/mapper/SubmitMapper.java

@@ -207,4 +207,10 @@ public interface SubmitMapper {
     void updateShopOrderCoupon(OrderShopPo s);
 
     AddressVo getAddressById(@Param("provinceId") Integer provinceId, @Param("cityId") Integer cityId, @Param("townId") Integer townId);
+
+    Integer findAccountType(Integer shopId);
+
+    Double findCmProfit(Integer shopOrderId);
+
+    void updateShopOrderOtherFee(Double profit, Integer shopOrderId);
 }

+ 25 - 9
src/main/java/com/caimei365/order/service/impl/SubmitServiceImpl.java

@@ -1359,7 +1359,7 @@ public class SubmitServiceImpl implements SubmitService {
             return ResponseJson.error("用户Id为空!", null);
         }
         CmReportingClub cmReportingClubById = cmReportingClubMapper.getCmReportingClubById(orderParamBo.getClubReportingId());
-        if (orderParamBo.getUserIdentity() == 8&&null!=cmReportingClubById.orderStatus()) {
+        if (orderParamBo.getUserIdentity() == 8 && null != cmReportingClubById.orderStatus()) {
             // 设置手动回滚事务
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             return ResponseJson.error("抱歉,该报备中已有人下单,暂无法下单!", null);
@@ -1376,9 +1376,9 @@ public class SubmitServiceImpl implements SubmitService {
         //分销人员下单修改报备记录
         if (orderParamBo.getUserIdentity() == 8) {
             cmReportingClubMapper.updateCmReportingClub(new CmReportingClub()
-                    .id(orderParamBo.getClubReportingId())
-                    .orderId(mainOrder.getOrderId())
-                    .orderStatus(0)
+                            .id(orderParamBo.getClubReportingId())
+                            .orderId(mainOrder.getOrderId())
+                            .orderStatus(0)
 //                    .splitCode(cmReportingClubMapper.getDistributionSplitCode(cmReportingClubById.distributionId()))
             );
         }
@@ -1646,6 +1646,14 @@ public class SubmitServiceImpl implements SubmitService {
                 productService.savePurchasePrice(mainOrder, orderProduct, secondHandOrderFlag, "【提交订单】");
             }
         }
+        shopOrderList.forEach(f -> {
+            Integer accountType = submitMapper.findAccountType(f.getShopId());
+            if (1 == accountType) {
+                // 所有私账订单子订单利润算为付第三方采美中介费
+                Double profit = submitMapper.findCmProfit(f.getShopOrderId());
+                submitMapper.updateShopOrderOtherFee(profit, f.getShopOrderId());
+            }
+        });
 
         /**
          * 更新主订单的子订单Id信息,如:1000,1002
@@ -2275,7 +2283,7 @@ public class SubmitServiceImpl implements SubmitService {
             // 该商品成本计算
             if (null != SkuInfo) {
                 // 商品为固定成本
-                if ( StringUtils.isNotBlank(SkuInfo.getCostCheckFlag()) && "1".equals(SkuInfo.getCostCheckFlag())) {
+                if (StringUtils.isNotBlank(SkuInfo.getCostCheckFlag()) && "1".equals(SkuInfo.getCostCheckFlag())) {
                     // 系统商城商品的成本之和
                     double sysProductPrice = MathUtil.add(SkuInfo.getCostPrice(), MathUtil.add(SkuInfo.getCmCostPrice(), SkuInfo.getOrganizeCostPrice())).doubleValue();
                     // 系统商品成本之和小于修改的价格,修改价格异常,不允许下单
@@ -2481,7 +2489,7 @@ public class SubmitServiceImpl implements SubmitService {
         }
         // 存在不修改商品价格异常商品,不可修改为该价格
         if (isOrder.get()) {
-            return ResponseJson.error(-1 , "订单商品价格修改异常", abnormalProductList);
+            return ResponseJson.error(-1, "订单商品价格修改异常", abnormalProductList);
         }
 
         // 佣金 采美应收
@@ -2601,7 +2609,7 @@ public class SubmitServiceImpl implements SubmitService {
             return ResponseJson.error("发票类型不能为空!", null);
         }
         orderParamBo.setInvoiceType(invoiceType);
-            // 联合丽格*/
+        // 联合丽格*/
         if (1 == invoiceType || 2 == invoiceType) {
             InvoicePo invoice = new InvoicePo();
             String invoiceTitle = (String) orderInvoice.get("invoiceTitle");
@@ -2661,7 +2669,7 @@ public class SubmitServiceImpl implements SubmitService {
 
         /**
          * todo 协销下单, 联合丽格供应商帮机构下的那没有协销信息 协销取固定官方协销
-        */
+         */
         Integer spUserId = submitMapper.getServiceProviderUserId(1342);
         if (null != spUserId && spUserId > 0) {
             buyUserId = spUserId;
@@ -3412,6 +3420,14 @@ public class SubmitServiceImpl implements SubmitService {
             }
         }
 
+        shopOrderList.forEach(f -> {
+            Integer accountType = submitMapper.findAccountType(f.getShopId());
+            if (1 == accountType) {
+                // 所有私账订单子订单利润算为付第三方采美中介费
+                Double profit = submitMapper.findCmProfit(f.getShopOrderId());
+                submitMapper.updateShopOrderOtherFee(profit, f.getShopOrderId());
+            }
+        });
         /**
          * 更新主订单的子订单Id信息,如:1000,1002
          */
@@ -3470,7 +3486,7 @@ public class SubmitServiceImpl implements SubmitService {
             // 保存 订单收货用户信息
             submitMapper.insertOrderUserInfo(userInfo);
             log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存订单用户地址(insert[bp_order_userinfo])orderId:" + mainOrder.getOrderId());
-        } catch ( Exception e) {
+        } catch (Exception e) {
             e.printStackTrace();
             //设置手动回滚事务
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

+ 2 - 1
src/main/resources/mapper/ReceiptMapper.xml

@@ -162,7 +162,8 @@
     </update>
     <update id="updateReceiptStatus">
         update cm_shop_order
-        set receiptStatus = 3
+        set receiptStatus = 3,
+            payStatus = 3
         where shopOrderID = #{shopOrderId}
     </update>
     <select id="getReceiptUserByOpenid" resultType="com.caimei365.order.model.vo.ReceiptUserVo">

+ 41 - 18
src/main/resources/mapper/SubmitMapper.xml

@@ -195,7 +195,7 @@
                         cds.price,
                         cs.unit,
                         cs.stock,
-                        ifnull(cds.costCheckFlag, 1)   as costCheckFlag,
+                        ifnull(cds.costCheckFlag, 1)     as costCheckFlag,
                         IFNULL(cds.organizeCostPrice, 0) AS organizeCostPrice,
                         IFNULL(cds.cmCostPrice, 0)       AS cmCostPrice,
                         ifnull(cds.organizePercent, 0)   as organizePercent,
@@ -277,24 +277,24 @@
           and cs.organizeId = 0
     </select>
     <select id="getDistributionProductDetails" resultType="com.caimei365.order.model.po.OrderProductPo">
-        SELECT cs.skuId                                                                   AS skuId,
-               p.productID                                                                AS productId,
-               p.shopID                                                                   AS shopId,
-               p.`name`                                                                   AS `name`,
-               p.mainImage                                                                AS image,
+        SELECT cs.skuId          AS skuId,
+               p.productID       AS productId,
+               p.shopID          AS shopId,
+               p.`name`          AS `name`,
+               p.mainImage       AS image,
                cds.price,
                cds.costPrice,
                cds.costCheckFlag AS costCheckFlag,
-               cds.shopPercent                                                             as costProportional,
+               cds.shopPercent   as costProportional,
                p.productCategory,
                cs.ladderPriceFlag,
                cdp.includedTax,
                cdp.invoiceType,
-               cdp.clubTaxPoint                                                                 AS taxRate,
-               cs.unit                                                                    AS productUnit,
+               cdp.clubTaxPoint  AS taxRate,
+               cs.unit           AS productUnit,
                cs.normalPrice,
-               cdp.shopTaxPoint                                                         AS shopTaxRate,
-               p.splitCode                                                                as splitCode
+               cdp.shopTaxPoint  AS shopTaxRate,
+               p.splitCode       as splitCode
         FROM product p
                  LEFT JOIN cm_distribution_product cdp ON p.productID = cdp.productId
                  LEFT JOIN cm_sku cs on p.productID = cs.productId
@@ -580,17 +580,22 @@
             shouldPayShopAmount = #{shouldPayShopAmount}
         where shopOrderId = #{shopOrderId}
     </update>
+    <update id="updateShopOrderOtherFee">
+        update cm_shop_order
+        set cmShopOtherFee = #{profit}
+        where shopOrderId = #{shopOrderId}
+    </update>
 
     <select id="getAddressById" resultType="com.caimei365.order.model.vo.AddressVo">
         SELECT
-               t.name       AS town,
-               c.name       AS city,
-               c.cityID     AS cityId,
-               p.name       AS province,
-               p.provinceID AS provinceId
+        t.name AS town,
+        c.name AS city,
+        c.cityID AS cityId,
+        p.name AS province,
+        p.provinceID AS provinceId
         FROM town t
-                 LEFT JOIN city c ON c.cityID = t.cityID
-                 LEFT JOIN province p ON p.provinceID = c.provinceID
+        LEFT JOIN city c ON c.cityID = t.cityID
+        LEFT JOIN province p ON p.provinceID = c.provinceID
         <where>
             <if test="provinceId != null and townId == null">
                 and p.provinceID = #{provinceId}
@@ -604,4 +609,22 @@
         </where>
         LIMIT 1
     </select>
+    <select id="findAccountType" resultType="java.lang.Integer">
+        select ifnull(cmAccountType, 0)
+        from shop
+        where shopId = #{shopId}
+    </select>
+    <select id="findCmProfit" resultType="java.lang.Double">
+        SELECT cso.needpayAmount
+                   - SUM(IFNULL(op.costprice, 0) * (IFNULL(op.num, 0) + IFNULL(op.presentNum, 0)))
+                   - SUM(IFNULL(op.organizeCostPrice, 0) * (IFNULL(op.num, 0) + IFNULL(op.presentNum, 0)))
+                   - SUM(IFNULL(op.cmCostPrice, 0) * (IFNULL(op.num, 0) + IFNULL(op.presentNum, 0)))
+                   - (IFNULL(SUM(cso.shopPostFee +
+                                 IF(cso.differenceType = 1, cso.differencePrice, 0) -
+                                 IF(cso.differenceType = 2, cso.differencePrice, 0)),
+                             0))
+        FROM cm_order_product op
+                 LEFT JOIN cm_shop_order cso ON cso.shopOrderId = op.shopOrderId
+        WHERE op.shopOrderId = #{shopOrderId}
+    </select>
 </mapper>