|
@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
7
|
7
|
import com.yunzhi.marketing.base.ResponseBean;
|
|
8
|
+import com.yunzhi.marketing.broker.entity.BkAccountRecord;
|
8
|
9
|
import com.yunzhi.marketing.broker.entity.BkAgentRule;
|
9
|
10
|
import com.yunzhi.marketing.broker.entity.BkInviteRecord;
|
|
11
|
+import com.yunzhi.marketing.broker.mapper.BkAccountRecordMapper;
|
10
|
12
|
import com.yunzhi.marketing.broker.mapper.BkAgentRuleMapper;
|
11
|
13
|
import com.yunzhi.marketing.broker.mapper.BkInviteRecordMapper;
|
12
|
14
|
import com.yunzhi.marketing.center.taUser.entity.TaUser;
|
|
@@ -76,6 +78,9 @@ public class ChannelCustomerServiceImpl extends ServiceImpl<ChannelCustomerMappe
|
76
|
78
|
@Autowired
|
77
|
79
|
private BkAgentRuleMapper bkAgentRuleMapper;
|
78
|
80
|
|
|
81
|
+ @Autowired
|
|
82
|
+ private BkAccountRecordMapper bkAccountRecordMapper;
|
|
83
|
+
|
79
|
84
|
/**
|
80
|
85
|
* 审核
|
81
|
86
|
*
|
|
@@ -552,16 +557,18 @@ public class ChannelCustomerServiceImpl extends ServiceImpl<ChannelCustomerMappe
|
552
|
557
|
customer.setRealtyConsultant(customerSignatory.getRealtyConsultant());
|
553
|
558
|
}
|
554
|
559
|
|
555
|
|
- channelCustomerMapper.updateById(customer);
|
556
|
|
-
|
557
|
560
|
// 全民经纪人佣金处理
|
558
|
561
|
boolean isBroker = CommConstant.PERSON_BROKER.equals(customer.getRecommendPersonType());
|
559
|
562
|
if (isBroker) {
|
560
|
563
|
// 处理推荐金额问题
|
561
|
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,6 +587,53 @@ public class ChannelCustomerServiceImpl extends ServiceImpl<ChannelCustomerMappe
|
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
|
639
|
* @param recommendPerson
|