xiaoyong931011
2023-09-27 a114c501d5fa8d7171eaa38614bc977605fd9c24
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
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.exception.FebsException;
import cc.mrbird.febs.common.properties.XcxProperties;
import cc.mrbird.febs.common.utils.*;
import cc.mrbird.febs.mall.conversion.MallMemberConversion;
import cc.mrbird.febs.mall.conversion.MallShopApplyConversion;
import cc.mrbird.febs.mall.dto.*;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.*;
import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.pay.model.BrandWCPayRequestData;
import cc.mrbird.febs.pay.service.IXcxPayService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
 
/**
 * @author wzy
 * @date 2021-09-16
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class ApiMallMemberServiceImpl extends ServiceImpl<MallMemberMapper, MallMember> implements IApiMallMemberService {
 
    private final MallMemberWalletMapper mallMemberWalletMapper;
    private final ICommonService commonService;
    private final RedisUtils redisUtils;
    private final MallOrderInfoMapper mallOrderInfoMapper;
    private final MallShoppingCartMapper mallShoppingCartMapper;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    private final IApiMallMemberWalletService walletService;
    private final MallMemberPaymentMapper mallMemberPaymentMapper;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallShopApplyMapper mallShopApplyMapper;
    private final MallRegisterAppealMapper mallRegisterAppealMapper;
    private final MallTeamLeaderMapper mallTeamLeaderMapper;
    private final SpringContextHolder springContextHolder;
    private final MallAgentRecordMapper mallAgentRecordMapper;
    private final IMallMoneyFlowService mallMoneyFlowService;
    private final IMallMemberCollectionService mallMemberCollectionService;
    private final IMallMemberFootprintService mallMemberFootprintService;
    private final SalemanCouponMapper salemanCouponMapper;
    private final CouponGoodsMapper couponGoodsMapper;
    private final MallGoodsCouponMapper mallGoodsCouponMapper;
    private final MallMemberCouponMapper mallMemberCouponMapper;
 
 
    @Value("${spring.profiles.active}")
    private String active;
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public FebsResponse register(RegisterDto registerDto) {
        MallMember mallMember = this.baseMapper.selectInfoByAccount(registerDto.getAccount());
        if (mallMember != null) {
            throw new FebsException("该账号已被占用");
        }
 
        List<MallMember> mallMembers = this.baseMapper.selectMemberByName(registerDto.getName());
        if (CollUtil.isNotEmpty(mallMembers)) {
            MallRegisterAppeal registerAppeal = mallRegisterAppealMapper.selectByPhoneAndName(registerDto.getName(), registerDto.getAccount());
            if (registerAppeal == null || registerAppeal.getStatus() != 1) {
                return new FebsResponse().code(HttpStatus.ACCEPTED).message("用户名已存在");
            }
        }
 
        String account = registerDto.getAccount();
        if (!"admin".equals(registerDto.getRegistType())) {
            String code = registerDto.getCode();
            boolean flags = commonService.verifyCode(account, code);
            if (!flags) {
                throw new FebsException("验证码错误");
            }
        }
 
        mallMember = new MallMember();
        mallMember.setPassword(SecureUtil.md5(registerDto.getPassword()));
 
        // 判断账号类型
        if (AppContants.ACCOUNT_TYPE_MOBILE.equals(registerDto.getType())) {
            mallMember.setPhone(registerDto.getAccount());
        } else {
            mallMember.setEmail(registerDto.getAccount());
        }
 
        Integer count = this.baseMapper.selectCount(null);
        if (count != null && count != 0) {
            MallMember inviteMember = this.baseMapper.selectInfoByInviteId(registerDto.getInviteId());
            if (inviteMember == null) {
                throw new FebsException("邀请码不存在");
            }
 
            mallMember.setReferrerId(registerDto.getInviteId());
 
        }
        mallMember.setName(registerDto.getName());
        mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE);
        mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL);
        mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name());
        mallMember.setSex("男");
        mallMember.setBindPhone(registerDto.getAccount());
 
        this.baseMapper.insert(mallMember);
 
        String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId());
        mallMember.setInviteId(inviteId);
 
        //推荐人和推荐人链
        boolean flag = false;
        String parentId = mallMember.getReferrerId();
        if (StrUtil.isBlank(parentId)) {
            flag = true;
        }
        String ids = "";
        while (!flag) {
            if (StrUtil.isBlank(ids)) {
                ids += parentId;
            } else {
                ids += ("," + parentId);
            }
            MallMember parentMember = this.baseMapper.selectInfoByInviteId(parentId);
            if (parentMember == null) {
                break;
            }
            parentId = parentMember.getReferrerId();
            if (StrUtil.isBlank(parentMember.getReferrerId())) {
                flag = true;
            }
        }
 
        if (StrUtil.isNotBlank(ids)) {
            mallMember.setReferrerIds(ids);
        }
        this.baseMapper.updateById(mallMember);
 
        MallMemberWallet wallet = new MallMemberWallet();
        wallet.setBalance(BigDecimal.ZERO);
        wallet.setMemberId(mallMember.getId());
        mallMemberWalletMapper.insert(wallet);
        return new FebsResponse().success().message("注册成功");
    }
 
    @Override
    public FebsResponse toLogin(LoginDto loginDto) {
        String md5Pwd = SecureUtil.md5(loginDto.getPassword());
 
        MallMember mallMember = this.baseMapper.selectInfoByAccountAndPwd(loginDto.getAccount(), md5Pwd);
        if (mallMember == null) {
            throw new FebsException("用户不存在或账号密码错误");
        }
 
        if (MallMember.ACCOUNT_STATUS_DISABLED.equals(mallMember.getAccountStatus())) {
            throw new FebsException("该账号存在异常, 暂限制登录");
        }
 
        String redisKey = AppContants.APP_LOGIN_PREFIX + mallMember.getId();
        String existToken = redisUtils.getString(redisKey);
        if (StrUtil.isNotBlank(existToken)) {
            Object o = redisUtils.get(existToken);
            if (ObjectUtil.isNotEmpty(o)) {
                redisUtils.del(existToken);
            }
        }
 
        String token = IdUtil.simpleUUID();
        redisUtils.set(token, JSONObject.toJSONString(mallMember), 360000);
        redisUtils.set(redisKey, token, 360000);
        Map<String, Object> authInfo = new HashMap<>();
        authInfo.put("token", token);
        authInfo.put("rasToken", generateAsaToken(token));
        return new FebsResponse().success().data(authInfo);
    }
 
    public String generateAsaToken(String token) {
        RSA rsa = new RSA(null, AppContants.PUBLIC_KEY);
//        return rsa.encryptBase64(token + "_" + System.currentTimeMillis(), KeyType.PublicKey);
        //去掉时间戳
        return rsa.encryptBase64(token, KeyType.PublicKey);
    }
 
    @Override
    public FebsResponse forgetPwd(ForgetPwdDto forgetPwdDto) {
        MallMember mallMember = this.baseMapper.selectInfoByAccount(forgetPwdDto.getAccount());
        if (mallMember == null) {
            throw new FebsException("账号不存在");
        }
 
        boolean b = commonService.verifyCode(forgetPwdDto.getAccount(), forgetPwdDto.getCode());
        if (!b) {
            throw new FebsException("验证码错误");
        }
 
        String pwd = SecureUtil.md5(forgetPwdDto.getPassword());
        mallMember.setPassword(pwd);
 
        this.baseMapper.updateById(mallMember);
        return new FebsResponse().success().message("重置成功");
    }
 
    @Override
    public FebsResponse logout() {
        Long id = LoginUserUtil.getLoginUser().getId();
 
        String redisKey = AppContants.XCX_LOGIN_PREFIX + id;
        String existToken = redisUtils.getString(redisKey);
        if (StrUtil.isNotBlank(existToken)) {
            Object o = redisUtils.get(existToken);
            if (ObjectUtil.isNotEmpty(o)) {
                redisUtils.del(existToken);
            }
        }
        redisUtils.del(AppContants.XCX_LOGIN_PREFIX + id);
        redisUtils.del(AppContants.XCX_LOGIN_PHONE_PREFIX + id);
        return new FebsResponse().success().message("退出登录");
    }
 
    @Override
    public FebsResponse findMemberInfo() {
        Long id = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = this.baseMapper.selectById(id);
 
        MallMemberVo mallMemberVo = MallMemberConversion.INSTANCE.entityToVo(mallMember);
        if(StrUtil.isNotEmpty(mallMember.getReferrerId())){
            MallMember referMember = this.baseMapper.selectInfoByInviteId(mallMember.getReferrerId());
            if (referMember != null) {
                mallMemberVo.setReferrerName(referMember.getName());
            }
        }
 
        if (StrUtil.isNotBlank(mallMember.getTradePassword())) {
            mallMemberVo.setHasTradePwd(1);
        }
 
        MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(id);
        if (payment != null) {
            mallMemberVo.setHasPayment(1);
        }
 
        MemberCollectionListDto memberCollectionListDto = new MemberCollectionListDto();
        memberCollectionListDto.setPageNow(1);
        memberCollectionListDto.setPageSize(10);
        List<CollectionListVo> collectionList = mallMemberCollectionService.findMemberCollectionList(memberCollectionListDto);
        mallMemberVo.setCollectionCnt(CollUtil.isNotEmpty(collectionList) ? collectionList.size() : 0);
 
        MemberFootprintListDto memberFootprintListDto = new MemberFootprintListDto();
        memberFootprintListDto.setPageNow(1);
        memberFootprintListDto.setPageSize(10);
        List<FootprintListVo> footprintList = mallMemberFootprintService.findMemberFootprintList(memberFootprintListDto);
        mallMemberVo.setFootprintCnt(CollUtil.isNotEmpty(footprintList) ? footprintList.size() : 0);
 
        List<MallMember> mallMembers = this.baseMapper.selectByRefererId(mallMember.getInviteId());
        mallMemberVo.setChildCnt(CollUtil.isNotEmpty(mallMembers) ? mallMembers.size() : 0);
 
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(mallMemberVo.getId());
        mallMemberVo.setBalance(wallet.getBalance());
//        mallMemberVo.setScore(wallet.getScore());
//        mallMemberVo.setPrizeScore(wallet.getPrizeScore());
//        mallMemberVo.setTotalCost(mallOrderInfoMapper.selectTotalAmount(id));
        return new FebsResponse().success().data(mallMemberVo);
    }
 
    @Override
    public FebsResponse findMemberMarkCnt() {
        Long id = LoginUserUtil.getLoginUser().getId();
 
        List<Map<String, Integer>> maps = mallOrderInfoMapper.selectMemberOrderStatusCnt(id);
        Map<Integer, Integer> orderCnt = new HashMap<>();
        if (CollUtil.isNotEmpty(maps)) {
            for (Map<String, Integer> map : maps) {
                orderCnt.put(map.get("status"), map.get("cnt"));
            }
        }
 
        List<MallShoppingCart> carts = mallShoppingCartMapper.selectCartGoodsList(id);
        Map<String, Object> result = new HashMap<>();
        result.put("order", orderCnt);
        result.put("carts", carts.size());
        return new FebsResponse().success().data(result);
    }
 
    @Override
    public FebsResponse setTradePwd(ForgetPwdDto forgetPwdDto) {
        MallMember memberId = LoginUserUtil.getLoginUser();
        MallMember mallMember = this.baseMapper.selectById(memberId);
        if (mallMember == null) {
            throw new FebsException("账号不存在");
        }
 
        boolean b = commonService.verifyCode(forgetPwdDto.getAccount(), forgetPwdDto.getCode());
        if (!b) {
            throw new FebsException("验证码错误");
        }
 
        mallMember.setTradePassword(SecureUtil.md5(forgetPwdDto.getPassword()));
        this.baseMapper.updateById(mallMember);
        return new FebsResponse().success().message("设置成功");
    }
 
    @Override
    public FebsResponse modifyMemberInfo(ModifyMemberInfoDto modifyMemberInfoDto) {
        MallMember member = LoginUserUtil.getLoginUser();
        MallMember mallMember = this.baseMapper.selectById(member.getId());
        if (StrUtil.isNotBlank(modifyMemberInfoDto.getName())) {
            mallMember.setName(modifyMemberInfoDto.getName());
        }
 
        if (StrUtil.isNotBlank(modifyMemberInfoDto.getPhoto())) {
            mallMember.setAvatar(modifyMemberInfoDto.getPhoto());
        }
 
        this.baseMapper.updateById(mallMember);
        return new FebsResponse().success().message("修改成功");
    }
 
    @Override
    public FebsResponse teamList(TeamListDto teamListDto) {
        Long memberId = null;
        if (teamListDto.getId() == null) {
            memberId = LoginUserUtil.getLoginUser().getId();
        } else {
            memberId = teamListDto.getId();
        }
 
        MallMember mallMember = this.baseMapper.selectById(memberId);
 
        List<TeamListVo> list = this.baseMapper.selectTeamListByInviteId(mallMember.getInviteId());
 
        MyTeamVo myTeamVo = new MyTeamVo();
        myTeamVo.setTeam(list);
        myTeamVo.setMyAchieve(this.mallOrderInfoMapper.selectAmountOrTeamAmount(mallMember.getInviteId(), 1));
        myTeamVo.setMyTeamAchieve(this.mallOrderInfoMapper.selectAmountOrTeamAmount(mallMember.getInviteId(), 2));
        myTeamVo.setMyTeamCnt(this.baseMapper.selectAllChildAgentListByInviteId(mallMember.getInviteId()).size());
        return new FebsResponse().success().data(myTeamVo);
    }
 
    @Override
    public MyTeamVo teamListForMine(TeamListDto teamListDto) {
        return null;
    }
 
    @Override
    public FebsResponse moneyFlows(MoneyFlowDto moneyFlowDto) {
        IPage<MoneyFlowVo> page = new Page<>(moneyFlowDto.getPageNum(), moneyFlowDto.getPageSize());
        Long id = LoginUserUtil.getLoginUser().getId();
        moneyFlowDto.setMemberId(id);
        IPage<MoneyFlowVo> pages = mallMoneyFlowMapper.selectApiMoneyFlowInPage(page, moneyFlowDto);
        return new FebsResponse().success().data(pages);
    }
 
    @Override
    public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status, Integer flowType) {
        MallMoneyFlow flow = new MallMoneyFlow();
        flow.setMemberId(memberId);
        flow.setAmount(amount);
        flow.setType(type);
        flow.setOrderNo(orderNo);
        flow.setDescription(description);
        flow.setRemark(remark);
        flow.setRtMemberId(rtMemberId);
        flow.setStatus(status);
        flow.setFlowType(flowType);
        mallMoneyFlowMapper.insert(flow);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void transfer(TransferDto transferDto) {
        MallMember mallMember = this.baseMapper.selectInfoByAccount(transferDto.getAccount());
        if (mallMember == null) {
            throw new FebsException("用户不存在");
        }
 
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember loginMember = this.baseMapper.selectById(memberId);
 
        if (loginMember.getPhone().equals(transferDto.getAccount()) || loginMember.getInviteId().equals(transferDto.getAccount())) {
            throw new FebsException("不能给自己转账");
        }
 
        if (StrUtil.isBlank(loginMember.getTradePassword())) {
            throw new FebsException("未设置支付密码");
        }
 
        if (!loginMember.getTradePassword().equals(SecureUtil.md5(transferDto.getTradePwd()))) {
            throw new FebsException("支付密码错误");
        }
 
        walletService.reduceBalance(transferDto.getAmount(), memberId);
        String orderNo = MallUtils.getOrderNum("T");
        this.addMoneyFlow(memberId, transferDto.getAmount().negate(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, mallMember.getId(), null, FlowTypeEnum.BALANCE.getValue());
 
        walletService.addBalance(transferDto.getAmount(), mallMember.getId());
        this.addMoneyFlow(mallMember.getId(), transferDto.getAmount(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, memberId, null, FlowTypeEnum.BALANCE.getValue());
    }
 
    @Override
    public void setPayment(MallMemberPayment mallMemberPayment) {
        MallMember member = LoginUserUtil.getLoginUser();
 
        MallMemberPayment exist = mallMemberPaymentMapper.selectByMemberId(member.getId());
        if (exist == null) {
            mallMemberPayment.setMemberId(member.getId());
            mallMemberPaymentMapper.insert(mallMemberPayment);
        } else {
            mallMemberPayment.setId(exist.getId());
            mallMemberPaymentMapper.updateById(mallMemberPayment);
        }
    }
 
    @Override
    public MallMemberPayment findMemberPayment() {
        MallMember member = LoginUserUtil.getLoginUser();
        return mallMemberPaymentMapper.selectByMemberId(member.getId());
    }
 
    @Override
    public void bindPhone(AccountAndCodeDto accountAndCodeDto) {
        boolean b = commonService.verifyCode(accountAndCodeDto.getAccount(), accountAndCodeDto.getCode());
        if (!b) {
            throw new FebsException("验证码错误");
        }
 
        Long id = LoginUserUtil.getLoginUser().getId();
        MallMember member = this.baseMapper.selectById(id);
 
        member.setPhone(accountAndCodeDto.getAccount());
        this.baseMapper.updateById(member);
    }
 
    @Override
    public BigDecimal canMoney() {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
        return wallet.getBalance().setScale(2,BigDecimal.ROUND_DOWN);
    }
 
    @Override
    public List<MallMember> findRankList(RankListDto rankListDto) {
        IPage<MallMember> page = new Page<>(rankListDto.getPageNum(), rankListDto.getPageSize());
 
        MallMember member = new MallMember();
        member.setQuery("2");
        member.setCreatedTime(new Date());
        IPage<MallMember> list = this.baseMapper.selectRankListInPage(page, member);
 
        return list.getRecords();
    }
 
    @Override
    public MallMember findMemberInfoByAccount(String phone) {
        return this.baseMapper.selectInfoByAccount(phone);
    }
 
    @Override
    public MyCommissionVo myCommission() {
        Long id = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = this.baseMapper.selectById(id);
 
        MyCommissionVo commissionVo = MallMemberConversion.INSTANCE.entityToCommissionVo(mallMember);
 
        MallMember referMember = this.baseMapper.selectInfoByInviteId(mallMember.getReferrerId());
        if (referMember != null) {
            commissionVo.setReferrerName(referMember.getName());
            commissionVo.setAvatar(referMember.getAvatar());
        }
 
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.AGENT_LEVEL, mallMember.getLevel());
        if (dic != null) {
            commissionVo.setLevelName(dic.getDescription());
        }
 
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(id);
        commissionVo.setCommission(wallet.getCommission());
        commissionVo.setToday(mallMoneyFlowMapper.selectCommissionIncome(1, new Date(), id));
        commissionVo.setMonth(mallMoneyFlowMapper.selectCommissionIncome(2, new Date(), id));
        commissionVo.setTotal(mallMoneyFlowMapper.selectCommissionIncome(null, null, id));
        commissionVo.setWaitCommission(BigDecimal.ZERO);
        return commissionVo;
    }
 
    @Override
    public void shopApply(ShopApplyDto shopApplyDto) {
        MallMember member = LoginUserUtil.getLoginUser();
 
        MallShopApply hasApply = mallShopApplyMapper.selectNewestApplyByMemberId(member.getId());
        if (hasApply != null) {
            if (!hasApply.getStatus().equals(MallShopApply.APPLY_DISAGREE)) {
                throw new FebsException("请勿重复提交申请");
            }
        }
 
        MallShopApply mallShopApply = new MallShopApply();
        BeanUtil.copyProperties(shopApplyDto, mallShopApply);
 
        mallShopApply.setStatus(MallShopApply.APPLY_ING);
        mallShopApply.setMemberId(member.getId());
        mallShopApplyMapper.insert(mallShopApply);
    }
 
    @Override
    public MallShopApply findNewestApply() {
        MallMember member = LoginUserUtil.getLoginUser();
 
        return mallShopApplyMapper.selectNewestApplyByMemberId(member.getId());
    }
 
    @Override
    public void addRegisterAppeal(RegisterAppealDto registerAppeal) {
        MallRegisterAppeal isExist = mallRegisterAppealMapper.selectByPhoneAndName(registerAppeal.getName(), registerAppeal.getPhone());
        if (isExist != null) {
            throw new FebsException("申诉已存在");
        }
 
        isExist = new MallRegisterAppeal();
        isExist.setName(registerAppeal.getName());
        isExist.setPhone(registerAppeal.getPhone());
        isExist.setStatus(2);
 
        mallRegisterAppealMapper.insert(isExist);
    }
 
    @Override
    public CashOutSettingVo cashOutSetting() {
        CashOutSettingVo cashOutSettingVo = new CashOutSettingVo();
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.CASHOUT_SETTING.getType(), DataDictionaryEnum.CASHOUT_SETTING.getCode());
        if (dic != null) {
            cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class);
        }
        return cashOutSettingVo;
    }
 
    @Override
    public List<ShopListVo> findShopListVo(ShopListDto shopListDto) {
        Page<MallShopApply> page = new Page<>(shopListDto.getPageNow(), shopListDto.getPageSize());
 
        MallShopApply shopApply = new MallShopApply();
        shopApply.setStatus(MallShopApply.APPLY_AGREE);
        IPage<MallShopApply> pageResult = mallShopApplyMapper.selectShopApplyInPage(shopApply, page);
 
        List<MallShopApply> list = pageResult.getRecords();
        if (CollUtil.isEmpty(list)) {
            list = new ArrayList<>();
        }
        return MallShopApplyConversion.INSTANCE.entitiesToVOs(list);
    }
 
 
    private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class);
 
    @Override
    public FebsResponse xcxLogin(ApiXcxLoginDto apiXcxLoginDto) throws IOException {
        log.info("登录请求参数:{}", JSONObject.toJSONString(apiXcxLoginDto));
        FebsResponse febsResponse = new FebsResponse();
        String code = apiXcxLoginDto.getCode();
        log.info("code:" + code);
        if (StrUtil.isNotBlank(code)) {
            String requrl = getXcxLoginUrl(code);
            String reslutData = HttpCurlUtil.sendGetHttp(requrl, null);
            net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(reslutData);
            log.info("微信登录获取到登录信息={}", json);
 
            if (json.containsKey("errcode")) {
                log.info("微信登录获取到异常信息errcode");
                return febsResponse.fail().message("自动登录失败");
            }
 
            String openId = json.getString("openid");
            String sessionKey = json.getString("session_key");
            log.info("openId={},sessionKey={}", openId, sessionKey);
            // 查询用户是否存在
            MallMember mallMember = null;
            synchronized (this) {
                mallMember = this.baseMapper.selectMemberByOpenId(openId);
                if (ObjectUtil.isEmpty(mallMember)) {
                    // 新增用户
                    mallMember = new MallMember();
                    mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE);
                    mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL);
                    mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name());
                    mallMember.setOpenId(openId);
                    mallMember.setSessionKey(sessionKey);
 
                    if (StrUtil.isNotBlank(apiXcxLoginDto.getInviteId())) {
                        MallMember member = this.baseMapper.selectInfoByInviteId(apiXcxLoginDto.getInviteId());
                        if (member != null) {
                            mallMember.setReferrerId(member.getInviteId());
 
                            //推荐人和推荐人链
                            boolean flag = false;
                            String parentId = mallMember.getReferrerId();
                            if (StrUtil.isBlank(parentId)) {
                                flag = true;
                            }
                            String ids = "";
                            while (!flag) {
                                if (StrUtil.isBlank(ids)) {
                                    ids += parentId;
                                } else {
                                    ids += ("," + parentId);
                                }
                                MallMember parentMember = this.baseMapper.selectInfoByInviteId(parentId);
                                if (parentMember == null) {
                                    break;
                                }
                                parentId = parentMember.getReferrerId();
                                if (StrUtil.isBlank(parentMember.getReferrerId())) {
                                    flag = true;
                                }
                            }
 
                            if (StrUtil.isNotBlank(ids)) {
                                mallMember.setReferrerIds(ids);
                            }
                        }
                    }
                    this.baseMapper.insert(mallMember);
 
                    mallMember = this.baseMapper.selectMemberByOpenId(openId);
                    String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId());
                    mallMember.setInviteId(inviteId);
                    this.baseMapper.updateById(mallMember);
                    MallMemberWallet wallet = new MallMemberWallet();
                    wallet.setBalance(BigDecimal.ZERO);
                    wallet.setMemberId(mallMember.getId());
                    mallMemberWalletMapper.insert(wallet);
                } else {
                    mallMember.setSessionKey(sessionKey);
                    this.baseMapper.updateById(mallMember);
                }
            }
            // 存放redis
            String redisKey = AppContants.XCX_LOGIN_PREFIX + mallMember.getId();
            String existToken = redisUtils.getString(redisKey);
            if (StrUtil.isNotBlank(existToken)) {
                Object o = redisUtils.get(existToken);
                if (ObjectUtil.isNotEmpty(o)) {
                    redisUtils.del(existToken);
                }
            }
            String token = IdUtil.simpleUUID();
            redisUtils.set(token, JSONObject.toJSONString(mallMember), -1);
            redisUtils.set(redisKey, token, -1);
            Map<String, Object> authInfo = new HashMap<>();
            authInfo.put("token", token);
            authInfo.put("appid", xcxProperties.getXcxAppid());
            authInfo.put("member", mallMember);
            authInfo.put("rasToken", generateAsaToken(token));
            febsResponse.success().data(authInfo);
        } else {
            return febsResponse.fail().message("自动登录失败");
        }
        return febsResponse;
    }
 
    @Override
    public FebsResponse xcxSaveInfo(ApiXcxSaveInfoDto apiXcxSaveInfoDto) {
        log.info("name={},phone={},avatar={},sex={}",
                apiXcxSaveInfoDto.getNickName(),apiXcxSaveInfoDto.getPhone(),apiXcxSaveInfoDto.getAvatarUrl(),apiXcxSaveInfoDto.getGender());
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = this.baseMapper.selectById(memberId);
        String nickName = apiXcxSaveInfoDto.getNickName();
        if(StrUtil.isNotEmpty(nickName)){
            mallMember.setName(nickName);
        }
        String phone = apiXcxSaveInfoDto.getPhone();
        if(StrUtil.isNotEmpty(phone)){
            mallMember.setPhone(phone);
        }
        String avatarUrl = apiXcxSaveInfoDto.getAvatarUrl();
        if(StrUtil.isNotEmpty(avatarUrl)){
            mallMember.setAvatar(avatarUrl);
        }
//        mallMember.setSex(1 == apiXcxSaveInfoDto.getGender() ? "女" : "男");
        this.baseMapper.updateById(mallMember);
        return new FebsResponse().success();
    }
 
    @Override
    public FebsResponse xcxPhoneLogin(ApiXcxPhoneLoginDto apiXcxPhoneLoginDto) {
        String phone = apiXcxPhoneLoginDto.getPhone();
        boolean flag = commonService.verifyCode(phone, apiXcxPhoneLoginDto.getCode());
        if (flag) {
            // 查询用户是否存在
            MallMember mallMember = null;
            synchronized (this) {
                mallMember = this.baseMapper.selectInfoByAccount(apiXcxPhoneLoginDto.getPhone());
                if (ObjectUtil.isEmpty(mallMember)) {
                    // 新增用户
                    mallMember = new MallMember();
                    mallMember.setPhone(phone);
                    mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE);
                    mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL);
                    mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name());
                    this.baseMapper.insert(mallMember);
 
                    String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId());
                    mallMember.setInviteId(inviteId);
                    this.baseMapper.updateById(mallMember);
                    MallMemberWallet wallet = new MallMemberWallet();
                    wallet.setBalance(BigDecimal.ZERO);
                    wallet.setMemberId(mallMember.getId());
                    mallMemberWalletMapper.insert(wallet);
                }
            }
            // 存放redis
            String redisKey = AppContants.XCX_LOGIN_PHONE_PREFIX + mallMember.getId();
            String existToken = redisUtils.getString(redisKey);
            if (StrUtil.isNotBlank(existToken)) {
                Object o = redisUtils.get(existToken);
                if (ObjectUtil.isNotEmpty(o)) {
                    redisUtils.del(existToken);
                }
            }
            String token = IdUtil.simpleUUID();
            redisUtils.set(token, JSONObject.toJSONString(mallMember), 360000);
            redisUtils.set(redisKey, token, 360000);
            Map<String, Object> authInfo = new HashMap<>();
            authInfo.put("token", token);
            authInfo.put("member", mallMember);
            authInfo.put("rasToken", generateAsaToken(token));
            return new FebsResponse().success().data(authInfo);
        }
        return new FebsResponse().fail().message("验证码错误");
    }
 
    @Override
    public FebsResponse xcxOpen(ApiXcxOpenDto apiXcxOpenDto) {
        DataDictionaryCustom rangeSwitch = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANGE_SWITCH.getType(), DataDictionaryEnum.RANGE_SWITCH.getCode());
        if(StrUtil.isNotBlank(rangeSwitch.getValue()) && "1".equals(rangeSwitch.getValue())){
            if(ObjectUtil.isNull(apiXcxOpenDto.getLongitude()) || ObjectUtil.isNull(apiXcxOpenDto.getLatitude())){
                return new FebsResponse().fail().message("请授权位置信息");
            }
            Double longitude = apiXcxOpenDto.getLongitude();
            Double latitude = apiXcxOpenDto.getLatitude();
 
            DataDictionaryCustom rangeSize = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANGE_SIZE.getType(), DataDictionaryEnum.RANGE_SIZE.getCode());
            if(ObjectUtil.isEmpty(rangeSize)){
                return new FebsResponse().success().data(2);
            }
            if(StrUtil.isBlank(rangeSize.getValue())){
                return new FebsResponse().success().data(2);
            }
            //方位大小,换成单位:米
            Integer value = Integer.parseInt(rangeSize.getValue()) * 1000;
            //根据经纬度获取周围团长的距离
            MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByLonAndLat(longitude, latitude);
            if(ObjectUtil.isEmpty(mallTeamLeader)){
                return new FebsResponse().success().data(2);
            }
            Double distance = mallTeamLeader.getDistance();
            if(value <= distance){
                return new FebsResponse().success().data(2);
            }
        }
        return new FebsResponse().success().data(1);
    }
 
    private final IXcxPayService iXcxPayService;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public FebsResponse rechargeWallet(ApiRechargeWalletDto apiRechargeWalletDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        BigDecimal amount = apiRechargeWalletDto.getAmount();
        if(BigDecimal.ZERO.compareTo(amount)>0){
            return new FebsResponse().fail().message("请输入正确的充值金额");
        }
        Integer type = apiRechargeWalletDto.getType();
        if(2 == type){
            //成为合伙人的充值金额
            MallAgentRecord mallAgentRecord = mallAgentRecordMapper.selectById(apiRechargeWalletDto.getAgentApplyId());
            BigDecimal agentPrice = mallAgentRecord.getAmount();
//            DataDictionaryCustom agentPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.PRICE_AMOUNT.getType(),
//                    DataDictionaryEnum.PRICE_AMOUNT.getCode());
//            String agentPrice = agentPriceDic.getValue();
//            BigDecimal price = new BigDecimal(agentPrice);
            if(agentPrice.compareTo(amount) != 0){
                return new FebsResponse().fail().message("成为合伙人的金额为"+agentPrice);
            }
        }
        String rechargeNo = "CZ_"+MallUtils.getOrderNum();
        apiRechargeWalletDto.setRechargeNo(rechargeNo);
        apiRechargeWalletDto.setMemberId(memberId);
        BrandWCPayRequestData brandWCPayRequestData = null;
        try {
            brandWCPayRequestData = iXcxPayService.startRechargeWallet(apiRechargeWalletDto);
        } catch (Exception e) {
            throw new FebsException("支付失败");
        }
        mallMoneyFlowService.addMoneyFlow(
                memberId,
                amount,
                MoneyFlowTypeEnum.RECHARGE.getValue(),
                rechargeNo,
                FlowTypeEnum.BALANCE.getValue(),
                "余额充值",1);
 
        String wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData);
        String payResultStr = brandWCPayRequestData.getPrepay_id();
        Map<String, Object> map = new HashMap<>();
        map.put("orderInfo", payResultStr);
        map.put("wxResultStr", wxResultStr);
        return new FebsResponse().success().data(map).message("充值即将到账");
    }
 
    @Override
    public void updateMemberAgent(Long memberId,String levelCode) {
        mallAgentRecordMapper.updateStateByMemberId(memberId);
        MallAgentRecord mallAgentRecord = mallAgentRecordMapper.selectById(memberId);
        //更新用户表中的LEVEL
        MallMember mallMember = this.baseMapper.selectById(mallAgentRecord.getMemberId());
        mallMember.setLevel(levelCode);
        this.baseMapper.updateById(mallMember);
    }
 
    @Override
    public FebsResponse agentDetail() {
        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.AGENT_DETAILS.getType(), DataDictionaryEnum.AGENT_DETAILS.getCode());
        Map<String, Object> map = new HashMap<>();
        if(ObjectUtil.isNotEmpty(dataDictionaryCustom)){
            map.put("agentDetail", dataDictionaryCustom.getValue());
        }
        return new FebsResponse().success().data(map);
    }
 
    @Override
    public FebsResponse activityInfo() {
        DataDictionaryCustom activityBulletinDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.ACTIVITY_BULLETIN.getType(), DataDictionaryEnum.ACTIVITY_BULLETIN.getCode());
        DataDictionaryCustom giveAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.GIVE_AMOUNT.getType(), DataDictionaryEnum.GIVE_AMOUNT.getCode());
        DataDictionaryCustom giveStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.GIVE_STATE.getType(), DataDictionaryEnum.GIVE_STATE.getCode());
        Map<String, Object> map = new HashMap<>();
        if(ObjectUtil.isNotEmpty(activityBulletinDic)){
            map.put("activityBulletin",
                    ObjectUtil.isEmpty(activityBulletinDic.getValue()) ? "暂无活动" : activityBulletinDic.getValue());
        }
        if(ObjectUtil.isNotEmpty(giveAmountDic)){
            map.put("giveAmount",
                    ObjectUtil.isEmpty(giveAmountDic.getValue()) ? 0 : giveAmountDic.getValue());
        }
        map.put("giveState",giveStateDic.getValue());
        return new FebsResponse().success().data(map);
    }
 
    @Override
    public FebsResponse agentApplyInfo() {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        ApiMallAgentRecordVo apiMallAgentRecordVo = mallAgentRecordMapper.selectApiMallAgentRecordVoByMemberIdAndState(memberId,MallAgentRecord.APPLY_ING);
        return new FebsResponse().success().data(apiMallAgentRecordVo);
    }
 
    @Override
    public FebsResponse getCoupon(GetCouponDto getCouponDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        //通过邀请人信息,获取能领取的优惠卷信息
        MallMember mallMember = this.baseMapper.selectInfoByInviteId(getCouponDto.getInviteId());
        if(ObjectUtil.isNotEmpty(mallMember)){
            SalemanCoupon salemanCoupon = salemanCouponMapper.selectByMemberId(mallMember.getId());
            if(ObjectUtil.isNotEmpty(salemanCoupon)){
                Long couponId = salemanCoupon.getCouponId();
                Long goodsId = getCouponDto.getGoodsId();
                List<MallMemberCoupon> mallMemberCoupons = mallMemberCouponMapper.selectListByMemberIdAndGoodsIdAndCouponId(memberId, goodsId, couponId);
                if(CollUtil.isEmpty(mallMemberCoupons)){
                    //商品优惠卷如果绑定了,那么当前登陆者获取一张卷
                    List<CouponGoods> couponGoodsList = couponGoodsMapper.selectByGoodIdAndCouponId(goodsId,couponId);
                    MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(couponId);
                    if(CollUtil.isNotEmpty(couponGoodsList)){
                        MallMemberCoupon mallMemberCoupon = new MallMemberCoupon();
                        mallMemberCoupon.setCouponId(couponId);
                        mallMemberCoupon.setCouponName(mallGoodsCoupon.getName());
                        mallMemberCoupon.setMemberId(memberId);
                        mallMemberCoupon.setGoodsId(goodsId);
                        mallMemberCoupon.setInviteId(mallMember.getInviteId());
                        mallMemberCoupon.setState(1);
                        mallMemberCoupon.setExpireTime(DateUtil.offsetDay(DateUtil.date(),mallGoodsCoupon.getExpireDay()));
                        mallMemberCouponMapper.insert(mallMemberCoupon);
                    }
                }
            }
        }
        return new FebsResponse().success();
    }
 
    @Override
    public FebsResponse memberCoupon(MallMemberCouponDto mallMemberCouponDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        IPage<MallMemberCouponVo> page = new Page<>(mallMemberCouponDto.getPageNum(), mallMemberCouponDto.getPageSize());
        mallMemberCouponDto.setMemberId(memberId);
        mallMemberCouponDto.setExpireTime(DateUtil.date());
        IPage<MallMemberCouponVo> pages = mallMemberCouponMapper.selectListInPage(page, mallMemberCouponDto);
        return new FebsResponse().success().data(pages);
    }
 
    @Override
    public FebsResponse couponDetails(Long id) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(id);
        MallMemberCouponVo mallMemberCouponVo = new MallMemberCouponVo();
        mallMemberCouponVo.setCouponName(mallMemberCoupon.getCouponName());
        MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(mallMemberCoupon.getCouponId());
        mallMemberCouponVo.setCostAmount(mallGoodsCoupon.getCostAmount());
        mallMemberCouponVo.setRealAmount(mallGoodsCoupon.getRealAmount());
        return new FebsResponse().success().data(mallMemberCouponVo);
    }
 
    @Override
    public FebsResponse setInvite(ApiSetInviteDto apiSetInviteDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = this.baseMapper.selectById(memberId);
        if(ObjectUtil.isNotEmpty(mallMember.getReferrerId())){
            throw new FebsException("已绑定");
        }
        String inviteId = apiSetInviteDto.getInviteId();
        if(inviteId.equals(mallMember.getReferrerId())){
            throw new FebsException("自己无法绑定自己");
        }
        MallMember member = this.baseMapper.selectInfoByInviteId(inviteId);
        if (member != null) {
            mallMember.setReferrerId(member.getInviteId());
 
            //推荐人和推荐人链
            boolean flag = false;
            String parentId = mallMember.getReferrerId();
            if (StrUtil.isBlank(parentId)) {
                flag = true;
            }
            String ids = "";
            while (!flag) {
                if (StrUtil.isBlank(ids)) {
                    ids += parentId;
                } else {
                    ids += ("," + parentId);
                }
                MallMember parentMember = this.baseMapper.selectInfoByInviteId(parentId);
                if (parentMember == null) {
                    break;
                }
                parentId = parentMember.getReferrerId();
                if (StrUtil.isBlank(parentMember.getReferrerId())) {
                    flag = true;
                }
            }
            if (StrUtil.isNotBlank(ids)) {
                mallMember.setReferrerIds(ids);
            }
            this.baseMapper.updateById(mallMember);
        }
        return new FebsResponse().success();
    }
 
    private  String getXcxLoginUrl(String code) {
        String wechatLoginUrl =xcxProperties.getWecharLoginUrl();
        return String.format(wechatLoginUrl, xcxProperties.getXcxAppid(), xcxProperties.getXcxSecret(), code);
    }
}