shopId为空时 余额为0

This commit is contained in:
wangw 2024-06-05 09:31:05 +08:00
parent b7ce764bdb
commit 4aa5bd33b1
1 changed files with 29 additions and 23 deletions

View File

@ -29,6 +29,7 @@ import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
@ -78,30 +79,35 @@ public class UserContoller {
// }
@GetMapping("/shopUserInfo")
public Result shopUserInfo(@RequestParam("userId") String userId ,@RequestHeader("openId") String openId,@RequestParam("shopId") String shopId ) throws Exception {
TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(userId,shopId);
if (ObjectUtil.isEmpty(shopUser)) {
TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
shopUser = new TbShopUser();
shopUser.setName(tbUserInfo.getNickName());
shopUser.setSex(tbUserInfo.getSex());
shopUser.setBirthDay(tbUserInfo.getBirthDay());
shopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone());
TbShopUser shopUser=new TbShopUser();
if (StringUtils.isNotBlank(shopId)) {
shopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId);
if (ObjectUtil.isEmpty(shopUser)) {
TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
shopUser = new TbShopUser();
shopUser.setName(tbUserInfo.getNickName());
shopUser.setSex(tbUserInfo.getSex());
shopUser.setBirthDay(tbUserInfo.getBirthDay());
shopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone());
shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0);
shopUser.setLevelConsume(BigDecimal.ZERO);
shopUser.setStatus(Byte.parseByte("1"));
shopUser.setShopId(shopId);
shopUser.setUserId(userId);
shopUser.setMiniOpenId(openId);
shopUser.setCreatedAt(System.currentTimeMillis());
shopUser.setUpdatedAt(System.currentTimeMillis());
shopUserMapper.insert(shopUser);
}
}else {
shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0);
shopUser.setLevelConsume(BigDecimal.ZERO);
shopUser.setStatus(Byte.parseByte("1"));
shopUser.setShopId(shopId);
shopUser.setUserId(userId);
shopUser.setMiniOpenId(openId);
shopUser.setCreatedAt(System.currentTimeMillis());
shopUser.setUpdatedAt(System.currentTimeMillis());
shopUserMapper.insert(shopUser);
}
return Result.success(CodeEnum.SUCCESS,shopUser);
}