创客额度相关,分享改bug,

This commit is contained in:
liuyingfang
2023-08-21 18:22:12 +08:00
parent cd190ba1f5
commit b108849572
27 changed files with 571 additions and 18 deletions

View File

@@ -0,0 +1,22 @@
package cn.pluss.platform.UserMakerQuota;
import cn.pluss.platform.entity.MerchantOrder;
import cn.pluss.platform.entity.UserMakerQuota;
import cn.pluss.platform.vo.UserMakerQuotaVO;
import com.baomidou.mybatisplus.extension.service.IService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* @author lyf
*/
public interface UserMakerQuotaService extends IService<UserMakerQuota> {
Map<String, BigDecimal> quota();
void quotaInfo(MerchantOrder order);
List<UserMakerQuotaVO> quotaList(Integer page, Integer size,Integer type);
}

View File

@@ -0,0 +1,232 @@
package cn.pluss.platform.UserMakerQuota.impl;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.pluss.platform.UserMakerQuota.UserMakerQuotaService;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.mapper.*;
import cn.pluss.platform.merchant.MerchantBaseInfoService;
import cn.pluss.platform.userAccount.UserAccountService;
import cn.pluss.platform.userApp.UserAppService;
import cn.pluss.platform.util.N;
import cn.pluss.platform.vo.UserMakerQuotaVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
/**
* @author lyf
*/
@Service
public class UserMakerQuotaServiceImpl extends ServiceImpl<UserMakerQuotaMapper, UserMakerQuota> implements UserMakerQuotaService {
@Resource
private UserMakerQuotaMapper userMakerQuotaMapper;
@Resource
private UserAppService userAppService;
@Resource
private UserAccountService userAccountService;
@Resource
private UserPromotionMapper userPromotionMapper;
@Resource
private MerchantBaseInfoService merchantBaseInfoService;
@Resource
private UserMakerFlowMapper userMakerFlowMapper;
@Resource
private UserAccountFlowMapper userAccountFlowMapper;
@Override
public Map<String, BigDecimal> quota() {
UserApp userApp = userAppService.queryUserAppByToken();
BigDecimal bigDecimal = userMakerQuotaMapper.sumQuota(userApp.getUserId());
UserAccount userAccountByUserId = userAccountService.getUserAccountByUserId(userApp.getUserId());
HashMap<String, BigDecimal> map = new HashMap<>(16);
map.put("freeQuota",bigDecimal == null?
new BigDecimal("0.00") : bigDecimal);
map.put("returnFree",userAccountByUserId == null || userAccountByUserId.getBalance() == null?
new BigDecimal("0.00") : userAccountByUserId.getBalance());
return map;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void quotaInfo(MerchantOrder order) {
BigDecimal consumeFee = new BigDecimal(String.valueOf(order.getConsumeFee()));
//商户码转userId
if (consumeFee.compareTo(new BigDecimal("0.01"))>0) {
MerchantBaseInfo merchantBaseInfoByMerchantCode = merchantBaseInfoService.getMerchantBaseInfoByMerchantCode(order.getMerchantCode());
//找到上级增加额度
UserPromotion userInfo = userPromotionMapper.selectByPrimaryKey(Long.valueOf(merchantBaseInfoByMerchantCode.getUserId()));
if (userInfo != null) {
UserPromotion userParent = userPromotionMapper.selectByUserIdMC(Long.valueOf(userInfo.getParentUserId()));
if (userParent != null && "1".equals(userParent.getIsExtend())){
BigDecimal profit = consumeFee.multiply(new BigDecimal("0.0038")).setScale(2,BigDecimal.ROUND_DOWN);
String s = String.valueOf(userParent.getUserId());
Integer integer = Integer.valueOf(s);
this.modMakerFunds(integer,"SD","免费额度",profit,"");
}
}
//自己如果是创客的话
assert userInfo != null;
if ("1".equals(userInfo.getIsExtend())){
profit(userInfo,consumeFee);
}
}
}
@Override
public List<UserMakerQuotaVO> quotaList(Integer page, Integer size, Integer type) {
Integer pageSize = size;
Integer offset = (page-1)*size;
UserApp userApp = userAppService.queryUserAppByToken();
MerchantBaseInfo merchantBaseInfoByUserId = merchantBaseInfoService.getMerchantBaseInfoByUserId(String.valueOf(userApp.getUserId()));
switch (type) {
//额度明细
case 1:
List<UserMakerFlow> userMakerFlowsList = userMakerFlowMapper.selectByUserId(userApp.getUserId(), pageSize, offset);
List<UserMakerQuotaVO> vos = new ArrayList<>();
for (UserMakerFlow userMakerFlow : userMakerFlowsList) {
UserMakerQuotaVO userMakerQuotaVO = new UserMakerQuotaVO();
userMakerQuotaVO.setUserName(merchantBaseInfoByUserId == null?"下级商户":merchantBaseInfoByUserId.getAlias());
userMakerQuotaVO.setAmount(userMakerFlow.getAmount());
userMakerQuotaVO.setCreateTime(userMakerFlow.getCreateTime());
if (userMakerFlow.getAmount().compareTo(new BigDecimal(BigInteger.ZERO))>0) {
userMakerQuotaVO.setLowerAmount(userMakerFlow.getAmount().multiply(new BigDecimal("2")).setScale(2, RoundingMode.DOWN));
}else {
userMakerQuotaVO.setLowerAmount(userMakerFlow.getAmount());
}
vos.add(userMakerQuotaVO);
}
return vos;
//返现明细
case 2:
List<UserAccountFlow> userAccountFlowsList = userAccountFlowMapper.selectByUserIdType(userApp.getUserId(),pageSize, offset);
List<UserMakerQuotaVO> userAccountVos = new ArrayList<>();
for (UserAccountFlow userAccountFlow : userAccountFlowsList) {
UserMakerQuotaVO userMakerQuotaVO = new UserMakerQuotaVO();
userMakerQuotaVO.setUserName(merchantBaseInfoByUserId == null?"下级商户":merchantBaseInfoByUserId.getAlias());
userMakerQuotaVO.setAmount(userAccountFlow.getAmount());
userMakerQuotaVO.setCreateTime(userAccountFlow.getCreateTime());
userMakerQuotaVO.setLowerAmount(userAccountFlow.getOrderAmount());
userAccountVos.add(userMakerQuotaVO);
}
return userAccountVos;
}
return new ArrayList<UserMakerQuotaVO>();
}
//增加额度
private void makerQuota(MerchantOrder order){
BigDecimal consumeFee = new BigDecimal(String.valueOf(order.getConsumeFee()));
//商户码转userId
if (consumeFee.compareTo(new BigDecimal("0.01"))>0) {
MerchantBaseInfo merchantBaseInfoByMerchantCode = merchantBaseInfoService.getMerchantBaseInfoByMerchantCode(order.getMerchantCode());
UserPromotion userInfo = userPromotionMapper.selectByPrimaryKey(Long.valueOf(merchantBaseInfoByMerchantCode.getUserId()));
if (userInfo != null && "1".equals(userInfo.getIsExtend())){
BigDecimal profit = consumeFee.multiply(new BigDecimal("0.0038")).setScale(2, RoundingMode.DOWN);
String s = String.valueOf(userInfo.getUserId());
Integer integer = Integer.valueOf(s);
this.modMakerFunds(integer,"SD","免费额度",profit,"");
}
if (userInfo != null) {
UserPromotion userParent = userPromotionMapper.selectByUserIdMC(Long.valueOf(userInfo.getParentUserId()));
if (userParent != null) {
UserMakerQuota userMakerQuota = new UserMakerQuota();
userMakerQuota.setUserId(userParent.getUserId());
userMakerQuota.setAmount(consumeFee.divide(new BigDecimal("2"),2,BigDecimal.ROUND_DOWN));
userMakerQuota.setCreateTime(new Date());
userMakerQuotaMapper.insert(userMakerQuota);
}
}
}
}
//增加提现金额
private void profit(UserPromotion userInfo,BigDecimal consumeFee){
UserMakerQuota userMakerQuota = userMakerQuotaMapper.selectByUserId(userInfo.getUserId());
BigDecimal sumbigDecimal = userMakerQuota.getAmount();
if (sumbigDecimal !=null && sumbigDecimal.compareTo(consumeFee)>=0){
BigDecimal profit = consumeFee.multiply(new BigDecimal("0.0038")).setScale(2,BigDecimal.ROUND_DOWN);
sumbigDecimal = sumbigDecimal.subtract(consumeFee);
String s = String.valueOf(userInfo.getUserId());
Integer integer = Integer.valueOf(s);
//提现金额
userAccountService.modFunds(integer,"SD","免提现额度",profit,"");
//额度改变
this.modMakerFunds(integer,"SD","免费额度",sumbigDecimal,"");
}else {
BigDecimal profit = sumbigDecimal.multiply(new BigDecimal("0.0038")).setScale(2, BigDecimal.ROUND_DOWN);
String s = String.valueOf(userInfo.getUserId());
Integer integer = Integer.valueOf(s);
//提现金额
userAccountService.modFunds(integer,"SD","免提现额度",profit,"");
//额度改变
this.modMakerFunds(integer,"SD","免费额度",BigDecimal.ZERO,"");
}
}
/**
* 创客额度相关
* @param userId
* @param bizCode
* @param bizName
* @param difference
* @param remark
*/
public void modMakerFunds(Integer userId, String bizCode, String bizName, BigDecimal difference, String remark) {
Assert.notNull(userId, "NOt Null");
Assert.notNull(bizCode, "Not Null");
Assert.notNull(bizName, "Not Null");
Assert.notNull(difference, "Not Null");
UserMakerQuota userMakerQuota= initUserMaker(userId);
if(N.gt(BigDecimal.ZERO,difference)){
difference=difference.abs().negate();
}
if(N.gt(difference,BigDecimal.ZERO)){
difference=difference.abs();
}
userMakerQuotaMapper.updateMakerFreeze(userId,difference);
UserMakerFlow flow=new UserMakerFlow();
flow.setUserId(userId);
flow.setBizCode(bizCode);
flow.setBizName(bizName);
flow.setAmount(difference.abs());
flow.setBalance(userMakerQuota.getAmount());
flow.setCreateTime(new Date());
userMakerFlowMapper.insert(flow);
}
private UserMakerQuota initUserMaker(Integer userId){
Assert.notNull(userId, "NOt Null");
synchronized (this){
UserMakerQuota userMakerQuota = getUserAccountByUserId(userId);
if(ObjectUtil.isEmpty(userMakerQuota)){
userMakerQuota=new UserMakerQuota();
userMakerQuota.setUserId(Long.valueOf(userId));
userMakerQuota.setAmount(BigDecimal.ZERO);
userMakerQuota.setCreateTime(new Date());
int result=baseMapper.insert(userMakerQuota);
if(result<1){
MsgException.checkNull(null,"账户信息不存在");
}
}
return userMakerQuota;
}
}
public UserMakerQuota getUserAccountByUserId(Integer userId) {
return baseMapper.selectById(userId);
}
}

View File

@@ -122,7 +122,7 @@ public class AliPayNotifyServiceImpl extends BaseCallbackService implements AliP
/**
* 更新订单信息和状态
*
* @param param 订单回调信息
* @param param 银收客信息
*/
private void updateOrderStatus(Map<String, Object> param) {
// 商户订单号

View File

@@ -13,7 +13,7 @@ public interface UserAccountService {
* @return
*/
public UserAccount getUserAccountByUserId(Integer userId);
public UserAccount getUserAccountByUserId(Long userId);
/**
* 查询用户信息行锁
* @param userId

View File

@@ -36,6 +36,11 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserA
return baseMapper.selectById(userId);
}
@Override
public UserAccount getUserAccountByUserId(Long userId) {
return baseMapper.selectById(userId);
}
@Override
public UserAccount getUserAccountByUserIdForUpdate(Integer userId) {
return userAccountMapper.selectUserByUserId(userId);

View File

@@ -8,6 +8,7 @@ import cn.pluss.platform.dto.ChangePwdDTO;
import cn.pluss.platform.entity.MerchantOrder;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.entity.UserInfo;
import cn.pluss.platform.entity.UserPromotion;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.mapper.UserInfoMapper;
import com.alibaba.fastjson.JSONObject;
@@ -27,6 +28,9 @@ public interface UserInfoService extends IService<UserInfo> {
*/
void register(UserInfo userInfo);
void goregister(UserInfo userInfo, UserApp userApp, UserPromotion userPromotion);
/**
* 忘记密码
* @param userInfo 用户信息

View File

@@ -5,9 +5,11 @@ import cn.jiguang.common.utils.StringUtils;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.jfShop.JfShopHandler;
import cn.pluss.platform.mapper.UserInfoMapper;
import cn.pluss.platform.mapper.UserPromotionMapper;
import cn.pluss.platform.roleUserInfo.RoleUserInfoService;
import cn.pluss.platform.systemConfig.SystemConfigService;
import cn.pluss.platform.user.UserIpRecordService;
import cn.pluss.platform.util.MD5Util;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
@@ -19,7 +21,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -211,15 +212,39 @@ public class UserInfoServiceImpl extends BaseUserInfoService {
// ipRecordService.saveRegIp(userInfo.getId() + "", operatorUserId);
}
@Autowired
private UserIpRecordService ipRecordService;
@Autowired
private UserInfoMapper userInfoMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void goregister(UserInfo userInfo, UserApp userApp, UserPromotion userPromotion) {
save(userInfo);
userAppService.save(userApp);
userPromotionMapper.insert(userPromotion);
ipRecordService.saveRegIp(userInfo.getId() + "", userInfo.getId() + "");
}
@Resource
private UserPromotionMapper userPromotionMapper;
private UserPromotion getUserPromotionByUserId(String userId){
private UserPromotion getUserPromotionByUserId(String userId) {
UserPromotion userPromotion = new UserPromotion();
userPromotion.setUserId(Long.valueOf(userId));
UserPromotion promotion= userPromotionMapper.selectOne(new QueryWrapper<>(userPromotion));
UserPromotion promotion = userPromotionMapper.selectOne(new QueryWrapper<>(userPromotion));
if(ObjectUtil.isNotEmpty(promotion)){
if (ObjectUtil.isNotEmpty(promotion)) {
if("MG".equals(promotion.getTypeCode())||"FB".equals(promotion.getTypeCode())||
"SB".equals(promotion.getTypeCode())||"1".equals(promotion.getIsExtend())||
"2".equals(promotion.getIsExtend()) ||"AG".equals(promotion.getTypeCode())){

View File

@@ -181,6 +181,24 @@ public class UserInfoServiceNewImpl extends BaseUserInfoService {
}
@Autowired
private UserIpRecordService ipRecordService;
@Override
@Transactional(rollbackFor = Exception.class)
public void goregister(UserInfo userInfo, UserApp userApp, UserPromotion userPromotion) {
save(userInfo);
userApp.setUserId(userInfo.getId());
userAppService.save(userApp);
userPromotion.setUserId(userInfo.getId());
userPromotionMapper.insert(userPromotion);
ipRecordService.saveRegIp(userInfo.getId() + "", userInfo.getId() + "");
}
private String getRandomNum() {
String inviteNum;
UserApp condition = new UserApp();