xiaoyong931011
2022-09-22 cf0f93a4c122121b205ab52bb5fc3b3b93682670
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.enumerates.AgentLevelEnum;
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
import cc.mrbird.febs.common.utils.AppContants;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.mall.service.IMallAchieveService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.service.IMemberProfitService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
 
/**
 * @author wzy
 * @date 2022-05-10
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class MemberProfitServiceImpl implements IMemberProfitService {
 
    private final MallMemberMapper mallMemberMapper;
    private final MallOrderInfoMapper mallOrderInfoMapper;
    private final MallOrderItemMapper mallOrderItemMapper;
    private final MallGoodsMapper mallGoodsMapper;
    private final IApiMallMemberWalletService walletService;
    private final IMallMoneyFlowService moneyFlowService;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    private final MallAchieveRecordMapper mallAchieveRecordMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void staticProfit(Date profitDate) {
        log.info("#####静态分红开始运行:{}#####", new Date());
        List<MallMember> members = mallMemberMapper.selectList(null);
        if (CollUtil.isEmpty(members)) {
            return;
        }
 
        if (profitDate == null) {
            profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        }
        // 套餐业绩
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
        // 普通商品业绩
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
 
        if (totalIncome.compareTo(BigDecimal.ZERO) == 0) {
            return;
        }
 
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.STATIC_BONUS.getType(), DataDictionaryEnum.STATIC_BONUS.getCode());
        BigDecimal perProfit = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
 
        Map<Long, List<Map<String, Object>>> map = new HashMap<>();
        Map<Long, BigDecimal> goodsProp = new HashMap<>();
        for (MallMember member : members) {
            List<MallGoods> goodsList = mallGoodsMapper.selectOrderGoodsList(member.getId(), profitDate);
 
            if (CollUtil.isEmpty(goodsList)) {
                continue;
            }
 
            for (MallGoods goods : goodsList) {
                if (goods.getIsNormal() == 1) {
                    continue;
                }
 
                List<Map<String, Object>> list = map.get(goods.getId());
                if (CollUtil.isEmpty(list)) {
                    list = new ArrayList<>();
                }
 
                Map<String, Object> listItem = new HashMap<>();
                listItem.put("memberId", member.getId());
                listItem.put("orderNo", goods.getOrderNo());
                list.add(listItem);
 
                map.put(goods.getId(), list);
                goodsProp.put(goods.getId(), goods.getStaticProp());
            }
        }
 
        if (!map.isEmpty()) {
            for (Map.Entry<Long, List<Map<String, Object>>> entry : map.entrySet()) {
                List<Map<String, Object>> list = entry.getValue();
                BigDecimal staticProfit = goodsProp.get(entry.getKey()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).multiply(perProfit);
                BigDecimal preStaticProfit = staticProfit.divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP);
 
                for (Map<String, Object> item : list) {
                    Long memberId = (Long) item.get("memberId");
                    String orderNo = (String) item.get("orderNo");
 
//                    int reduce = walletService.reduce(preStaticProfit, memberId, "score");
//                    if (reduce == 2) {
//                        break;
//                    }
//
//                    walletService.add(preStaticProfit, memberId, "commission");
//                    moneyFlowService.addMoneyFlow(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.COMMISSION.getValue());
//                    moneyFlowService.addMoneyFlow(memberId, preStaticProfit.negate(), MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.SCORE.getValue());
                    changeScoreAndCommission(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo);
                }
            }
        }
    }
 
    @Override
    public void dynamicProfit(Long orderId) {
        dynamicProfit(orderId, 2);
    }
 
    /**
     * 直推20%,隔代收益为直推奖励金额的30%,a_b_c_d,d购买1000套餐,c得200,b得200*30%=60元,a得60*30%=18元。。。
     * 以此类推,结算到一元为止。
     *
     * @param orderId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void dynamicProfit(Long orderId, Integer isNormal) {
        log.info("######直推奖励, 订单ID:{}######", orderId);
        MallOrderInfo orderInfo = mallOrderInfoMapper.selectById(orderId);
        if (orderInfo.getOrderType() == 2) {
            log.info("积分订单无返利");
            return;
        }
 
        MallMember member = mallMemberMapper.selectById(orderInfo.getMemberId());
 
        if (StrUtil.isBlank(member.getReferrerId())) {
            return;
        }
 
        // 直推奖励字典
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DYNAMIC_BONUS.getType(), DataDictionaryEnum.DYNAMIC_BONUS.getCode());
 
        // 直接父级
        MallMember parent = mallMemberMapper.selectInfoByInviteId(member.getReferrerId());
 
        List<MallOrderItem> items = mallOrderInfoMapper.getMallOrderItemByOrderId(orderId);
        for (MallOrderItem item : items) {
            item.setHasSettle(1);
            mallOrderItemMapper.updateById(item);
 
            // 减去成本后算收益
            BigDecimal amount = item.getPrice().subtract(item.getCostPrice()).multiply(BigDecimal.valueOf(item.getCnt()));
            if (amount.compareTo(BigDecimal.ZERO) < 1) {
                continue;
            }
 
            // 判断套餐或者普通商品,结算对应商品的动态分红
            if (!Objects.equals(item.getIsNormal(), isNormal)) {
                continue;
            }
 
            // =======直推返利== start =====
            // 直接奖励收益
            BigDecimal dynamicProfit = amount.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP));
 
            if (dynamicProfit.compareTo(BigDecimal.ZERO) < 1) {
                continue;
            }
 
//            int reduce = walletService.reduce(dynamicProfit, parent.getId(), "score");
//            if (reduce == 2) {
//                continue;
//            }
//            walletService.add(dynamicProfit, parent.getId(), "commission");
//            moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue());
//            moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue());
 
            dynamicProfit = changeScoreAndCommission(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo());
            if (dynamicProfit.compareTo(BigDecimal.ZERO) < 1) {
                continue;
            }
            // =======直推返利== end =====
 
            // =======隔代奖== start =====
            if (StrUtil.isBlank(parent.getReferrerId())) {
                continue;
            }
 
            List<String> parents = StrUtil.split(parent.getReferrerIds(), ',');
            List<MallMember> members = mallMemberMapper.selectByInviteIds(parents);
            if (CollUtil.isEmpty(members)) {
                return;
            }
 
            BigDecimal direct = dynamicProfit;
            for (MallMember parentMember : members) {
                if (parent.getInviteId().equals(parentMember.getInviteId())) {
                    continue;
                }
 
                // 直推数量
                Integer directCnt = mallMemberMapper.selectOwnCntByInviteId(parentMember.getInviteId());
                List<DataDictionaryCustom> dataDices = dataDictionaryCustomMapper.selectDicByType(DataDictionaryEnum.INDIRECT_BONUS_SETTING.getType());
 
                directCnt = directCnt == null ? 0 : directCnt;
 
                // 隔代比例
                BigDecimal indrectDicProp = BigDecimal.ZERO;
                for (DataDictionaryCustom dataDic : dataDices) {
                    JSONObject jsonObject = JSONObject.parseObject(dataDic.getValue());
                    if (directCnt >= jsonObject.getInteger("pushCnt")) {
                        indrectDicProp = jsonObject.getBigDecimal("prop");
                    }
                }
 
                // 隔代推荐奖 收益
                direct = direct.multiply(indrectDicProp.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
 
                // direct 收益小于1,则跳出
                if (direct.compareTo(BigDecimal.ONE) < 1) {
                    break;
                }
//                int reduceResult = walletService.reduce(direct, parentMember.getId(), "score");
//                if (reduceResult == 2) {
//                    continue;
//                }
//
//                walletService.add(direct, parentMember.getId(), "commission");
//                moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue());
//                moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue());
                changeScoreAndCommission(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo());
            }
            // =======隔代奖== end =====
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void agentProfit(Date profitDate) {
        log.info("#####==代理分红==start==#####");
        if (profitDate == null) {
            profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        }
        // 套餐业绩
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
        // 普通商品业绩
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
 
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.AGENT_BONUS.getType(), DataDictionaryEnum.AGENT_BONUS.getCode());
        BigDecimal profit = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
 
        List<MallMember> agentMembers = mallMemberMapper.selectByIdAndNoLevel(null, AgentLevelEnum.FIRST_LEVEL.name());
        if (CollUtil.isEmpty(agentMembers)) {
            return;
        }
 
        List<DataDictionaryCustom> dics = dataDictionaryCustomMapper.selectDicByType(AppContants.AGENT_LEVEL_REQUIRE);
        for (DataDictionaryCustom agentDic : dics) {
            JSONObject jsonObject = JSONObject.parseObject(agentDic.getValue());
            BigDecimal profitProp = jsonObject.getBigDecimal("profitProp").divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
 
            List<MallMember> agentMemberList = mallMemberMapper.selectMemberWithLevel(agentDic.getCode());
            if (CollUtil.isEmpty(agentMemberList)) {
                continue;
            }
 
            BigDecimal income = profit.multiply(profitProp).divide(BigDecimal.valueOf(agentMemberList.size()), 2, RoundingMode.HALF_UP);
            if (income.compareTo(BigDecimal.ZERO) < 1) {
                continue;
            }
 
            for (MallMember agentMember : agentMemberList) {
//                int reduce = walletService.reduce(income, agentMember.getId(), "score");
//                if (reduce == 2) {
//                    continue;
//                }
//
//                walletService.add(income, agentMember.getId(), "commission");
//
//                moneyFlowService.addMoneyFlow(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
//                moneyFlowService.addMoneyFlow(agentMember.getId(), income.negate(), MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
                changeScoreAndCommission(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null);
            }
        }
        log.info("#####==代理分红==end==#####");
    }
 
    private BigDecimal changeScoreAndCommission(Long memberId, BigDecimal income, Integer type, String orderNo) {
        Map<String, BigDecimal> map = new HashMap<>();
        map.put("amount", income);
 
        int reduce = walletService.reduce(income, memberId, "score", map);
        if (reduce == 2) {
            return BigDecimal.ZERO;
        }
 
        income = map.get("amount");
        walletService.add(income, memberId, "commission");
        moneyFlowService.addMoneyFlow(memberId, income, type, orderNo, FlowTypeEnum.COMMISSION.getValue());
        moneyFlowService.addMoneyFlow(memberId, income.negate(), type, orderNo, FlowTypeEnum.SCORE.getValue());
        return income;
    }
 
    @Override
    public void rankProfit() {
        log.info("######==排名分红==####");
        Page<MallMember> page = new Page<>(1, 5);
        MallMember query = new MallMember();
        query.setQuery("2");
 
        Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        query.setCreatedTime(profitDate);
        IPage<MallMember> rankListInPage = mallMemberMapper.selectRankListInPage(page, query);
 
        List<MallMember> rankList = rankListInPage.getRecords();
        if (CollUtil.isEmpty(rankList)) {
            return;
        }
 
        // 套餐业绩
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2);
        // 普通商品业绩
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("M", profitDate);
 
        List<DataDictionaryCustom> rankAward = dataDictionaryCustomMapper.selectDicByType("RANK_AWARD");
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANK_BONUS.getType(), DataDictionaryEnum.RANK_BONUS.getCode());
 
 
        BigDecimal rankBonusTotal = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
        BigDecimal preBonus = rankBonusTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
 
        int i = 0;
        for (MallMember member : rankList) {
            DataDictionaryCustom rank = rankAward.get(i);
            i++;
            BigDecimal bonus = preBonus.multiply(new BigDecimal(rank.getValue()));
//            int reduce = walletService.reduce(bonus, member.getId(), "score");
//            if (reduce == 2) {
//                continue;
//            }
//            walletService.add(bonus, member.getId(), "commission");
//            moneyFlowService.addMoneyFlow(member.getId(), bonus, MoneyFlowTypeEnum.RANK_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
//            moneyFlowService.addMoneyFlow(member.getId(), bonus.negate(), MoneyFlowTypeEnum.RANK_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
 
            changeScoreAndCommission(member.getId(), bonus, MoneyFlowTypeEnum.RANK_BONUS.getValue(), null);
        }
    }
 
    /**
     * 拿推荐人的收益(代理,直推,排名)的10%加权平分给下面直推
     */
    @Override
    public void thankfulProfit(Date date) {
        log.info("######==感恩奖==start==####");
        List<MallMember> mallMembers = mallMemberMapper.selectMemberListHasChild();
        if (CollUtil.isEmpty(mallMembers)) {
            return;
        }
        if (date == null) {
            date = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        }
 
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.THANKFUL_BONUS.getType(), DataDictionaryEnum.THANKFUL_BONUS.getCode());
        // 感恩奖比例
        BigDecimal prop = new BigDecimal(dic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
 
        for (MallMember mallMember : mallMembers) {
            BigDecimal income = mallMoneyFlowMapper.selectThankfulCommission(date, mallMember.getId());
            List<MallMember> children = mallMemberMapper.selectMemberDirectForHasLevel(mallMember.getInviteId());
            if (CollUtil.isEmpty(children)) {
                continue;
            }
 
            BigDecimal reduceProfit = income.multiply(prop);
            if (reduceProfit.compareTo(BigDecimal.ZERO) < 1) {
                continue;
            }
 
            int reduce = walletService.reduce(reduceProfit, mallMember.getId(), "commission");
            if (reduce == 2) {
                continue;
            }
            moneyFlowService.addMoneyFlow(mallMember.getId(), reduceProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
 
            for (MallMember child : children) {
                BigDecimal preProfit = income.multiply(prop).divide(BigDecimal.valueOf(children.size()), 2, RoundingMode.HALF_DOWN);
                if (preProfit.compareTo(BigDecimal.ZERO) < 1) {
                    continue;
                }
 
//                int reduce1 = walletService.reduce(preProfit, child.getId(), "score");
//                if (reduce1 == 2) {
//                    continue;
//                }
//                walletService.add(preProfit, child.getId(), "commission");
//                moneyFlowService.addMoneyFlow(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.COMMISSION.getValue());
//                moneyFlowService.addMoneyFlow(child.getId(), preProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.SCORE.getValue());
                changeScoreAndCommission(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null);
            }
        }
        log.info("######==感恩奖==end==####");
    }
 
    @Override
    public void storeAndDirectorProfit(Date profitDate) {
        log.info("#####==店补/董事==start==######");
        if (profitDate == null) {
            profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        }
        // 套餐业绩
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
        // 普通商品业绩
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
 
        // 董事
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECTOR_BONUS.getType(), DataDictionaryEnum.DIRECTOR_BONUS.getCode());
        List<MallMember> directors = mallMemberMapper.selectDirectorsOrStoreMaster(1);
        if (CollUtil.isNotEmpty(directors)) {
            BigDecimal total = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
            BigDecimal pre = total.divide(new BigDecimal(directors.size()), 2, RoundingMode.HALF_UP);
 
            for (MallMember director : directors) {
                if (pre.compareTo(BigDecimal.ZERO) < 1) {
                    continue;
                }
 
//                int reduce = walletService.reduce(pre, director.getId(), "score");
//                if (reduce == 2) {
//                    continue;
//                }
//                walletService.add(pre, director.getId(), "commission");
//                moneyFlowService.addMoneyFlow(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
//                moneyFlowService.addMoneyFlow(director.getId(), pre.negate(), MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
                changeScoreAndCommission(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null);
            }
        }
 
        // 店补
        dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.COMMUNITY_BONUS.getType(), DataDictionaryEnum.COMMUNITY_BONUS.getCode());
        List<MallMember> storeMasters = mallMemberMapper.selectDirectorsOrStoreMaster(2);
        if (CollUtil.isNotEmpty(storeMasters)) {
            BigDecimal total = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
            BigDecimal pre = total.divide(new BigDecimal(storeMasters.size()), 2, RoundingMode.HALF_UP);
 
            for (MallMember storeMaster : storeMasters) {
                if (pre.compareTo(BigDecimal.ZERO) < 1) {
                    continue;
                }
 
//                int reduce = walletService.reduce(pre, storeMaster.getId(), "score");
//                if (reduce == 2) {
//                    continue;
//                }
//                walletService.add(pre, storeMaster.getId(), "commission");
//                moneyFlowService.addMoneyFlow(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
//                moneyFlowService.addMoneyFlow(storeMaster.getId(), pre.negate(), MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
                changeScoreAndCommission(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null);
            }
        }
        log.info("#####==店补/董事==end==######");
    }
}