Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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<String> code() {
|
||||
return CzgResult.success(shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), StpKit.USER.getShopId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,4 +12,6 @@ public interface RedisCst {
|
||||
|
||||
|
||||
String SMS_CODE = "sms:code:";
|
||||
// 店铺会员动态支付码
|
||||
String SHOP_USER_DYNAMIC_CODE = "shop:user:dynamic:code:";
|
||||
}
|
||||
|
||||
@@ -30,4 +30,5 @@ public interface ShopUserService extends IService<ShopUser> {
|
||||
*/
|
||||
Page<ShopUserVipCardDTO> vipCard(long userInfoId);
|
||||
|
||||
String getCode(long userInfoId, long shopId);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -33,6 +37,8 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser>
|
||||
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();
|
||||
@@ -122,4 +128,32 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser>
|
||||
public Page<ShopUserVipCardDTO> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user