|
|
|
|
@@ -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<ShopUserMapper, ShopUser> implements ShopUserService {
|
|
|
|
|
public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> 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<ShopUserMapper, ShopUser>
|
|
|
|
|
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<ShopUserMapper, ShopUser>
|
|
|
|
|
|
|
|
|
|
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<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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|