切换店铺统计 √

下单选择会员 √
注册会员 √
完善手机号 √
会员流水信息同步 √
This commit is contained in:
谭凯凯
2025-04-10 15:37:17 +08:00
committed by Tankaikai
parent e17a2ee5d1
commit 63e608a208
26 changed files with 263 additions and 64 deletions

View File

@@ -2,7 +2,6 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.log.Log;
import com.czg.account.dto.ShopBranchDTO;
import com.czg.account.entity.ShopConfig;
import com.czg.account.entity.ShopInfo;
@@ -109,12 +108,14 @@ public class ShopBranchServiceImpl implements ShopBranchService {
branchConfig.setIsEnableConsSync(YesNoEnum.YES.value());
branchConfig.setIsEnableVipSync(YesNoEnum.YES.value());
shopConfigMapper.update(branchConfig);
// ThreadUtil.execAsync(() -> {
log.info("开始同步店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), StpKit.USER.getLoginIdAsLong());
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
ThreadUtil.safeSleep(3000L);
log.info("开始同步店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), sysUserId);
// 同步商品和耗材
shopSyncService.sync(shopId, branchShop.getId(), StpKit.USER.getLoginIdAsLong());
log.info("同步结束店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), StpKit.USER.getLoginIdAsLong());
// });
shopSyncService.sync(shopId, branchShop.getId(), sysUserId);
log.info("同步结束店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), sysUserId);
});
ThreadUtil.execAsync(() -> {
// 同步会员信息
shopUserSyncService.syncMergeShopUser(shopId, branchShop.getId());

View File

@@ -9,6 +9,7 @@ import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.config.RedisCst;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderDetailService;
@@ -16,6 +17,7 @@ import com.czg.order.service.OrderInfoService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.service.account.mapper.ShopConfigMapper;
import com.czg.service.account.mapper.ShopInfoMapper;
import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.system.entity.SysParams;
@@ -67,6 +69,8 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
private ShopExtendService shopExtendService;
@Resource
private FreeDineConfigService freeDineConfigService;
@Resource
private ShopConfigMapper shopConfigMapper;
private ShopUser getUserInfo(Long shopId, Long shopUserId) {
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one();
@@ -80,7 +84,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override
public Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount) {
PageHelper.startPage(PageUtil.buildPageHelp());
return PageUtil.convert(new PageInfo<>(mapper.selectPageByKeyAndIsVip(StpKit.USER.getShopId(), isVip, key, amount)));
return PageUtil.convert(new PageInfo<>(mapper.selectPageByKeyAndIsVip(StpKit.USER.getHeadShopId(), isVip, key, amount)));
}
@Override
@@ -148,6 +152,10 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override
public ShopUser getShopUserInfo(Long shopId, long userId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId).one();
if (shopUser == null) {
shopUser = new ShopUser();
@@ -185,6 +193,10 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override
public CzgResult<String> getCode(long userInfoId, long shopId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfoId).one();
AssertUtil.isNull(shopUser, "会员信息不存在");
if (shopUser.getIsVip().equals(0)) {
@@ -300,6 +312,10 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override
public ShopUserDetailDTO getInfo(Long shopId, long userId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId));
UserInfo userInfo = userInfoService.getById(userId);
if (userInfo == null) {
@@ -336,11 +352,11 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override
public ShopUser getDetail(Integer id, Integer userId) {
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId));
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getHeadShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId));
long count = shopActivateCouponRecordService.count(new QueryWrapper().eq(ShopActivateCouponRecord::getShopUserId, shopUser.getId()).eq(ShopActivateCouponRecord::getStatus, 0));
ShopUserDTO shopUserDTO = BeanUtil.copyProperties(shopUser, ShopUserDTO.class);
shopUserDTO.setCouponNum(count);
shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, shopUser.getShopId()).eq(OrderInfo::getStatus, "done")));
shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, StpKit.USER.getShopId(0L)).eq(OrderInfo::getStatus, "done")));
return shopUserDTO;
}
}

View File

