用户余额充值
This commit is contained in:
@@ -40,18 +40,6 @@ public class PlayBalanceDetailsInfoController {
|
||||
return R.ok(playBalanceDetailsInfoService.selectPlayBalanceDetailsInfoById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增余额明细
|
||||
*/
|
||||
@Log(title = "余额明细", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/create")
|
||||
public R create(@RequestBody PlayBalanceDetailsInfoEntity playBalanceDetailsInfo) {
|
||||
boolean success = playBalanceDetailsInfoService.create(playBalanceDetailsInfo);
|
||||
if (success) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error("添加失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改余额明细
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.starry.admin.modules.balance.module.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.starry.common.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -64,13 +67,25 @@ public class PlayBalanceDetailsInfoEntity extends BaseEntity<PlayBalanceDetailsI
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
private Date operationTime;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime operationTime;
|
||||
|
||||
/**
|
||||
* 操作金额
|
||||
*/
|
||||
private BigDecimal balanceMoney;
|
||||
|
||||
/**
|
||||
* 赠送金额
|
||||
*/
|
||||
private BigDecimal giftAmount;
|
||||
|
||||
/**
|
||||
* 支付金额
|
||||
*/
|
||||
private BigDecimal paymentAmount;
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.math.BigDecimal;
|
||||
* @since 2024-04-30
|
||||
*/
|
||||
public interface IPlayBalanceDetailsInfoService extends IService<PlayBalanceDetailsInfoEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 查询余额明细
|
||||
*
|
||||
@@ -50,11 +52,12 @@ public interface IPlayBalanceDetailsInfoService extends IService<PlayBalanceDeta
|
||||
* @param balanceBeforeOperation 操作前余额
|
||||
* @param balanceAfterOperation 操作后余额
|
||||
* @param operationType 操作类型(0:充值;1:消费)
|
||||
* @param operationAction 操作动作
|
||||
* @param operationAction 操作动作
|
||||
* @param balanceMoney 操作金额
|
||||
* @param orderId 操作金额
|
||||
* @param giftAmount 赠送金额
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
void create(String userType, String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, String orderId);
|
||||
void insertBalanceDetailsInfo(String userType, String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, BigDecimal giftAmount, String orderId);
|
||||
|
||||
/**
|
||||
* 新增余额明细
|
||||
|
||||
@@ -13,11 +13,13 @@ import com.starry.admin.modules.balance.module.vo.PlayBalanceDetailsReturnVo;
|
||||
import com.starry.admin.modules.balance.service.IPlayBalanceDetailsInfoService;
|
||||
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
|
||||
import com.starry.admin.modules.order.module.entity.PlayOrderInfoEntity;
|
||||
import com.starry.admin.modules.order.service.IPlayOrderInfoService;
|
||||
import com.starry.common.utils.IdUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -32,6 +34,9 @@ public class PlayBalanceDetailsInfoServiceImpl extends ServiceImpl<PlayBalanceDe
|
||||
@Resource
|
||||
private PlayBalanceDetailsInfoMapper playBalanceDetailsInfoMapper;
|
||||
|
||||
@Resource
|
||||
private IPlayOrderInfoService playOrderInfoService;
|
||||
|
||||
/**
|
||||
* 查询余额明细
|
||||
*
|
||||
@@ -94,7 +99,8 @@ public class PlayBalanceDetailsInfoServiceImpl extends ServiceImpl<PlayBalanceDe
|
||||
|
||||
|
||||
@Override
|
||||
public void create(String userType, String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, String orderId) {
|
||||
public void insertBalanceDetailsInfo(String userType, String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, BigDecimal giftAmount, String orderId) {
|
||||
PlayOrderInfoEntity orderInfo = playOrderInfoService.selectOrderInfoById(orderId);
|
||||
PlayBalanceDetailsInfoEntity entity = new PlayBalanceDetailsInfoEntity();
|
||||
entity.setId(IdUtils.getUuid());
|
||||
entity.setUserType(userType);
|
||||
@@ -103,7 +109,9 @@ public class PlayBalanceDetailsInfoServiceImpl extends ServiceImpl<PlayBalanceDe
|
||||
entity.setBalanceAfterOperation(balanceAfterOperation);
|
||||
entity.setOperationType(operationType);
|
||||
entity.setBalanceMoney(balanceMoney);
|
||||
entity.setOperationTime(new Date());
|
||||
entity.setGiftAmount(giftAmount);
|
||||
entity.setPaymentAmount(orderInfo == null ? balanceMoney : orderInfo.getFinalAmount());
|
||||
entity.setOperationTime(LocalDateTime.now());
|
||||
entity.setOrderId(orderId);
|
||||
this.baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ public class PlayClerkRankingInfoServiceImpl extends ServiceImpl<PlayClerkRankin
|
||||
if (StrUtil.isNotBlank(vo.getWeeklyRanking())) {
|
||||
lambdaQueryWrapper.eq(PlayClerkRankingInfoEntity::getWeeklyRanking, vo.getWeeklyRanking());
|
||||
}
|
||||
if (StrUtil.isNotBlank(vo.getSex())) {
|
||||
lambdaQueryWrapper.eq(PlayClerkUserInfoEntity::getSex, vo.getSex());
|
||||
}
|
||||
if (vo.getSettlementDate() != null) {
|
||||
lambdaQueryWrapper.eq(PlayClerkRankingInfoEntity::getSettlementDate, vo.getSettlementDate());
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class PlayClerkUserInfoServiceImpl extends ServiceImpl<PlayClerkUserInfoM
|
||||
//修改用户余额
|
||||
this.baseMapper.updateById(new PlayClerkUserInfoEntity(userId, balanceAfterOperation));
|
||||
//记录余额变更记录
|
||||
playBalanceDetailsInfoService.create("0", userId, balanceBeforeOperation, balanceAfterOperation, operationType, operationAction, balanceMoney, orderId);
|
||||
playBalanceDetailsInfoService.insertBalanceDetailsInfo("0", userId, balanceBeforeOperation, balanceAfterOperation, operationType, operationAction, balanceMoney, BigDecimal.ZERO,orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,6 +92,16 @@ public class PlayCustomUserInfoEntity extends BaseEntity<PlayCustomUserInfoEntit
|
||||
*/
|
||||
private BigDecimal accountBalance;
|
||||
|
||||
/**
|
||||
* 累计充值金额
|
||||
*/
|
||||
private BigDecimal accumulatedRechargeAmount;
|
||||
|
||||
/**
|
||||
* 累计消费金额
|
||||
*/
|
||||
private BigDecimal accumulatedConsumptionAmount;
|
||||
|
||||
/**
|
||||
* 余额状态[0:不存在余额,1:存在余额]
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,25 @@ public interface IPlayCustomUserInfoService extends IService<PlayCustomUserInfoE
|
||||
*/
|
||||
PlayCustomUserInfoEntity selectByOpenid(String openId);
|
||||
|
||||
/**
|
||||
* 根据顾客等级,查询顾客充值余额时,实际支付金额
|
||||
*
|
||||
* @param rechargeAmount 重置金额,单位分
|
||||
* @param customId 顾客ID
|
||||
* @return 实际支付金额
|
||||
*/
|
||||
BigDecimal getCustomPaymentAmount(BigDecimal rechargeAmount, String customId);
|
||||
|
||||
|
||||
/**
|
||||
* 顾客账户余额充值
|
||||
*
|
||||
* @param rechargeAmount 充值金额,单位分
|
||||
* @param customId 顾客ID
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
void customAccountBalanceRecharge(BigDecimal rechargeAmount, String customId, String orderId);
|
||||
|
||||
/**
|
||||
* 查询顾客
|
||||
*
|
||||
@@ -90,11 +109,12 @@ public interface IPlayCustomUserInfoService extends IService<PlayCustomUserInfoE
|
||||
* @param balanceBeforeOperation 操作前余额
|
||||
* @param balanceAfterOperation 操作后余额
|
||||
* @param operationType 操作类型(0:充值;1:消费;2:服务)
|
||||
* @param operationAction 操作动作
|
||||
* @param operationAction 操作动作
|
||||
* @param balanceMoney 操作金额
|
||||
* @param giftAmount 赠送金额
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
void updateAccountBalanceById(String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, String orderId);
|
||||
void updateAccountBalanceById(String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, BigDecimal giftAmount,String orderId);
|
||||
|
||||
/**
|
||||
* 修改顾客
|
||||
|
||||
@@ -17,10 +17,12 @@ import com.starry.admin.modules.custom.module.vo.PlayCustomRankingQueryVo;
|
||||
import com.starry.admin.modules.custom.module.vo.PlayCustomRankingReturnVo;
|
||||
import com.starry.admin.modules.custom.module.vo.PlayCustomUserQueryVo;
|
||||
import com.starry.admin.modules.custom.module.vo.PlayCustomUserReturnVo;
|
||||
import com.starry.admin.modules.custom.service.IPlayCustomLevelInfoService;
|
||||
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
|
||||
import com.starry.admin.modules.order.module.entity.PlayOrderInfoEntity;
|
||||
import com.starry.admin.modules.order.service.impl.PlayOrderInfoServiceImpl;
|
||||
import com.starry.common.utils.IdUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -35,6 +37,7 @@ import java.util.stream.Collectors;
|
||||
* @author admin
|
||||
* @since 2024-04-08
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PlayCustomUserInfoServiceImpl extends ServiceImpl<PlayCustomUserInfoMapper, PlayCustomUserInfoEntity> implements IPlayCustomUserInfoService {
|
||||
@Resource
|
||||
@@ -43,11 +46,11 @@ public class PlayCustomUserInfoServiceImpl extends ServiceImpl<PlayCustomUserInf
|
||||
@Resource
|
||||
private PlayOrderInfoServiceImpl playOrderInfoService;
|
||||
|
||||
|
||||
@Resource
|
||||
private IPlayBalanceDetailsInfoService playBalanceDetailsInfoService;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PlayCustomUserInfoEntity selectByOpenid(String openId) {
|
||||
LambdaQueryWrapper<PlayCustomUserInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -55,6 +58,38 @@ public class PlayCustomUserInfoServiceImpl extends ServiceImpl<PlayCustomUserInf
|
||||
return this.baseMapper.selectOne(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getCustomPaymentAmount(BigDecimal rechargeAmount, String customId) {
|
||||
//根据顾客ID,查询顾客对应等级
|
||||
MPJLambdaWrapper<PlayCustomUserInfoEntity> lambdaQueryWrapper = new MPJLambdaWrapper<>();
|
||||
lambdaQueryWrapper.selectAll(PlayCustomLevelInfoEntity.class);
|
||||
lambdaQueryWrapper.leftJoin(PlayCustomLevelInfoEntity.class, PlayCustomLevelInfoEntity::getId, PlayCustomUserInfoEntity::getLevelId);
|
||||
lambdaQueryWrapper.eq(PlayCustomUserInfoEntity::getId, customId);
|
||||
PlayCustomLevelInfoEntity entity = this.baseMapper.selectJoinOne(PlayCustomLevelInfoEntity.class, lambdaQueryWrapper);
|
||||
if (entity == null) {
|
||||
log.error("未查询当前顾客的充值优惠金额,支付金额等于充值金额,rechargeAmount={},customId={}", rechargeAmount, customId);
|
||||
return rechargeAmount;
|
||||
}
|
||||
try {
|
||||
BigDecimal paymentAmount = BigDecimal.valueOf(entity.getDiscount()).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP).add(rechargeAmount);
|
||||
log.info("等级为{}的顾客{},充值{}元,实际应该支付{}元", entity.getName(), customId, rechargeAmount, paymentAmount);
|
||||
return paymentAmount;
|
||||
} catch (Exception e) {
|
||||
log.error("计算顾客充值优惠金额发生异常,支付金额等于充值金额,rechargeAmount={},customId={}", rechargeAmount, customId);
|
||||
return rechargeAmount;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customAccountBalanceRecharge(BigDecimal rechargeAmount, String customId, String orderId) {
|
||||
PlayCustomUserInfoEntity userInfo = this.selectById(customId);
|
||||
//查询充值赠送金额(暂是设置为0)
|
||||
BigDecimal giftAmount = BigDecimal.ZERO;
|
||||
//修改用户账户余额
|
||||
this.updateAccountBalanceById(customId, userInfo.getAccountBalance(), userInfo.getAccountBalance().add(rechargeAmount).add(giftAmount), "0", "重置", rechargeAmount.add(giftAmount), giftAmount, orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询顾客
|
||||
*
|
||||
@@ -236,11 +271,15 @@ public class PlayCustomUserInfoServiceImpl extends ServiceImpl<PlayCustomUserInf
|
||||
|
||||
|
||||
@Override
|
||||
public void updateAccountBalanceById(String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, String orderId) {
|
||||
public void updateAccountBalanceById(String userId, BigDecimal balanceBeforeOperation, BigDecimal balanceAfterOperation, String operationType, String operationAction, BigDecimal balanceMoney, BigDecimal giftAmount, String orderId) {
|
||||
//更新余额
|
||||
this.baseMapper.updateById(new PlayCustomUserInfoEntity(userId, balanceAfterOperation));
|
||||
PlayCustomUserInfoEntity entity = new PlayCustomUserInfoEntity();
|
||||
entity.setId(userId);
|
||||
entity.setAccountBalance(balanceAfterOperation);
|
||||
entity.setAccountState(balanceAfterOperation.compareTo(new BigDecimal(0)) > 0 ? "`" : "0");
|
||||
this.baseMapper.updateById(entity);
|
||||
//记录余额变更记录
|
||||
playBalanceDetailsInfoService.create("1", userId, balanceBeforeOperation, balanceAfterOperation, operationType, operationAction, balanceMoney, orderId);
|
||||
playBalanceDetailsInfoService.insertBalanceDetailsInfo("1", userId, balanceBeforeOperation, balanceAfterOperation, operationType, operationAction, balanceMoney, giftAmount, orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -198,7 +198,7 @@ public class WxCustomController {
|
||||
//
|
||||
// playOrderInfoService.createRewardOrder(orderId, new BigDecimal(vo.getMoney()), new BigDecimal(vo.getMoney()), userId, clerkUserInfo.getId(), vo.getRemark(), vo.getWeiChatCode());
|
||||
// 顾客减少余额
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(new BigDecimal(vo.getMoney())), "1", "打赏", new BigDecimal(vo.getMoney()), orderId);
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(new BigDecimal(vo.getMoney())), "1", "打赏", new BigDecimal(vo.getMoney()), BigDecimal.ZERO, orderId);
|
||||
// 陪聊增加余额
|
||||
// clerkUserInfoService.updateAccountBalanceById(clerkUserInfo.getId(), clerkUserInfo.getAccountBalance(), clerkUserInfo.getAccountBalance().add(new BigDecimal(vo.getMoney())), "2", "打赏", new BigDecimal(vo.getMoney()), orderId);
|
||||
return R.ok("成功");
|
||||
@@ -225,7 +225,7 @@ public class WxCustomController {
|
||||
|
||||
// playOrderInfoService.createGiftOrder(orderId, vo.getGiftId(), giftInfo.getPrice(), String.valueOf(vo.getGiftQuantity()), money, money, userId, clerkUserInfo.getId(), vo.getRemark(), vo.getWeiChatCode());
|
||||
// 顾客减少余额
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(money), "1", "赠送礼物", money, orderId);
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(money), "1", "赠送礼物", money, BigDecimal.ZERO, orderId);
|
||||
// 陪聊增加余额
|
||||
// clerkUserInfoService.updateAccountBalanceById(clerkUserInfo.getId(), clerkUserInfo.getAccountBalance(), clerkUserInfo.getAccountBalance().add(money), "2", "赠送礼物", money, orderId);
|
||||
// 修改顾客和礼物消息
|
||||
@@ -284,7 +284,7 @@ public class WxCustomController {
|
||||
playOrderInfoService.createOrderInfo(orderId, playOrderInfoService.getOrderNo(), "0", "2", "0", "", "1", commodityInfo.getCommodityId(), "1", commodityInfo.getCommodityPrice(), commodityInfo.getServiceDuration(), commodityInfo.getCommodityName(), String.valueOf(vo.getCommodityQuantity()), money, money, BigDecimal.ZERO, customId, clerkUserInfo.getId(), vo.getWeiChatCode(), vo.getRemark());
|
||||
// playOrderInfoService.createOrdinaryOrder(orderId, commodityInfo.getCommodityId(), commodityInfo.getCommodityPrice(), String.valueOf(vo.getCommodityQuantity()), commodityInfo.getCommodityName(), commodityInfo.getServiceDuration(), money, money, customId, clerkUserInfo.getId(), vo.getRemark(), vo.getWeiChatCode());
|
||||
// 顾客减少余额
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(money), "1", "下单-指定单", money, orderId);
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(money), "1", "下单-指定单", money, BigDecimal.ZERO, orderId);
|
||||
// 陪聊增加余额
|
||||
// clerkUserInfoService.updateAccountBalanceById(clerkUserInfo.getId(), clerkUserInfo.getAccountBalance(), clerkUserInfo.getAccountBalance().add(money), "2", "下单-指定单", money, orderId);
|
||||
return R.ok("成功");
|
||||
@@ -324,7 +324,7 @@ public class WxCustomController {
|
||||
|
||||
// playOrderInfoService.createRandomOrder(orderId, customUserInfo.getId(), commodityInfo.getCommodityPrice(), String.valueOf(vo.getCommodityQuantity()), commodityInfo.getServiceDuration(), commodityInfo.getCommodityName(), money, money, customId, vo.getRemark(), vo.getWeiChatCode());
|
||||
// 顾客减少余额
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(money), "1", "下单-随机单", money, orderId);
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(), customUserInfo.getAccountBalance().subtract(money), "1", "下单-随机单", money, BigDecimal.ZERO, orderId);
|
||||
// 下单成功后,先根据用户条件进行随机分配
|
||||
return R.ok("下单成功");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user