From 33caf2bb79bb3c561916c91ae386ec772411e2e8 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期一, 11 五月 2026 18:21:50 +0800
Subject: [PATCH] 代码生成

---
 server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java |  797 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 624 insertions(+), 173 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
index efd4e45..149dd06 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
@@ -14,6 +14,7 @@
 import com.doumee.core.utils.Utils;
 import com.doumee.biz.system.AreasBiz;
 import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.utils.aliyun.AliSmsService;
 import com.doumee.dao.business.MemberMapper;
 import com.doumee.dao.business.MultifileMapper;
 import com.doumee.dao.business.OrdersMapper;
@@ -25,7 +26,14 @@
 import com.doumee.dao.business.model.Orders;
 import com.doumee.dao.business.model.PricingRule;
 import com.doumee.dao.business.model.ShopInfo;
+import com.doumee.config.xyy.XyyConfig;
+import com.doumee.config.xyy.dto.AddPrinterRequest;
+import com.doumee.config.xyy.dto.AddPrinterRequestItem;
+import com.doumee.config.xyy.dto.DelPrinterRequest;
+import com.doumee.config.xyy.vo.ObjectRestResponse;
+import com.doumee.config.xyy.vo.PrinterResult;
 import com.doumee.dao.dto.*;
+import com.doumee.dao.system.model.SystemDictData;
 import com.doumee.dao.system.SystemUserMapper;
 import com.doumee.dao.system.model.SystemUser;
 import com.doumee.dao.vo.ShopDetailVO;
@@ -36,6 +44,9 @@
 import com.doumee.dao.vo.ShopWebDetailVO;
 import com.doumee.service.business.AreasService;
 import com.doumee.service.business.ShopInfoService;
+import com.doumee.dao.business.SmsrecordMapper;
+import com.doumee.dao.business.model.Smsrecord;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.RandomStringUtils;
@@ -52,6 +63,7 @@
  * @author rk
  * @date 2026/04/08
  */
+@Slf4j
 @Service
 public class ShopInfoServiceImpl implements ShopInfoService {
 
@@ -84,6 +96,15 @@
 
     @Autowired
     private AreasService areasService;
+
+    @Autowired
+    private SmsrecordMapper smsrecordMapper;
+
+    @Autowired
+    private PrintService printService;
+
+    @Autowired
+    private XyyConfig xyyConfig;
     @Override
     public Integer create(ShopInfo shopInfo) {
         shopInfoMapper.insert(shopInfo);
@@ -198,6 +219,9 @@
         if (pageWrap.getModel().getAreaId() != null) {
             queryWrapper.lambda().eq(ShopInfo::getAreaId, pageWrap.getModel().getAreaId());
         }
+        if (pageWrap.getModel().getAddress() != null) {
+            queryWrapper.lambda().like(ShopInfo::getAddress, pageWrap.getModel().getAddress());
+        }
         if (pageWrap.getModel().getAuditStatus() != null) {
             queryWrapper.lambda().eq(ShopInfo::getAuditStatus, pageWrap.getModel().getAuditStatus());
         }
@@ -217,13 +241,7 @@
         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());
-            }
-        }
+        queryWrapper.lambda().orderByDesc(ShopInfo::getId);
         return PageData.from(shopInfoMapper.selectPage(page, queryWrapper));
     }
 