@@ -9,9 +9,11 @@ import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.ShopUserFlow;
import com.czg.account.service.ShopUserSyncService;
import com.czg.service.account.mapper.ShopUserMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@@ -56,12 +58,20 @@ public class ShopUserSyncServiceImpl implements ShopUserSyncService {
}));
// 分店没有绑定手机号的会员
for (ShopUser shopUser : branchShopNotPhoneUserList) {
Long historyShopId = shopUser.getShopId();
Long historyUserId = shopUser.getUserId();
JSONObject branch = JSONObject.from(shopUser, JSONWriter.Feature.WriteMapNullValue);
JSONArray objects = new JSONArray();
objects.add(branch);
shopUser.setShopId(headShopId);
shopUser.setMergedUsers(objects.toJSONString(JSONWriter.Feature.WriteMapNullValue));
shopUserMapper.update(shopUser);
// 更新会员流水记录到主店
UpdateChain.of(ShopUserFlow.class)
.set(ShopUserFlow::getShopId, headShopId)
.eq(ShopUserFlow::getShopId, historyShopId)
.eq(ShopUserFlow::getUserId, historyUserId)
.update();
}
List<ShopUser> headShopUserList = shopUserMapper.selectListByQuery(QueryWrapper.create().eq(ShopUser::getShopId, headShopId).isNotNull(ShopUser::getPhone));
List<ShopUser> branchShopUserList = shopUserMapper.selectListByQuery(QueryWrapper.create().eq(ShopUser::getShopId, branchShopId).isNotNull(ShopUser::getPhone));
@@ -114,6 +124,12 @@ public class ShopUserSyncServiceImpl implements ShopUserSyncService {
objects.add(JSONObject.from(branchShopUser, JSONWriter.Feature.WriteMapNullValue));
headShopUser.setMergedUsers(JSON.toJSONString(objects, JSONWriter.Feature.WriteMapNullValue));
shopUserMapper.update(headShopUser);
// 更新会员流水记录到主店
UpdateChain.of(ShopUserFlow.class)
.set(ShopUserFlow::getShopId, headShopUser.getShopId())
.eq(ShopUserFlow::getShopId, branchShopUser.getShopId())
.eq(ShopUserFlow::getUserId, branchShopUser.getUserId())
.update();
shopUserMapper.delete(branchShopUser);
}
@@ -135,12 +151,20 @@ public class ShopUserSyncServiceImpl implements ShopUserSyncService {
*/
public void toMergeCase3(Long headShopId, ShopUser branchShopUser) {
// 合并逻辑3主店没有、分店有把shop_id改为主店shop_id把分店会员信息jsonArray格式化存储至merged_users字段中
Long historyShopId = branchShopUser.getShopId();
Long historyUserId = branchShopUser.getUserId();
JSONObject branch = JSONObject.from(branchShopUser, JSONWriter.Feature.WriteMapNullValue);
JSONArray objects = new JSONArray();
objects.add(branch);
branchShopUser.setShopId(headShopId);
branchShopUser.setMergedUsers(objects.toJSONString(JSONWriter.Feature.WriteMapNullValue));
shopUserMapper.update(branchShopUser);
// 更新会员流水记录到主店
UpdateChain.of(ShopUserFlow.class)
.set(ShopUserFlow::getShopId, headShopId)
.eq(ShopUserFlow::getShopId, historyShopId)
.eq(ShopUserFlow::getUserId, historyUserId)
.update();
}
}

View File

@@ -6,7 +6,6 @@ import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.*;
@@ -43,7 +42,6 @@ import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil;
import com.czg.utils.MD5Util;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import lombok.NonNull;
@@ -656,7 +654,7 @@ public class PayServiceImpl implements PayService {
.setType(1)
.setRelationId(orderInfo.getId())
.setBizEnum(ShopUserFlowBizEnum.ORDER_REFUND);
shopUserService.updateMoney(orderInfo.getShopId(), shopUserMoneyEditDTO);
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
} else if (orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) {
AssertUtil.isNull(orderInfo.getCreditBuyerId(), "挂账单退款失败,未查询到挂账人");
buyerOrderService.partRefund(orderInfo.getCreditBuyerId().toString(), orderInfo.getId(), param.getRefundAmount());

View File

@@ -82,6 +82,7 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
//entity.setStatus(StatusEnum.ENABLED.value());
entity.setShopId(shopId);
super.save(entity);
dto.setId(entity.getId());
}
@Override

View File

@@ -128,6 +128,7 @@ public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> i
entity.setIsStock(YesNoEnum.NO.value());
entity.setShopId(shopId);
super.save(entity);
dto.setId(entity.getId());
return true;
}

View File

