多店铺需求

This commit is contained in:
Tankaikai
2025-04-07 11:40:25 +08:00
parent ec5de0f9ba
commit fffa1e5389
14 changed files with 513 additions and 15 deletions

View File

@@ -0,0 +1,16 @@
package com.czg.service.account.mapper;
import com.czg.account.entity.ShopConfig;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 店铺配置扩展
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-04-03
*/
@Mapper
public interface ShopConfigMapper extends BaseMapper<ShopConfig> {
}

View File

@@ -0,0 +1,39 @@
package com.czg.service.account.service.impl;
import com.czg.account.dto.ShopConfigDTO;
import com.czg.account.entity.ShopConfig;
import com.czg.account.service.ShopConfigService;
import com.czg.sa.StpKit;
import com.czg.service.account.mapper.ShopConfigMapper;
import com.czg.service.account.mapper.ShopInfoMapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
/**
* 店铺配置扩展
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-04-03
*/
@Service
public class ShopConfigServiceImpl extends ServiceImpl<ShopConfigMapper, ShopConfig> implements ShopConfigService {
@Resource
private ShopInfoMapper shopInfoMapper;
private QueryWrapper buildQueryWrapper(ShopConfigDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
/*if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ShopConfig::getName, param.getName());
}*/
Long shopId = StpKit.USER.getLoginIdAsLong();
queryWrapper.eq(ShopConfig::getMainId, shopId);
queryWrapper.orderBy(ShopConfig::getId, false);
return queryWrapper;
}
}

View File

