张延森 2 年前
父节点
当前提交
01ff6b3ed9

+ 6
- 0
src/main/java/com/yunzhi/marketing/broker/mapper/BkAccountRecordMapper.java 查看文件

3
 import com.yunzhi.marketing.broker.entity.BkAccountRecord;
3
 import com.yunzhi.marketing.broker.entity.BkAccountRecord;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
6
 
7
 
7
 /**
8
 /**
8
  * <p>
9
  * <p>
15
 @Mapper
16
 @Mapper
16
 public interface BkAccountRecordMapper extends BaseMapper<BkAccountRecord> {
17
 public interface BkAccountRecordMapper extends BaseMapper<BkAccountRecord> {
17
 
18
 
19
+    Integer getTotalChargesBy(@Param("channelCustomerId") String channelCustomerId,
20
+                              @Param("chargeCode") String chargeCode);
21
+
22
+    BkAccountRecord getRecordBy(@Param("channelCustomerId") String channelCustomerId,
23
+                                @Param("chargeCode") String chargeCode);
18
 }
24
 }

+ 58
- 4
src/main/java/com/yunzhi/marketing/xlk/service/impl/ChannelCustomerServiceImpl.java 查看文件

5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
 import com.yunzhi.marketing.base.ResponseBean;
7
 import com.yunzhi.marketing.base.ResponseBean;
8
+import com.yunzhi.marketing.broker.entity.BkAccountRecord;
8
 import com.yunzhi.marketing.broker.entity.BkAgentRule;
9
 import com.yunzhi.marketing.broker.entity.BkAgentRule;
9
 import com.yunzhi.marketing.broker.entity.BkInviteRecord;
10
 import com.yunzhi.marketing.broker.entity.BkInviteRecord;
11
+import com.yunzhi.marketing.broker.mapper.BkAccountRecordMapper;
10
 import com.yunzhi.marketing.broker.mapper.BkAgentRuleMapper;
12
 import com.yunzhi.marketing.broker.mapper.BkAgentRuleMapper;
11
 import com.yunzhi.marketing.broker.mapper.BkInviteRecordMapper;
13
 import com.yunzhi.marketing.broker.mapper.BkInviteRecordMapper;
12
 import com.yunzhi.marketing.center.taUser.entity.TaUser;
14
 import com.yunzhi.marketing.center.taUser.entity.TaUser;
76
     @Autowired
78
     @Autowired
77
     private BkAgentRuleMapper bkAgentRuleMapper;
79
     private BkAgentRuleMapper bkAgentRuleMapper;
78
 
80
 
81
+    @Autowired
82
+    private BkAccountRecordMapper bkAccountRecordMapper;
83
+
79
     /**
84
     /**
80
      * 审核
85
      * 审核
81
      *
86
      *
552
                 customer.setRealtyConsultant(customerSignatory.getRealtyConsultant());
557
                 customer.setRealtyConsultant(customerSignatory.getRealtyConsultant());
553
             }
558
             }
554
 
559
 
555
-            channelCustomerMapper.updateById(customer);
556
-
557
             // 全民经纪人佣金处理
560
             // 全民经纪人佣金处理
558
             boolean isBroker = CommConstant.PERSON_BROKER.equals(customer.getRecommendPersonType());
561
             boolean isBroker = CommConstant.PERSON_BROKER.equals(customer.getRecommendPersonType());
559
             if (isBroker) {
562
             if (isBroker) {
560
                 // 处理推荐金额问题
563
                 // 处理推荐金额问题
561
                 processInviteRecord(recommendPerson, taBuilding);
564
                 processInviteRecord(recommendPerson, taBuilding);
562
-                //
563
-
565
+                // 记录佣金金额
566
+                if (null != params.getTotalCommission() && params.getTotalCommission() > 0) {
567
+                    processCommission(params, customer, recommendPerson, bizType, taBuilding);
568
+                }
564
             }
569
             }
570
+
571
+            channelCustomerMapper.updateById(customer);
565
         }
572
         }
566
 
573
 
567
         // 置业顾问-接待人
574
         // 置业顾问-接待人
580
         }
587
         }
581
     }
588
     }
582
 
589
 
590
+    private Integer intIfNvl(Integer i) {
591
+        return i == null ? 0 : i;
592
+    }
593
+
594
+    private void processCommission(MarkingSignatoryCustomerDTO params, ChannelCustomer customer, TaPerson recommendPerson, String bizType, TaBuilding taBuilding) {
595
+        if (null == recommendPerson) return;
596
+
597
+        // 为了防止数据有改动, 比如更新操作
598
+        // 那么需要把原来的值减掉,再使用新的值
599
+        Integer totalCommission = intIfNvl(recommendPerson.getTotalCommission()) -
600
+                intIfNvl(customer.getTotalCommission()) +
601
+                intIfNvl(params.getTotalCommission());
602
+        recommendPerson.setTotalCommission(totalCommission);
603
+        customer.setTotalCommission(intIfNvl(params.getTotalCommission()));
604
+
605
+        Integer settledCommission = intIfNvl(bkAccountRecordMapper.getTotalChargesBy(customer.getChannelCustomerId(), bizType));
606
+        settledCommission += intIfNvl(params.getSettledCommission()); // 最新的需要加上本次结算佣金
607
+        recommendPerson.setSettledCommission(intIfNvl(recommendPerson.getSettledCommission()) -
608
+                intIfNvl(customer.getSettledCommission()) +
609
+                settledCommission);
610
+        customer.setSettledCommission(settledCommission);
611
+        customer.setUnsettledCommission(customer.getTotalCommission() - customer.getSettledCommission());
612
+
613
+        // 更新记录, customer 在本函数外部更新
614
+        taPersonMapper.updateById(recommendPerson);
615
+
616
+        // 生成佣金记录
617
+        BkAccountRecord bkAccountRecord = bkAccountRecordMapper.getRecordBy(customer.getChannelCustomerId(), bizType);
618
+        if (bkAccountRecord != null) {
619
+            bkAccountRecord.setCharges(params.getSettledCommission());
620
+            bkAccountRecordMapper.updateById(bkAccountRecord);
621
+        } else {
622
+            bkAccountRecord = new BkAccountRecord();
623
+            bkAccountRecord.setChannelCustomerId(customer.getChannelCustomerId());
624
+            bkAccountRecord.setPersonId(recommendPerson.getPersonId());
625
+            bkAccountRecord.setBuildingId(taBuilding.getBuildingId());
626
+            bkAccountRecord.setBuildingName(StringUtils.ifNull(taBuilding.getName(), taBuilding.getBuildingName()));
627
+            bkAccountRecord.setCustomerName(customer.getName());
628
+            bkAccountRecord.setCharges(intIfNvl(params.getSettledCommission()));
629
+            bkAccountRecord.setChargeType(1);
630
+            bkAccountRecord.setChargeCode(bizType);
631
+            bkAccountRecord.setStatus(CommConstant.STATUS_NORMAL);
632
+            bkAccountRecord.setCreateDate(LocalDateTime.now());
633
+            bkAccountRecordMapper.insert(bkAccountRecord);
634
+        }
635
+    }
636
+
583
     /**
637
     /**
584
      * 处理推荐金
638
      * 处理推荐金
585
      * @param recommendPerson
639
      * @param recommendPerson

+ 22
- 0
src/main/resources/mapper/BkAccountRecordMapper.xml 查看文件

2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
 <mapper namespace="com.yunzhi.marketing.broker.mapper.BkAccountRecordMapper">
3
 <mapper namespace="com.yunzhi.marketing.broker.mapper.BkAccountRecordMapper">
4
 
4
 
5
+    <select id="getTotalChargesBy" resultType="java.lang.Integer">
6
+        SELECT
7
+            SUM( t.charges )
8
+        FROM
9
+            bk_account_record t
10
+        WHERE
11
+            t.channel_customer_id = #{channelCustomerId}
12
+          <if test="chargeCode != null and chargeCode != ''">
13
+              AND t.charge_code != #{chargeCode}
14
+          </if>
15
+          AND t.`status` &gt; -1
16
+    </select>
17
+    <select id="getRecordBy" resultType="com.yunzhi.marketing.broker.entity.BkAccountRecord">
18
+        SELECT
19
+            *
20
+        FROM
21
+            bk_account_record t
22
+        WHERE
23
+            t.channel_customer_id = #{channelCustomerId}
24
+            AND t.charge_code != #{chargeCode}
25
+            AND t.`status` &gt; -1
26
+    </select>
5
 </mapper>
27
 </mapper>