MrShi
昨天 7ee466ebc953bb5640bcf42f2b8e2a87aa471c21
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
990
991
992
993
994
995
996
package com.doumee.service.business.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.config.jwt.JwtTokenUtil;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Utils;
import com.doumee.biz.system.AreasBiz;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.dao.business.MemberMapper;
import com.doumee.dao.business.MultifileMapper;
import com.doumee.dao.business.ShopInfoMapper;
import com.doumee.dao.business.model.Areas;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.business.model.Multifile;
import com.doumee.dao.business.model.ShopInfo;
import com.doumee.dao.dto.*;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.vo.ShopDetailVO;
import com.doumee.dao.vo.ShopLoginVO;
import com.doumee.dao.vo.ShopNearbyVO;
import com.doumee.dao.vo.ShopWebDetailVO;
import com.doumee.service.business.ShopInfoService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 门店信息Service实现
 * @author rk
 * @date 2026/04/08
 */
@Service
public class ShopInfoServiceImpl implements ShopInfoService {
 
    @Autowired
    private ShopInfoMapper shopInfoMapper;
 
    @Autowired
    private MemberMapper memberMapper;
 
    @Autowired
    private MultifileMapper multifileMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Autowired
    private SystemUserMapper systemUserMapper;
 
    @Autowired
    private AreasBiz areasBiz;
 
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Override
    public Integer create(ShopInfo shopInfo) {
        shopInfoMapper.insert(shopInfo);
        return shopInfo.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        shopInfoMapper.deleteById(id);
    }
 