@@ -7,9 +7,12 @@ import cn.hutool.crypto.SecureUtil;
import com.czg.account.dto.PageDTO;
import com.czg.account.dto.shopinfo.*;
import com.czg.account.entity.*;
import com.czg.account.enums.BranchDataSyncMethodEnum;
import com.czg.account.enums.ShopTypeEnum;
import com.czg.account.service.*;
import com.czg.config.RedisCst;
import com.czg.enums.StatusEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.resp.CzgResult;
@@ -27,6 +30,7 @@ import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.cache.annotation.CacheConfig;
@@ -44,6 +48,7 @@ import java.util.stream.Collectors;
/**
* @author Administrator
*/
@Slf4j
@DubboService
@CacheConfig(cacheNames = "shopInfo")
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService {
@@ -65,6 +70,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
private FreeDineConfigService freeDineConfigService;
@Resource
private PointsBasicSettingService pointsBasicSettingService;
@Resource
private ShopConfigService shopConfigService;
@DubboReference
private SysParamsService sysParamsService;
@@ -72,7 +79,10 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
@Override
@Cacheable(key = "#id")
public ShopInfo getById(Serializable id) {
return super.getById(id);
ShopInfo shopInfo = super.getById(id);
ShopConfig shopConfig = shopConfigService.getById(shopInfo.getId());
BeanUtil.copyProperties(shopConfig, shopInfo);
return shopInfo;
}
private ShopInfo getShopInfo(Long shopId) {
@@ -94,7 +104,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
}
@Override
public Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status) {
public Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status, Integer isHeadShop) {
QueryWrapper queryWrapper = new QueryWrapper();
if (StrUtil.isNotBlank(shopName)) {
queryWrapper.like(ShopInfo::getShopName, shopName);
@@ -103,7 +113,12 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
queryWrapper.eq(ShopInfo::getStatus, status);
}
queryWrapper.orderBy(ShopInfo::getCreateTime, false);
return page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
Page<ShopInfo> page = page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
page.getRecords().forEach(shopInfo -> {
ShopConfig shopConfig = shopConfigService.getById(shopInfo.getId());
BeanUtil.copyProperties(shopConfig, shopInfo);
});
return page;
}
private void activateShop(ShopInfo shopInfo, String activateCode) {
@@ -116,7 +131,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
// 续期
if (shopInfo.getExpireTime() != null && shopInfo.getExpireTime().isAfter(LocalDateTime.now())) {
shopInfo.setExpireTime(DateUtil.offsetMonth(DateUtil.date(shopInfo.getExpireTime()), merchantRegister.getPeriodMonth()).toLocalDateTime());
}else {
} else {
shopInfo.setExpireTime(DateUtil.offsetMonth(DateUtil.date(), merchantRegister.getPeriodMonth()).toLocalDateTime());
}
merchantRegister.setStatus(1);
@@ -127,6 +142,21 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean add(ShopInfoAddDTO shopInfoAddDTO) {
// 如果店铺类型是单店,是否主店要设为否
if (ShopTypeEnum.ONLY.getValue().equals(shopInfoAddDTO.getShopType())) {
shopInfoAddDTO.setIsHeadShop(YesNoEnum.NO.value());
shopInfoAddDTO.setMainId(null);
} else {
if (shopInfoAddDTO.getIsHeadShop() == null) {
throw new CzgException("加盟店/连锁店请选择是否主店");
}
if (shopInfoAddDTO.getIsHeadShop() == YesNoEnum.NO.value() && shopInfoAddDTO.getMainId() == null) {
throw new CzgException("请选择一个店铺做为主店");
}
if (shopInfoAddDTO.getIsHeadShop() == YesNoEnum.YES.value()) {
shopInfoAddDTO.setMainId(null);
}
}
shopInfoAddDTO.setPhone(shopInfoAddDTO.getPhone().trim());
if (StrUtil.isBlank(shopInfoAddDTO.getPhone())) {
throw new ApiNotPrintException("请输入手机号");
@@ -156,7 +186,50 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
// 初始化积分霸王餐设置
freeDineConfigService.getConfig(shopInfo.getId());
pointsBasicSettingService.initInfo(shopInfo.getId());
return updateById(shopInfo);
updateById(shopInfo);
syncSaveConfig(shopInfo, shopInfoAddDTO);
return true;
}
/**
* 同步创建配置信息
*
* @param shopInfo 店铺信息实体
* @param dto 新增店铺信息DTO
*/
private void syncSaveConfig(ShopInfo shopInfo, ShopInfoAddDTO dto) {
ShopConfig shopConfig = new ShopConfig();
shopConfig.setId(shopInfo.getId());
shopConfig.setMainId(shopInfo.getMainId());
shopConfig.setIsEnableProdSync(0);
shopConfig.setIsEnableVipSync(0);
shopConfig.setIsEnableConsSync(0);
shopConfig.setIsAllowAccountLogin(1);
shopConfig.setRemark(null);
shopConfig.setIsCustomAmount(0);
shopConfig.setIsReturnPwd(0);
shopConfig.setIsMemberInPwd(0);
shopConfig.setIsMemberReturnPwd(0);
shopConfig.setIsTableFee(1);
shopConfig.setIsMemberPrice(0);
shopConfig.setIsAccountPay(0);
shopConfig.setBranchDataSyncMethod(null);
if (dto.getIsHeadShop() == YesNoEnum.YES.value()) {
shopConfig.setBranchDataSyncMethod(BranchDataSyncMethodEnum.AUTO.getValue());
}
shopConfigService.save(shopConfig);
}
/**
* 同步修改配置信息
*
* @param shopInfo 店铺信息实体
* @param dto 新增店铺信息DTO
*/
private void syncUpdateConfig(ShopInfo shopInfo, ShopInfoEditDTO dto) {
ShopConfig shopConfig = shopConfigService.getById(shopInfo.getId());
BeanUtil.copyProperties(dto, shopConfig);
shopConfigService.updateById(shopConfig);
}
@Override
@@ -165,14 +238,25 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
ShopInfo shopInfo;
if (!StpKit.USER.isAdmin()) {
shopInfo = queryChain().eq(ShopInfo::getId, StpKit.USER.getLoginIdAsLong()).one();
}else {
} else {
shopInfo = getById(StpKit.USER.getLoginIdAsLong());
}
if (shopInfo == null) {
throw new CzgException("店铺不存在");
}
BeanUtil.copyProperties(shopInfoEditDTO, shopInfo);
String shopType = shopInfo.getShopType();
Long mainId = shopInfo.getMainId();
Integer isHeadShop = shopInfo.getIsHeadShop();
// 禁止加盟店/连锁店修改为单店
if (!shopType.equals(shopInfoEditDTO.getShopType())) {
throw new CzgException("禁止修改店铺类型");
}
if (!isHeadShop.equals(shopInfoEditDTO.getIsHeadShop())) {
throw new CzgException("禁止修改是否主店");
}
if (!mainId.equals(shopInfoEditDTO.getMainId())) {
throw new CzgException("禁止从新选择店铺设为主店");
}
if (shopInfoEditDTO.getActivateCode() != null) {
activateShop(shopInfo, shopInfoEditDTO.getActivateCode());
}
@@ -188,6 +272,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
redisService.del(key);
}
if (updateById(shopInfo)) {
syncUpdateConfig(shopInfo, shopInfoEditDTO);
SysUser sysUser = sysUserService.getById(shopInfo.getId());
boolean flag = false;
if (!sysUser.getNickName().equals(shopInfo.getShopName())) {
@@ -218,12 +303,16 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
if (!StpKit.USER.isAdmin() && !Objects.equals(StpKit.USER.getShopId(), shopInfo.getId())) {
throw new ApiNotPrintException("店铺信息不存在");
}
ShopConfig shopConfig = shopConfigService.getById(shopInfo.getId());
if (shopConfig == null) {
throw new CzgException("店铺配置不存在");
}
ShopDetailDTO shopDetailDTO = BeanUtil.copyProperties(shopInfo, ShopDetailDTO.class);
SysUser sysUser = sysUserService.getById(shopInfo.getId());
shopDetailDTO.setAccount(sysUser.getAccount());
CzgResult<SysParamsDTO> shopOrderPayBaseUrl = sysParamsService.getParamsByCode("shop_order_pay_base_url");
shopDetailDTO.setPaymentQrcode(shopOrderPayBaseUrl.getData().getParamValue() + "?shopId=" + id);
BeanUtil.copyProperties(shopConfig, shopDetailDTO);
return shopDetailDTO;
}
@@ -238,7 +327,6 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
throw new ApiNotPrintException("台桌状态不可用");
}
ShopInfo shopInfo = getShopInfo(shopTable.getShopId());
double distance = 0;
if (StrUtil.isAllNotBlank(lat, lng, shopInfo.getLat(), shopInfo.getLng())) {
// 计算距离,单位:米

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopConfigMapper">
</mapper>