会员码接口

This commit is contained in:
张松
2025-02-15 17:40:56 +08:00
parent 3315bfbb28
commit 6b77134c05
4 changed files with 49 additions and 4 deletions

View File

@@ -31,7 +31,6 @@ public class UShopUserController {
return CzgResult.success(shopUserService.getShopUserInfo(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong())); return CzgResult.success(shopUserService.getShopUserInfo(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong()));
} }
/** /**
* 获取当前用户所有店铺会员信息 * 获取当前用户所有店铺会员信息
* @return 店铺会员信息列表 * @return 店铺会员信息列表
@@ -41,4 +40,13 @@ public class UShopUserController {
return CzgResult.success(shopUserService.vipCard(StpKit.USER.getLoginIdAsLong())); return CzgResult.success(shopUserService.vipCard(StpKit.USER.getLoginIdAsLong()));
} }
/**
* 获取动态会员码
* @return 店铺会员信息列表
*/
@GetMapping("/code")
public CzgResult<String> code() {
return CzgResult.success(shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), StpKit.USER.getShopId()));
}
} }

View File

@@ -12,4 +12,6 @@ public interface RedisCst {
String SMS_CODE = "sms:code:"; String SMS_CODE = "sms:code:";
// 店铺会员动态支付码
String SHOP_USER_DYNAMIC_CODE = "shop:user:dynamic:code:";
} }

View File

@@ -30,4 +30,5 @@ public interface ShopUserService extends IService<ShopUser> {
*/ */
Page<ShopUserVipCardDTO> vipCard(long userInfoId); Page<ShopUserVipCardDTO> vipCard(long userInfoId);
String getCode(long userInfoId, long shopId);
} }

View File

@@ -2,6 +2,8 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.czg.account.dto.shopuser.*; import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.entity.ShopUserFlow; import com.czg.account.entity.ShopUserFlow;
@@ -9,9 +11,11 @@ import com.czg.account.entity.UserInfo;
import com.czg.account.service.ShopUserFlowService; import com.czg.account.service.ShopUserFlowService;
import com.czg.account.service.ShopUserService; import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService; import com.czg.account.service.UserInfoService;
import com.czg.config.RedisCst;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.ApiNotPrintException; import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.service.account.mapper.ShopUserMapper; import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.utils.PageUtil; import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
@@ -28,11 +32,13 @@ import java.math.RoundingMode;
* @since 2025-02-08 * @since 2025-02-08
*/ */
@Service @Service
public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService { public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService {
@Resource @Resource
private ShopUserFlowService shopUserFlowService; private ShopUserFlowService shopUserFlowService;
@Resource @Resource
private UserInfoService userInfoService; private UserInfoService userInfoService;
@Resource
private RedisService redisService;
private ShopUser getUserInfo(Long shopUserId, Long shopId) { private ShopUser getUserInfo(Long shopUserId, Long shopId) {
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one(); ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one();
@@ -64,7 +70,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser>
int flag = 0; int flag = 0;
if (shopUserEditDTO.getType() == 0) { if (shopUserEditDTO.getType() == 0) {
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney()); flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
}else { } else {
flag = mapper.incrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney()); flag = mapper.incrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
} }
if (flag == 0) { if (flag == 0) {
@@ -114,7 +120,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser>
ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class); ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class);
shopUser.setShopId(shopId); shopUser.setShopId(shopId);
shopUser.setJoinTime(shopUser.getIsVip() != null &&shopUser.getIsVip() == 1 ? DateUtil.date().toLocalDateTime() : null); shopUser.setJoinTime(shopUser.getIsVip() != null && shopUser.getIsVip() == 1 ? DateUtil.date().toLocalDateTime() : null);
return save(shopUser); return save(shopUser);
} }
@@ -122,4 +128,32 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser>
public Page<ShopUserVipCardDTO> vipCard(long userInfoId) { public Page<ShopUserVipCardDTO> vipCard(long userInfoId) {
return mapper.selectVipCard(PageUtil.buildPage(), userInfoId); return mapper.selectVipCard(PageUtil.buildPage(), userInfoId);
} }
@Override
public String getCode(long userInfoId, long shopId) {
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfoId).one();
if (shopUser == null) {
throw new ApiNotPrintException("会员信息不存在");
}
String dynamicCode = generatePaymentCode(String.valueOf(shopId), String.valueOf(userInfoId));
redisService.set(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getId(), dynamicCode, 300);
shopUser.setDynamicCode(dynamicCode);
updateById(shopUser);
return 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;
}
} }