rk
5 小时以前 7eebfc8a64d2cbbd73453a2b653d5a5bfd66a32f
server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
@@ -16,18 +16,24 @@
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.*;
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;
@@ -68,6 +74,15 @@
    @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);
@@ -299,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);
@@ -328,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);
@@ -407,6 +424,38 @@
        shopInfo.setAuditRemark(auditDTO.getAuditRemark());
        shopInfo.setAuditUserId(auditDTO.getAuditUser());
        shopInfo.setUpdateTime(now);
        // 审批通过时,校验城市pricing_rule配置,读取押金金额
        if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) {
            // 1. 解析门店所在城市
            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. 从PricingRule读取押金金额
            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);
    }
@@ -612,7 +661,7 @@
        // 拼接图片前缀
        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) {
            // 未配置时忽略
@@ -670,7 +719,7 @@
            if (payMember != null && StringUtils.isNotBlank(payMember.getCoverImage())) {
                String memberPrefix = "";
                try {
                    memberPrefix = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.RESOURCE_PATH).getCode()
                    memberPrefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                            + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.MEMBER_FILES).getCode();
                } catch (Exception e) {
                    // 未配置时忽略
@@ -861,7 +910,7 @@
     */
    private String getShopPrefix() {
        try {
            return systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.RESOURCE_PATH).getCode()
            return systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                    + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SHOP_FILES).getCode();
        } catch (Exception e) {
            return "";
@@ -903,7 +952,37 @@
        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);
        // 待核验订单数量(存件门店,status=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());
        // 待收货订单数量(取件门店,status 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;
    }
    /**
     * 商户账号密码登录
@@ -993,4 +1072,91 @@
        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 预计时效:fieldA=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 门店注册押金:fieldA=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 分成比例:fieldA=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;
    }
}