@@ -240,10 +258,105 @@
     public void applyShop(ShopApplyDTO request) {
         Member member = memberMapper.selectById(request.getMemberId());
 
+        // 鏍规嵁绫诲瀷鏍¢獙闄勪欢
+        validateCompanyTypeFields(request);
 
-        // 2. 鏍规嵁绫诲瀷鏍¢獙闄勪欢
+        Date now = new Date();
+
+        // 鏌ヨ璇ヤ細鍛樻渶鏂扮殑鍙樻洿鐗堟湰璁板綍
+        QueryWrapper<ShopInfo> changeQw = new QueryWrapper<>();
+        changeQw.lambda()
+                .eq(ShopInfo::getRegionMemberId, member.getId())
+                .eq(ShopInfo::getVersionType, Constants.ONE)
+                .eq(ShopInfo::getDeleted, Constants.ZERO)
+                .orderByDesc(ShopInfo::getCreateTime)
+                .last("limit 1");
+        ShopInfo changeVersion = shopInfoMapper.selectOne(changeQw);
+
+        if (changeVersion == null) {
+            // 棣栨鐢宠锛氬垱寤烘寮忕増鏈� + 鍙樻洿鐗堟湰
+            checkTelephoneUnique(request.getTelephone(), null);
+
+            String rawPassword = generateDefaultPassword(request.getTelephone());
+            String salt = RandomStringUtils.randomAlphabetic(6);
+            String encryptedPassword = Utils.Secure.encryptPassword(rawPassword, salt);
+
+            // 姝e紡鐗堟湰
+            ShopInfo official = new ShopInfo();
+            applyFieldsFromRequest(official, request, member, encryptedPassword, salt, now);
+            official.setVersionType(Constants.ZERO);
+            official.setAuditStatus(Constants.ZERO);
+            official.setStatus(Constants.ZERO);
+            official.setDeleted(Constants.ZERO);
+            official.setCreateTime(now);
+            official.setUpdateTime(now);
+            official.setRegionMemberId(member.getId());
+            setDepositAmountFromPricingRule(official);
+            setDefaultDeliveryRange(official);
+            shopInfoMapper.insert(official);
+
+            // 淇濆瓨姝e紡鐗堟湰闄勪欢
+            saveShopAttachments(official.getId(), request, now);
+
+            // 鍒涘缓鍙樻洿鐗堟湰锛堟嫹璐濇寮忕増鏈暟鎹級
+            createChangeVersion(official, official.getId(), now);
+        } else if (Constants.equalsInteger(changeVersion.getAuditStatus(), Constants.ONE)) {
+            // 瀹℃壒閫氳繃寰呮敮浠樻娂閲�
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "闂ㄥ簵宸插鎵归�氳繃锛岃瀹屾垚鎶奸噾鏀粯");
+        } else if (Constants.equalsInteger(changeVersion.getAuditStatus(), Constants.THREE)) {
+            // 鏈�鏂板彉鏇寸増鏈凡鏀粯鎶奸噾(status=3)锛氱敓鎴愭柊鐨勫彉鏇寸増鏈�
+            Integer relationShopId = changeVersion.getRelationShopId();
+
+            // 鏍¢獙鎵嬫満鍙峰敮涓�鎬э紙鎺掗櫎姝e紡鐗堟湰鍜屽彉鏇寸増鏈級
+            checkTelephoneUnique(request.getTelephone(), relationShopId);
+
+            String rawPassword = generateDefaultPassword(request.getTelephone());
+            String salt = RandomStringUtils.randomAlphabetic(6);
+            String encryptedPassword = Utils.Secure.encryptPassword(rawPassword, salt);
+
+            ShopInfo newChange = new ShopInfo();
+            applyFieldsFromRequest(newChange, request, member, encryptedPassword, salt, now);
+            newChange.setVersionType(Constants.ONE);
+            newChange.setRelationShopId(relationShopId);
+            newChange.setAuditStatus(Constants.ZERO);
+            newChange.setStatus(Constants.ZERO);
+            newChange.setDeleted(Constants.ZERO);
+            newChange.setCreateTime(now);
+            newChange.setUpdateTime(now);
+            newChange.setRegionMemberId(member.getId());
+            setDepositAmountFromPricingRule(newChange);
+            shopInfoMapper.insert(newChange);
+
+            // 淇濆瓨鏂板彉鏇寸増鏈檮浠�
+            saveShopAttachments(newChange.getId(), request, now);
+        } else {
+            // 鏈�鏂板彉鏇寸増鏈� status=0(寰呭鎵�) 鎴� 2(琚┏鍥�)锛氱洿鎺ユ洿鏂�
+            Integer relationShopId = changeVersion.getRelationShopId();
+
+            // 鏍¢獙鎵嬫満鍙峰敮涓�鎬�
+            checkTelephoneUnique(request.getTelephone(), relationShopId);
+
+            String rawPassword = generateDefaultPassword(request.getTelephone());
+            String salt = RandomStringUtils.randomAlphabetic(6);
+            String encryptedPassword = Utils.Secure.encryptPassword(rawPassword, salt);
+
+            applyFieldsFromRequest(changeVersion, request, member, encryptedPassword, salt, now);
+            changeVersion.setAuditStatus(Constants.ZERO);
+            changeVersion.setAuditRemark(null);
+            changeVersion.setAuditTime(null);
+            changeVersion.setAuditUserId(null);
+            changeVersion.setUpdateTime(now);
+            setDepositAmountFromPricingRule(changeVersion);
+            shopInfoMapper.updateById(changeVersion);
+
+            // 鍒犻櫎鏃ч檮浠� + 淇濆瓨鏂伴檮浠�
+            deleteShopAttachments(changeVersion.getId());
+            saveShopAttachments(changeVersion.getId(), request, now);
+        }
+    }
+
+    private void validateCompanyTypeFields(ShopApplyDTO request) {
         if (Constants.equalsInteger(request.getCompanyType(), Constants.ZERO)) {
-            // 涓汉绫诲瀷锛氬繀椤讳笂浼犲姵鍔ㄥ悎鍚屽拰绀句繚璇佹槑
             if (CollectionUtils.isEmpty(request.getLaborContractImgs())) {
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "涓汉绫诲瀷蹇呴』涓婁紶鏈夋晥鍔冲姩鍚堝悓");
             }
@@ -251,7 +364,6 @@
                 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(), "浼佷笟绫诲瀷蹇呴』涓婁紶钀ヤ笟鎵х収");
             }
@@ -265,98 +377,43 @@
                 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);
+    private void applyFieldsFromRequest(ShopInfo shop, ShopApplyDTO request, Member member,
+                                        String password, String salt, Date now) {
+        shop.setCompanyType(request.getCompanyType());
+        shop.setName(request.getName());
+        shop.setTelephone(request.getTelephone());
+        shop.setLinkName(request.getLinkName());
+        shop.setLinkPhone(request.getLinkPhone());
+        shop.setIdcard(request.getIdcard());
+        shop.setAreaId(request.getAreaId());
+        shop.setLongitude(request.getLongitude());
+        shop.setLatitude(request.getLatitude());
+        shop.setAddress(request.getAddress());
+        shop.setIdcardImg(request.getIdcardImg());
+        shop.setIdcardImgBack(request.getIdcardImgBack());
+        shop.setBusinessImg(request.getBusinessImg());
+        shop.setLegalPersonName(request.getLegalPersonName());
+        shop.setLegalPersonPhone(request.getLegalPersonPhone());
+        shop.setLegalPersonCard(request.getLegalPersonCard());
+        shop.setPassword(password);
+        shop.setSalt(salt);
+        shop.setAliAccount(request.getAliAccount());
+        shop.setAliName(request.getAliName());
+        shop.setRevenueShareConfig(buildRevenueShareConfig(request.getLocalDeposit(), request.getRemoteDeposit(), request.getRemoteTake()));
+        shop.setOpenid(member.getOpenid());
+    }
 
-        // 3. 鏌ヨ璇ヤ細鍛樻槸鍚﹀凡鏈夐棬搴楄褰�
-        QueryWrapper<ShopInfo> existQw = new QueryWrapper<>();
-        existQw.lambda()
-                .eq(ShopInfo::getRegionMemberId, member.getId())
-                .eq(ShopInfo::getDeleted, Constants.ZERO)
-                .last("limit 1");
-        ShopInfo existing = shopInfoMapper.selectOne(existQw);
+    private void saveShopAttachments(Integer shopId, ShopApplyDTO request, Date now) {
+        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);
+    }
 
