diff --git a/cash-api/account-server/src/main/java/com/czg/controller/user/UShopUserController.java b/cash-api/account-server/src/main/java/com/czg/controller/user/UShopUserController.java index 66cfb8a8c..4ae9b3fb6 100644 --- a/cash-api/account-server/src/main/java/com/czg/controller/user/UShopUserController.java +++ b/cash-api/account-server/src/main/java/com/czg/controller/user/UShopUserController.java @@ -31,7 +31,6 @@ public class UShopUserController { return CzgResult.success(shopUserService.getShopUserInfo(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong())); } - /** * 获取当前用户所有店铺会员信息 * @return 店铺会员信息列表 @@ -41,4 +40,13 @@ public class UShopUserController { return CzgResult.success(shopUserService.vipCard(StpKit.USER.getLoginIdAsLong())); } + /** + * 获取动态会员码 + * @return 店铺会员信息列表 + */ + @GetMapping("/code") + public CzgResult code() { + return CzgResult.success(shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), StpKit.USER.getShopId())); + } + } diff --git a/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java b/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java index 1bf57bf3b..dccc99c05 100644 --- a/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java +++ b/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java @@ -12,4 +12,6 @@ public interface RedisCst { String SMS_CODE = "sms:code:"; + // 店铺会员动态支付码 + String SHOP_USER_DYNAMIC_CODE = "shop:user:dynamic:code:"; } diff --git a/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserService.java b/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserService.java index b8d1fc327..1dc513c0d 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserService.java @@ -30,4 +30,5 @@ public interface ShopUserService extends IService { */ Page vipCard(long userInfoId); + String getCode(long userInfoId, long shopId); } diff --git a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserServiceImpl.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserServiceImpl.java index dfb398b11..67779881f 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserServiceImpl.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserServiceImpl.java @@ -2,6 +2,8 @@ package com.czg.service.account.service.impl; import cn.hutool.core.bean.BeanUtil; 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.entity.ShopUser; 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.ShopUserService; import com.czg.account.service.UserInfoService; +import com.czg.config.RedisCst; import com.czg.enums.ShopUserFlowBizEnum; import com.czg.exception.ApiNotPrintException; import com.czg.sa.StpKit; +import com.czg.service.RedisService; import com.czg.service.account.mapper.ShopUserMapper; import com.czg.utils.PageUtil; import com.mybatisflex.core.paginate.Page; @@ -28,11 +32,13 @@ import java.math.RoundingMode; * @since 2025-02-08 */ @Service -public class ShopUserServiceImpl extends ServiceImpl implements ShopUserService { +public class ShopUserServiceImpl extends ServiceImpl implements ShopUserService { @Resource private ShopUserFlowService shopUserFlowService; @Resource private UserInfoService userInfoService; + @Resource + private RedisService redisService; private ShopUser getUserInfo(Long shopUserId, Long shopId) { ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one(); @@ -64,7 +70,7 @@ public class ShopUserServiceImpl extends ServiceImpl int flag = 0; if (shopUserEditDTO.getType() == 0) { flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney()); - }else { + } else { flag = mapper.incrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney()); } if (flag == 0) { @@ -114,7 +120,7 @@ public class ShopUserServiceImpl extends ServiceImpl ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class); 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); } @@ -122,4 +128,32 @@ public class ShopUserServiceImpl extends ServiceImpl public Page vipCard(long 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; + } }