余额相关

This commit is contained in:
liuyingfang
2023-08-24 09:29:30 +08:00
parent 67626eff09
commit 4e833b7585
13 changed files with 138 additions and 137 deletions

View File

@@ -2,6 +2,7 @@ package cn.pluss.platform.controller;
import cn.hutool.json.JSONUtil;
import cn.pluss.platform.IdCardService;
import cn.pluss.platform.UserMakerQuota.UserMakerQuotaService;
import cn.pluss.platform.annotation.OpLog;
import cn.pluss.platform.api.PageInfo;
import cn.pluss.platform.api.Result;
@@ -539,6 +540,8 @@ public class MerchantOrderController {
@Resource
private MerchantProfitService profitService;
@Resource
private UserMakerQuotaService userMakerQuotaService;
@PostMapping("/orderTest")
public Result<Object> orderTest(@RequestBody MerchantOrder merchantOrder){
UserApp tokenUa = userAppService.queryUserAppByToken();
@@ -564,6 +567,7 @@ public class MerchantOrderController {
boolean save = merchantOrderService.save(merchantOrder);
profitService.createOrderProfitV2(merchantOrder,"1");
userMakerQuotaService.quotaInfo(merchantOrder);
if (save){
return ResultGenerator.genSuccessResult();
}else {

View File

@@ -26,6 +26,7 @@ import cn.pluss.platform.merchantStore.MerchantStoreService;
import cn.pluss.platform.systemConfig.SystemConfigService;
import cn.pluss.platform.systemInfo.SystemInfoService;
import cn.pluss.platform.user.UserProfitService;
import cn.pluss.platform.userAccount.UserAccountService;
import cn.pluss.platform.userApp.UserAppService;
import cn.pluss.platform.userInfo.UserInfoService;
import cn.pluss.platform.userPromotion.UserPromotionService;
@@ -121,6 +122,10 @@ public class UserAppController {
private UserPromotionService userPromotionService;
@Resource
private CashMapper cashMapper;
@Resource
private UserAccountService userAccountService;
@Resource
private UserAccountFlowMapper userAccountFlowMapper;
private static String keyStoreUrl =
"/home/syb/resources/wechatCert/apiclient_cert.p12"; // 验证证书路径
@@ -498,102 +503,51 @@ public class UserAppController {
if (nextLevel != null) {
nextRate = nextLevel.getRate();
}
Double totalShareMoneyToday = 0d; // 今日分润总额
Double totalAccumulateShareMoney = 0d; // 累计总分润
Double merchantShareMoneyToday = 0d; // 推广商户今日分润
Double merchantShareMoneyHistory = 0d; // 推广商户历史分润
Double allowCashMoney = 0d; // 可提现分润
Double noCashMoney = 0d; // 不可提现分润
Double cashedMoney = 0d; // 已提现分润
BigDecimal totalShareMoneyToday = null; // 今日分润总额ok
BigDecimal totalAccumulateShareMoney = null; // 累计总分润ok
BigDecimal allowCashMoney = null; // 可提现分润ok
BigDecimal examineMoney = null;
// 获取当前商户的所有的下级商户信息
// Map<String, Object> queryMap = new HashMap<>();
// if ("agent_staff".equals(queryUserApp.getUserType())) {
// queryMap.put("agentStaffId", userId);
// } else {
// queryMap.put("userId", userId);
// }
//
// queryMap.put("status", 1);
Map<String, Object> queryMap = new HashMap<>();
if ("agent_staff".equals(queryUserApp.getUserType())) {
queryMap.put("agentStaffId", userId);
// 累计总分润 TODO 改变方式
UserAccount userAccountByUserId = userAccountService.getUserAccountByUserId(userId);
if (userAccountByUserId == null) {
totalShareMoneyToday = BigDecimal.ZERO;
totalAccumulateShareMoney = BigDecimal.ZERO;
allowCashMoney = BigDecimal.ZERO;
examineMoney = BigDecimal.ZERO;
}else {
queryMap.put("userId", userId);
}
queryMap.put("status", 1);
// 累计总分润
totalAccumulateShareMoney =
merchantProfitService.queryMerchantProfitSumPrice(queryMap);
if (totalAccumulateShareMoney == null) {
totalAccumulateShareMoney = 0d;
}
queryMap.put("startTime", DateUtils.getDayBegin());
totalShareMoneyToday =
merchantProfitService.queryMerchantProfitSumPrice(queryMap);
if (totalShareMoneyToday == null) {
totalShareMoneyToday = 0d;
}
totalAccumulateShareMoney = userAccountByUserId.getBalance();
queryMap.put("retype", "1");
// 商户今日分润
merchantShareMoneyToday =
merchantProfitService.queryMerchantProfitSumPrice(queryMap);
if (merchantShareMoneyToday == null) {
merchantShareMoneyToday = 0d;
}
// 商户历史分润
queryMap.put("startTime", null);
queryMap.put("endTime", DateUtils.getDayBegin());
merchantShareMoneyHistory =
merchantProfitService.queryMerchantProfitSumPrice(queryMap);
if (merchantShareMoneyHistory == null) {
merchantShareMoneyHistory = 0d;
}
//今日分润总额
totalShareMoneyToday = userAccountFlowMapper.selectSumByUserId(userId, DateUtils.getDayBegin(), DateUtils.getDayEnd());
// 今日总分润 = 今日商户分润
// 已经提现与正在提现的分润 //+ cashService.sumFansAreadlyCash(map);
cashedMoney = cashService.sumMerchantSuccessCash(userId);
if (cashedMoney == null) {
cashedMoney = 0d;
}
noCashMoney = totalShareMoneyToday;
allowCashMoney = totalAccumulateShareMoney - cashedMoney - noCashMoney;
// 可提现分润
allowCashMoney = userAccountByUserId.getBalance();
//审核中的提现金额
BigDecimal bigDecimal = cashMapper.selectCashAmtTotal(String.valueOf(userId), Cash.STATUS_CHECKING);
examineMoney = userAccountByUserId.getFreezeBalance();
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put(
"totalShareMoneyToday",
StringUtil.bigDecimal(totalShareMoneyToday)
); //今日总分润
resultMap.put(
"totalAccumulateShareMoney",
StringUtil.bigDecimal(totalAccumulateShareMoney)
); //累计总分润
resultMap.put(
"merchantShareMoneyToday",
StringUtil.bigDecimal(merchantShareMoneyToday)
); //今日推广分润
resultMap.put(
"merchantShareMoneyHistory",
StringUtil.bigDecimal(merchantShareMoneyHistory)
); //历史推广分润
resultMap.put(
"nextMerchantShareMoneyToday",
StringUtil.bigDecimal(totalShareMoneyToday - merchantShareMoneyToday)
); //今日升级分润
resultMap.put(
"nextMerchantShareMoneyHistory",
StringUtil.bigDecimal(
totalAccumulateShareMoney -
merchantShareMoneyHistory -
totalShareMoneyToday
)
); //历史升级分润
resultMap.put(
"allowCashMoney",
StringUtil.bigDecimal(allowCashMoney, RoundingMode.DOWN)
);
resultMap.put("noCashMoney", StringUtil.bigDecimal(noCashMoney));
resultMap.put("cashedMoney", StringUtil.bigDecimal(cashedMoney));
resultMap.put("examineMoney", bigDecimal);
//今日总分润
resultMap.put("totalShareMoneyToday", totalShareMoneyToday.setScale(2,RoundingMode.DOWN));
//累计总分润
resultMap.put("totalAccumulateShareMoney", totalAccumulateShareMoney.setScale(2,RoundingMode.DOWN));
//可提现分润
resultMap.put("allowCashMoney",allowCashMoney.setScale(2,RoundingMode.DOWN));
//审核中的提现金额
resultMap.put("examineMoney", examineMoney.setScale(2,RoundingMode.DOWN));
return ResultGenerator.genSuccessResult(resultMap);
}

View File

@@ -8,6 +8,8 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
@@ -32,4 +34,17 @@ public interface UserAccountFlowMapper extends BaseMapper<UserAccountFlow> {
"\tAND mf.biz_code = 'LD'\n" +
"\torder by id desc limit #{pageSize} offset #{offset} ")
List<UserMakerQuotaVO> selectByUserIdType(@Param("userId") Long userId, @Param("pageSize") Integer pageSize, @Param("offset") Integer offset);
@Select("SELECT\n" +
"\tSUM( amount ) \n" +
"FROM\n" +
"\ttb_pluss_user_account_flow \n" +
"WHERE\n" +
"\tuser_id = #{userId} \n" +
"AND\n" +
"\tbiz_code IN('102','LD')\n" +
"AND\n" +
"\tcreate_time < #{endTime} \n" +
"AND\n" +
"\tcreate_time\t> #{startTime}\t")
BigDecimal selectSumByUserId(@Param("userId") Long userId,@Param("startTime") Date startTime,@Param("endTime") Date endTime);
}

View File

@@ -13,9 +13,11 @@ import java.math.BigDecimal;
public interface UserAccountMapper extends BaseMapper<UserAccount> {
@Select(value = "select user_id AS userId,freeze_balance AS freezeBalance,balance,out_balance AS out_balance,create_time AS createTime,update_time AS updateTime from tb_pluss_user_account where user_id=#{userId}")
UserAccount selectUserByUserId(@Param("userId")Integer userId,Integer t);
@Select(value = "select * from tb_pluss_user_account where user_id=#{userId} for update")
UserAccount selectUserByUserId(Integer userId);
@Select(value = "select user_id AS userId,freeze_balance AS freezeBalance,balance,out_balance AS out_balance,create_time AS createTime,update_time AS updateTime from tb_pluss_user_account where user_id=#{userId} for update")
UserAccount selectUserByUserId(@Param("userId")Integer userId);
@Update(value = "update tb_pluss_user_account set freeze_balance=freeze_balance+#{amount} where user_id=#{userId}")
Integer updateFreezon(@Param("userId") Integer userId, @Param("amount") BigDecimal amount);

View File

@@ -1,5 +1,6 @@
package cn.pluss.platform.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -20,6 +21,7 @@ public class UserAccount implements Serializable {
@TableField("user_id")
@TableId(value = "user_id", type = IdType.AUTO)
private Integer userId;
@TableField("freeze_balance")
private BigDecimal freezeBalance;

View File

@@ -18,13 +18,13 @@ import java.util.Date;
@TableName("tb_pluss_user_account_flow")
public class UserAccountFlow implements Serializable {
@TableId(type = IdType.AUTO)
@TableId(value = "id",type = IdType.AUTO)
private Integer id;
@TableField("user_id")
private Integer userId;
@TableField("biz_code")
private String bizCode;
@TableField("biz_name")
private String bizName;
private BigDecimal amount;
@@ -32,8 +32,8 @@ public class UserAccountFlow implements Serializable {
private BigDecimal balance;
private String remark;
@TableField("create_time")
private Date createTime;
@TableField("update_time")
private Date updateTime;
}

View File

@@ -129,6 +129,7 @@ public class UserMakerQuotaServiceImpl extends ServiceImpl<UserMakerQuotaMapper,
//增加提现金额
private void profit(UserPromotion userInfo,BigDecimal consumeFee){
UserMakerQuota userMakerQuota = userMakerQuotaMapper.selectByUserId(userInfo.getUserId());
if (userMakerQuota != null) {
BigDecimal sumbigDecimal = userMakerQuota.getAmount();
if (sumbigDecimal != null && sumbigDecimal.compareTo(consumeFee) >= 0) {
BigDecimal profit = consumeFee.multiply(new BigDecimal("0.0038")).setScale(2, BigDecimal.ROUND_DOWN);
@@ -136,17 +137,18 @@ public class UserMakerQuotaServiceImpl extends ServiceImpl<UserMakerQuotaMapper,
String s = String.valueOf(userInfo.getUserId());
Integer integer = Integer.valueOf(s);
//提现金额
userAccountService.modFunds(integer,"SD","免提现额度",profit,"");
userAccountService.modFunds(integer, "LD", "免提现额度", profit, "");
//额度改变
this.modMakerFunds(integer,"SD","免费额度",sumbigDecimal,"");
this.modMakerFunds(integer, "LD", "收款消耗", 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,"");
userAccountService.modFunds(integer, "LD", "收款消耗", profit, "");
//额度改变
this.modMakerFunds(integer,"SD","免费额度",BigDecimal.ZERO,"");
this.modMakerFunds(integer, "LD", "收款消耗", BigDecimal.ZERO, "");
}
}
}

View File

@@ -14,11 +14,9 @@ import cn.pluss.platform.common.RiskBlacklistService;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.fans.FansService;
import cn.pluss.platform.mapper.CashMapper;
import cn.pluss.platform.mapper.FansMapper;
import cn.pluss.platform.mapper.MerchantProfitMapper;
import cn.pluss.platform.mapper.UserPromotionMapper;
import cn.pluss.platform.mapper.*;
import cn.pluss.platform.merchantProfit.MerchantProfitService;
import cn.pluss.platform.userAccount.UserAccountService;
import cn.pluss.platform.userApp.UserAppService;
import cn.pluss.platform.userInfo.UserInfoService;
import cn.pluss.platform.user.impl.GeneralPushUtil;
@@ -94,6 +92,9 @@ public class CashServiceImpl extends ServiceImpl<CashMapper, Cash> implements Ca
private MerchantProfitMapper mpMapper;
@Resource
private CashMapper cashMapper;
@Resource
private UserAccountService userAccountService;
private void checkStatus(Integer userId) {
RiskBlacklist condition = new RiskBlacklist();
@@ -261,20 +262,21 @@ public class CashServiceImpl extends ServiceImpl<CashMapper, Cash> implements Ca
Map<String, Object> map = new HashMap<>();
map.put("lastMerchantCode", tokenUa.getMerchantCode());
// 查询可提现粉丝分润
Double sum = fansService.queryFansSumShareMoney(map);
if (sum != null) {
BigDecimal fansProfit = BigDecimal.valueOf(sum);
totalProfit = totalProfit.add(fansProfit);
}
// Double sum = fansService.queryFansSumShareMoney(map);
// if (sum != null) {
// BigDecimal fansProfit = BigDecimal.valueOf(sum);
// totalProfit = totalProfit.add(fansProfit);
// }
}
// 查询商户已提现总数
BigDecimal totalCashAmt = getSumValidCashAmtTotal(cash.getUserId() + "");
if (totalCashAmt == null) {
totalCashAmt = BigDecimal.ZERO;
//BigDecimal totalCashAmt = getSumValidCashAmtTotal(cash.getUserId() + "");
UserAccount userAccountByUserId = userAccountService.getUserAccountByUserId(cash.getUserId());
if (userAccountByUserId == null) {
throw new MsgException("可提现金额不足!");
}
// 校验提现金额是否充足
int flag = cash.getCashAmt().compareTo(totalProfit.subtract(totalCashAmt));
int flag = cash.getCashAmt().compareTo(totalProfit.subtract(userAccountByUserId.getBalance()));
if (flag > 0) {
throw new MsgException("可提现金额不足!");
}

View File

@@ -2076,7 +2076,7 @@ public class MerchantOrderServiceImpl extends ServiceImpl<MerchantOrderMapper, M
@Override
public List<Map<String, Object>> getCouponList(String orderNumber) {
MerchantOrder merchantOrder = new MerchantOrder().setOrderNumber(orderNumber).setStatus("1");
MerchantOrder merchantOrder = new MerchantOrder().setOrderNumber(orderNumber);
MerchantOrder one = getOne(new QueryWrapper<>(merchantOrder));
if (one == null) {
throw new MsgException("订单不存在");

View File

@@ -15,6 +15,7 @@ import cn.pluss.platform.notice.NoticeService;
import cn.pluss.platform.user.UserLevelService;
import cn.pluss.platform.user.impl.GeneralPushUtil;
import cn.pluss.platform.userAccount.UserAccountService;
import cn.pluss.platform.userAccount.impl.UserAccountFlowServiceImpl;
import cn.pluss.platform.userAccount.impl.UserAccountServiceImpl;
import cn.pluss.platform.userAssess.UserAssessService;
import cn.pluss.platform.userRewardFlow.UserRewardFlowService;
@@ -61,6 +62,8 @@ public class MerchantProfitServiceImpl extends ServiceImpl<MerchantProfitMapper,
@Autowired
UserAccountServiceImpl userAccountService;
@Resource
private UserAccountFlowServiceImpl userAccountFlowService;
@Override
@@ -301,8 +304,7 @@ public class MerchantProfitServiceImpl extends ServiceImpl<MerchantProfitMapper,
//更新账户余额
userAccountService.updateBatchById(userAccounts);
//添加账户流水
userAccountFlowService.saveBatch(userAccountFlows);
log.info("【分润插入】插入分润成功!");
} catch (Exception e) {
@@ -384,7 +386,7 @@ public class MerchantProfitServiceImpl extends ServiceImpl<MerchantProfitMapper,
MerchantProfit profit = new MerchantProfit(nowUserApp,nowUserApp , order, profitAmt, profitRate, "5", "1");
profits.add(profit);
UserAccount userAccount= userAccountService.getUserAccountByUserId(Integer.valueOf(userId));
UserAccount userAccount= userAccountService.initUserAccount(Integer.valueOf(userId));
userAccount.setBalance(userAccount.getBalance().add(profitAmt));
userAccount.setUpdateTime(new Date());
UserAccountFlow flow=new UserAccountFlow();

View File

@@ -0,0 +1,4 @@
package cn.pluss.platform.userAccount;
public interface UserAccontFlowService {
}

View File

@@ -0,0 +1,14 @@
package cn.pluss.platform.userAccount.impl;
import cn.pluss.platform.entity.UserAccount;
import cn.pluss.platform.entity.UserAccountFlow;
import cn.pluss.platform.mapper.UserAccountFlowMapper;
import cn.pluss.platform.mapper.UserAccountMapper;
import cn.pluss.platform.userAccount.UserAccontFlowService;
import cn.pluss.platform.userAccount.UserAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class UserAccountFlowServiceImpl extends ServiceImpl<UserAccountFlowMapper, UserAccountFlow> implements UserAccontFlowService {
}

View File

@@ -33,12 +33,12 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserA
@Override
public UserAccount getUserAccountByUserId(Integer userId) {
return baseMapper.selectById(userId);
return userAccountMapper.selectUserByUserId(userId,1);
}
@Override
public UserAccount getUserAccountByUserId(Long userId) {
return baseMapper.selectById(userId);
return baseMapper.selectUserByUserId(userId.intValue(),1);
}
@Override
@@ -48,7 +48,7 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserA
private UserAccount initUserAccount(Integer userId){
public UserAccount initUserAccount(Integer userId){
Assert.notNull(userId, "NOt Null");
synchronized (this){
UserAccount userAccount=getUserAccountByUserId(userId);