-        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.setAliAccount(request.getAliAccount());
-            existing.setAliName(request.getAliName());
-            existing.setUpdateTime(now);
-            existing.setAuditRemark(null);
-            existing.setAuditTime(null);
-            existing.setAuditUserId(null);
-            existing.setAuditStatus(Constants.ZERO);
-            shopInfoMapper.updateById(existing);
-            shopId = existing.getId();
-        } else {
-            // 1. 鏍¢獙闂ㄥ簵鎵嬫満鍙峰敮涓�鎬э紙shop_info.telephone锛�
-            checkTelephoneUnique(request.getTelephone(), null);
-            // 鏂板缓
-            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.setAliAccount(request.getAliAccount());
-            shopInfo.setAliName(request.getAliName());
-            shopInfo.setStatus(Constants.ZERO);
-            shopInfo.setDeleted(Constants.ZERO);
-            shopInfo.setCreateTime(now);
-            shopInfo.setUpdateTime(now);
-            shopInfo.setRegionMemberId(member.getId());
-            shopInfoMapper.insert(shopInfo);
-            shopId = shopInfo.getId();
-        }
-
-        // 4. 鍒犻櫎鏃ч檮浠惰褰�
+    private void deleteShopAttachments(Integer shopId) {
         multifileMapper.delete(new QueryWrapper<Multifile>().lambda()
                 .eq(Multifile::getObjId, shopId)
                 .in(Multifile::getObjType,
@@ -365,13 +422,6 @@
                         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
@@ -385,12 +435,25 @@
 
     @Override
     public ShopDetailVO getMyShop(Integer memberId) {
+        // 鏌ヨ鏈�鏂扮殑鍙樻洿鐗堟湰
         QueryWrapper<ShopInfo> qw = new QueryWrapper<>();
         qw.lambda()
                 .eq(ShopInfo::getRegionMemberId, memberId)
+                .eq(ShopInfo::getVersionType, Constants.ONE)
                 .eq(ShopInfo::getDeleted, Constants.ZERO)
+                .orderByDesc(ShopInfo::getCreateTime)
                 .last("limit 1");
         ShopInfo shopInfo = shopInfoMapper.selectOne(qw);
+        if (shopInfo == null) {
+            // 鏃犲彉鏇寸増鏈垯鏌ユ寮忕増鏈�
+            QueryWrapper<ShopInfo> officialQw = new QueryWrapper<>();
+            officialQw.lambda()
+                    .eq(ShopInfo::getRegionMemberId, memberId)
+                    .eq(ShopInfo::getVersionType, Constants.ZERO)
+                    .eq(ShopInfo::getDeleted, Constants.ZERO)
+                    .last("limit 1");
+            shopInfo = shopInfoMapper.selectOne(officialQw);
+        }
         if (shopInfo == null) {
             return null;
         }
@@ -407,55 +470,166 @@
                 || (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)) {
+        // 瀹℃壒鐨勬槸鍙樻洿鐗堟湰
+        ShopInfo changeVersion = shopInfoMapper.selectById(auditDTO.getId());
+        if (changeVersion == null || Constants.equalsInteger(changeVersion.getDeleted(), Constants.ONE)) {
             throw new BusinessException(ResponseStatus.DATA_EMPTY);
         }
-        if (!Constants.equalsInteger(shopInfo.getAuditStatus(), Constants.ZERO)) {
+        if (!Constants.equalsInteger(changeVersion.getAuditStatus(), Constants.ZERO)) {
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠鐘舵�佷笉鍏佽瀹℃壒");
         }
 
         Date now = new Date();
-        // auditDTO.auditStatus: 0=閫氳繃 鈫� auditStatus=1, 1=椹冲洖 鈫� auditStatus=2
+        // auditDTO.auditStatus: 0=閫氳繃 鈫� 1, 1=椹冲洖 鈫� 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);
-        // 瀹℃壒閫氳繃鏃讹紝鏍¢獙鍩庡競pricing_rule閰嶇疆锛岃鍙栨娂閲戦噾棰�
-        if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) {
-            // 1. 瑙f瀽闂ㄥ簵鎵�鍦ㄥ煄甯�
-            Areas area = areasBiz.resolveArea(shopInfo.getAreaId());
-            if (area == null || area.getParentId() == null) {
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "闂ㄥ簵鍖哄垝淇℃伅寮傚父锛屾棤娉曠‘瀹氭墍鍦ㄥ煄甯�");
-            }
-            Integer cityId = area.getParentId();
 
-            // 2. 鏍¢獙 pricing_rule 閰嶇疆锛堝煄甯傚紑閫氬湪鎶奸噾鏀粯瀹屾垚鍚庡鐞嗭級
-            Areas cityArea = areasService.findById(cityId, Constants.ONE);
-            if (cityArea == null) {
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍩庡競淇℃伅涓嶅瓨鍦�");
+        // 鏌ユ壘姝e紡鐗堟湰
+        Integer officialId = changeVersion.getRelationShopId();
+        ShopInfo official = officialId != null ? shopInfoMapper.selectById(officialId) : null;
+        boolean hasPaidOfficial = official != null
+                && Constants.equalsInteger(official.getAuditStatus(), Constants.THREE);
+
+        if (!hasPaidOfficial) {
+            // 鍦烘櫙1锛氫笉瀛樺湪auditStatus=3鐨勬寮忕増鏈紙棣栨瀹℃壒锛�
+            changeVersion.setAuditStatus(newAuditStatus);
+            changeVersion.setAuditTime(now);
+            changeVersion.setAuditRemark(auditDTO.getAuditRemark());
+            changeVersion.setAuditUserId(auditDTO.getAuditUser());
+            changeVersion.setUpdateTime(now);
+
+            if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) {
+                validateCityAndSetDeposit(changeVersion);
             }
-            if (!Constants.equalsInteger(cityArea.getStatus(), Constants.ONE)) {
-                List<String> errors = validateCityPricingRules(cityId);
-                if (!errors.isEmpty()) {
-                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
-                            "鍩庡競[" + cityArea.getName() + "]灏氭湭寮�閫氾紝瀹氫环瑙勫垯鏈厤缃畬鏁达細" + String.join("锛�", errors));
+            shopInfoMapper.updateById(changeVersion);
+
+            // 鍚屾鏇存柊姝e紡鐗堟湰瀹℃壒鐘舵��
+            if (official != null) {
+                official.setAuditStatus(newAuditStatus);
+                official.setAuditTime(now);
+                official.setAuditRemark(auditDTO.getAuditRemark());
+                official.setAuditUserId(auditDTO.getAuditUser());
+                official.setUpdateTime(now);
+                if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) {
+                    official.setDepositAmount(changeVersion.getDepositAmount());
                 }
+                shopInfoMapper.updateById(official);
             }
 
-            // 3. 浠嶱ricingRule璇诲彇鎶奸噾閲戦
-            PricingRule pricingRule = pricingRuleMapper.selectOne(new QueryWrapper<PricingRule>().lambda()
-                    .eq(PricingRule::getDeleted, Constants.ZERO)
-                    .eq(PricingRule::getType, Constants.THREE)
-                    .eq(PricingRule::getFieldA, String.valueOf(shopInfo.getCompanyType()))
-                    .last("limit 1"));
-            if (pricingRule != null && StringUtils.isNotBlank(pricingRule.getFieldB())) {
-                shopInfo.setDepositAmount(Long.parseLong(pricingRule.getFieldB()));
+            // 鐭俊閫氱煡
+            sendAuditSms(changeVersion, newAuditStatus, auditDTO.getAuditRemark());
+        } else {
+            // 鍦烘櫙2锛氬瓨鍦╝uditStatus=3鐨勬寮忕増鏈紙鍙樻洿瀹℃壒锛�
+            if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) {
+                // 瀹℃壒閫氳繃锛氬彉鏇寸増鏈洿鎺ユ爣璁癮uditStatus=3锛屽悓姝ユ暟鎹埌姝e紡鐗堟湰
+                changeVersion.setAuditStatus(Constants.THREE);
+                changeVersion.setAuditTime(now);
+                changeVersion.setAuditRemark(auditDTO.getAuditRemark());
+                changeVersion.setAuditUserId(auditDTO.getAuditUser());
+                changeVersion.setUpdateTime(now);
+                shopInfoMapper.updateById(changeVersion);
+
+                // 鍚屾鍙樻洿鐗堟湰鏁版嵁鍒版寮忕増鏈�
+                syncChangeToOfficial(changeVersion, official, now);
+            } else {
+                // 瀹℃壒椹冲洖锛氫粎鏍囪鍙樻洿鐗堟湰鐘舵��
+                changeVersion.setAuditStatus(Constants.TWO);
+                changeVersion.setAuditTime(now);
+                changeVersion.setAuditRemark(auditDTO.getAuditRemark());
+                changeVersion.setAuditUserId(auditDTO.getAuditUser());
+                changeVersion.setUpdateTime(now);
+                shopInfoMapper.updateById(changeVersion);
             }
         }
-        shopInfoMapper.updateById(shopInfo);
+    }
+
+    private void validateCityAndSetDeposit(ShopInfo shopInfo) {
+        Areas area = areasBiz.resolveArea(shopInfo.getAreaId());
+        if (area == null || area.getParentId() == null) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "闂ㄥ簵鍖哄垝淇℃伅寮傚父锛屾棤娉曠‘瀹氭墍鍦ㄥ煄甯�");
+        }
+        Integer cityId = area.getParentId();
+        Areas cityArea = areasService.findById(cityId, Constants.ONE);
+        if (cityArea == null) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍩庡競淇℃伅涓嶅瓨鍦�");
+        }
+        if (!Constants.equalsInteger(cityArea.getStatus(), Constants.ONE)) {
+            List<String> errors = validateCityPricingRules(cityId);
+            if (!errors.isEmpty()) {
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
+                        "鍩庡競[" + cityArea.getName() + "]灏氭湭寮�閫氾紝瀹氫环瑙勫垯鏈厤缃畬鏁达細" + String.join("锛�", errors));
+            }
+        }
+        setDepositAmountFromPricingRule(shopInfo);
+    }
+
+    private void syncChangeToOfficial(ShopInfo changeVersion, ShopInfo official, Date now) {
+        official.setCompanyType(changeVersion.getCompanyType());
+        official.setName(changeVersion.getName());
+        official.setTelephone(changeVersion.getTelephone());
+        official.setLinkName(changeVersion.getLinkName());
+        official.setLinkPhone(changeVersion.getLinkPhone());
+        official.setIdcard(changeVersion.getIdcard());
+        official.setAreaId(changeVersion.getAreaId());
+        official.setLongitude(changeVersion.getLongitude());
+        official.setLatitude(changeVersion.getLatitude());
+        official.setAddress(changeVersion.getAddress());
+        official.setIdcardImg(changeVersion.getIdcardImg());
+        official.setIdcardImgBack(changeVersion.getIdcardImgBack());
+        official.setBusinessImg(changeVersion.getBusinessImg());
+        official.setLegalPersonName(changeVersion.getLegalPersonName());
+        official.setLegalPersonPhone(changeVersion.getLegalPersonPhone());
+        official.setLegalPersonCard(changeVersion.getLegalPersonCard());
+        official.setPassword(changeVersion.getPassword());
+        official.setSalt(changeVersion.getSalt());
+        official.setAliAccount(changeVersion.getAliAccount());
+        official.setAliName(changeVersion.getAliName());
+        official.setRevenueShareConfig(changeVersion.getRevenueShareConfig());
+        official.setDepositAmount(changeVersion.getDepositAmount());
+        official.setUpdateTime(now);
+        shopInfoMapper.updateById(official);
+
+        // 鍚屾闄勪欢锛氬厛鍒犳寮忕増鏈棫闄勪欢锛屽啀浠庡彉鏇寸増鏈嫹璐�
+        deleteShopAttachments(official.getId());
+        List<Multifile> changeFiles = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
+                .eq(Multifile::getObjId, changeVersion.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()));
+        for (Multifile f : changeFiles) {
+            Multifile copy = new Multifile();
+            copy.setCreator(f.getCreator());
+            copy.setCreateDate(now);
+            copy.setIsdeleted(Constants.ZERO);
+            copy.setName(f.getName());
+            copy.setInfo(f.getInfo());
+            copy.setObjId(official.getId());
+            copy.setType(f.getType());
+            copy.setObjType(f.getObjType());
+            copy.setFileurl(f.getFileurl());
+            copy.setSortnum(f.getSortnum());
+            multifileMapper.insert(copy);
+        }
+    }
+
+    private void sendAuditSms(ShopInfo shopInfo, Integer newAuditStatus, String auditRemark) {
+        if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) {
+            String depositMoney = shopInfo.getDepositAmount() != null
+                    ? new java.math.BigDecimal(shopInfo.getDepositAmount())
+                        .divide(new java.math.BigDecimal(100), 2, java.math.RoundingMode.HALF_UP).toPlainString() : "0";
+            sendSmsNotify(shopInfo.getTelephone(),
+                    Constants.SmsNotify.SHOP_AUTH_APPROVED_DEPOSIT,
+                    "storeName", shopInfo.getName(),
+                    "money", depositMoney);
+        } else if (Constants.equalsInteger(newAuditStatus, Constants.TWO)) {
+            sendSmsNotify(shopInfo.getTelephone(),
+                    Constants.SmsNotify.SHOP_AUTH_REJECTED,
+                    "storeName", shopInfo.getName(),
+                    "reason", auditRemark != null ? auditRemark : "");
+        }
     }
 
     @Override
