From 55642c818f14bf8cf52c98e6858014bd8dc3d3a7 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期四, 16 四月 2026 20:10:58 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java |  533 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 523 insertions(+), 10 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 97d1f7d..bf5a84a 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
@@ -1,9 +1,11 @@
 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;
@@ -14,22 +16,30 @@
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.dao.business.MemberMapper;
 import com.doumee.dao.business.MultifileMapper;
+import com.doumee.dao.business.OrdersMapper;
+import com.doumee.dao.business.PricingRuleMapper;
 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.Orders;
+import com.doumee.dao.business.model.PricingRule;
 import com.doumee.dao.business.model.ShopInfo;
-import com.doumee.dao.dto.AuditDTO;
-import com.doumee.dao.dto.ChangeStatusDTO;
-import com.doumee.dao.dto.ResetPasswordDTO;
-import com.doumee.dao.dto.ShopApplyDTO;
-import com.doumee.dao.dto.ShopUpdateDTO;
+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.ShopCenterVO;
+import com.doumee.dao.vo.ShopLoginVO;
+import com.doumee.dao.vo.ShopNearbyVO;
+import com.doumee.dao.vo.ShopWebDetailVO;
+import com.doumee.service.business.AreasService;
 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;
 
@@ -57,8 +67,22 @@
     private SystemDictDataBiz systemDictDataBiz;
 
     @Autowired
+    private SystemUserMapper systemUserMapper;
+
+    @Autowired
     private AreasBiz areasBiz;
 
+    @Autowired
+    private RedisTemplate<String,Object> redisTemplate;
+
+    @Autowired
+    private PricingRuleMapper pricingRuleMapper;
+
+    @Autowired
+    private OrdersMapper ordersMapper;
+
+    @Autowired
+    private AreasService areasService;
     @Override
     public Integer create(ShopInfo shopInfo) {
         shopInfoMapper.insert(shopInfo);
@@ -176,6 +200,9 @@
         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());
         }
@@ -287,6 +314,7 @@
             existing.setLegalPersonCard(request.getLegalPersonCard());
             existing.setPassword(encryptedPassword);
             existing.setSalt(salt);
+            existing.setAliAccount(request.getAliAccount());
             existing.setAuditStatus(Constants.ZERO);
             existing.setUpdateTime(now);
             existing.setUpdateUser(memberId);
@@ -316,6 +344,7 @@
             shopInfo.setLegalPersonCard(request.getLegalPersonCard());
             shopInfo.setPassword(encryptedPassword);
             shopInfo.setSalt(salt);
+            shopInfo.setAliAccount(request.getAliAccount());
             shopInfo.setOpenid(member.getOpenid());
             shopInfo.setAuditStatus(Constants.ZERO);
             shopInfo.setStatus(Constants.ZERO);
@@ -395,6 +424,38 @@
         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(), "鍩庡競淇℃伅涓嶅瓨鍦�");
+            }
+            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));
+                }
+            }
+
+            // 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()));
+            }
+        }
         shopInfoMapper.updateById(shopInfo);
     }
 
@@ -586,6 +647,11 @@
         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());
