切换店铺统计 √

下单选择会员 √
注册会员 √
完善手机号 √
会员流水信息同步 √
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();
}
}