@@ -555,6 +729,7 @@
         shopInfo.setLegalPersonCard(request.getLegalPersonCard());
         shopInfo.setAliAccount(request.getAliAccount());
         shopInfo.setAliName(request.getAliName());
+        shopInfo.setRevenueShareConfig(buildRevenueShareConfig(request.getLocalDeposit(), request.getRemoteDeposit(), request.getRemoteTake()));
         shopInfo.setUpdateTime(now);
         shopInfoMapper.updateById(shopInfo);
 
@@ -586,6 +761,81 @@
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鎵嬫満鍙锋牸寮忓紓甯革紝鏃犳硶鐢熸垚榛樿瀵嗙爜");
         }
         return telephone.substring(telephone.length() - 6) + "@123456";
+    }
+
+    private String buildRevenueShareConfig(Double localDeposit, Double remoteDeposit, Double remoteTake) {
+        if (localDeposit == null && remoteDeposit == null && remoteTake == null) {
+            return null;
+        }
+        JSONObject config = new JSONObject();
+        if (localDeposit != null) {
+            config.put("localDeposit", localDeposit);
+        }
+        if (remoteDeposit != null) {
+            config.put("remoteDeposit", remoteDeposit);
+        }
+        if (remoteTake != null) {
+            config.put("remoteTake", remoteTake);
+        }
+        return config.toJSONString();
+    }
+
+    private void createChangeVersion(ShopInfo origin, Integer originShopId, Date now) {
+        ShopInfo changeShop = new ShopInfo();
+        changeShop.setCompanyType(origin.getCompanyType());
+        changeShop.setName(origin.getName());
+        changeShop.setTelephone(origin.getTelephone());
+        changeShop.setLinkName(origin.getLinkName());
+        changeShop.setLinkPhone(origin.getLinkPhone());
+        changeShop.setIdcard(origin.getIdcard());
+        changeShop.setAreaId(origin.getAreaId());
+        changeShop.setLongitude(origin.getLongitude());
+        changeShop.setLatitude(origin.getLatitude());
+        changeShop.setAddress(origin.getAddress());
+        changeShop.setIdcardImg(origin.getIdcardImg());
+        changeShop.setIdcardImgBack(origin.getIdcardImgBack());
+        changeShop.setBusinessImg(origin.getBusinessImg());
+        changeShop.setLegalPersonName(origin.getLegalPersonName());
+        changeShop.setLegalPersonPhone(origin.getLegalPersonPhone());
+        changeShop.setLegalPersonCard(origin.getLegalPersonCard());
+        changeShop.setAliAccount(origin.getAliAccount());
+        changeShop.setAliName(origin.getAliName());
+        changeShop.setDepositAmount(origin.getDepositAmount());
+        changeShop.setRevenueShareConfig(origin.getRevenueShareConfig());
+        changeShop.setVersionType(Constants.ONE);
+        changeShop.setRelationShopId(originShopId);
+        changeShop.setRegionMemberId(origin.getRegionMemberId());
+        changeShop.setOpenid(origin.getOpenid());
+        changeShop.setStatus(Constants.ZERO);
+        changeShop.setDeleted(Constants.ZERO);
+        changeShop.setCreateTime(now);
+        changeShop.setUpdateTime(now);
+        shopInfoMapper.insert(changeShop);
+
+        // 鎷疯礉闄勪欢鍒板彉鏇寸増鏈�
+        List<Multifile> originFiles = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
+                .eq(Multifile::getObjId, originShopId)
+                .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()));
+        for (Multifile f : originFiles) {
+            Multifile copy = new Multifile();
+            copy.setCreator(f.getCreator());
+            copy.setCreateDate(now);
+            copy.setIsdeleted(Constants.ZERO);
+            copy.setName(f.getName());
+            copy.setInfo(f.getInfo());
+            copy.setObjId(changeShop.getId());
+            copy.setType(f.getType());
+            copy.setObjType(f.getObjType());
+            copy.setFileurl(f.getFileurl());
+            copy.setSortnum(f.getSortnum());
+            multifileMapper.insert(copy);
+        }
     }
 
     private void checkTelephoneUnique(String telephone, Integer excludeId) {
@@ -661,6 +911,21 @@
         vo.setAliAccount(shopInfo.getAliAccount());
         vo.setAliName(shopInfo.getAliName());
         vo.setDepositAmount(shopInfo.getDepositAmount());
+        vo.setDeliveryRange(shopInfo.getDeliveryArea());
+        vo.setVersionType(shopInfo.getVersionType());
+        vo.setRelationShopId(shopInfo.getRelationShopId());
+        // 瑙f瀽鏀剁泭姣斾緥閰嶇疆
+        if (StringUtils.isNotBlank(shopInfo.getRevenueShareConfig())) {
+            try {
+                JSONObject config = JSONObject.parseObject(shopInfo.getRevenueShareConfig());
+                if (config != null) {
+                    vo.setLocalDeposit(config.getDouble("localDeposit"));
+                    vo.setRemoteDeposit(config.getDouble("remoteDeposit"));
+                    vo.setRemoteTake(config.getDouble("remoteTake"));
+                }
+            } catch (Exception ignored) {
+            }
+        }
 
         // 鎷兼帴鍥剧墖鍓嶇紑
         String imgPrefix = "";
@@ -732,6 +997,13 @@
             }
         }
 