@@ -595,17 +661,20 @@
         // 鎷兼帴鍥剧墖鍓嶇紑
         String imgPrefix = "";
         try {
-            imgPrefix = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.RESOURCE_PATH).getCode()
+            imgPrefix = systemDictDataBiz.queryByCode(Constants.OSS, 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<>();
@@ -621,10 +690,13 @@
                 .orderByAsc(Multifile::getObjType, Multifile::getSortnum);
         List<Multifile> files = multifileMapper.selectList(fileQw);
 
-        // 鎸� objType 鍒嗙粍锛岃繑鍥炲崐璺緞
+        // 鎸� 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<>()));
@@ -633,17 +705,458 @@
         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) {
-                vo.setPayMemberCoverImage(payMember.getCoverImage());
+            if (payMember != null && StringUtils.isNotBlank(payMember.getCoverImage())) {
+                String memberPrefix = "";
+                try {
+                    memberPrefix = systemDictDataBiz.queryByCode(Constants.OSS, 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璺濈鍏紡锛堝崟浣峩m锛�
+        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());
+        }
+
+        // 璺濈绛涢�夛紙鍗曚綅锛氱背 鈫� 杞崲涓簁m姣旇緝锛�
+        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.OSS, 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;
+    }
+
+    @Override
+    public ShopCenterVO getShopCenterInfo(Integer shopId) {
+        ShopInfo shop = shopInfoMapper.selectById(shopId);
+        if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        ShopCenterVO vo = new ShopCenterVO();
+        vo.setShopName(shop.getName());
+        vo.setLinkName(shop.getLinkName());
+        vo.setCompanyType(shop.getCompanyType());
+        vo.setCoverImg(shop.getCoverImg());
+        if (StringUtils.isNotBlank(shop.getCoverImg())) {
+            String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
+                    + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SHOP_FILES).getCode();
+            vo.setFullCoverImg(path + shop.getCoverImg());
+        }
+        vo.setHasMessage(false);
+        // 寰呮牳楠岃鍗曟暟閲忥紙瀛樹欢闂ㄥ簵锛宻tatus=1锛�
+        Long waitDepositCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
+                .eq(Orders::getDepositShopId, shopId)
+                .eq(Orders::getDeleted, Constants.ZERO)
+                .eq(Orders::getStatus, Constants.OrderStatus.waitDeposit.getStatus()));
+        vo.setWaitDepositCount(waitDepositCount.intValue());
+        // 寰呮敹璐ц鍗曟暟閲忥紙鍙栦欢闂ㄥ簵锛宻tatus IN 4,5锛�
+        Long waitReceiveCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
+                .eq(Orders::getTakeShopId, shopId)
+                .eq(Orders::getDeleted, Constants.ZERO)
+                .in(Orders::getStatus, Constants.OrderStatus.delivering.getStatus(), Constants.OrderStatus.arrived.getStatus()));
+        vo.setWaitReceiveCount(waitReceiveCount.intValue());
+        return vo;
+    }
+
+    /**
+     * 鍟嗘埛璐﹀彿瀵嗙爜鐧诲綍
+     * @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);
+        }
+
+        // 鏇存柊褰撳墠鐧诲綍浼氬憳鐨刼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());
+        }
+
+        // 鍒涘缓token锛坓enerateTokenForRedis 宸茶嚜鍔ㄦ竻闄よ鐢ㄦ埛鏃oken锛屼繚璇佸敮涓�鏈夋晥锛�
+        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锛坓enerateTokenForRedis 宸茶嚜鍔ㄦ竻闄よ鐢ㄦ埛鏃oken锛屼繚璇佸敮涓�鏈夋晥锛�
+        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;
+    }
+
+    /**
+     * 鏍¢獙鍩庡競瀹氫环瑙勫垯閰嶇疆鏄惁瀹屾暣
+     * @param cityId 鍩庡競涓婚敭
+     * @return 閿欒淇℃伅鍒楄〃锛岀┖琛ㄧず鏍¢獙閫氳繃
+     */
+    private List<String> validateCityPricingRules(Integer cityId) {
+        List<String> errors = new ArrayList<>();
+
+        // type=0 灏卞湴瀛樺彇瑙勫垯锛氳嚦灏�1鏉★紝fieldB涓嶄负绌�
+        List<PricingRule> type0 = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
+                .eq(PricingRule::getDeleted, Constants.ZERO)
+                .eq(PricingRule::getType, Constants.ZERO)
+                .eq(PricingRule::getCityId, cityId));
+        if (type0.isEmpty()) {
+            errors.add("缂哄皯灏卞湴瀛樺彇瑙勫垯");
+        } else if (type0.stream().allMatch(r -> StringUtils.isBlank(r.getFieldB()))) {
+            errors.add("灏卞湴瀛樺彇瑙勫垯鏈厤缃敹璐瑰崟浠�");
+        }
+
+        // type=1 寮傚湴瀵勯�佽鍒欙細鑷冲皯1鏉★紝fieldB/C/D/E涓嶄负绌�
+        List<PricingRule> type1 = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
+                .eq(PricingRule::getDeleted, Constants.ZERO)
+                .eq(PricingRule::getType, Constants.ONE)
+                .eq(PricingRule::getCityId, cityId));
+        if (type1.isEmpty()) {
+            errors.add("缂哄皯寮傚湴瀵勯�佽鍒�");
+        } else if (type1.stream().allMatch(r -> StringUtils.isAnyBlank(r.getFieldB(), r.getFieldC(), r.getFieldD(), r.getFieldE()))) {
+            errors.add("寮傚湴瀵勯�佽鍒欓厤缃笉瀹屾暣");
+        }
+
+        // type=2 棰勮鏃舵晥锛歠ieldA=1(鏍囬�熻揪) 鍜� fieldA=2(鏋侀�熻揪) 鍚�1鏉�
+        List<PricingRule> type2 = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
+                .eq(PricingRule::getDeleted, Constants.ZERO)
+                .eq(PricingRule::getType, Constants.TWO)
+                .eq(PricingRule::getCityId, cityId));
+        Map<String, PricingRule> type2Map = type2.stream()
+                .collect(Collectors.toMap(PricingRule::getFieldA, r -> r, (a, b) -> a));
+        if (!type2Map.containsKey("1")) {
+            errors.add("缂哄皯棰勮鏃舵晥-鏍囬�熻揪閰嶇疆");
+        } else if (StringUtils.isAnyBlank(type2Map.get("1").getFieldB(), type2Map.get("1").getFieldC(),
+                type2Map.get("1").getFieldD(), type2Map.get("1").getFieldE())) {
+            errors.add("棰勮鏃舵晥-鏍囬�熻揪閰嶇疆涓嶅畬鏁�");
+        }
+        if (!type2Map.containsKey("2")) {
+            errors.add("缂哄皯棰勮鏃舵晥-鏋侀�熻揪閰嶇疆");
+        } else if (StringUtils.isAnyBlank(type2Map.get("2").getFieldB(), type2Map.get("2").getFieldC(),
+                type2Map.get("2").getFieldD(), type2Map.get("2").getFieldE())) {
+            errors.add("棰勮鏃舵晥-鏋侀�熻揪閰嶇疆涓嶅畬鏁�");
+        }
+
+        // type=3 闂ㄥ簵娉ㄥ唽鎶奸噾锛歠ieldA=0(浼佷笟) 鍜� fieldA=1(涓汉) 鍚�1鏉★紝fieldB涓嶄负绌�
+        List<PricingRule> type3 = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
+                .eq(PricingRule::getDeleted, Constants.ZERO)
+                .eq(PricingRule::getType, Constants.THREE)
+                .eq(PricingRule::getCityId, cityId));
+        Map<String, PricingRule> type3Map = type3.stream()
+                .collect(Collectors.toMap(PricingRule::getFieldA, r -> r, (a, b) -> a));
+        String[] depositNames = {"浼佷笟", "涓汉"};
+        for (int i = 0; i <= 1; i++) {
+            String key = String.valueOf(i);
+            if (!type3Map.containsKey(key)) {
+                errors.add("缂哄皯闂ㄥ簵娉ㄥ唽鎶奸噾-" + depositNames[i] + "閰嶇疆");
+            } else if (StringUtils.isBlank(type3Map.get(key).getFieldB())) {
+                errors.add("闂ㄥ簵娉ㄥ唽鎶奸噾-" + depositNames[i] + "鏈厤缃娂閲戦噾棰�");
+            }
+        }
+
+        // type=4 鍒嗘垚姣斾緥锛歠ieldA=0~4 鍏�5鏉★紝fieldB涓嶄负绌�
+        List<PricingRule> type4 = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
+                .eq(PricingRule::getDeleted, Constants.ZERO)
+                .eq(PricingRule::getType, Constants.FOUR)
+                .eq(PricingRule::getCityId, cityId));
+        String[] shareNames = {"浼佷笟瀵�", "涓汉瀵�", "浼佷笟鍙�", "涓汉鍙�", "閰嶉�佸憳"};
+        Map<String, PricingRule> type4Map = type4.stream()
+                .collect(Collectors.toMap(PricingRule::getFieldA, r -> r, (a, b) -> a));
+        for (int i = 0; i <= 4; i++) {
+            String key = String.valueOf(i);
+            if (!type4Map.containsKey(key)) {
+                errors.add("缂哄皯鍒嗘垚姣斾緥-" + shareNames[i] + "閰嶇疆");
+            } else if (StringUtils.isBlank(type4Map.get(key).getFieldB())) {
+                errors.add("鍒嗘垚姣斾緥-" + shareNames[i] + "鏈厤缃垎鎴愭瘮渚�");
+            }
+        }
+
+        return errors;
+    }
+
 }

--
Gitblit v1.9.3