会员 mainShopId
This commit is contained in:
@@ -23,12 +23,13 @@ public interface ShopUserMapper extends BaseMapper<ShopUser> {
|
||||
|
||||
List<ShopUserDTO> selectPageByKeyAndIsVip(@Param("shopId") Long shopId, @Param("isVip") Integer isVip, @Param("key") String key, @Param("amount") BigDecimal amount);
|
||||
|
||||
int incrAccount(@Param("shopId") long shopId, @Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);
|
||||
int decrAccount(@Param("shopId") long shopId, @Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);
|
||||
int incrAccount(@Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);
|
||||
int decrAccount(@Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);
|
||||
|
||||
ShopUserSummaryDTO selectUserSummary(@Param("shopId") Long shopId, @Param("isVip") Integer isVip);
|
||||
|
||||
Page<ShopUserVipCardDTO> selectVipCard();
|
||||
|
||||
long selectVipCard_COUNT();
|
||||
|
||||
UserInfoAssetsSummaryDTO selectAssetsSummary(@Param("userId") Long userInfoId);
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.shopuser.*;
|
||||
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.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.TbMemberConfigService;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
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.ShopUserMapper;
|
||||
import com.czg.system.entity.SysParams;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.JoinQueryWrapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
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;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 商户储值会员 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-08
|
||||
*/
|
||||
@Service
|
||||
public class AShopUserServiceImpl implements AShopUserService {
|
||||
@Resource
|
||||
private ShopUserService shopUserService;
|
||||
@Resource
|
||||
private ShopUserMapper shopUserMapper;
|
||||
@DubboReference
|
||||
private SysParamsService sysParamsService;
|
||||
@DubboReference
|
||||
private OrderInfoService orderInfoService;
|
||||
@DubboReference
|
||||
private OrderDetailService orderDetailService;
|
||||
|
||||
@Resource
|
||||
private ShopUserFlowService shopUserFlowService;
|
||||
@Resource
|
||||
private UserInfoService userInfoService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@DubboReference
|
||||
private MkShopCouponRecordService couponRecordService;
|
||||
@Resource
|
||||
// private ShopInfoMapper shopInfoMapper;
|
||||
private ShopInfoService shopInfoService;
|
||||
@Resource
|
||||
private ShopExtendService shopExtendService;
|
||||
@Resource
|
||||
private FreeDineConfigService freeDineConfigService;
|
||||
@Resource
|
||||
private ShopConfigMapper shopConfigMapper;
|
||||
@DubboReference
|
||||
private TbMemberConfigService memberConfigService;
|
||||
|
||||
private ShopUser getUserInfo(Long shopUserId) {
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getId, shopUserId).one();
|
||||
if (shopUser == null) {
|
||||
throw new ApiNotPrintException("用户信息不存在");
|
||||
}
|
||||
return shopUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount) {
|
||||
Long shopId = StpKit.USER.getHeadShopIdBySession();
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
return PageUtil.convert(new PageInfo<>(shopUserMapper.selectPageByKeyAndIsVip(shopId, isVip, key, amount)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO) {
|
||||
if (StrUtil.isNotBlank(shopUserEditDTO.getPhone())) {
|
||||
long count = count(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getPhone, shopUserEditDTO.getPhone()).ne(ShopUser::getId, shopUserEditDTO.getId()));
|
||||
if (count > 0) {
|
||||
throw new ApiNotPrintException("手机号已存在");
|
||||
}
|
||||
}
|
||||
ShopUser shopUser = getUserInfo(shopId, shopUserEditDTO.getId());
|
||||
BeanUtil.copyProperties(shopUserEditDTO, shopUser);
|
||||
return updateById(shopUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopUserSummaryDTO getSummary(Long shopId, Integer isVip) {
|
||||
return mapper.selectUserSummary(shopId, isVip);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO) {
|
||||
UserInfo userInfo = userInfoService.queryChain().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()).one();
|
||||
if (userInfo == null) {
|
||||
userInfo = BeanUtil.copyProperties(shopUserAddDTO, UserInfo.class);
|
||||
userInfoService.save(userInfo);
|
||||
}
|
||||
|
||||
ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class);
|
||||
shopUser.setCode(generateCode(shopId));
|
||||
shopUser.setSourceShopId(shopId);
|
||||
shopUser.setSourceShopId(shopId);
|
||||
shopUser.setUserId(userInfo.getId());
|
||||
shopUser.setJoinTime(shopUser.getIsVip() != null && shopUser.getIsVip() == 1 ? DateUtil.date().toLocalDateTime() : null);
|
||||
return save(shopUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopUser getDetail(Integer id, Integer userId) {
|
||||
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getUsableShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId));
|
||||
long count = couponRecordService.count(new QueryWrapper()
|
||||
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.eq(MkShopCouponRecord::getIsDel, 0)
|
||||
);
|
||||
ShopUserDTO shopUserDTO = BeanUtil.copyProperties(shopUser, ShopUserDTO.class);
|
||||
shopUserDTO.setCouponNum(count);
|
||||
shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, StpKit.USER.getShopId(0L)).eq(OrderInfo::getStatus, "done")));
|
||||
return shopUserDTO;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
if (!isAllowAccountLogin) {
|
||||
throw new ApiNotPrintException("当前分店账号被禁止登录");
|
||||
}
|
||||
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), shopInfo.getShopName(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin(), platType);
|
||||
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), shopInfo.getMainId(), shopInfo.getShopName(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin(), platType);
|
||||
// 查询角色
|
||||
List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
|
||||
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
|
||||
@@ -161,13 +161,10 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
if (shopStaffPromissionList != null && !shopStaffPromissionList.isEmpty()) {
|
||||
promissionList.addAll(shopStaffPromissionList);
|
||||
}
|
||||
boolean isEnableSync = StpKit.USER.isEnableSync(shopInfo.getId());
|
||||
if (isEnableSync && CollUtil.contains(roleNames, "商户")) {
|
||||
if (shopInfo.getMainId() != null && CollUtil.contains(roleNames, "商户")) {
|
||||
roleNames.remove("商户");
|
||||
roleNames.add("分店商户");
|
||||
List<String> headShopPromissionList = sysMenuMapper.selectByRoleId(2L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
|
||||
List<String> branchShopPromissionList = sysMenuMapper.selectByRoleId(3L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
|
||||
// promissionList.removeAll(headShopPromissionList);
|
||||
promissionList.addAll(branchShopPromissionList);
|
||||
}
|
||||
StpKit.USER.addRoleList(roleNames);
|
||||
@@ -187,7 +184,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
Long headId = StpKit.USER.getHeadId();
|
||||
long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
ShopInfo currentInfo = shopInfoService.getById(shopId);
|
||||
if (currentInfo.getIsHeadShop() != YesNoEnum.YES.value() && headId == null) {
|
||||
if (currentInfo.getIsHeadShop() != YesNoEnum.YES.value()) {
|
||||
throw new ApiNotPrintException("登录账号无权限切换");
|
||||
}
|
||||
|
||||
@@ -201,15 +198,9 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
throw new ApiNotPrintException("店铺信息不存在");
|
||||
}
|
||||
|
||||
|
||||
// 主店铺切换子店铺
|
||||
if ((headId == null && !shopInfo.getMainId().equals(shopId)) || (!sysUser.getId().equals(headId) && shopInfo.getMainId() == null) ||
|
||||
(headId != null && !sysUserId.equals(headId) && !shopInfo.getMainId().equals(headId))) {
|
||||
Long headShopId = StpKit.USER.getHeadShopId();
|
||||
Long changeHeadShopId = StpKit.USER.getHeadShopId(sysUserId);
|
||||
if (!changeHeadShopId.equals(headShopId)) {
|
||||
throw new ApiNotPrintException("目标店铺非登录账号所有");
|
||||
}
|
||||
if (!shopInfo.getMainId().equals(shopId)) {
|
||||
throw new ApiNotPrintException("目标店铺非登录账号所有");
|
||||
}
|
||||
|
||||
// 查询角色
|
||||
@@ -221,8 +212,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
// 权限赋予
|
||||
List<String> promissionList = sysMenuMapper.selectByUserId(sysUser.getId(), null).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
|
||||
List<String> newPromissionList = new ArrayList<>(promissionList);
|
||||
boolean isEnableSync = StpKit.USER.isEnableSync(shopInfo.getId());
|
||||
if (isEnableSync && CollUtil.contains(roleNames, "商户")) {
|
||||
if (shopInfo.getMainId() != null && CollUtil.contains(roleNames, "商户")) {
|
||||
roleNames.remove("商户");
|
||||
roleNames.add("分店商户");
|
||||
List<String> headShopPromissionList = sysMenuMapper.selectByRoleId(2L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
|
||||
|
||||
@@ -7,9 +7,11 @@ import com.czg.account.dto.points.OrderDeductionPointsDTO;
|
||||
import com.czg.account.entity.MemberPoints;
|
||||
import com.czg.account.entity.MemberPointsLog;
|
||||
import com.czg.account.entity.PointsBasicSetting;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.enums.PointUserGroupEnum;
|
||||
import com.czg.account.param.MemberPointsParam;
|
||||
import com.czg.account.service.MemberPointsService;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.enums.YesNoEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
@@ -42,6 +44,8 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
||||
private PointsBasicSettingMapper pointsBasicSettingMapper;
|
||||
@Resource
|
||||
private MemberPointsLogMapper memberPointsLogMapper;
|
||||
@Resource
|
||||
private ShopInfoService shopInfoService;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(MemberPointsParam param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
@@ -52,7 +56,14 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
||||
queryWrapper.like(MemberPoints::getPhone, param.getPhone());
|
||||
}
|
||||
|
||||
Long shopId = StpKit.USER.getUsableShopId();
|
||||
Long shopId = StpKit.USER.getShopId();
|
||||
ShopInfo byId = shopInfoService.getById(shopId);
|
||||
if (byId == null) {
|
||||
throw new CzgException("店铺不存在");
|
||||
}
|
||||
if (byId.getIsEnableVipSync().equals(1)) {
|
||||
shopId = byId.getMainId();
|
||||
}
|
||||
queryWrapper.eq(MemberPoints::getShopId, shopId);
|
||||
queryWrapper.orderBy(MemberPoints::getShopUserId, false);
|
||||
return queryWrapper;
|
||||
|
||||
@@ -353,7 +353,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
distance = GeoUtil.getDistance(Long.parseLong(shopInfo.getLat()), Long.parseLong(shopInfo.getLng()), Long.parseLong(lat), Long.parseLong(lng));
|
||||
}
|
||||
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, shopInfo.getId()).eq(ShopUser::getUserId, StpKit.USER.getLoginIdAsLong()).one();
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getUserId, StpKit.USER.getLoginIdAsLong()).one();
|
||||
List<ShopExtend> shopExtends = shopExtendService.listInfo(shopInfo.getId(), null);
|
||||
Map<String, ShopExtend> shopExtendMap = shopExtends.stream().collect(Collectors.toMap(ShopExtend::getAutoKey, i -> i));
|
||||
return new ShopInfoByCodeDTO(distance, shopInfo, shopExtendMap, shopTable, shopUser != null && shopUser.getIsVip() != null && shopUser.getIsVip() == 1);
|
||||
@@ -382,7 +382,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
head.setShopName(shopInfo.getShopName());
|
||||
list.add(head);
|
||||
MyStpLogic.LoginType loginType = (MyStpLogic.LoginType) StpKit.USER.getSession().get("loginType");
|
||||
if(loginType.compareTo(MyStpLogic.LoginType.STAFF) == 0){
|
||||
if (loginType.compareTo(MyStpLogic.LoginType.STAFF) == 0) {
|
||||
return list;
|
||||
}
|
||||
List<ShopInfo> branchList = mapper.selectListByQuery(query().select(ShopInfo::getId, ShopInfo::getShopName).eq(ShopInfo::getMainId, shopId).orderBy(ShopInfo::getId, true));
|
||||
@@ -394,4 +394,14 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getMainIdByShopId(Long shopId) {
|
||||
ShopInfo shopInfo = this.getById(shopId);
|
||||
if (shopInfo == null) {
|
||||
throw new CzgException("店铺信息不存在");
|
||||
}
|
||||
return shopInfo.getMainId() == null ? shopId : shopInfo.getMainId();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,45 +2,24 @@ package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.shopuser.*;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.entity.ShopUserFlow;
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserFlowService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.enums.YesNoEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.TbMemberConfigService;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
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;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.JoinQueryWrapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,85 +30,62 @@ import java.util.List;
|
||||
*/
|
||||
@DubboService
|
||||
public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService {
|
||||
@DubboReference
|
||||
private SysParamsService sysParamsService;
|
||||
@DubboReference
|
||||
private OrderInfoService orderInfoService;
|
||||
@DubboReference
|
||||
private OrderDetailService orderDetailService;
|
||||
|
||||
@Resource
|
||||
private ShopUserFlowService shopUserFlowService;
|
||||
@Resource
|
||||
private UserInfoService userInfoService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@DubboReference
|
||||
private MkShopCouponRecordService couponRecordService;
|
||||
@Resource
|
||||
private ShopInfoMapper shopInfoMapper;
|
||||
@Resource
|
||||
private ShopExtendService shopExtendService;
|
||||
@Resource
|
||||
private FreeDineConfigService freeDineConfigService;
|
||||
@Resource
|
||||
private ShopConfigMapper shopConfigMapper;
|
||||
@DubboReference
|
||||
private TbMemberConfigService memberConfigService;
|
||||
private ShopInfoService shopInfoService;
|
||||
|
||||
private ShopUser getUserInfo(Long shopId, Long shopUserId) {
|
||||
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one();
|
||||
private ShopUser getUserInfo(Long shopUserId) {
|
||||
ShopUser shopUser = queryChain().eq(ShopUser::getId, shopUserId).one();
|
||||
if (shopUser == null) {
|
||||
throw new ApiNotPrintException("用户信息不存在");
|
||||
}
|
||||
|
||||
return shopUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount) {
|
||||
Long shopId = StpKit.USER.getUsableShopId();
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
return PageUtil.convert(new PageInfo<>(mapper.selectPageByKeyAndIsVip(shopId, isVip, key, amount)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO) {
|
||||
if (StrUtil.isNotBlank(shopUserEditDTO.getPhone())) {
|
||||
long count = count(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getPhone, shopUserEditDTO.getPhone()).ne(ShopUser::getId, shopUserEditDTO.getId()));
|
||||
if (count > 0) {
|
||||
throw new ApiNotPrintException("手机号已存在");
|
||||
}
|
||||
public ShopUser getShopUserInfo(Long shopId, long userId) {
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||
ShopUser shopUser = queryChain().eq(ShopUser::getMainShopId, shopId).eq(ShopUser::getUserId, userId).one();
|
||||
if (shopUser == null) {
|
||||
shopUser = new ShopUser();
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
BeanUtil.copyProperties(userInfo, shopUser);
|
||||
shopUser.setMainShopId(mainShopId);
|
||||
shopUser.setSourceShopId(shopId);
|
||||
shopUser.setUserId(userId);
|
||||
shopUser.setId(null);
|
||||
save(shopUser);
|
||||
}
|
||||
ShopUser shopUser = getUserInfo(shopId, shopUserEditDTO.getId());
|
||||
BeanUtil.copyProperties(shopUserEditDTO, shopUser);
|
||||
return updateById(shopUser);
|
||||
return shopUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
|
||||
shopUserEditDTO.setMoney(shopUserEditDTO.getMoney().setScale(2, RoundingMode.DOWN));
|
||||
ShopUser userInfo = getUserInfo(shopId, shopUserEditDTO.getId());
|
||||
ShopUser userInfo = getUserInfo(shopUserEditDTO.getId());
|
||||
|
||||
ShopUserFlow userFlow = new ShopUserFlow();
|
||||
int flag;
|
||||
if (shopUserEditDTO.getType() == 0) {
|
||||
if (shopUserEditDTO.getMoney().compareTo(userInfo.getAmount()) > 0) {
|
||||
//如果超额退款 则退为0
|
||||
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), userInfo.getAmount());
|
||||
flag = mapper.decrAccount(shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), userInfo.getAmount());
|
||||
} else {
|
||||
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
|
||||
flag = mapper.decrAccount(shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
|
||||
}
|
||||
} else {
|
||||
flag = mapper.incrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
|
||||
flag = mapper.incrAccount(shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
|
||||
}
|
||||
if (flag == 0) {
|
||||
throw new ApiNotPrintException("增减用户余额操作失败");
|
||||
}
|
||||
|
||||
userFlow.setUserId(userInfo.getUserId());
|
||||
userFlow.setShopId(userInfo.getShopId());
|
||||
userFlow.setShopId(userInfo.getSourceShopId());
|
||||
userFlow.setAmount(shopUserEditDTO.getType() == 0 ? shopUserEditDTO.getMoney().negate() : shopUserEditDTO.getMoney());
|
||||
userFlow.setBalance(shopUserEditDTO.getType() == 0 ? userInfo.getAmount().subtract(shopUserEditDTO.getMoney()) : userInfo.getAmount().add(shopUserEditDTO.getMoney()));
|
||||
if (userFlow.getBalance().compareTo(BigDecimal.ZERO) < 0) {
|
||||
@@ -150,234 +106,4 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
||||
}
|
||||
return userFlow.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopUserSummaryDTO getSummary(Long shopId, Integer isVip) {
|
||||
return mapper.selectUserSummary(shopId, isVip);
|
||||
}
|
||||
|
||||
@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();
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
BeanUtil.copyProperties(userInfo, shopUser);
|
||||
shopUser.setShopId(shopId);
|
||||
shopUser.setUserId(userId);
|
||||
shopUser.setId(null);
|
||||
save(shopUser);
|
||||
}
|
||||
return shopUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO) {
|
||||
UserInfo userInfo = userInfoService.queryChain().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()).one();
|
||||
if (userInfo == null) {
|
||||
userInfo = BeanUtil.copyProperties(shopUserAddDTO, UserInfo.class);
|
||||
userInfoService.save(userInfo);
|
||||
}
|
||||
|
||||
ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class);
|
||||
shopUser.setCode(generateCode(shopId));
|
||||
shopUser.setShopId(shopId);
|
||||
shopUser.setUserId(userInfo.getId());
|
||||
shopUser.setJoinTime(shopUser.getIsVip() != null && shopUser.getIsVip() == 1 ? DateUtil.date().toLocalDateTime() : null);
|
||||
return save(shopUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopUserVipCardDTO> vipCard(long userInfoId) {
|
||||
return mapper.xmlPaginate("selectVipCard", PageUtil.buildPage(), new JoinQueryWrapper().eq(ShopUser::getUserId, userInfoId));
|
||||
}
|
||||
|
||||
@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)) {
|
||||
return CzgResult.failure("加入会员后使用");
|
||||
}
|
||||
String dynamicCode = generatePaymentCode(String.valueOf(shopId), String.valueOf(userInfoId));
|
||||
redisService.set(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getShopId() + ":" + dynamicCode, shopUser.getId(), 180);
|
||||
return CzgResult.success(dynamicCode);
|
||||
}
|
||||
|
||||
public String generatePaymentCode(String shopId, String platformNumber) {
|
||||
// 获取当前毫秒时间戳的后四位
|
||||
String date = String.format("%04d", System.currentTimeMillis() % 10000);
|
||||
|
||||
// 获取店铺ID的最后2位数字
|
||||
String shopIdLastTwoDigits = String.format("%02d", Integer.parseInt(shopId) % 100);
|
||||
|
||||
// 生成一个6位随机数
|
||||
String randomPart = RandomUtil.randomNumbers(6);
|
||||
|
||||
// 拼接生成支付码:毫秒后的四位 + 平台号码 + 店铺ID的最后2位 + 随机数
|
||||
|
||||
return date + platformNumber + shopIdLastTwoDigits + randomPart;
|
||||
}
|
||||
|
||||
public String generateCode(long shopId) {
|
||||
String code = "shop_user_code_val%d".formatted(shopId);
|
||||
SysParams sysParam = sysParamsService.getOne(new QueryWrapper().eq(SysParams::getParamCode, code));
|
||||
|
||||
if (sysParam == null) {
|
||||
SysParams sysParams = new SysParams()
|
||||
.setParamValue("1")
|
||||
.setParamType(1)
|
||||
.setCreateTime(DateUtil.date().toLocalDateTime())
|
||||
.setParamCode(code);
|
||||
sysParamsService.save(sysParams);
|
||||
return generateRandomCode(1);
|
||||
}
|
||||
|
||||
long parseLong = Long.parseLong(sysParam.getParamValue());
|
||||
long l = ++parseLong;
|
||||
sysParam.setParamValue(String.valueOf(l));
|
||||
sysParamsService.updateById(sysParam);
|
||||
|
||||
return generateRandomCode(l);
|
||||
}
|
||||
|
||||
// 使用Hutool生成十六进制代码并随机填充字母
|
||||
private String generateRandomCode(long value) {
|
||||
// 生成十六进制代码,确保为10位
|
||||
String hexCode = String.format("%010X", value);
|
||||
|
||||
// 计算需要补充的字母数量
|
||||
int missingLength = 10 - hexCode.length();
|
||||
StringBuilder codeBuilder = new StringBuilder(hexCode);
|
||||
|
||||
for (int i = 0; i < missingLength; i++) {
|
||||
// 生成随机字母
|
||||
char randomChar = RandomUtil.randomChar("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
codeBuilder.append(randomChar);
|
||||
}
|
||||
|
||||
return codeBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean join(Long shopId, Long userId, ShopUserAddDTO shopUserAddDTO) {
|
||||
// 当前用户信息
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
|
||||
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfo.getId()));
|
||||
if (shopUser == null) {
|
||||
shopUser = new ShopUser();
|
||||
shopUser.setUserId(userId);
|
||||
shopUser.setShopId(shopId);
|
||||
}
|
||||
|
||||
// 查询系统添加的会员
|
||||
UserInfo oriInfo = userInfoService.getOne(new QueryWrapper().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()));
|
||||
if (oriInfo != null && !oriInfo.getId().equals(userId)) {
|
||||
// 迁移订单
|
||||
OrderInfo orderInfo = new OrderInfo();
|
||||
orderInfo.setUserId(userId);
|
||||
orderInfoService.update(orderInfo, new QueryWrapper().eq(OrderInfo::getUserId, oriInfo.getId()));
|
||||
// 删除多余用户信息
|
||||
userInfoService.removeById(oriInfo.getId());
|
||||
BeanUtil.copyProperties(oriInfo, userInfo, "id", "alipayOpenId", "wechatOpenId");
|
||||
|
||||
ShopUser oldUserInfo = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, oriInfo.getId()));
|
||||
if (oldUserInfo != null) {
|
||||
removeById(oldUserInfo.getId());
|
||||
BeanUtil.copyProperties(oldUserInfo, shopUser, "id", "userId");
|
||||
}
|
||||
}
|
||||
|
||||
BeanUtil.copyProperties(shopUserAddDTO, shopUser, "accountPoints", "amount");
|
||||
BeanUtil.copyProperties(shopUserAddDTO, userInfo);
|
||||
userInfoService.updateById(userInfo);
|
||||
|
||||
if ((shopUser.getIsVip() == null || shopUser.getIsVip() != 1) && shopUser.getId() != null) {
|
||||
shopUser.setIsVip(1);
|
||||
if (StrUtil.isBlank(shopUser.getCode())) {
|
||||
shopUser.setCode(generateCode(shopId));
|
||||
}
|
||||
shopUser.setJoinTime(DateUtil.date().toLocalDateTime());
|
||||
shopUser.setUserId(null);
|
||||
shopUser.setShopId(null);
|
||||
}
|
||||
|
||||
memberConfigService.joinMember(shopId, userId, null);
|
||||
return saveOrUpdate(shopUser);
|
||||
}
|
||||
|
||||
@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) {
|
||||
throw new ApiNotPrintException("用户信息不存在");
|
||||
}
|
||||
|
||||
long couponNum = 0;
|
||||
if (shopUser == null) {
|
||||
shopUser = BeanUtil.copyProperties(userInfo, ShopUser.class);
|
||||
shopUser.setShopId(shopId);
|
||||
shopUser.setId(null);
|
||||
shopUser.setUserId(userId);
|
||||
save(shopUser);
|
||||
shopUser = getById(shopUser.getId());
|
||||
} else {
|
||||
couponNum = couponRecordService.count(new QueryWrapper()
|
||||
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.eq(MkShopCouponRecord::getIsDel,0)
|
||||
);
|
||||
}
|
||||
ShopUserDetailDTO shopUserDetailDTO = BeanUtil.copyProperties(shopUser, ShopUserDetailDTO.class);
|
||||
shopUserDetailDTO.setCouponNum(couponNum);
|
||||
|
||||
ShopInfo shopInfo = shopInfoMapper.selectOneById(shopId);
|
||||
if (shopInfo != null) {
|
||||
shopUserDetailDTO.setShopName(shopInfo.getShopName());
|
||||
shopUserDetailDTO.setShopId(shopInfo.getId());
|
||||
|
||||
ShopConfig config = shopConfigMapper.selectOneByQuery(new QueryWrapper().eq(ShopConfig::getId, shopId));
|
||||
if (config != null) {
|
||||
BeanUtil.copyProperties(config, shopInfo, "id");
|
||||
}
|
||||
shopUserDetailDTO.setShopInfo(shopInfo);
|
||||
List<ShopExtend> shopExtends = shopExtendService.list(new QueryWrapper().eq(ShopExtend::getShopId, shopInfo.getId()));
|
||||
shopUserDetailDTO.setShopExtendList(shopExtends);
|
||||
}
|
||||
|
||||
shopUserDetailDTO.setFreeDineConfig(freeDineConfigService.getConfig(shopId));
|
||||
shopUserDetailDTO.setPayPwd(userInfo.getPayPwd());
|
||||
return shopUserDetailDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopUser getDetail(Integer id, Integer userId) {
|
||||
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getUsableShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId));
|
||||
long count = couponRecordService.count(new QueryWrapper()
|
||||
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.eq(MkShopCouponRecord::getIsDel,0)
|
||||
);
|
||||
ShopUserDTO shopUserDTO = BeanUtil.copyProperties(shopUser, ShopUserDTO.class);
|
||||
shopUserDTO.setCouponNum(count);
|
||||
shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, StpKit.USER.getShopId(0L)).eq(OrderInfo::getStatus, "done")));
|
||||
return shopUserDTO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.shopuser.ShopUserAddDTO;
|
||||
import com.czg.account.dto.shopuser.ShopUserDetailDTO;
|
||||
import com.czg.account.dto.shopuser.ShopUserVipCardDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.TbMemberConfigService;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.account.mapper.ShopConfigMapper;
|
||||
import com.czg.system.entity.SysParams;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.JoinQueryWrapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 商户储值会员 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-08
|
||||
*/
|
||||
@Service
|
||||
public class UShopUserServiceImpl implements UShopUserService {
|
||||
@Resource
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private SysParamsService sysParamsService;
|
||||
@DubboReference
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private UserInfoService userInfoService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@DubboReference
|
||||
private MkShopCouponRecordService couponRecordService;
|
||||
@Resource
|
||||
private ShopInfoService shopInfoService;
|
||||
@Resource
|
||||
private ShopExtendService shopExtendService;
|
||||
@Resource
|
||||
private FreeDineConfigService freeDineConfigService;
|
||||
@Resource
|
||||
private ShopConfigMapper shopConfigMapper;
|
||||
@DubboReference
|
||||
private TbMemberConfigService memberConfigService;
|
||||
|
||||
@Override
|
||||
public ShopUser getShopUserInfo(Long shopId, long userId) {
|
||||
return shopUserService.getShopUserInfo(shopId, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopUserVipCardDTO> vipCard(long userInfoId) {
|
||||
return shopUserService.getMapper().xmlPaginate("selectVipCard", PageUtil.buildPage(), new JoinQueryWrapper().eq(ShopUser::getUserId, userInfoId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<String> getCode(long userInfoId, long shopId) {
|
||||
shopId = shopInfoService.getMainIdByShopId(shopId);
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getMainShopId, shopId).eq(ShopUser::getUserId, userInfoId).one();
|
||||
AssertUtil.isNull(shopUser, "会员信息不存在");
|
||||
if (shopUser.getIsVip().equals(0)) {
|
||||
return CzgResult.failure("加入会员后使用");
|
||||
}
|
||||
String dynamicCode = generatePaymentCode(String.valueOf(shopId), String.valueOf(userInfoId));
|
||||
redisService.set(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getMainShopId() + ":" + dynamicCode, shopUser.getId(), 180);
|
||||
return CzgResult.success(dynamicCode);
|
||||
}
|
||||
|
||||
public String generatePaymentCode(String shopId, String platformNumber) {
|
||||
// 获取当前毫秒时间戳的后四位
|
||||
String date = String.format("%04d", System.currentTimeMillis() % 10000);
|
||||
|
||||
// 获取店铺ID的最后2位数字
|
||||
String shopIdLastTwoDigits = String.format("%02d", Integer.parseInt(shopId) % 100);
|
||||
|
||||
// 生成一个6位随机数
|
||||
String randomPart = RandomUtil.randomNumbers(6);
|
||||
|
||||
// 拼接生成支付码:毫秒后的四位 + 平台号码 + 店铺ID的最后2位 + 随机数
|
||||
|
||||
return date + platformNumber + shopIdLastTwoDigits + randomPart;
|
||||
}
|
||||
|
||||
public String generateCode(long shopId) {
|
||||
String code = "shop_user_code_val%d".formatted(shopId);
|
||||
SysParams sysParam = sysParamsService.getOne(new QueryWrapper().eq(SysParams::getParamCode, code));
|
||||
|
||||
if (sysParam == null) {
|
||||
SysParams sysParams = new SysParams()
|
||||
.setParamValue("1")
|
||||
.setParamType(1)
|
||||
.setCreateTime(DateUtil.date().toLocalDateTime())
|
||||
.setParamCode(code);
|
||||
sysParamsService.save(sysParams);
|
||||
return generateRandomCode(1);
|
||||
}
|
||||
|
||||
long parseLong = Long.parseLong(sysParam.getParamValue());
|
||||
long l = ++parseLong;
|
||||
sysParam.setParamValue(String.valueOf(l));
|
||||
sysParamsService.updateById(sysParam);
|
||||
|
||||
return generateRandomCode(l);
|
||||
}
|
||||
|
||||
// 使用Hutool生成十六进制代码并随机填充字母
|
||||
private String generateRandomCode(long value) {
|
||||
// 生成十六进制代码,确保为10位
|
||||
String hexCode = String.format("%010X", value);
|
||||
|
||||
// 计算需要补充的字母数量
|
||||
int missingLength = 10 - hexCode.length();
|
||||
StringBuilder codeBuilder = new StringBuilder(hexCode);
|
||||
|
||||
for (int i = 0; i < missingLength; i++) {
|
||||
// 生成随机字母
|
||||
char randomChar = RandomUtil.randomChar("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
codeBuilder.append(randomChar);
|
||||
}
|
||||
|
||||
return codeBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean join(Long shopId, Long userId, ShopUserAddDTO shopUserAddDTO) {
|
||||
Long mainId = shopInfoService.getMainIdByShopId(shopId);
|
||||
// 当前用户信息
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getSourceShopId, shopId).eq(ShopUser::getUserId, userInfo.getId()));
|
||||
if (shopUser == null) {
|
||||
shopUser = new ShopUser();
|
||||
shopUser.setUserId(userId);
|
||||
shopUser.setSourceShopId(shopId);
|
||||
shopUser.setMainShopId(mainId);
|
||||
}
|
||||
|
||||
// 查询系统添加的会员
|
||||
UserInfo oriInfo = userInfoService.getOne(new QueryWrapper().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()));
|
||||
if (oriInfo != null && !oriInfo.getId().equals(userId)) {
|
||||
// 迁移订单
|
||||
OrderInfo orderInfo = new OrderInfo();
|
||||
orderInfo.setUserId(userId);
|
||||
orderInfoService.update(orderInfo, new QueryWrapper().eq(OrderInfo::getUserId, oriInfo.getId()));
|
||||
// 删除多余用户信息
|
||||
userInfoService.removeById(oriInfo.getId());
|
||||
BeanUtil.copyProperties(oriInfo, userInfo, "id", "alipayOpenId", "wechatOpenId");
|
||||
|
||||
ShopUser oldUserInfo = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, mainId).eq(ShopUser::getUserId, oriInfo.getId()));
|
||||
if (oldUserInfo != null) {
|
||||
shopUserService.removeById(oldUserInfo.getId());
|
||||
BeanUtil.copyProperties(oldUserInfo, shopUser, "id", "userId");
|
||||
}
|
||||
}
|
||||
|
||||
BeanUtil.copyProperties(shopUserAddDTO, shopUser, "accountPoints", "amount");
|
||||
BeanUtil.copyProperties(shopUserAddDTO, userInfo);
|
||||
userInfoService.updateById(userInfo);
|
||||
|
||||
if ((shopUser.getIsVip() == null || shopUser.getIsVip() != 1) && shopUser.getId() != null) {
|
||||
shopUser.setIsVip(1);
|
||||
if (StrUtil.isBlank(shopUser.getCode())) {
|
||||
shopUser.setCode(generateCode(shopId));
|
||||
}
|
||||
shopUser.setJoinTime(DateUtil.date().toLocalDateTime());
|
||||
shopUser.setUserId(null);
|
||||
shopUser.setSourceShopId(shopId);
|
||||
shopUser.setMainShopId(mainId);
|
||||
}
|
||||
|
||||
memberConfigService.joinMember(shopId, userId, null);
|
||||
return shopUserService.saveOrUpdate(shopUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopUserDetailDTO getInfo(Long shopId, long userId) {
|
||||
Long mainId = shopInfoService.getMainIdByShopId(shopId);
|
||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, mainId).eq(ShopUser::getUserId, userId));
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
if (userInfo == null) {
|
||||
throw new ApiNotPrintException("用户信息不存在");
|
||||
}
|
||||
|
||||
long couponNum = 0;
|
||||
if (shopUser == null) {
|
||||
shopUser = BeanUtil.copyProperties(userInfo, ShopUser.class);
|
||||
shopUser.setMainShopId(mainId);
|
||||
shopUser.setSourceShopId(shopId);
|
||||
shopUser.setId(null);
|
||||
shopUser.setUserId(userId);
|
||||
shopUserService.save(shopUser);
|
||||
// shopUser = getById(shopUser.getId());
|
||||
} else {
|
||||
couponNum = couponRecordService.count(new QueryWrapper()
|
||||
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.eq(MkShopCouponRecord::getIsDel, 0)
|
||||
);
|
||||
}
|
||||
ShopUserDetailDTO shopUserDetailDTO = BeanUtil.copyProperties(shopUser, ShopUserDetailDTO.class);
|
||||
shopUserDetailDTO.setCouponNum(couponNum);
|
||||
|
||||
ShopInfo shopInfo = shopInfoService.getById(shopId);
|
||||
if (shopInfo != null) {
|
||||
shopUserDetailDTO.setShopName(shopInfo.getShopName());
|
||||
shopUserDetailDTO.setShopId(shopInfo.getId());
|
||||
|
||||
ShopConfig config = shopConfigMapper.selectOneByQuery(new QueryWrapper().eq(ShopConfig::getId, shopId));
|
||||
if (config != null) {
|
||||
BeanUtil.copyProperties(config, shopInfo, "id");
|
||||
}
|
||||
shopUserDetailDTO.setShopInfo(shopInfo);
|
||||
List<ShopExtend> shopExtends = shopExtendService.list(new QueryWrapper().eq(ShopExtend::getShopId, shopInfo.getId()));
|
||||
shopUserDetailDTO.setShopExtendList(shopExtends);
|
||||
}
|
||||
|
||||
shopUserDetailDTO.setFreeDineConfig(freeDineConfigService.getConfig(shopId));
|
||||
shopUserDetailDTO.setPayPwd(userInfo.getPayPwd());
|
||||
return shopUserDetailDTO;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
//import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -73,7 +74,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
if (jsonObject.containsKey("phoneNumber")) {
|
||||
mobile = jsonObject.getString("phoneNumber");
|
||||
}else {
|
||||
} else {
|
||||
throw new ApiNotPrintException("手机号获取失败");
|
||||
}
|
||||
}
|
||||
@@ -117,7 +118,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
userInfo.setLastLoginTime(DateUtil.date().toLocalDateTime());
|
||||
userInfoService.saveOrUpdate(userInfo);
|
||||
// StpKit.USER.login(userInfo.getId());
|
||||
StpKit.USER.login(userInfo.getId(), openId, null, null, MyStpLogic.LoginType.USER, false, "userMini");
|
||||
StpKit.USER.login(userInfo.getId(), openId, null, null, null, MyStpLogic.LoginType.USER, false, "userMini");
|
||||
return new LoginTokenDTO(StpKit.USER.getTokenValue(), userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@
|
||||
set amount=amount + #{money},
|
||||
update_time=#{time}
|
||||
where id = #{id}
|
||||
and shop_id = #{shopId}
|
||||
</update>
|
||||
<update id="decrAccount">
|
||||
update tb_shop_user
|
||||
set amount=amount - #{money},
|
||||
update_time=#{time}
|
||||
where id = #{id}
|
||||
and shop_id = #{shopId}
|
||||
and amount - #{money} >= 0
|
||||
</update>
|
||||
|
||||
@@ -30,6 +28,7 @@
|
||||
and a.is_vip=#{isVip}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectVipCard" resultType="com.czg.account.dto.shopuser.ShopUserVipCardDTO">
|
||||
select tb_shop_info.logo, tb_shop_info.shop_name shopName, tb_shop_user.amount, tb_shop_user.shop_id shopId
|
||||
from tb_shop_user
|
||||
|
||||
Reference in New Issue
Block a user