+        // 闂ㄥ簵澶村儚锛氫紭鍏堜娇鐢� coverImg锛屼负绌哄垯鍙栭棬澶寸収绗竴寮�
+        if (StringUtils.isNotBlank(shopInfo.getCoverImg())) {
+            vo.setShopAvatar(imgPrefix + shopInfo.getCoverImg());
+        } else if (!CollectionUtils.isEmpty(vo.getStoreFrontImgUrls())) {
+            vo.setShopAvatar(vo.getStoreFrontImgUrls().get(0));
+        }
+
         return vo;
     }
 
@@ -753,6 +1025,7 @@
         qw.lambda()
                 .eq(ShopInfo::getDeleted, Constants.ZERO)
                 .eq(ShopInfo::getStatus, Constants.ZERO)
+                .eq(ShopInfo::getVersionType, Constants.ZERO)
                 .eq(ShopInfo::getAuditStatus, Constants.THREE);
 
         // 闂ㄥ簵钀ヤ笟绫诲瀷绛涢��
@@ -762,7 +1035,8 @@
 
         // 闂ㄥ簵鍚嶇О妯$硦鏌ヨ
         if (StringUtils.isNotBlank(dto.getName())) {
-            qw.lambda().like(ShopInfo::getName, dto.getName());
+            qw.lambda().and(q -> q.like(ShopInfo::getName, dto.getName()).or()
+                    .like(ShopInfo::getAddress, dto.getName()));
         }
 
         // 鍩庡競绛涢�夛紙areaId鏄尯鍘匡紝闇�鍖归厤鍏秔arentId绛変簬鍩庡競ID锛�
@@ -826,7 +1100,7 @@
     @Override
     public ShopWebDetailVO getShopWebDetail(ShopDetailQueryDTO dto) {
         ShopInfo shop = shopInfoMapper.selectById(dto.getId());
-        if (Objects.isNull(shop) || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
+        if (Objects.isNull(shop) || Constants.equalsInteger(shop.getDeleted(), Constants.ONE) || Constants.equalsInteger(shop.getVersionType(), Constants.ONE)) {
             throw new BusinessException(ResponseStatus.DATA_EMPTY);
         }
 
@@ -839,6 +1113,7 @@
         vo.setFeeStandard(shop.getFeeStandard());
         vo.setLatitude(shop.getLatitude());
         vo.setLongitude(shop.getLongitude());
+        vo.setLinkPhone(shop.getLinkPhone());
 
         // 闂ㄥご鐓� + 鍐呴儴鐓� 鍏ㄨ矾寰勯泦鍚�
         String imgPrefix = getShopPrefix();
@@ -881,8 +1156,8 @@
     }
 
     @Override
-    public ShopInfoMaintainDTO getShopMaintainInfo(Integer memberId) {
-        ShopInfo shop = shopInfoMapper.selectById(memberId);
+    public ShopInfoMaintainDTO getShopMaintainInfo(Integer shopId) {
+        ShopInfo shop = shopInfoMapper.selectById(shopId);
         if (Objects.isNull(shop) || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
             return null;
         }
@@ -894,6 +1169,10 @@
         dto.setDeliveryArea(shop.getDeliveryArea());
         dto.setShopHours(shop.getShopHours());
         dto.setBusinessType(shop.getBusinessType());
+        // 澶村儚鍏ㄨ矾寰�
+        if (StringUtils.isNotBlank(shop.getCoverImg())) {
+            dto.setCoverImgUrl(getShopPrefix() + shop.getCoverImg());
+        }
         return dto;
     }
 
@@ -971,7 +1250,7 @@
     @Override
     public ShopCenterVO getShopCenterInfo(Integer shopId) {
         ShopInfo shop = shopInfoMapper.selectById(shopId);
-        if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
+        if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE) || Constants.equalsInteger(shop.getVersionType(), Constants.ONE)) {
             throw new BusinessException(ResponseStatus.DATA_EMPTY);
         }
         ShopCenterVO vo = new ShopCenterVO();
@@ -1047,12 +1326,15 @@
         // 瀛樹欢闂ㄥ簵
         List<Orders> depositSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda()
                 .eq(Orders::getDeleted, Constants.ZERO)
+                .notIn(Orders::getStatus,Constants.OrderStatus.cancelled.getStatus(),Constants.OrderStatus.waitPay.getStatus())
                 .ge(Orders::getCreateTime, startTime)
                 .lt(Orders::getCreateTime, endTime)
                 .eq(Orders::getDepositShopId, shopId));
         // 鍙栦欢闂ㄥ簵
         List<Orders> takeSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda()
                 .eq(Orders::getDeleted, Constants.ZERO)
+                .eq(Orders::getType,Constants.ONE)
+                .notIn(Orders::getStatus,Constants.OrderStatus.cancelled.getStatus(),Constants.OrderStatus.waitPay.getStatus())
                 .ge(Orders::getCreateTime, startTime)
                 .lt(Orders::getCreateTime, endTime)
                 .eq(Orders::getTakeShopId, shopId));
@@ -1083,19 +1365,27 @@
         vo.setSettlementProfit(depositFee + takeFee);
 
         // 3. 鍦ㄥ簱璁㈠崟鏁�
-        // 3.1 瀛樹欢闂ㄥ簵=鏈棬搴楋紝status in (2宸插瘎瀛�, 5寰呭彇浠�)
-        Long depositStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
+        // 3.1 灏卞湴璁㈠崟锛氬瓨浠堕棬搴�=鏈棬搴楋紝type=0锛宻tatus in (2宸插瘎瀛�, 5寰呭彇浠�)
+        Long localStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
                 .eq(Orders::getDeleted, Constants.ZERO)
                 .eq(Orders::getDepositShopId, shopId)
+                .eq(Orders::getType, Constants.ZERO)
                 .in(Orders::getStatus,
                         Constants.OrderStatus.deposited.getStatus(),
                         Constants.OrderStatus.arrived.getStatus()));