@@ -31,8 +31,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import static com.czg.constant.CacheConstant.ADMIN_CLIENT_PRODUCT_LIST;
/**
* 商品分组
*
@@ -98,6 +96,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
ProdGroup entity = BeanUtil.copyProperties(dto, ProdGroup.class);
entity.setShopId(shopId);
super.save(entity);
dto.setId(entity.getId());
Long[] productIds = dto.getProductIds();
if (ArrayUtil.isNotEmpty(productIds)) {
int sort = 0;

View File

@@ -278,6 +278,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
flow.setInOutType(InOutTypeEnum.IN.value());
flow.setInOutItem(InOutItemEnum.WIN_IN.value());
productStockFlowService.saveFlow(flow);
dto.setId(entity.getId());
}
@Override

View File

@@ -74,6 +74,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
entity.setPid(0L);
entity.setShopId(shopId);
super.save(entity);
dto.setId(entity.getId());
}
@Override

View File

@@ -67,7 +67,7 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
}
@Override
public void addShopProdUnit(ShopProdUnitDTO dto) {
public Long addShopProdUnit(ShopProdUnitDTO dto) {
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ShopProdUnit::getName, dto.getName())
.and(q -> {
@@ -88,6 +88,7 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
entity.setStatus(StatusEnum.ENABLED.value());
entity.setShopId(shopId);
super.save(entity);
return entity.getId();
}
@Override

View File

@@ -17,11 +17,13 @@ import com.czg.utils.PageUtil;
import com.czg.utils.TreeUtils;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.DbChain;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import static com.czg.product.entity.table.ShopProdSpecTableDef.SHOP_PROD_SPEC;
@@ -36,7 +38,6 @@ import static com.czg.product.entity.table.ShopProdSpecTableDef.SHOP_PROD_SPEC;
@Service
public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper, ShopProdSpec> implements ShopProdSpecService {
private QueryWrapper buildQueryWrapper(ShopProdSpecDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
if (ObjUtil.isNotNull(param.getPid())) {
@@ -110,6 +111,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override
@Transactional(rollbackFor = Exception.class)
public void updateShopProdSpec(ShopProdSpecDTO dto) {
List<Long> affectedIdList = new ArrayList<>();
//上级规格不能为自身
if (dto.getId().equals(dto.getPid())) {
throw new CzgException("上级规格不能为自身");
@@ -142,6 +144,10 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
.like(ShopProdSpec::getPids, "," + entity.getId() + ",")
.eq(ShopProdSpec::getShopId, entity.getShopId()).update();
super.updateById(entity);
affectedIdList.add(entity.getId());
List<Long> ids = DbChain.table("tb_shop_prod_spec").select("id").where("pids like concat('%,',?,',%') and shop_id = ?", entity.getId(), entity.getShopId()).listAs(Long.class);
affectedIdList.addAll(ids);
dto.setAffectedIdList(affectedIdList);
}
@Override
@@ -174,6 +180,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override
@Transactional(rollbackFor = Exception.class)
public void quickAddShopProdSpec(ShopProdSpecDTO dto) {
List<Long> affectedIdList = new ArrayList<>();
String name = dto.getName();
AssertUtil.isBlank(name, "1级规格名称不能为空");
List<ShopProdSpecDTO> level2List = dto.getChildren();
@@ -201,6 +208,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
dto.setSort(ObjUtil.defaultIfNull(maxId, 0).intValue() + 1);
dto.setPid(GlobalConstant.TREE_ROOT);
addShopProdSpec(dto);
affectedIdList.add(dto.getId());
int xIndex = 0;
for (ShopProdSpecDTO level2Dto : level2List) {
xIndex++;
@@ -208,6 +216,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
level2Dto.setSort(xIndex);
level2Dto.setPid(dto.getId());
addShopProdSpec(level2Dto);
affectedIdList.add(level2Dto.getId());
List<ShopProdSpecDTO> level3List = level2Dto.getChildren();
int yIndex = 0;
for (ShopProdSpecDTO level3Dto : level3List) {
@@ -216,8 +225,10 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
level3Dto.setSort(yIndex);
level3Dto.setPid(level2Dto.getId());
addShopProdSpec(level3Dto);
affectedIdList.add(level3Dto.getId());
}
}
dto.setAffectedIdList(affectedIdList);
}
@Override

View File

@@ -3,7 +3,6 @@ package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
@@ -18,14 +17,12 @@ import com.czg.exception.CzgException;
import com.czg.product.entity.*;
import com.czg.product.service.*;
import com.czg.product.vo.ProductGroupVo;
import com.czg.sa.StpKit;
import com.czg.utils.AssertUtil;
import com.mybatisflex.core.query.QueryWrapper;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;