浏览代码

Merge remote-tracking branch 'origin/master'

Ben 5 月之前
父节点
当前提交
5c558e6506

+ 6 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/ptprofitlog/PtProfitLogDO.java

@@ -79,4 +79,10 @@ public class PtProfitLogDO extends BaseDO {
     private Long ancestorQuotaAmount;
 
 
+    /**
+     * 产生积分的用户ID,例如:下订单的用户ID
+     */
+    private Long generateUserId;
+
+
 }

+ 5 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/mq/message/order/OrderItemMessage.java

@@ -43,6 +43,11 @@ public class OrderItemMessage {
      */
     private Long increaseIntegral;
 
+    /**
+     * 推荐用户获得积分
+     */
+    private Long ancestorIncreaseIntegral;
+
     /**
      * 订单项ID
      */

+ 12 - 7
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcServiceImpl.java

@@ -200,7 +200,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
             // 计算
             // 计算利润: (价格 - 成本价格) * 产品数量
-            final BigDecimal[] profit = {new BigDecimal("0"), new BigDecimal("0")};      //用户自得不用要计算,从orderItem里面获取
+            //用户自得和直推奖不用计算,从orderItem里面获取
+            final BigDecimal[] profit = {new BigDecimal("0"), new BigDecimal("0"), new BigDecimal("0")};
             k.getOrderItemMessages().forEach(j -> {
                 BigDecimal onePrice = new BigDecimal(j.getPrice());
                 BigDecimal oneCostPrice = new BigDecimal(j.getCostPrice());
@@ -208,6 +209,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                 BigDecimal oneGrossProfit = onePrice.subtract(oneCostPrice).multiply(productCount);
                 profit[0] = profit[0].add(oneGrossProfit);  // 注意这里的改动
                 profit[1] = profit[1].add(new BigDecimal(j.getIncreaseIntegral()));     //自得积分
+                profit[2] = profit[2].add(new BigDecimal(j.getAncestorIncreaseIntegral()));     //自得积分
 
                 updateOrderItem(j.getOrderItemId());
             });
@@ -227,7 +229,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             BigDecimal descendantQuota = profit[1];
 
             // 直推奖: 毛利 * 0.3 (上一级)
-            BigDecimal ancestorQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc())).setScale(4, RoundingMode.DOWN);
+            BigDecimal ancestorQuota = profit[2];
 
             // 合赢将: 毛利 * 0.08
             BigDecimal bonusQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitBonusQuotaPerc())).setScale(4, RoundingMode.DOWN);
@@ -241,7 +243,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
             // 乘以 10000 并转换为整数
             Long grossProfitInt = grossProfit.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
-            Long ancestorQuotaInt = ancestorQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
+            Long ancestorQuotaInt = ancestorQuota.longValue();
             Long descendantQuotaInt = descendantQuota.longValue();
             Long bonusQuotaInt = bonusQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
             Long highQuotaInt = highQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
@@ -252,9 +254,9 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             // 获取当前下单人关系
             SharePathDO sharePath = getSharePath(k.getUserId());
             // 如果sharePath为空, 则说明没有直推人关系
-            IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor());
-            IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());
-            IntegralDO ptIntegral = integralService.selectByUser(1L);
+            IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor());      //父级
+            IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());            //自己
+            IntegralDO ptIntegral = integralService.selectByUser(1L);                         //pt
 
 
             // ========== 身价计算 ==============
@@ -372,6 +374,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                     .userId(sharePath.getAncestor())
                     .amount(amount)
                     .afterAmount(integralDOAncestor.getCurrentQuota())
+                    .freezeAmount(amount)
+                    .afterFreezeAmount(integralDOAncestor.getFreezeQuota())
                     .ancestorQuotaAmount(ptReplenish)
                     .maxAvailablePointsAmount(-amount)
                     .afterMaxAvailablePointsAmount(ancestorHighQuota - amount)
@@ -386,7 +390,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                     .orderNo(k.getNo())
                     .userId(sharePath.getDescendant())
                     .amount(descendantQuotaInt)
-                    .afterAmount(integralDO.getCurrentQuota() + descendantQuotaInt)
+                    .afterAmount(integralDO.getCurrentQuota())
                     .freezeAmount(-descendantQuotaInt)
                     .afterFreezeAmount(integralDO.getFreezeQuota())
                     .maxAvailablePointsAmount(highQuotaInt)
@@ -514,6 +518,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
         // 减少推荐人的可获取额度
         integralDOAncestor.setHighQuota(integralDOAncestor.getHighQuota() - ancestorQuota);
         integralDOAncestor.setAncestorQuota(integralDOAncestor.getAncestorQuota() + ancestorQuota);
+        integralDOAncestor.setFreezeQuota(integralDOAncestor.getFreezeQuota() - ancestorQuota);
         integralService.updateIntegral(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
 
         // 增加平台额度

+ 5 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/dataobject/order/TradeOrderItemDO.java

@@ -158,6 +158,11 @@ public class TradeOrderItemDO extends BaseDO {
      */
     private Boolean distributeBenefit;
 
+    /**
+     * 推荐用户获得积分
+      */
+    private Long ancestorIncreaseIntegral;
+
     /**
      * 商品属性
      */

+ 20 - 18
feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/order/BrokerageUserMapper.xml

@@ -20,19 +20,21 @@
     </resultMap>
 
     <select id="queryAllOrder" resultMap="BaseResultMap">
-        select tor.total_price   as totalPrice,
-               ps.cost_price     as costPrice,
-               ps.price          as price,
+        select tor.total_price as totalPrice,
+               ps.cost_price as costPrice,
+               ps.price as price,
                tor.product_count as productCount,
-               tor.`no`          as `no`,
-               tor.id            as orderId,
-               tor.user_id       as userId,
-               ps.merchant_id    as merchantId,
-               ps.shop_id        as shopId,
-               ps.shop_id        as shopId,
-               mu.`name`         as name,
-               mu.nickname       as nickname,
-               toi.count  as `count`
+               tor.`no` as `no`,
+               tor.id as orderId,
+               tor.user_id as userId,
+               ps.merchant_id as merchantId,
+               ps.shop_id as shopId,
+               mu.`name` as name,
+               mu.nickname as nickname,
+               toi.count as `count`,
+               toi.id as orderItemId,
+               toi.increase_integral AS increaseIntegral,
+               toi.ancestor_increase_integral AS ancestorIncreaseIntegral
         from trade_order tor
                  LEFT JOIN member_user mu
                            ON tor.user_id = mu.id
@@ -40,11 +42,10 @@
                            on tor.id = toi.order_id
                  LEFT JOIN product_sku ps
                            on toi.sku_id = ps.id
-        where toi.after_sale_status &lt; 10
-           or toi.after_sale_status &gt; 50
-            and tor.update_time BETWEEN #{start} AND #{end}
-
-
+        where tor.pay_status = 1
+        and toi.distribute_benefit = 0
+        and (toi.after_sale_status = 0 or toi.after_sale_status = 61)
+        and tor.receiving_time &lt; DATE_SUB(NOW(), INTERVAL 7 DAY)
     </select>
     <select id="queryAllOrderByOrderIds"
             resultMap="BaseResultMap">
@@ -61,7 +62,8 @@
         mu.nickname as nickname,
         toi.count as `count`,
         toi.id as orderItemId,
-        toi.increase_integral AS increaseIntegral
+        toi.increase_integral AS increaseIntegral,
+        toi.ancestor_increase_integral AS ancestorIncreaseIntegral
         from trade_order tor
         LEFT JOIN member_user mu
         ON tor.user_id = mu.id