-        // 3.2 鍙栦欢闂ㄥ簵=鏈棬搴楋紝status = 5寰呭彇浠�
+        // 3.2 寮傚湴璁㈠崟锛氬瓨浠堕棬搴�=鏈棬搴楋紝type=1锛宻tatus=2宸插瘎瀛�
+        Long remoteStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
+                .eq(Orders::getDeleted, Constants.ZERO)
+                .eq(Orders::getDepositShopId, shopId)
+                .eq(Orders::getType, Constants.ONE)
+                .eq(Orders::getStatus, Constants.OrderStatus.deposited.getStatus()));
+        // 3.3 鍙栦欢闂ㄥ簵=鏈棬搴楋紝寮傚湴璁㈠崟锛宻tatus = 5寰呭彇浠�
         Long takeStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
                 .eq(Orders::getDeleted, Constants.ZERO)
+                .eq(Orders::getType,Constants.ONE)
                 .eq(Orders::getTakeShopId, shopId)
                 .eq(Orders::getStatus, Constants.OrderStatus.arrived.getStatus()));
-        vo.setStorageCount(depositStorageCount.intValue() + takeStorageCount.intValue());
+        vo.setStorageCount(localStorageCount.intValue() + remoteStorageCount.intValue() + takeStorageCount.intValue());
 
         return vo;
     }
@@ -1109,48 +1399,51 @@
     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)
+                .eq(ShopInfo::getVersionType,Constants.ZERO)
                 .last("limit 1")
         );
         if(shop==null){
-            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇锋牳瀵圭櫥褰曟墜鏈哄彿鏄惁姝g‘");
+        }
+        if(Constants.equalsInteger(shop.getStatus(),Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闂ㄥ簵宸茬鐢紝璇疯仈绯荤鐞嗗憳");
+        }
+        if(!Constants.equalsInteger(shop.getAuditStatus(),Constants.THREE)){
+            if(Constants.equalsInteger(shop.getAuditStatus(),Constants.ONE)){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇峰畬鎴愬鎵规祦绋� - 鏀粯鎶奸噾");
+            }
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闂ㄥ簵瀹℃壒娴佺▼鏈畬鎴愶紝璇峰畬鎴愬鎵规祦绋�");
         }
         //鍔犲瘑瀵嗙爜
         String pwd = Utils.Secure.encryptPassword( dto.getPassword(), shop.getSalt());
         if(!pwd.equals(shop.getPassword())){
             throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
         }
-
-        // 鏇存柊褰撳墠鐧诲綍浼氬憳鐨刼penid鍒伴棬搴�
-        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());
+        if(Objects.nonNull(dto.getMemberId())){
+            Member member = memberMapper.selectById(dto.getMemberId());
+            if(Objects.nonNull(member)){
+                memberMapper.update(new UpdateWrapper<Member>().lambda()
+                        .set(Member::getLoginShopId,shop.getId())
+                        .eq(Member::getId,member.getId())
+                );
+                shop.setMemberId(member.getId());
+            }else{
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浼氬憳淇℃伅寮傚父锛岃鑱旂郴绠$悊鍛�");
+            }
         }
-
         // 鍒涘缓token锛坓enerateTokenForRedis 宸茶嚜鍔ㄦ竻闄よ鐢ㄦ埛鏃oken锛屼繚璇佸敮涓�鏈夋晥锛�
-        String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate);
-
+        String token = JwtTokenUtil.generateShopTokenForRedis(shop.getMemberId(), 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) {
@@ -1162,18 +1455,25 @@
     @Override
     public ShopLoginVO shopSilentLogin(Integer memberId) {
         Member member = memberMapper.selectById(memberId);
-        if(Objects.isNull(member)||StringUtils.isBlank(member.getOpenid())){
+        if(Objects.isNull(member)){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "褰撳墠鐧诲綍浼氬憳韬唤寮傚父,璇疯仈绯荤鐞嗗憳!");
         }
+        if (Objects.isNull(member.getLoginShopId())) {
+            return null;
+        }
         ShopInfo shop = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda()
-                .eq(ShopInfo::getOpenid, member.getOpenid())
+                .eq(ShopInfo::getId, member.getLoginShopId())
+                .eq(ShopInfo::getVersionType,Constants.ZERO)
                 .eq(ShopInfo::getDeleted, Constants.ZERO)
                 .last("limit 1"));
         if (shop == null) {
             return null;
         }
+        if(Constants.equalsInteger(shop.getStatus(),Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闂ㄥ簵宸茬鐢紝璇疯仈绯荤鐞嗗憳");
+        }
         // 鍒涘缓token锛坓enerateTokenForRedis 宸茶嚜鍔ㄦ竻闄よ鐢ㄦ埛鏃oken锛屼繚璇佸敮涓�鏈夋晥锛�
-        String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate);
+        String token = JwtTokenUtil.generateShopTokenForRedis(member.getId(), JSONObject.toJSONString(shop), redisTemplate);
 
         ShopLoginVO vo = new ShopLoginVO();
         vo.setToken(token);
@@ -1275,4 +1575,155 @@
         return errors;
     }
 