    @Override
    public void delete(ShopInfo shopInfo) {
        UpdateWrapper<ShopInfo> deleteWrapper = new UpdateWrapper<>(shopInfo);
        shopInfoMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (ids == null || ids.isEmpty()) {
            return;
        }
        shopInfoMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(ShopInfo shopInfo) {
        shopInfoMapper.updateById(shopInfo);
    }
 
    @Override
    public void updateByIdInBatch(List<ShopInfo> shopInfos) {
        if (shopInfos == null || shopInfos.isEmpty()) {
            return;
        }
        for (ShopInfo shopInfo : shopInfos) {
            this.updateById(shopInfo);
        }
    }
 
    @Override
    public ShopInfo findById(Integer id) {
        ShopInfo shopInfo = shopInfoMapper.selectById(id);
        if (Objects.isNull(shopInfo)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        return shopInfo;
    }
 
    @Override
    public ShopInfo findOne(ShopInfo shopInfo) {
        QueryWrapper<ShopInfo> wrapper = new QueryWrapper<>(shopInfo);
        return shopInfoMapper.selectOne(wrapper);
    }
 
    @Override
    public List<ShopInfo> findList(ShopInfo shopInfo) {
        QueryWrapper<ShopInfo> wrapper = new QueryWrapper<>(shopInfo);
        return shopInfoMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<ShopInfo> findPage(PageWrap<ShopInfo> pageWrap) {
        IPage<ShopInfo> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<ShopInfo> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        pageWrap.getModel().setDeleted(Constants.ZERO);
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(ShopInfo::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getDeleted() != null) {
            queryWrapper.lambda().eq(ShopInfo::getDeleted, pageWrap.getModel().getDeleted());
        }
        if (pageWrap.getModel().getCreateUser() != null) {
            queryWrapper.lambda().eq(ShopInfo::getCreateUser, pageWrap.getModel().getCreateUser());
        }
        if (pageWrap.getModel().getCreateTime() != null) {
            queryWrapper.lambda().ge(ShopInfo::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime()));
            queryWrapper.lambda().le(ShopInfo::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime()));
        }
        if (pageWrap.getModel().getCreateStartTime() != null) {
            queryWrapper.lambda().ge(ShopInfo::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateStartTime()));
        }
        if (pageWrap.getModel().getCreateEndTime() != null) {
            queryWrapper.lambda().le(ShopInfo::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateEndTime()));
        }
        if (pageWrap.getModel().getUpdateUser() != null) {
            queryWrapper.lambda().eq(ShopInfo::getUpdateUser, pageWrap.getModel().getUpdateUser());
        }
        if (pageWrap.getModel().getUpdateTime() != null) {
            queryWrapper.lambda().ge(ShopInfo::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime()));
            queryWrapper.lambda().le(ShopInfo::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime()));
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(ShopInfo::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getCompanyType() != null) {
            queryWrapper.lambda().eq(ShopInfo::getCompanyType, pageWrap.getModel().getCompanyType());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().like(ShopInfo::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getTelephone() != null) {
            queryWrapper.lambda().like(ShopInfo::getTelephone, pageWrap.getModel().getTelephone());
        }
        if (pageWrap.getModel().getLinkName() != null) {
            queryWrapper.lambda().like(ShopInfo::getLinkName, pageWrap.getModel().getLinkName());
        }
        if (pageWrap.getModel().getLinkPhone() != null) {
            queryWrapper.lambda().like(ShopInfo::getLinkPhone, pageWrap.getModel().getLinkPhone());
        }
        if (pageWrap.getModel().getAreaId() != null) {
            queryWrapper.lambda().eq(ShopInfo::getAreaId, pageWrap.getModel().getAreaId());
        }
        if (pageWrap.getModel().getAuditStatus() != null) {
            queryWrapper.lambda().eq(ShopInfo::getAuditStatus, pageWrap.getModel().getAuditStatus());
        }
        if (pageWrap.getModel().getAuditStatusList() != null && !pageWrap.getModel().getAuditStatusList().isEmpty()) {
            queryWrapper.lambda().in(ShopInfo::getAuditStatus, pageWrap.getModel().getAuditStatusList());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(ShopInfo::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getAuditTime() != null) {
            queryWrapper.lambda().ge(ShopInfo::getAuditTime, Utils.Date.getStart(pageWrap.getModel().getAuditTime()));
            queryWrapper.lambda().le(ShopInfo::getAuditTime, Utils.Date.getEnd(pageWrap.getModel().getAuditTime()));
        }
        if (pageWrap.getModel().getAuditUserId() != null) {
            queryWrapper.lambda().eq(ShopInfo::getAuditUserId, pageWrap.getModel().getAuditUserId());
        }
        if (pageWrap.getModel().getOpenid() != null) {
            queryWrapper.lambda().like(ShopInfo::getOpenid, pageWrap.getModel().getOpenid());
        }
        for (PageWrap.SortData sortData : pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(shopInfoMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(ShopInfo shopInfo) {
        QueryWrapper<ShopInfo> wrapper = new QueryWrapper<>(shopInfo);
        return shopInfoMapper.selectCount(wrapper);
    }
 
    // ========== 门店入驻业务 ==========
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void applyShop(ShopApplyDTO request, Member member) {
        Integer memberId = member.getId();
 
        // 1. 校验门店手机号唯一性(shop_info.telephone)
        checkTelephoneUnique(request.getTelephone(), null);
 
        // 2. 根据类型校验附件
        if (Constants.equalsInteger(request.getCompanyType(), Constants.ZERO)) {
            // 个人类型:必须上传劳动合同和社保证明
            if (CollectionUtils.isEmpty(request.getLaborContractImgs())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "个人类型必须上传有效劳动合同");
            }
            if (CollectionUtils.isEmpty(request.getSocialSecurityImgs())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "个人类型必须上传社保缴纳证明");
            }
        } else if (Constants.equalsInteger(request.getCompanyType(), Constants.ONE)) {
            // 企业类型:必须填写法人信息和营业执照
            if (StringUtils.isBlank(request.getBusinessImg())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须上传营业执照");
            }
            if (StringUtils.isBlank(request.getLegalPersonName())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须填写法人姓名");
            }
            if (StringUtils.isBlank(request.getLegalPersonPhone())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须填写法人电话");
            }
            if (StringUtils.isBlank(request.getLegalPersonCard())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须填写法人身份证号码");
            }
        }
 
        Date now = new Date();
        String rawPassword = generateDefaultPassword(request.getTelephone());
        String salt = RandomStringUtils.randomAlphabetic(6);
        String encryptedPassword = Utils.Secure.encryptPassword(rawPassword, salt);
 
        // 3. 查询该会员是否已有门店记录
        QueryWrapper<ShopInfo> existQw = new QueryWrapper<>();
        existQw.lambda()
                .eq(ShopInfo::getRegionMemberId, memberId)
                .eq(ShopInfo::getDeleted, Constants.ZERO)
                .last("limit 1");
        ShopInfo existing = shopInfoMapper.selectOne(existQw);
 
        Integer shopId;
        if (existing != null) {
            // 校验状态:只有待审批(0)和被驳回(2)可修改
            if (!Constants.equalsInteger(existing.getAuditStatus(), Constants.ZERO)
                    && !Constants.equalsInteger(existing.getAuditStatus(), Constants.TWO)) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前门店状态不允许修改");
            }
            // 校验openid匹配:当前登录会员的openid必须与门店的openid一致
            if (existing.getOpenid() != null && !existing.getOpenid().equals(member.getOpenid())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "无权限操作当前门店信息");
            }
            // 校验手机号唯一性(排除自身)
            if (!request.getTelephone().equals(existing.getTelephone())) {
                checkTelephoneUnique(request.getTelephone(), existing.getId());
            }
            // 更新
            existing.setCompanyType(request.getCompanyType());
            existing.setName(request.getName());
            existing.setTelephone(request.getTelephone());
            existing.setLinkName(request.getLinkName());
            existing.setLinkPhone(request.getLinkPhone());
            existing.setIdcard(request.getIdcard());
            existing.setAreaId(request.getAreaId());
            existing.setLongitude(request.getLongitude());
            existing.setLatitude(request.getLatitude());
            existing.setAddress(request.getAddress());
            existing.setIdcardImg(request.getIdcardImg());
            existing.setIdcardImgBack(request.getIdcardImgBack());
            existing.setBusinessImg(request.getBusinessImg());
            existing.setLegalPersonName(request.getLegalPersonName());
            existing.setLegalPersonPhone(request.getLegalPersonPhone());
            existing.setLegalPersonCard(request.getLegalPersonCard());
            existing.setPassword(encryptedPassword);
            existing.setSalt(salt);
            existing.setAuditStatus(Constants.ZERO);
            existing.setUpdateTime(now);
            existing.setUpdateUser(memberId);
            existing.setAuditRemark(null);
            existing.setAuditTime(null);
            existing.setAuditUserId(null);
            shopInfoMapper.updateById(existing);
            shopId = existing.getId();
        } else {
            // 新建
            ShopInfo shopInfo = new ShopInfo();
            shopInfo.setCompanyType(request.getCompanyType());
            shopInfo.setName(request.getName());
            shopInfo.setTelephone(request.getTelephone());
            shopInfo.setLinkName(request.getLinkName());
            shopInfo.setLinkPhone(request.getLinkPhone());
            shopInfo.setIdcard(request.getIdcard());
            shopInfo.setAreaId(request.getAreaId());
            shopInfo.setLongitude(request.getLongitude());
            shopInfo.setLatitude(request.getLatitude());
            shopInfo.setAddress(request.getAddress());
            shopInfo.setIdcardImg(request.getIdcardImg());
            shopInfo.setIdcardImgBack(request.getIdcardImgBack());
            shopInfo.setBusinessImg(request.getBusinessImg());
            shopInfo.setLegalPersonName(request.getLegalPersonName());
            shopInfo.setLegalPersonPhone(request.getLegalPersonPhone());
            shopInfo.setLegalPersonCard(request.getLegalPersonCard());
            shopInfo.setPassword(encryptedPassword);
            shopInfo.setSalt(salt);
            shopInfo.setOpenid(member.getOpenid());
            shopInfo.setAuditStatus(Constants.ZERO);
            shopInfo.setStatus(Constants.ZERO);
            shopInfo.setDeleted(Constants.ZERO);
            shopInfo.setCreateTime(now);
            shopInfo.setUpdateTime(now);
            shopInfo.setCreateUser(memberId);
            shopInfo.setRegionMemberId(memberId);
            shopInfoMapper.insert(shopInfo);
            shopId = shopInfo.getId();
        }
 
        // 4. 删除旧附件记录
        multifileMapper.delete(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId, shopId)
                .in(Multifile::getObjType,
                        Constants.FileType.STORE_FRONT.getKey(),
                        Constants.FileType.STORE_INTERIOR.getKey(),
                        Constants.FileType.OTHER_MATERIAL.getKey(),
                        Constants.FileType.LABOR_CONTRACT.getKey(),
                        Constants.FileType.SOCIAL_SECURITY.getKey()));
 
        // 5. 保存新附件记录
        saveMultifileList(shopId, Constants.FileType.STORE_FRONT.getKey(), request.getStoreFrontImgs(), now);
        saveMultifileList(shopId, Constants.FileType.STORE_INTERIOR.getKey(), request.getStoreInteriorImgs(), now);
        saveMultifileList(shopId, Constants.FileType.OTHER_MATERIAL.getKey(), request.getOtherMaterialImgs(), now);
        saveMultifileList(shopId, Constants.FileType.LABOR_CONTRACT.getKey(), request.getLaborContractImgs(), now);
        saveMultifileList(shopId, Constants.FileType.SOCIAL_SECURITY.getKey(), request.getSocialSecurityImgs(), now);
    }
 
    @Override
    public ShopDetailVO getShopDetail(Integer shopId) {
        ShopInfo shopInfo = shopInfoMapper.selectById(shopId);
        if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        return buildShopDetailVO(shopInfo);
    }
 
    @Override
    public ShopDetailVO getMyShop(Integer memberId) {
        QueryWrapper<ShopInfo> qw = new QueryWrapper<>();
        qw.lambda()
                .eq(ShopInfo::getRegionMemberId, memberId)
                .eq(ShopInfo::getDeleted, Constants.ZERO)
                .last("limit 1");
        ShopInfo shopInfo = shopInfoMapper.selectOne(qw);
        if (shopInfo == null) {
            return null;
        }
        return buildShopDetailVO(shopInfo);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void auditShop(AuditDTO auditDTO) {
        if (auditDTO.getId() == null) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "主键不能为空");
        }
        if (auditDTO.getAuditStatus() == null
                || (auditDTO.getAuditStatus() != 0 && auditDTO.getAuditStatus() != 1)) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "审批状态参数错误");
        }
        ShopInfo shopInfo = shopInfoMapper.selectById(auditDTO.getId());
        if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if (!Constants.equalsInteger(shopInfo.getAuditStatus(), Constants.ZERO)) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前状态不允许审批");
        }
 
        Date now = new Date();
        // auditDTO.auditStatus: 0=通过 → auditStatus=1, 1=驳回 → auditStatus=2
        Integer newAuditStatus = Constants.equalsInteger(auditDTO.getAuditStatus(), Constants.ZERO) ? Constants.ONE : Constants.TWO;
        shopInfo.setAuditStatus(newAuditStatus);
        shopInfo.setAuditTime(now);
        shopInfo.setAuditRemark(auditDTO.getAuditRemark());
        shopInfo.setAuditUserId(auditDTO.getAuditUser());
        shopInfo.setUpdateTime(now);
        shopInfoMapper.updateById(shopInfo);
    }
 
    @Override
    public void changeStatus(ChangeStatusDTO dto) {
        if (dto.getId() == null) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "主键不能为空");
        }
        if (dto.getStatus() == null || (dto.getStatus() != 0 && dto.getStatus() != 1)) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "状态参数错误,0=启用;1=禁用");
        }
        ShopInfo shopInfo = shopInfoMapper.selectById(dto.getId());
        if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        shopInfo.setStatus(dto.getStatus());
        shopInfo.setUpdateTime(new Date());
        shopInfoMapper.updateById(shopInfo);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void resetPassword(ResetPasswordDTO dto) {
        if (dto.getId() == null) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "门店主键不能为空");
        }
        ShopInfo shopInfo = shopInfoMapper.selectById(dto.getId());
        if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        String rawPassword = generateDefaultPassword(shopInfo.getTelephone());
        String salt = RandomStringUtils.randomAlphabetic(6);
        shopInfo.setPassword(Utils.Secure.encryptPassword(rawPassword, salt));
        shopInfo.setSalt(salt);
        shopInfo.setUpdateTime(new Date());
        shopInfoMapper.updateById(shopInfo);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateShop(ShopUpdateDTO request) {
        if (request.getId() == null) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "门店主键不能为空");
        }
        ShopInfo shopInfo = shopInfoMapper.selectById(request.getId());
        if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
 
        // 校验手机号唯一性(排除自身)
        if (!request.getTelephone().equals(shopInfo.getTelephone())) {
            checkTelephoneUnique(request.getTelephone(), shopInfo.getId());
        }
 
        // 根据类型校验必填
        if (Constants.equalsInteger(request.getCompanyType(), Constants.ZERO)) {
            // 个人类型:必须上传劳动合同和社保证明
            if (CollectionUtils.isEmpty(request.getLaborContractImgs())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "个人类型必须上传有效劳动合同");
            }
            if (CollectionUtils.isEmpty(request.getSocialSecurityImgs())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "个人类型必须上传社保缴纳证明");
            }
        } else if (Constants.equalsInteger(request.getCompanyType(), Constants.ONE)) {
            // 企业类型:必须填写法人信息和营业执照
            if (StringUtils.isBlank(request.getBusinessImg())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须上传营业执照");
            }
            if (StringUtils.isBlank(request.getLegalPersonName())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须填写法人姓名");
            }
            if (StringUtils.isBlank(request.getLegalPersonPhone())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须填写法人电话");
            }
            if (StringUtils.isBlank(request.getLegalPersonCard())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "企业类型必须填写法人身份证号码");
            }
        }
 
        Date now = new Date();
        // 更新基础信息
        shopInfo.setCompanyType(request.getCompanyType());
        shopInfo.setName(request.getName());
        shopInfo.setTelephone(request.getTelephone());
        shopInfo.setLinkName(request.getLinkName());
        shopInfo.setLinkPhone(request.getLinkPhone());
        shopInfo.setIdcard(request.getIdcard());
        shopInfo.setAreaId(request.getAreaId());
        shopInfo.setLongitude(request.getLongitude());
        shopInfo.setLatitude(request.getLatitude());
        shopInfo.setAddress(request.getAddress());
        // 企业类信息
        shopInfo.setIdcardImg(request.getIdcardImg());
        shopInfo.setIdcardImgBack(request.getIdcardImgBack());
        shopInfo.setBusinessImg(request.getBusinessImg());
        shopInfo.setLegalPersonName(request.getLegalPersonName());
        shopInfo.setLegalPersonPhone(request.getLegalPersonPhone());
        shopInfo.setLegalPersonCard(request.getLegalPersonCard());
        shopInfo.setUpdateTime(now);
        shopInfoMapper.updateById(shopInfo);
 
        // 删除旧附件记录
        multifileMapper.delete(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId, shopInfo.getId())
                .in(Multifile::getObjType,
                        Constants.FileType.STORE_FRONT.getKey(),
                        Constants.FileType.STORE_INTERIOR.getKey(),
                        Constants.FileType.OTHER_MATERIAL.getKey(),
                        Constants.FileType.LABOR_CONTRACT.getKey(),
                        Constants.FileType.SOCIAL_SECURITY.getKey()));
 
        // 保存新附件记录
        saveMultifileList(shopInfo.getId(), Constants.FileType.STORE_FRONT.getKey(), request.getStoreFrontImgs(), now);
        saveMultifileList(shopInfo.getId(), Constants.FileType.STORE_INTERIOR.getKey(), request.getStoreInteriorImgs(), now);
        saveMultifileList(shopInfo.getId(), Constants.FileType.OTHER_MATERIAL.getKey(), request.getOtherMaterialImgs(), now);
        saveMultifileList(shopInfo.getId(), Constants.FileType.LABOR_CONTRACT.getKey(), request.getLaborContractImgs(), now);
        saveMultifileList(shopInfo.getId(), Constants.FileType.SOCIAL_SECURITY.getKey(), request.getSocialSecurityImgs(), now);
    }
 
    // ========== 私有方法 ==========
 
    /**
     * 生成默认密码:手机号后6位 + @123456
     */
    private String generateDefaultPassword(String telephone) {
        if (StringUtils.isBlank(telephone) || telephone.length() < 6) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "手机号格式异常,无法生成默认密码");
        }
        return telephone.substring(telephone.length() - 6) + "@123456";
    }
 
    private void checkTelephoneUnique(String telephone, Integer excludeId) {
        QueryWrapper<ShopInfo> qw = new QueryWrapper<>();
        qw.lambda()
                .eq(ShopInfo::getTelephone, telephone)
                .eq(ShopInfo::getDeleted, Constants.ZERO);
        if (excludeId != null) {
            qw.lambda().ne(ShopInfo::getId, excludeId);
        }
        long count = shopInfoMapper.selectCount(qw);
        if (count > 0) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "该手机号已注册门店");
        }
    }
 
    private void saveMultifileList(Integer objId, Integer objType, List<String> urls, Date now) {
        if (CollectionUtils.isEmpty(urls)) {
            return;
        }
        int sortNum = 0;
        for (String url : urls) {
            Multifile multifile = new Multifile();
            multifile.setObjId(objId);
            multifile.setObjType(objType);
            multifile.setType(Constants.ZERO);
            multifile.setFileurl(url);
            multifile.setIsdeleted(Constants.ZERO);
            multifile.setCreateDate(now);
            multifile.setSortnum(sortNum++);
            multifileMapper.insert(multifile);
        }
    }
 
    private ShopDetailVO buildShopDetailVO(ShopInfo shopInfo) {
        ShopDetailVO vo = new ShopDetailVO();
        vo.setId(shopInfo.getId());
        vo.setCompanyType(shopInfo.getCompanyType());
        vo.setName(shopInfo.getName());
        vo.setTelephone(shopInfo.getTelephone());
        vo.setLinkName(shopInfo.getLinkName());
        vo.setLinkPhone(shopInfo.getLinkPhone());
        vo.setIdcard(shopInfo.getIdcard());
        vo.setAreaId(shopInfo.getAreaId());
        // 填充省市区名称及主键
        Areas area = areasBiz.resolveArea(shopInfo.getAreaId());
        if (area != null) {
            vo.setProvinceId(area.getProvinceId());
            vo.setCityId(area.getCityId());
            vo.setProvinceName(area.getProvinceName());
            vo.setCityName(area.getCityName());
            vo.setAreaName(area.getName());
        }
        vo.setLongitude(shopInfo.getLongitude());
        vo.setLatitude(shopInfo.getLatitude());
        vo.setAddress(shopInfo.getAddress());
        vo.setLegalPersonName(shopInfo.getLegalPersonName());
        vo.setLegalPersonPhone(shopInfo.getLegalPersonPhone());
        vo.setLegalPersonCard(shopInfo.getLegalPersonCard());
        vo.setAuditStatus(shopInfo.getAuditStatus());
        vo.setStatus(shopInfo.getStatus());
        vo.setAuditTime(shopInfo.getAuditTime());
        if(Objects.nonNull(shopInfo.getAuditUserId())){
            SystemUser systemUser = systemUserMapper.selectById(shopInfo.getAuditUserId());
            if (systemUser != null) vo.setAuditName(systemUser.getRealname());
 
        }
        vo.setAuditRemark(shopInfo.getAuditRemark());
        vo.setOpenid(shopInfo.getOpenid());
        vo.setPayStatus(shopInfo.getPayStatus());
        vo.setScore(shopInfo.getScore());
        vo.setCreateTime(shopInfo.getCreateTime());
 
        // 拼接图片前缀
        String imgPrefix = "";
        try {
            imgPrefix = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.RESOURCE_PATH).getCode()
                    + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SHOP_FILES).getCode();
        } catch (Exception e) {
            // 未配置时忽略
        }
        vo.setImgPrefix(imgPrefix);
 
        // 单图字段:半路径 + 全路径
        vo.setIdcardImg(shopInfo.getIdcardImg());
        vo.setIdcardImgUrl(StringUtils.isNotBlank(shopInfo.getIdcardImg()) ? imgPrefix + shopInfo.getIdcardImg() : null);
        vo.setIdcardImgBack(shopInfo.getIdcardImgBack());
        vo.setIdcardImgBackUrl(StringUtils.isNotBlank(shopInfo.getIdcardImgBack()) ? imgPrefix + shopInfo.getIdcardImgBack() : null);
        vo.setBusinessImg(shopInfo.getBusinessImg());
        vo.setBusinessImgUrl(StringUtils.isNotBlank(shopInfo.getBusinessImg()) ? imgPrefix + shopInfo.getBusinessImg() : null);
 
        // 查询附件
        QueryWrapper<Multifile> fileQw = new QueryWrapper<>();
        fileQw.lambda()
                .eq(Multifile::getObjId, shopInfo.getId())
                .eq(Multifile::getIsdeleted, Constants.ZERO)
                .in(Multifile::getObjType,
                        Constants.FileType.STORE_FRONT.getKey(),
                        Constants.FileType.STORE_INTERIOR.getKey(),
                        Constants.FileType.OTHER_MATERIAL.getKey(),
                        Constants.FileType.LABOR_CONTRACT.getKey(),
                        Constants.FileType.SOCIAL_SECURITY.getKey())
                .orderByAsc(Multifile::getObjType, Multifile::getSortnum);
        List<Multifile> files = multifileMapper.selectList(fileQw);
 
        // 按 objType 分组,半路径 + 全路径
        Map<Integer, List<String>> fileMap = new HashMap<>();
        Map<Integer, List<String>> fileUrlMap = new HashMap<>();
        for (Multifile f : files) {
            fileMap.computeIfAbsent(f.getObjType(), k -> new ArrayList<>()).add(f.getFileurl());
            String fullUrl = StringUtils.isNotBlank(f.getFileurl()) ? imgPrefix + f.getFileurl() : f.getFileurl();
            fileUrlMap.computeIfAbsent(f.getObjType(), k -> new ArrayList<>()).add(fullUrl);
        }
 
        vo.setStoreFrontImgs(fileMap.getOrDefault(Constants.FileType.STORE_FRONT.getKey(), new ArrayList<>()));
        vo.setStoreInteriorImgs(fileMap.getOrDefault(Constants.FileType.STORE_INTERIOR.getKey(), new ArrayList<>()));
        vo.setOtherMaterialImgs(fileMap.getOrDefault(Constants.FileType.OTHER_MATERIAL.getKey(), new ArrayList<>()));
        vo.setLaborContractImgs(fileMap.getOrDefault(Constants.FileType.LABOR_CONTRACT.getKey(), new ArrayList<>()));
        vo.setSocialSecurityImgs(fileMap.getOrDefault(Constants.FileType.SOCIAL_SECURITY.getKey(), new ArrayList<>()));
 
        vo.setStoreFrontImgUrls(fileUrlMap.getOrDefault(Constants.FileType.STORE_FRONT.getKey(), new ArrayList<>()));
        vo.setStoreInteriorImgUrls(fileUrlMap.getOrDefault(Constants.FileType.STORE_INTERIOR.getKey(), new ArrayList<>()));
        vo.setOtherMaterialImgUrls(fileUrlMap.getOrDefault(Constants.FileType.OTHER_MATERIAL.getKey(), new ArrayList<>()));
        vo.setLaborContractImgUrls(fileUrlMap.getOrDefault(Constants.FileType.LABOR_CONTRACT.getKey(), new ArrayList<>()));
        vo.setSocialSecurityImgUrls(fileUrlMap.getOrDefault(Constants.FileType.SOCIAL_SECURITY.getKey(), new ArrayList<>()));
 
        // 查询绑定开户会员头像(payMemberOpenId 关联 member.openid)
        if (StringUtils.isNotBlank(shopInfo.getPayMemberOpenId())) {
            QueryWrapper<Member> memberQw = new QueryWrapper<>();
            memberQw.lambda().eq(Member::getOpenid, shopInfo.getPayMemberOpenId()).last("limit 1");
            Member payMember = memberMapper.selectOne(memberQw);
            if (payMember != null && StringUtils.isNotBlank(payMember.getCoverImage())) {
                String memberPrefix = "";
                try {
                    memberPrefix = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.RESOURCE_PATH).getCode()
                            + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.MEMBER_FILES).getCode();
                } catch (Exception e) {
                    // 未配置时忽略
                }
                vo.setPayMemberCoverImage(memberPrefix + payMember.getCoverImage());
            }
        }
 
        return vo;
    }
 
    @Override
    public PageData<ShopNearbyVO> findNearbyShops(PageWrap<ShopNearbyDTO> pageWrap) {
        IPage<ShopInfo> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        ShopNearbyDTO dto = pageWrap.getModel();
        Double longitude = dto.getLongitude();
        Double latitude = dto.getLatitude();
        Integer sortType = dto.getSortType();
        Integer distanceMeter = dto.getDistance();
 
        // Haversine距离公式(单位km)
        String distanceFormula = "(6371 * acos(cos(radians(" + latitude + ")) * cos(radians(latitude)) " +
                "* cos(radians(longitude) - radians(" + longitude + ")) " +
                "+ sin(radians(" + latitude + ")) * sin(radians(latitude))))";
 
        QueryWrapper<ShopInfo> qw = new QueryWrapper<>();
        qw.lambda()
                .eq(ShopInfo::getDeleted, Constants.ZERO)
                .eq(ShopInfo::getStatus, Constants.ZERO)
                .eq(ShopInfo::getAuditStatus, Constants.THREE);
 
        // 门店营业类型筛选
        if (dto.getBusinessType() != null) {
            qw.lambda().eq(ShopInfo::getBusinessType, dto.getBusinessType());
        }
 
        // 门店名称模糊查询
        if (StringUtils.isNotBlank(dto.getName())) {
            qw.lambda().like(ShopInfo::getName, dto.getName());
        }
 
        // 距离筛选(单位:米 → 转换为km比较)
        if (distanceMeter != null && distanceMeter > 0) {
            double maxKm = distanceMeter / 1000.0;
            qw.apply(distanceFormula + " <= {0}", maxKm);
        }
 
        // 排序
        if (longitude != null && latitude != null) {
            if (sortType != null && sortType == 2) {
                // 按评分降序
                qw.last("ORDER BY score DESC");
            } else {
                // 默认:按距离升序
                qw.last("ORDER BY " + distanceFormula + " ASC");
            }
        } else {
            qw.lambda().orderByDesc(ShopInfo::getCreateTime);
        }
 
        IPage<ShopInfo> result = shopInfoMapper.selectPage(page, qw);
 
        // 图片前缀
        String imgPrefix = getShopPrefix();
 
        List<ShopNearbyVO> voList = new ArrayList<>();
        for (ShopInfo shop : result.getRecords()) {
            ShopNearbyVO vo = new ShopNearbyVO();
            vo.setId(shop.getId());
            vo.setName(shop.getName());
            vo.setShopHours(shop.getShopHours());
            vo.setAddress(shop.getAddress());
            vo.setScore(shop.getScore());
            // 门头照第一张
            vo.setCoverImg(getFirstImage(shop.getId(), Constants.FileType.STORE_FRONT.getKey(), imgPrefix));
            // 距离
            if (longitude != null && latitude != null && shop.getLongitude() != null && shop.getLatitude() != null) {
                double distKm = haversine(latitude, longitude, shop.getLatitude(), shop.getLongitude());
                vo.setDistanceText(formatDistance(distKm));
            }
            voList.add(vo);
        }
        IPage<ShopNearbyVO> vPage = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        PageData<ShopNearbyVO> pageData = PageData.from(vPage);
        pageData.setRecords(voList);
        pageData.setTotal(result.getTotal());
        pageData.setPage(result.getCurrent());
        pageData.setCapacity(result.getSize());
        return pageData;
    }
 
    @Override
    public ShopWebDetailVO getShopWebDetail(ShopDetailQueryDTO dto) {
        ShopInfo shop = shopInfoMapper.selectById(dto.getId());
        if (Objects.isNull(shop) || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
 
        ShopWebDetailVO vo = new ShopWebDetailVO();
        vo.setId(shop.getId());
        vo.setName(shop.getName());
        vo.setAddress(shop.getAddress());
        vo.setContent(shop.getContent());
 
        // 门头照 + 内部照 全路径集合
        String imgPrefix = getShopPrefix();
        List<String> images = new ArrayList<>();
        images.addAll(getImageList(dto.getId(), Constants.FileType.STORE_FRONT.getKey(), imgPrefix));
        images.addAll(getImageList(dto.getId(), Constants.FileType.STORE_INTERIOR.getKey(), imgPrefix));
        vo.setImages(images);
 
        // 距离
        if (dto.getLongitude() != null && dto.getLatitude() != null && shop.getLongitude() != null && shop.getLatitude() != null) {
            double distKm = haversine(dto.getLatitude(), dto.getLongitude(), shop.getLatitude(), shop.getLongitude());
            vo.setDistanceText(formatDistance(distKm));
        }
        return vo;
    }
 
    @Override
    public void maintainShopInfo(Integer memberId, ShopInfoMaintainDTO dto) {
        // 门店主键与会员主键一致
        ShopInfo shop = shopInfoMapper.selectById(memberId);
        if (Objects.isNull(shop) || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        // 需要支付完押金后才可维护(auditStatus >= 2)
        if (shop.getAuditStatus() == null || shop.getAuditStatus() < Constants.TWO) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "请先完成押金支付后再维护门店信息");
        }
        UpdateWrapper<ShopInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda()
                .eq(ShopInfo::getId, shop.getId())
                .set(ShopInfo::getUpdateTime, new Date())
                .set(dto.getCoverImg() != null, ShopInfo::getCoverImg, dto.getCoverImg())
                .set(dto.getContent() != null, ShopInfo::getContent, dto.getContent())
                .set(dto.getDepositTypes() != null, ShopInfo::getDepositTypes, dto.getDepositTypes())
                .set(dto.getFeeStandard() != null, ShopInfo::getFeeStandard, dto.getFeeStandard())
                .set(dto.getDeliveryArea() != null, ShopInfo::getDeliveryArea, dto.getDeliveryArea())
                .set(dto.getShopHours() != null, ShopInfo::getShopHours, dto.getShopHours())
                .set(dto.getBusinessType() != null, ShopInfo::getBusinessType, dto.getBusinessType());
        shopInfoMapper.update(updateWrapper);
    }
 
    @Override
    public ShopInfoMaintainDTO getShopMaintainInfo(Integer memberId) {
        ShopInfo shop = shopInfoMapper.selectById(memberId);
        if (Objects.isNull(shop) || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
            return null;
        }
        ShopInfoMaintainDTO dto = new ShopInfoMaintainDTO();
        dto.setCoverImg(shop.getCoverImg());
        dto.setContent(shop.getContent());
        dto.setDepositTypes(shop.getDepositTypes());
        dto.setFeeStandard(shop.getFeeStandard());
        dto.setDeliveryArea(shop.getDeliveryArea());
        dto.setShopHours(shop.getShopHours());
        dto.setBusinessType(shop.getBusinessType());
        return dto;
    }
 
    /**
     * Haversine公式计算两点间距离(km)
     */
    private double haversine(double lat1, double lng1, double lat2, double lng2) {
        double R = 6371;
        double dLat = Math.toRadians(lat2 - lat1);
        double dLng = Math.toRadians(lng2 - lng1);
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
                + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2))
                * Math.sin(dLng / 2) * Math.sin(dLng / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        return R * c;
    }
 
    /**
     * 格式化距离:小于1km显示米,大于等于1km显示千米(保留1位小数)
     */
    private String formatDistance(double km) {
        if (km < 1) {
            return Math.round(km * 1000) + "m";
        }
        return String.format("%.1fkm", km);
    }
 
    /**
     * 获取门店图片前缀
     */
    private String getShopPrefix() {
        try {
            return systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.RESOURCE_PATH).getCode()
                    + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SHOP_FILES).getCode();
        } catch (Exception e) {
            return "";
        }
    }
 
    /**
     * 获取门店指定类型的第一张图片全路径
     */
    private String getFirstImage(Integer shopId, int objType, String imgPrefix) {
        QueryWrapper<Multifile> qw = new QueryWrapper<>();
        qw.lambda()
                .eq(Multifile::getObjId, shopId)
                .eq(Multifile::getObjType, objType)
                .eq(Multifile::getIsdeleted, Constants.ZERO)
                .orderByAsc(Multifile::getSortnum)
                .last("limit 1");
        Multifile f = multifileMapper.selectOne(qw);
        return f != null && StringUtils.isNotBlank(f.getFileurl()) ? imgPrefix + f.getFileurl() : null;
    }
 
    /**
     * 获取门店指定类型的所有图片全路径
     */
    private List<String> getImageList(Integer shopId, int objType, String imgPrefix) {
        QueryWrapper<Multifile> qw = new QueryWrapper<>();
        qw.lambda()
                .eq(Multifile::getObjId, shopId)
                .eq(Multifile::getObjType, objType)
                .eq(Multifile::getIsdeleted, Constants.ZERO)
                .orderByAsc(Multifile::getSortnum);
        List<Multifile> files = multifileMapper.selectList(qw);
        List<String> urls = new ArrayList<>();
        for (Multifile f : files) {
            if (StringUtils.isNotBlank(f.getFileurl())) {
                urls.add(imgPrefix + f.getFileurl());
            }
        }
        return urls;
    }
 
 
 
    /**
     * 商户账号密码登录
     * @param dto
     * @return
             */
    @Override
    public ShopLoginVO shopPasswordLogin(ShopLoginDTO dto){
        if(StringUtils.isBlank(dto.getTelephone())
                || StringUtils.isBlank(dto.getPassword())
                || StringUtils.isBlank(dto.getOpenid())
        ){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户名或密码不能为空");
        }
        ShopInfo shop = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda().eq(ShopInfo::getTelephone, dto.getTelephone())
                .eq(ShopInfo::getDeleted,Constants.ZERO)
                .last("limit 1")
        );
        if(shop==null){
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
        }
        //加密密码
        String pwd = Utils.Secure.encryptPassword( dto.getPassword(), shop.getSalt());
        if(!pwd.equals(shop.getPassword())){
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
        }
 
        // 更新当前登录会员的openid到门店
        if(StringUtils.isNotBlank(dto.getOpenid())){
            shopInfoMapper.update(null,new UpdateWrapper<ShopInfo>().lambda()
                    .set(ShopInfo::getOpenid,dto.getOpenid())
                    .eq(ShopInfo::getId,shop.getId())
            );
            // 清空其他门店的同一openid,保证唯一
            shopInfoMapper.update(null,new UpdateWrapper<ShopInfo>().lambda()
                    .set(ShopInfo::getOpenid,null)
                    .eq(ShopInfo::getOpenid,dto.getOpenid())
                    .ne(ShopInfo::getId,shop.getId())
            );
            shop.setOpenid(dto.getOpenid());
        }
 
        // 创建token(generateTokenForRedis 已自动清除该用户旧token,保证唯一有效)
        String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate);
 
        // 构建响应
        ShopLoginVO vo = new ShopLoginVO();
        vo.setToken(token);
        vo.setShopId(shop.getId());
        vo.setShopName(shop.getName());
        vo.setCompanyType(shop.getCompanyType());
 
        // 所属城市名称
        Areas area = areasBiz.resolveArea(shop.getAreaId());
        if (area != null) {
            vo.setCityName(area.getCityName());
        }
        return vo;
    }
 
    @Override
    public ShopLoginVO shopSilentLogin(String openid) {
        if (StringUtils.isBlank(openid)) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "openid不能为空");
        }
        ShopInfo shop = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda()
                .eq(ShopInfo::getOpenid, openid)
                .eq(ShopInfo::getDeleted, Constants.ZERO)
                .last("limit 1"));
        if (shop == null) {
            return null;
        }
 
        // 创建token(generateTokenForRedis 已自动清除该用户旧token,保证唯一有效)
        String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate);
 
        ShopLoginVO vo = new ShopLoginVO();
        vo.setToken(token);
        vo.setShopId(shop.getId());
        vo.setShopName(shop.getName());
        vo.setCompanyType(shop.getCompanyType());
 
        Areas area = areasBiz.resolveArea(shop.getAreaId());
        if (area != null) {
            vo.setCityName(area.getCityName());
        }
        return vo;
    }
 
}