+    /**
+     * 浠嶱ricingRule璇诲彇鎶奸噾閲戦骞惰祴鍊煎埌闂ㄥ簵璁板綍
+     */
+    private void setDepositAmountFromPricingRule(ShopInfo shopInfo) {
+        if (shopInfo.getCompanyType() == null) {
+            return;
+        }
+        Areas areas = areasService.findById(shopInfo.getAreaId());
+        PricingRule pricingRule = pricingRuleMapper.selectOne(new QueryWrapper<PricingRule>().lambda()
+                .eq(PricingRule::getDeleted, Constants.ZERO)
+                .eq(PricingRule::getType, Constants.THREE)
+                .eq(PricingRule::getFieldA, String.valueOf(Constants.equalsInteger(shopInfo.getCompanyType(),Constants.ZERO)?Constants.ONE:Constants.ZERO))
+                .eq(PricingRule::getCityId, areas.getParentId())
+                .last("limit 1"));
+        if (pricingRule != null && StringUtils.isNotBlank(pricingRule.getFieldB())) {
+            shopInfo.setDepositAmount(Long.parseLong(pricingRule.getFieldB()));
+        }
+    }
+
+    /**
+     * 浠庤繍钀ラ厤缃鍙栭粯璁ら厤閫佽寖鍥村苟璧嬪�煎埌闂ㄥ簵璁板綍
+     */
+    private void setDefaultDeliveryRange(ShopInfo shopInfo) {
+        SystemDictData data = systemDictDataBiz.queryByCode(Constants.OPERATION_CONFIG, Constants.OP_DEFAULT_DELIVERY_RANGE);
+        if (data != null && StringUtils.isNotBlank(data.getCode())) {
+            shopInfo.setDeliveryArea(new java.math.BigDecimal(data.getCode()));
+        }
+    }
+
+    /**
+     * 鍙戦�佺煭淇¢�氱煡锛堝け璐ヤ笉褰卞搷涓讳笟鍔★級
+     */
+    private void sendSmsNotify(String phone, Constants.SmsNotify smsNotify, String... paramPairs) {
+        if (StringUtils.isBlank(phone)) {
+            return;
+        }
+        if (!smsNotify.isEnabled()) {
+            return;
+        }
+        String content = smsNotify.format(paramPairs);
+        try {
+            JSONObject templateParam = new JSONObject();
+            for (int i = 0; i < paramPairs.length - 1; i += 2) {
+                templateParam.put(paramPairs[i], paramPairs[i + 1]);
+            }
+            String error = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(),
+                    templateParam.toJSONString());
+            Smsrecord smsRecord = new Smsrecord();
+            smsRecord.setPhone(phone);
+            smsRecord.setContent(content);
+            smsRecord.setType(Constants.ONE);
+            smsRecord.setStatus(error == null ? Constants.ONE : Constants.ZERO);
+            if (error != null) {
+                smsRecord.setRemark(error);
+            }
+            smsRecord.setCreateTime(new Date());
+            smsRecord.setDeleted(Constants.ZERO);
+            smsrecordMapper.insert(smsRecord);
+        } catch (Exception e) {
+            log.error("鐭俊鍙戦�佸紓甯�: phone={}, template={}, error={}", phone, smsNotify.name(), e.getMessage());
+        }
+    }
+
+    @Override
+    public void changePassword(Integer shopId, String oldPassword, String newPassword, String token) {
+        if (StringUtils.isBlank(oldPassword)) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏃у瘑鐮佷笉鑳戒负绌�");
+        }
+        if (StringUtils.isBlank(newPassword)) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏂板瘑鐮佷笉鑳戒负绌�");
+        }
+        // 鏍¢獙鏂板瘑鐮佸繀椤诲悓鏃跺寘鍚瓧姣嶅拰鏁板瓧
+        boolean hasLetter = newPassword.chars().anyMatch(Character::isLetter);
+        boolean hasDigit = newPassword.chars().anyMatch(Character::isDigit);
+        if (!hasLetter || !hasDigit) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵嗙爜蹇呴』鍚屾椂鍖呭惈瀛楁瘝鍜屾暟瀛�");
+        }
+        // 鏌ヨ闂ㄥ簵
+        ShopInfo shopInfo = shopInfoMapper.selectById(shopId);
+        if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) {
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        // 鏍¢獙鏃у瘑鐮�
+        String oldEncryptPwd = Utils.Secure.encryptPassword(oldPassword, shopInfo.getSalt());
+        if (!oldEncryptPwd.equals(shopInfo.getPassword())) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏃у瘑鐮侀敊璇�");
+        }
+        // 閲嶆柊鐢熸垚salt锛屽姞瀵嗘柊瀵嗙爜骞舵洿鏂�
+        String salt = RandomStringUtils.randomAlphabetic(6);
+        shopInfo.setPassword(Utils.Secure.encryptPassword(newPassword, salt));
+        shopInfo.setSalt(salt);
+        shopInfoMapper.updateById(shopInfo);
+        // 娓呴櫎token锛屽己鍒堕噸鏂扮櫥褰�
+        if (StringUtils.isNotBlank(token)) {
+            redisTemplate.delete(token);
+        }
+    }
+
+    @Override
+    public void maintainPrinterSn(ShopPrinterDTO dto) {
+        ShopInfo shop = shopInfoMapper.selectById(dto.getId());
+        if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        String oldSn = shop.getPrinterSn();
+        String newSn = dto.getPrinterSn();
+        boolean hasNewSn = StringUtils.isNotBlank(newSn);
+        boolean hasOldSn = StringUtils.isNotBlank(oldSn);
+
+        if (!hasNewSn) {
+            // 鏈紶鎵撳嵃鏈篠N 鈫� 鍒犻櫎閫昏緫
+            if (hasOldSn) {
+                delPrinterFromXyy(oldSn);
+                shop.setPrinterSn(null);
+                shopInfoMapper.updateById(shop);
+            }
+            return;
+        }
+
+        // 浼犱簡鎵撳嵃鏈篠N 鈫� 濡傛灉鏃х粦瀹氬瓨鍦紝鍏堝垹闄�
+        if (hasOldSn) {
+            delPrinterFromXyy(oldSn);
+        }
+
+        // 缁戝畾鏂版墦鍗版満
+        AddPrinterRequest addReq = new AddPrinterRequest();
+        xyyConfig.createRequestHeader(addReq);
+        addReq.setItems(new AddPrinterRequestItem[]{new AddPrinterRequestItem() {{
+            setSn(newSn);
+            setName(shop.getName());
+        }}});
+        ObjectRestResponse<PrinterResult> addResp = printService.addPrinters(addReq);
+        if (addResp.getCode() != 0) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "缁戝畾鎵撳嵃鏈哄け璐ワ細" + addResp.getMsg());
+        }
+        log.info("缁戝畾鎴愬姛锛歿}", newSn);
+        shop.setPrinterSn(newSn);
+        shopInfoMapper.updateById(shop);
+    }
+
+    private void delPrinterFromXyy(String sn) {
+        DelPrinterRequest delReq = new DelPrinterRequest();
+        xyyConfig.createRequestHeader(delReq);
+        delReq.setSnlist(new String[]{sn});
+        ObjectRestResponse<PrinterResult> delResp = printService.delPrinters(delReq);
+        if (delResp.getCode() != 0) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瑙g粦鎵撳嵃鏈哄け璐ワ細" + delResp.getMsg());
+        }
+        log.info("瑙g粦鎴愬姛锛歿}", sn);
+    }
+
 }

--
Gitblit v1.9.3