下单充值余额并生成记录

This commit is contained in:
SjS 2025-04-27 20:00:53 +08:00
parent 054375ebc0
commit 3e86bb3018
26 changed files with 719 additions and 528 deletions

View File

@ -103,7 +103,7 @@ public interface BonusService
* @param id 分成明细ID * @param id 分成明细ID
* @return 结果 * @return 结果
*/ */
public int payBonus(Long id); // public int payBonus(Long id);
/** /**
* 进行分成打款指定时间之前的分成 * 进行分成打款指定时间之前的分成

View File

@ -78,6 +78,11 @@ public class BonusServiceImpl implements BonusService
return this.selectOne(query); return this.selectOne(query);
} }
@Override
public BonusVO selectBonusById(Long id) {
return BonusService.super.selectBonusById(id);
}
private BonusVO selectOne(BonusQuery query) { private BonusVO selectOne(BonusQuery query) {
PageHelper.startPage(1, 1); PageHelper.startPage(1, 1);
List<BonusVO> list = this.selectBonusList(query); List<BonusVO> list = this.selectBonusList(query);
@ -172,6 +177,11 @@ public class BonusServiceImpl implements BonusService
return rows == list.size(); return rows == list.size();
} }
@Override
public int payBonus(BonusVO bonus) {
return 0;
}
// 预分成 // 预分成
private int prepay(List<BonusVO> list) { private int prepay(List<BonusVO> list) {
if (CollectionUtils.isEmptyElement(list)) { if (CollectionUtils.isEmptyElement(list)) {
@ -242,39 +252,39 @@ public class BonusServiceImpl implements BonusService
return sum; return sum;
} }
@Override // @Override
public int payBonus(BonusVO bonus) { // public int payBonus(BonusVO bonus) {
ServiceUtil.assertion(bonus == null, "待打款的分成不存在"); // ServiceUtil.assertion(bonus == null, "待打款的分成不存在");
ServiceUtil.assertion(!BonusStatus.canPay().contains(bonus.getStatus()), "ID为%s的分成当前状态不允许打款", bonus.getId()); // ServiceUtil.assertion(!BonusStatus.canPay().contains(bonus.getStatus()), "ID为%s的分成当前状态不允许打款", bonus.getId());
//
// Integer result = transactionTemplate.execute(status -> {
// // 更新分成状态为已分成
// int pay = bonusMapper.pay(bonus.getId(), bonus.getWaitAmount(), LocalDateTime.now());
// ServiceUtil.assertion(pay != 1, "分成打款失败,待分金额不足或状态已改变");
//
// // 若需要打款到余额根据类型添加金额
// if (bonus.getToBalance() != null && bonus.getToBalance()) {
// if (BonusArrivalType.userList().contains(bonus.getArrivalType())) {
// BalanceLogBstType bstType = BalanceLogBstType.parseByBonusBstType(bonus.getBstType());
// int add = userService.addBalance(bonus.getArrivalId(), bonus.getWaitAmount(), bstType, bonus.getBstId(), bonus.getReason());
// ServiceUtil.assertion(add != 1, "为用户%s增加账户金额失败", bonus.getArrivalId());
// }
// }
//
// return pay;
// });
//
// return result == null ? 0 : result;
// }
Integer result = transactionTemplate.execute(status -> { // @Override
// 更新分成状态为已分成 // public int payBonus(Long id) {
int pay = bonusMapper.pay(bonus.getId(), bonus.getWaitAmount(), LocalDateTime.now()); // if (id == null) {
ServiceUtil.assertion(pay != 1, "分成打款失败,待分金额不足或状态已改变"); // return 0;
// }
// 若需要打款到余额根据类型添加金额 // BonusVO bonus = this.selectBonusById(id);
if (bonus.getToBalance() != null && bonus.getToBalance()) { // return this.payBonus(bonus);
if (BonusArrivalType.userList().contains(bonus.getArrivalType())) { // }
BalanceLogBstType bstType = BalanceLogBstType.parseByBonusBstType(bonus.getBstType());
int add = userService.addBalance(bonus.getArrivalId(), bonus.getWaitAmount(), bstType, bonus.getBstId(), bonus.getReason());
ServiceUtil.assertion(add != 1, "为用户%s增加账户金额失败", bonus.getArrivalId());
}
}
return pay;
});
return result == null ? 0 : result;
}
@Override
public int payBonus(Long id) {
if (id == null) {
return 0;
}
BonusVO bonus = this.selectBonusById(id);
return this.payBonus(bonus);
}
@Override @Override

View File

@ -1,6 +1,7 @@
package com.ruoyi.bst.changeRecord.domain; package com.ruoyi.bst.changeRecord.domain;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
@ -30,15 +31,15 @@ public class ChangeRecord extends BaseEntity
@Excel(name = "变动次数") @Excel(name = "变动次数")
@ApiModelProperty("变动次数") @ApiModelProperty("变动次数")
private Long number; private Integer number;
@Excel(name = "变动前次数") @Excel(name = "变动前次数")
@ApiModelProperty("变动前次数") @ApiModelProperty("变动前次数")
private Long beforeNum; private Integer beforeNum;
@Excel(name = "变动后次数") @Excel(name = "变动后次数")
@ApiModelProperty("变动后次数") @ApiModelProperty("变动后次数")
private Long afterNum; private Integer afterNum;
@Excel(name = "业务类型") @Excel(name = "业务类型")
@ApiModelProperty("业务类型") @ApiModelProperty("业务类型")

View File

@ -0,0 +1,27 @@
package com.ruoyi.bst.changeRecord.domain.enums;
import com.ruoyi.bst.bonus.domain.enums.BonusBstType;
import com.ruoyi.bst.lightingNum.domain.LightingBstType;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ChangeRecordBstType {
ORDER("ORDER", "订单"),
WITHDRAW("WITHDRAW", "提现"),
SMS("SMS", "短信");
private final String code;
private final String name;
public static ChangeRecordBstType parseByBonusBstType(String bstType) {
if (LightingBstType.ORDER.getType().equals(bstType)) {
return ORDER;
}
return null;
}
}

View File

@ -0,0 +1,19 @@
package com.ruoyi.bst.lightingNum.domain;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author wjh
* 2025/1/18
*/
@Getter
@AllArgsConstructor
public enum LightingBstType {
ORDER("1", "订单");
private final String type;
private final String msg;
}

View File

@ -1,6 +1,7 @@
package com.ruoyi.bst.lightingNum.domain; package com.ruoyi.bst.lightingNum.domain;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
@ -30,6 +31,6 @@ public class LightingNum extends BaseEntity
@Excel(name = "爆灯次数") @Excel(name = "爆灯次数")
@ApiModelProperty("爆灯次数") @ApiModelProperty("爆灯次数")
private Long number; private Integer number;
} }

View File

@ -1,10 +1,12 @@
package com.ruoyi.bst.lightingNum.mapper; package com.ruoyi.bst.lightingNum.mapper;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import com.ruoyi.bst.lightingNum.domain.LightingNum; import com.ruoyi.bst.lightingNum.domain.LightingNum;
import com.ruoyi.bst.lightingNum.domain.LightingNumVO; import com.ruoyi.bst.lightingNum.domain.LightingNumVO;
import com.ruoyi.bst.lightingNum.domain.LightingNumQuery; import com.ruoyi.bst.lightingNum.domain.LightingNumQuery;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.security.core.parameters.P;
/** /**
* 爆灯次数列表Mapper接口 * 爆灯次数列表Mapper接口
@ -71,4 +73,14 @@ public interface LightingNumMapper
* @return 结果 * @return 结果
*/ */
public int deleteLightingNumByIds(Long[] ids); public int deleteLightingNumByIds(Long[] ids);
/**
* 查询用户爆灯次数
* @param userId
* @return
*/
Integer selectLightingNumberForUpdate(@Param("userId") Long userId);
int addLightingNum(@Param("userId") Long userId,@Param("storeId") Long storeId, @Param("lightingNumber")Integer lightingNumber);
} }

View File

@ -14,12 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectLightingNumVo"> <sql id="selectLightingNumVo">
select select
id, bln.id,
user_id, bln.user_id,
store_id, bln.store_id,
number, bln.number,
create_time bln.create_time
from bst_lighting_num from bst_lighting_num bln
</sql> </sql>
<sql id="searchCondition"> <sql id="searchCondition">
@ -41,6 +41,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id} where id = #{id}
</select> </select>
<select id="selectLightingNumberForUpdate" resultType="java.lang.Integer">
select bln.number
from bst_lighting_num bln
where bln.user_id = #{userId}
</select>
<insert id="insertLightingNum" parameterType="LightingNum" useGeneratedKeys="true" keyProperty="id"> <insert id="insertLightingNum" parameterType="LightingNum" useGeneratedKeys="true" keyProperty="id">
insert into bst_lighting_num insert into bst_lighting_num
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -80,6 +86,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</insert> </insert>
<!-- addLightingNum -->
<update id="addLightingNum">
update bst_lighting_num bln
set bln.number = bln.number + #{lightingNumber}
where bln.store_id = #{storeId} and bln.user_id = #{userId}
</update>
<update id="batchUpdate"> <update id="batchUpdate">
update bst_lighting_num update bst_lighting_num
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">

View File

@ -66,7 +66,7 @@ public class Order extends BaseEntity
@Excel(name = "套餐次数") @Excel(name = "套餐次数")
@ApiModelProperty("套餐次数") @ApiModelProperty("套餐次数")
private Long suitNum; private Integer suitNum;
@Excel(name = "套餐金额", readConverterExp = "单=位:元") @Excel(name = "套餐金额", readConverterExp = "单=位:元")
@ApiModelProperty("套餐金额") @ApiModelProperty("套餐金额")

View File

@ -11,42 +11,23 @@ import java.util.List;
public enum OrderStatus { public enum OrderStatus {
WAIT_PAY("WAIT_PAY", "待支付"), WAIT_PAY("WAIT_PAY", "待支付"),
PROCESSING("PROCESSING", "进行中"),
FINISHED("FINISHED", "已结束"), FINISHED("FINISHED", "已结束"),
CANCELED("CANCELED", "已取消"), CANCELED("CANCELED", "已取消"),
WAIT_VERIFY("WAIT_VERIFY", "待审核"),
REJECTED("REJECTED", "已驳回"),
REFUNDED("REFUNDED", "已退款"); REFUNDED("REFUNDED", "已退款");
private final String code; private final String code;
private final String name; private final String name;
// 允许支付的订单状态 // 允许支付的订单状态
public static List<String> canPay() { public static List<String> canPay() {
return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY); return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY);
} }
// 正在使用中的订单状态
public static List<String> inUse() {
return CollectionUtils.map(OrderStatus::getCode, PROCESSING);
}
// 可以支付成功的订单状态 // 可以支付成功的订单状态
public static List<String> canPaySuccess() { public static List<String> canPaySuccess() {
return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY); return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY);
} }
// 可以结束的订单状态
public static List<String> canEnd() {
return CollectionUtils.map(OrderStatus::getCode, PROCESSING);
}
// 可以退款的订单状态
public static List<String> canRefund() {
return CollectionUtils.map(OrderStatus::getCode, FINISHED, REFUNDED, REJECTED, WAIT_VERIFY);
}
// 未支付的订单状态 // 未支付的订单状态
public static List<String> unPayList() { public static List<String> unPayList() {
return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY); return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY);
@ -57,13 +38,4 @@ public enum OrderStatus {
return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY); return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY);
} }
// 可以审核的订单状态
public static List<String> canVerify() {
return CollectionUtils.map(OrderStatus::getCode, WAIT_VERIFY);
}
// 有效的订单状态已支付的订单
public static List<String> valid() {
return CollectionUtils.map(OrderStatus::getCode, PROCESSING, FINISHED, WAIT_VERIFY, REJECTED, REFUNDED);
}
} }

View File

@ -20,7 +20,7 @@ public interface OrderMapper
* @param id 订单列表主键 * @param id 订单列表主键
* @return 订单列表 * @return 订单列表
*/ */
OrderVO selectOrderById(Long id); OrderVO selectOrderById(@Param("id") Long id);
/** /**
* 查询订单列表列表 * 查询订单列表列表
@ -88,4 +88,5 @@ public interface OrderMapper
*/ */
int updateByQuery(@Param("data") Order data, @Param("query") OrderQuery query); int updateByQuery(@Param("data") Order data, @Param("query") OrderQuery query);
OrderVO selectOrderByBstId(@Param("bstId") Long bstId);
} }

View File

@ -77,7 +77,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectOrderById" parameterType="Long" resultMap="OrderResult"> <select id="selectOrderById" parameterType="Long" resultMap="OrderResult">
<include refid="selectOrderVo"/> <include refid="selectOrderVo"/>
where id = #{id} where bo.id = #{id}
</select>
<select id="selectOrderByBstId" parameterType="Long" resultMap="OrderResult">
<include refid="selectOrderVo"/>
where bo.bst_id = #{bstId}
</select> </select>
<!-- selectIdByQuery --> <!-- selectIdByQuery -->

View File

@ -108,4 +108,5 @@ public interface OrderService
*/ */
public int cancelOrder(Long id, String remark); public int cancelOrder(Long id, String remark);
OrderVO selectOrderByBstId(Long bstId);
} }

View File

@ -11,10 +11,13 @@ import com.ruoyi.bst.model.service.ModelService;
import com.ruoyi.bst.order.domain.Order; import com.ruoyi.bst.order.domain.Order;
import com.ruoyi.bst.order.domain.bo.OrderCreateBO; import com.ruoyi.bst.order.domain.bo.OrderCreateBO;
import com.ruoyi.bst.order.domain.dto.*; import com.ruoyi.bst.order.domain.dto.*;
import com.ruoyi.bst.order.domain.enums.OrderStatus;
import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO; import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO;
import com.ruoyi.bst.order.service.OrderConverter; import com.ruoyi.bst.order.service.OrderConverter;
import com.ruoyi.bst.order.service.OrderService; import com.ruoyi.bst.order.service.OrderService;
import com.ruoyi.bst.order.utils.OrderUtil; import com.ruoyi.bst.order.utils.OrderUtil;
import com.ruoyi.bst.store.domain.StoreVO;
import com.ruoyi.bst.store.service.StoreService;
import com.ruoyi.bst.suit.domain.SuitVO; import com.ruoyi.bst.suit.domain.SuitVO;
import com.ruoyi.bst.suit.service.SuitService; import com.ruoyi.bst.suit.service.SuitService;
import com.ruoyi.bst.userApp.domain.UserAppVO; import com.ruoyi.bst.userApp.domain.UserAppVO;
@ -57,6 +60,8 @@ public class OrderConverterImpl implements OrderConverter{
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
@Autowired
private StoreService storeService;
@Override @Override
@ -117,16 +122,29 @@ public class OrderConverterImpl implements OrderConverter{
order.setUserId(user.getUserId()); order.setUserId(user.getUserId());
} }
// 套餐信息 // 套餐店铺信息
SuitVO suit = bo.getSuit(); SuitVO suit = bo.getSuit();
if (suit != null) { if (suit != null) {
StoreVO store = storeService.selectStoreById(suit.getStoreId());
if (store != null) {
order.setStoreName(store.getStoreName());
}
order.setStoreId(suit.getStoreId()); order.setStoreId(suit.getStoreId());
order.setSuitId(suit.getSuitId()); order.setSuitId(suit.getSuitId());
order.setSuitName(suit.getSuitName()); order.setSuitName(suit.getSuitName());
order.setPayAmount(suit.getRechargeAmount()); order.setSuitAmount(suit.getRechargeAmount());
order.setSuitNum(suit.getLightingNums()); order.setSuitNum(suit.getLightingNums());
} }
// 价格信息
OrderPrePriceVO prePrice = bo.getPrePrice();
if (prePrice != null) {
order.setPayAmount(prePrice.getPayAmount());
}
// 订单状态
order.setStatus(OrderStatus.WAIT_PAY.getCode());
return order; return order;
} }

View File

@ -0,0 +1,68 @@
package com.ruoyi.bst.order.service.impl;
import com.ruoyi.bst.bonus.domain.enums.BonusBstType;
import com.ruoyi.bst.changeRecord.domain.ChangeRecord;
import com.ruoyi.bst.lightingNum.domain.LightingNum;
import com.ruoyi.bst.order.domain.Order;
import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.OrderVO;
import com.ruoyi.bst.order.domain.enums.OrderStatus;
import com.ruoyi.bst.order.mapper.OrderMapper;
import com.ruoyi.bst.order.service.OrderService;
import com.ruoyi.bst.pay.domain.PayVO;
import com.ruoyi.bst.pay.domain.enums.PayBstType;
import com.ruoyi.bst.pay.interfaces.PayHandler;
import com.ruoyi.bst.refund.domain.RefundVO;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.system.user.service.UserService;
import org.geotools.data.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
import java.time.LocalDateTime;
@Service
public class OrderPayHandler implements PayHandler {
@Autowired
private OrderService orderService;
@Autowired
private TransactionTemplate transactionTemplate;
@Autowired
private OrderMapper orderMapper;
@Autowired
private UserService userService;
/**
* TODO 支付成功后处理
*/
@Override
public boolean onPaySuccess(PayVO pay) {
ServiceUtil.assertion(pay == null, "支付信息不能为空");
ServiceUtil.assertion(pay.getBstId() == null, "订单ID不能为空");
ServiceUtil.assertion(!PayBstType.ORDER.getType().equals(pay.getBstType()), "订单支付类型错误");
// 查询订单
OrderVO order = orderService.selectOrderById(pay.getBstId());
ServiceUtil.assertion(order == null, "ID为%s的订单不存在", pay.getBstId());
Integer result = transactionTemplate.execute(status -> {
// 修改订单状态
Order data = new Order();
data.setStatus(OrderStatus.FINISHED.getCode());
data.setPayId(pay.getId());
OrderQuery query = new OrderQuery();
query.setId(order.getId());
query.setStatusList(OrderStatus.canPaySuccess());
int rows = orderMapper.updateByQuery(data, query);
ServiceUtil.assertion(rows != 1, "更新ID为%s的订单失败", order.getId());
// 增加用户爆灯次数(余额)
userService.addLightingNum(order.getUserId(),order.getStoreId(),order.getSuitNum(),"订单支付成功,增加爆灯次数"+order.getPayNo());
return rows;
});
return result != null && result == 1;
}
}

View File

@ -232,6 +232,11 @@ public class OrderServiceImpl implements OrderService
return result == null ? 0 : result; return result == null ? 0 : result;
} }
@Override
public OrderVO selectOrderByBstId(Long bstId) {
return orderMapper.selectOrderByBstId(bstId);
}
@Override @Override
public OrderVO selectOrderByNo(String no, boolean scope) { public OrderVO selectOrderByNo(String no, boolean scope) {
if (StringUtils.isBlank(no)) { if (StringUtils.isBlank(no)) {

View File

@ -54,6 +54,7 @@ public class OrderValidatorImpl implements OrderValidator{
// 价格 // 价格
OrderPrePriceVO prePrice = bo.getPrePrice(); OrderPrePriceVO prePrice = bo.getPrePrice();
ServiceUtil.assertion(prePrice == null, "价格计算失败"); ServiceUtil.assertion(prePrice == null, "价格计算失败");
// 是否和前端传输的价格一致 // 是否和前端传输的价格一致
boolean priceEquals = OrderUtil.isEquals(prePrice, dto.getPrice()); boolean priceEquals = OrderUtil.isEquals(prePrice, dto.getPrice());
ServiceUtil.assertion(!priceEquals, "当前价格已发生变化,请刷新后重新下单"); ServiceUtil.assertion(!priceEquals, "当前价格已发生变化,请刷新后重新下单");

View File

@ -1,5 +1,6 @@
package com.ruoyi.bst.pay.domain.enums; package com.ruoyi.bst.pay.domain.enums;
import com.ruoyi.bst.order.service.impl.OrderPayHandler;
import com.ruoyi.bst.pay.interfaces.PayHandler; import com.ruoyi.bst.pay.interfaces.PayHandler;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -15,7 +16,7 @@ import java.util.stream.Collectors;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum PayBstType { public enum PayBstType {
ORDER("1", "订单", null); ORDER("1", "订单", OrderPayHandler.class);
private final String type; private final String type;
private final String msg; private final String msg;

View File

@ -175,6 +175,12 @@ public class PayServiceImpl implements PayService {
int update = this.updateChannelNo(pay.getNo(), vo.getPayParams()); int update = this.updateChannelNo(pay.getNo(), vo.getPayParams());
ServiceUtil.assertion(update != 1, "更新渠道订单号失败"); ServiceUtil.assertion(update != 1, "更新渠道订单号失败");
// 3秒后支付成功
// 开发测试用正式环境需要删除
scheduledExecutorService.schedule(() -> {
this.handleSuccess(pay.getNo(), LocalDateTime.now());
}, 3, TimeUnit.SECONDS);
return vo; return vo;
}); });
} finally { } finally {

View File

@ -47,7 +47,7 @@ public class Suit extends BaseEntity
@ApiModelProperty("爆灯次数") @ApiModelProperty("爆灯次数")
@NotNull(message = "爆灯次数不能为空",groups = {ValidGroup.Create.class}) @NotNull(message = "爆灯次数不能为空",groups = {ValidGroup.Create.class})
@Min(value = 0,message = "爆灯次数不能为负数") @Min(value = 0,message = "爆灯次数不能为负数")
private Long lightingNums; private Integer lightingNums;
@Excel(name = "套餐名称") @Excel(name = "套餐名称")
@ApiModelProperty("套餐名称") @ApiModelProperty("套餐名称")

View File

@ -1,70 +1,70 @@
package com.ruoyi.bst.withdraw.service; //package com.ruoyi.bst.withdraw.service;
//
import com.ruoyi.bst.withdraw.domain.Withdraw; //import com.ruoyi.bst.withdraw.domain.Withdraw;
import com.ruoyi.bst.withdraw.domain.WithdrawQuery; //import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
import com.ruoyi.bst.withdraw.domain.WithdrawVO; //import com.ruoyi.bst.withdraw.domain.WithdrawVO;
import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO; //import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
//
import java.util.List; //import java.util.List;
//
/** ///**
* 提现Service接口 // * 提现Service接口
* // *
* @author ruoyi // * @author ruoyi
* @date 2025-04-07 // * @date 2025-04-07
*/ // */
public interface WithdrawService //public interface WithdrawService
{ //{
/** // /**
* 查询提现 // * 查询提现
* // *
* @param id 提现主键 // * @param id 提现主键
* @return 提现 // * @return 提现
*/ // */
public WithdrawVO selectWithdrawById(Long id); // public WithdrawVO selectWithdrawById(Long id);
//
/** // /**
* 查询提现列表 // * 查询提现列表
* // *
* @param withdraw 提现 // * @param withdraw 提现
* @return 提现集合 // * @return 提现集合
*/ // */
public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw); // public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw);
//
/** // /**
* 新增提现 // * 新增提现
* // *
* @param withdraw 提现 // * @param withdraw 提现
* @return 结果 // * @return 结果
*/ // */
public int insertWithdraw(Withdraw withdraw); // public int insertWithdraw(Withdraw withdraw);
//
/** // /**
* 修改提现 // * 修改提现
* // *
* @param withdraw 提现 // * @param withdraw 提现
* @return 结果 // * @return 结果
*/ // */
public int updateWithdraw(Withdraw withdraw); // public int updateWithdraw(Withdraw withdraw);
//
/** // /**
* 批量删除提现 // * 批量删除提现
* // *
* @param ids 需要删除的提现主键集合 // * @param ids 需要删除的提现主键集合
* @return 结果 // * @return 结果
*/ // */
public int deleteWithdrawByIds(Long[] ids); // public int deleteWithdrawByIds(Long[] ids);
//
/** // /**
* 删除提现信息 // * 删除提现信息
* // *
* @param id 提现主键 // * @param id 提现主键
* @return 结果 // * @return 结果
*/ // */
public int deleteWithdrawById(Long id); // public int deleteWithdrawById(Long id);
//
/** // /**
* 提现审核 // * 提现审核
*/ // */
int verify(WithdrawVerifyDTO dto); // int verify(WithdrawVerifyDTO dto);
} //}

View File

@ -1,226 +1,226 @@
package com.ruoyi.bst.withdraw.service.impl; //package com.ruoyi.bst.withdraw.service.impl;
//
import com.ruoyi.bst.account.domain.AccountVO; //import com.ruoyi.bst.account.domain.AccountVO;
import com.ruoyi.bst.account.domain.enums.AccountType; //import com.ruoyi.bst.account.domain.enums.AccountType;
import com.ruoyi.bst.account.service.AccountService; //import com.ruoyi.bst.account.service.AccountService;
import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType; //import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType;
import com.ruoyi.bst.withdraw.domain.Withdraw; //import com.ruoyi.bst.withdraw.domain.Withdraw;
import com.ruoyi.bst.withdraw.domain.WithdrawQuery; //import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
import com.ruoyi.bst.withdraw.domain.WithdrawVO; //import com.ruoyi.bst.withdraw.domain.WithdrawVO;
import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO; //import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
import com.ruoyi.bst.withdraw.domain.enums.WithdrawStatus; //import com.ruoyi.bst.withdraw.domain.enums.WithdrawStatus;
import com.ruoyi.bst.withdraw.domain.vo.WithdrawAmountVO; //import com.ruoyi.bst.withdraw.domain.vo.WithdrawAmountVO;
import com.ruoyi.bst.withdraw.mapper.WithdrawMapper; //import com.ruoyi.bst.withdraw.mapper.WithdrawMapper;
import com.ruoyi.bst.withdraw.service.WithdrawConverter; //import com.ruoyi.bst.withdraw.service.WithdrawConverter;
import com.ruoyi.bst.withdraw.service.WithdrawService; //import com.ruoyi.bst.withdraw.service.WithdrawService;
import com.ruoyi.common.core.domain.vo.UserVO; //import com.ruoyi.common.core.domain.vo.UserVO;
import com.ruoyi.common.exception.ServiceException; //import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils; //import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MathUtils; //import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.ServiceUtil; //import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.SnowFlakeUtil; //import com.ruoyi.common.utils.SnowFlakeUtil;
import com.ruoyi.system.user.service.UserService; //import com.ruoyi.system.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate; //import org.springframework.transaction.support.TransactionTemplate;
//
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.util.List; //import java.util.List;
//
/** ///**
* 提现Service业务层处理 // * 提现Service业务层处理
* // *
* @author ruoyi // * @author ruoyi
* @date 2025-04-07 // * @date 2025-04-07
*/ // */
@Service //@Service
public class WithdrawServiceImpl implements WithdrawService //public class WithdrawServiceImpl implements WithdrawService
{ //{
@Autowired // @Autowired
private WithdrawMapper withdrawMapper; // private WithdrawMapper withdrawMapper;
//
@Autowired // @Autowired
private UserService userService; // private UserService userService;
//
@Autowired // @Autowired
private WithdrawConverter withdrawConverter; // private WithdrawConverter withdrawConverter;
//
@Autowired // @Autowired
private AccountService accountService; // private AccountService accountService;
//
@Autowired // @Autowired
private TransactionTemplate transactionTemplate; // private TransactionTemplate transactionTemplate;
//
/** // /**
* 查询提现 // * 查询提现
* // *
* @param id 提现主键 // * @param id 提现主键
* @return 提现 // * @return 提现
*/ // */
@Override // @Override
public WithdrawVO selectWithdrawById(Long id) // public WithdrawVO selectWithdrawById(Long id)
{ // {
return withdrawMapper.selectWithdrawById(id); // return withdrawMapper.selectWithdrawById(id);
} // }
//
/** // /**
* 查询提现列表 // * 查询提现列表
* // *
* @param withdraw 提现 // * @param withdraw 提现
* @return 提现 // * @return 提现
*/ // */
@Override // @Override
public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw) // public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw)
{ // {
return withdrawMapper.selectWithdrawList(withdraw); // return withdrawMapper.selectWithdrawList(withdraw);
} // }
//
/** // /**
* 新增提现 // * 新增提现
* // *
* @param withdraw 提现 // * @param withdraw 提现
* @return 结果 // * @return 结果
*/ // */
@Override // @Override
public int insertWithdraw(Withdraw withdraw) { // public int insertWithdraw(Withdraw withdraw) {
// 获取用户信息 // // 获取用户信息
UserVO user = userService.selectUserById(withdraw.getUserId()); // UserVO user = userService.selectUserById(withdraw.getUserId());
ServiceUtil.assertion(user == null, "ID为%s的用户不存在", withdraw.getUserId()); // ServiceUtil.assertion(user == null, "ID为%s的用户不存在", withdraw.getUserId());
// 获取账户信息 // // 获取账户信息
AccountVO account = accountService.selectAccountById(withdraw.getAccountId()); // AccountVO account = accountService.selectAccountById(withdraw.getAccountId());
ServiceUtil.assertion(account == null, "ID为%s的收款账户不存在", withdraw.getAccountId()); // ServiceUtil.assertion(account == null, "ID为%s的收款账户不存在", withdraw.getAccountId());
//
// 获取金额 // // 获取金额
WithdrawAmountVO amountVo = withdrawConverter.calcAmount(user, withdraw.getAmount()); // WithdrawAmountVO amountVo = withdrawConverter.calcAmount(user, withdraw.getAmount());
ServiceUtil.assertion(amountVo == null, "计算金额出错"); // ServiceUtil.assertion(amountVo == null, "计算金额出错");
// 校验金额 // // 校验金额
ServiceUtil.assertion(!MathUtils.equals(amountVo.getServiceCharge(), withdraw.getServiceCharge()), "服务费金额发生变化,请刷新后重试"); // ServiceUtil.assertion(!MathUtils.equals(amountVo.getServiceCharge(), withdraw.getServiceCharge()), "服务费金额发生变化,请刷新后重试");
ServiceUtil.assertion(!MathUtils.equals(amountVo.getAmount(), withdraw.getArrivalAmount()), "到账金额发生变化,请刷新后重试"); // ServiceUtil.assertion(!MathUtils.equals(amountVo.getAmount(), withdraw.getArrivalAmount()), "到账金额发生变化,请刷新后重试");
ServiceUtil.assertion(MathUtils.smallerThan(withdraw.getAmount(), amountVo.getMinAmount()), "提现金额不允许小于最低金额:%s", amountVo.getMinAmount()); // ServiceUtil.assertion(MathUtils.smallerThan(withdraw.getAmount(), amountVo.getMinAmount()), "提现金额不允许小于最低金额:%s", amountVo.getMinAmount());
ServiceUtil.assertion(MathUtils.biggerThan(withdraw.getAmount(), amountVo.getMaxAmount()), "提现金额不允许大于最高金额:%s", amountVo.getMaxAmount()); // ServiceUtil.assertion(MathUtils.biggerThan(withdraw.getAmount(), amountVo.getMaxAmount()), "提现金额不允许大于最高金额:%s", amountVo.getMaxAmount());
//
// 组装提现数据 // // 组装提现数据
Withdraw data = new Withdraw(); // Withdraw data = new Withdraw();
// 基础 // // 基础
data.setUserId(withdraw.getUserId()); // data.setUserId(withdraw.getUserId());
data.setCreateTime(DateUtils.getNowDate()); // data.setCreateTime(DateUtils.getNowDate());
data.setNo(String.valueOf(SnowFlakeUtil.newId())); // data.setNo(String.valueOf(SnowFlakeUtil.newId()));
data.setStatus(WithdrawStatus.WAIT_VERIFY.getCode()); // data.setStatus(WithdrawStatus.WAIT_VERIFY.getCode());
// 账户 // // 账户
data.setAccountId(withdraw.getAccountId()); // data.setAccountId(withdraw.getAccountId());
data.setAccountType(account.getType()); // data.setAccountType(account.getType());
data.setAccountNo(account.getNo()); // data.setAccountNo(account.getNo());
data.setAccountName(account.getName()); // data.setAccountName(account.getName());
data.setAccountMobile(account.getMobile()); // data.setAccountMobile(account.getMobile());
data.setAccountIdCard(account.getIdCard()); // data.setAccountIdCard(account.getIdCard());
data.setBankName(account.getBankName()); // data.setBankName(account.getBankName());
data.setBankCardName(account.getBankCardName()); // data.setBankCardName(account.getBankCardName());
data.setBankType(account.getBankType()); // data.setBankType(account.getBankType());
// 金额 // // 金额
data.setServiceType(amountVo.getType()); // data.setServiceType(amountVo.getType());
data.setServiceCharge(amountVo.getServiceCharge()); // data.setServiceCharge(amountVo.getServiceCharge());
data.setServicePoint(amountVo.getPoint()); // data.setServicePoint(amountVo.getPoint());
data.setAmount(withdraw.getAmount()); // data.setAmount(withdraw.getAmount());
data.setArrivalAmount(amountVo.getAmount()); // data.setArrivalAmount(amountVo.getAmount());
Integer result = transactionTemplate.execute(status -> { // Integer result = transactionTemplate.execute(status -> {
int rows = withdrawMapper.insertWithdraw(data); // int rows = withdrawMapper.insertWithdraw(data);
//
if (rows > 0) { // if (rows > 0) {
// 扣减用户余额 // // 扣减用户余额
int sub = userService.subtractBalance(data.getUserId(), data.getAmount(), BalanceLogBstType.WITHDRAW, data.getId(), "提现申请:" + data.getNo(), true); // int sub = userService.subtractBalance(data.getUserId(), data.getAmount(), BalanceLogBstType.WITHDRAW, data.getId(), "提现申请:" + data.getNo(), true);
ServiceUtil.assertion(sub != 1, "扣减用户余额失败,请检查余额是否充足"); // ServiceUtil.assertion(sub != 1, "扣减用户余额失败,请检查余额是否充足");
} // }
//
return rows; // return rows;
}); // });
//
return result == null ? 0 : result; // return result == null ? 0 : result;
} // }
//
/** // /**
* 修改提现 // * 修改提现
* // *
* @param withdraw 提现 // * @param withdraw 提现
* @return 结果 // * @return 结果
*/ // */
@Override // @Override
public int updateWithdraw(Withdraw withdraw) // public int updateWithdraw(Withdraw withdraw)
{ // {
return withdrawMapper.updateWithdraw(withdraw); // return withdrawMapper.updateWithdraw(withdraw);
} // }
//
/** // /**
* 批量删除提现 // * 批量删除提现
* // *
* @param ids 需要删除的提现主键 // * @param ids 需要删除的提现主键
* @return 结果 // * @return 结果
*/ // */
@Override // @Override
public int deleteWithdrawByIds(Long[] ids) // public int deleteWithdrawByIds(Long[] ids)
{ // {
return withdrawMapper.deleteWithdrawByIds(ids); // return withdrawMapper.deleteWithdrawByIds(ids);
} // }
//
/** // /**
* 删除提现信息 // * 删除提现信息
* // *
* @param id 提现主键 // * @param id 提现主键
* @return 结果 // * @return 结果
*/ // */
@Override // @Override
public int deleteWithdrawById(Long id) // public int deleteWithdrawById(Long id)
{ // {
return withdrawMapper.deleteWithdrawById(id); // return withdrawMapper.deleteWithdrawById(id);
} // }
//
@Override // @Override
public int verify(WithdrawVerifyDTO dto) { // public int verify(WithdrawVerifyDTO dto) {
WithdrawVO withdraw = selectWithdrawById(dto.getId()); // WithdrawVO withdraw = selectWithdrawById(dto.getId());
ServiceUtil.assertion(withdraw == null, "待审核的提现不存在"); // ServiceUtil.assertion(withdraw == null, "待审核的提现不存在");
ServiceUtil.assertion(!WithdrawStatus.canVerify().contains(withdraw.getStatus()), "ID为%s的提现当前状态不允许审核", dto.getId()); // ServiceUtil.assertion(!WithdrawStatus.canVerify().contains(withdraw.getStatus()), "ID为%s的提现当前状态不允许审核", dto.getId());
//
boolean pass = dto.getPass() != null && dto.getPass(); // boolean pass = dto.getPass() != null && dto.getPass();
//
Integer result = transactionTemplate.execute(status -> { // Integer result = transactionTemplate.execute(status -> {
Withdraw data = new Withdraw(); // Withdraw data = new Withdraw();
if (pass) { // if (pass) {
if (AccountType.offline().contains(withdraw.getAccountType())) { // if (AccountType.offline().contains(withdraw.getAccountType())) {
data.setStatus(WithdrawStatus.SUCCESS.getCode()); // data.setStatus(WithdrawStatus.SUCCESS.getCode());
} else { // } else {
data.setStatus(WithdrawStatus.PAYING.getCode()); // data.setStatus(WithdrawStatus.PAYING.getCode());
} // }
} else { // } else {
data.setStatus(WithdrawStatus.REJECTED.getCode()); // data.setStatus(WithdrawStatus.REJECTED.getCode());
} // }
data.setVerifyUserId(dto.getVerifyId()); // data.setVerifyUserId(dto.getVerifyId());
data.setVerifyTime(LocalDateTime.now()); // data.setVerifyTime(LocalDateTime.now());
data.setVerifyRemark(dto.getRemark()); // data.setVerifyRemark(dto.getRemark());
WithdrawQuery query = new WithdrawQuery(); // WithdrawQuery query = new WithdrawQuery();
query.setId(dto.getId()); // query.setId(dto.getId());
query.setStatusList(WithdrawStatus.canVerify()); // query.setStatusList(WithdrawStatus.canVerify());
int rows = withdrawMapper.updateByQuery(data, query); // int rows = withdrawMapper.updateByQuery(data, query);
//
if (rows > 0 ) { // if (rows > 0 ) {
if (WithdrawStatus.PAYING.getCode().equals(data.getStatus())) { // if (WithdrawStatus.PAYING.getCode().equals(data.getStatus())) {
// TODO 支付中线上提现打款 // // TODO 支付中线上提现打款
throw new ServiceException("暂未开通线上提现打款"); // throw new ServiceException("暂未开通线上提现打款");
} else if (WithdrawStatus.REJECTED.getCode().equals(data.getStatus())) { // } else if (WithdrawStatus.REJECTED.getCode().equals(data.getStatus())) {
// 驳回恢复用户余额 // // 驳回恢复用户余额
int add = userService.addBalance( // int add = userService.addBalance(
withdraw.getUserId(), // withdraw.getUserId(),
withdraw.getAmount(), // withdraw.getAmount(),
BalanceLogBstType.WITHDRAW, // BalanceLogBstType.WITHDRAW,
withdraw.getId(), // withdraw.getId(),
"提现驳回:" + withdraw.getNo() // "提现驳回:" + withdraw.getNo()
); // );
ServiceUtil.assertion(add != 1, "恢复用户余额失败"); // ServiceUtil.assertion(add != 1, "恢复用户余额失败");
} // }
} // }
//
return rows; // return rows;
}); // });
//
return result == null ? 0 : result; // return result == null ? 0 : result;
} // }
//
} //}

View File

@ -4,6 +4,7 @@ import java.math.BigDecimal;
import java.util.List; import java.util.List;
import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType; import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType;
import com.ruoyi.bst.changeRecord.domain.enums.ChangeRecordBstType;
import com.ruoyi.common.core.domain.entity.User; import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.core.domain.vo.UserVO; import com.ruoyi.common.core.domain.vo.UserVO;
import com.ruoyi.system.user.domain.UserQuery; import com.ruoyi.system.user.domain.UserQuery;
@ -235,15 +236,15 @@ public interface UserService
public UserVO selectByAppOpenId(Long appId, String openId); public UserVO selectByAppOpenId(Long appId, String openId);
/** /**
* 增加余额 * 增加爆灯次数
* @param userId 用户ID * @param userId 用户ID
* @param amount 金额 * @param number 次数
* @param bstType 业务类型
* @param bstId 业务ID
* @param reason 原因 * @param reason 原因
* @return 结果 * @return 结果
*/ */
public int addBalance(Long userId, BigDecimal amount, BalanceLogBstType bstType, Long bstId, String reason); public int addLightingNum(Long userId, Long storeId, Integer number,String reason);
/** /**
* 减少余额 * 减少余额

View File

@ -12,6 +12,13 @@ import javax.validation.Validator;
import com.ruoyi.bst.balanceLog.domain.BalanceLog; import com.ruoyi.bst.balanceLog.domain.BalanceLog;
import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType; import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType;
import com.ruoyi.bst.balanceLog.service.BalanceLogService; import com.ruoyi.bst.balanceLog.service.BalanceLogService;
import com.ruoyi.bst.changeRecord.domain.ChangeRecord;
import com.ruoyi.bst.changeRecord.domain.enums.ChangeRecordBstType;
import com.ruoyi.bst.changeRecord.mapper.ChangeRecordMapper;
import com.ruoyi.bst.lightingNum.domain.LightingNum;
import com.ruoyi.bst.lightingNum.domain.LightingNumVO;
import com.ruoyi.bst.lightingNum.mapper.LightingNumMapper;
import com.ruoyi.common.utils.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -100,6 +107,10 @@ public class UserServiceImpl implements UserService
@Autowired @Autowired
private BalanceLogService balanceLogService; private BalanceLogService balanceLogService;
@Autowired
private LightingNumMapper lightingNumMapper;
@Autowired
private ChangeRecordMapper changeRecordMapper;
/** /**
* 根据条件分页查询用户列表 * 根据条件分页查询用户列表
@ -684,41 +695,57 @@ public class UserServiceImpl implements UserService
} }
@Override @Override
public int addBalance(Long userId, BigDecimal amount, BalanceLogBstType bstType, Long bstId, String reason) { public int addLightingNum(Long userId, Long storeId , Integer number, String reason) {
if (userId == null || amount == null ) { if (userId == null || number == null ) {
return 0; return 0;
} }
// 如果金额为0则不进行任何操作 // 如果次数为0则不进行任何操作
if (amount.compareTo(BigDecimal.ZERO) == 0) { if (number == 0) {
return 1; return 1;
} }
// 如果金额为负数则抛出异常 // 如果金额为负数则抛出异常
ServiceUtil.assertion(amount.compareTo(BigDecimal.ZERO) < 0, "增加的金额不能为负数"); ServiceUtil.assertion(number < 0, "增加的次数不能为负数");
Integer result = transactionTemplate.execute(status -> { Integer result = transactionTemplate.execute(status -> {
// 查询用户余额并锁定 // 查询用户爆灯次数并锁定
BigDecimal balance = userMapper.selectBalanceForUpdate(userId); Integer lightingNumber = lightingNumMapper.selectLightingNumberForUpdate(userId);
if (balance == null) { if (lightingNumber == null) {
balance = BigDecimal.ZERO; lightingNumber = 0;
} }
// 更新用户余额 // 更新用户爆灯次数
int rows = userMapper.addBalance(userId, amount); LightingNumVO vo = lightingNumMapper.selectLightingNumById(userId);
int rows = 0;
// 新增余额日志 // 第一次插入新建一条爆灯次数记录
if (vo == null) {
LightingNum lightingNum = new LightingNum();
lightingNum.setUserId(userId);
lightingNum.setStoreId(storeId);
lightingNum.setNumber(number);
lightingNum.setCreateTime(DateUtils.getNowDate());
rows = lightingNumMapper.insertLightingNum(lightingNum);
}
// 更新用户爆灯次数
else {
rows = lightingNumMapper.addLightingNum(userId, storeId,lightingNumber);
}
// 新增爆灯次数变化
if (rows > 0) { if (rows > 0) {
BalanceLog log = new BalanceLog(); ChangeRecord record = new ChangeRecord();
log.setUserId(userId); record.setUserId(userId);
log.setAmount(amount); record.setStoreId(userId);
log.setBeforeBalance(balance); record.setNumber(lightingNumber);
log.setAfterBalance(balance.add(amount)); if (lightingNumber == 0){
log.setBstType(bstType.getCode()); record.setBeforeNum(0);
log.setBstId(bstId); }else {
log.setReason(reason); record.setBeforeNum(lightingNumber-number);
int logInsert = balanceLogService.insertBalanceLog(log); }
record.setAfterNum(lightingNumber+number);
record.setReason(reason);
record.setCreateTime(DateUtils.getNowDate());
int logInsert = changeRecordMapper.insertChangeRecord(record);
ServiceUtil.assertion(logInsert != 1, "新增余额日志失败"); ServiceUtil.assertion(logInsert != 1, "新增余额日志失败");
} }
return rows; return rows;
}); });

View File

@ -89,14 +89,14 @@ public class BonusController extends BaseController
// return success(list); // return success(list);
// } // }
/** // /**
* 支付分成 // * 支付分成
*/ // */
@PreAuthorize("@ss.hasPermi('bst:bonus:pay')") // @PreAuthorize("@ss.hasPermi('bst:bonus:pay')")
@PutMapping("/pay") // @PutMapping("/pay")
@Log(title = "支付分成", businessType = BusinessType.OTHER) // @Log(title = "支付分成", businessType = BusinessType.OTHER)
public AjaxResult pay(Long id) { // public AjaxResult pay(Long id) {
return success(bonusService.payBonus(id)); // return success(bonusService.payBonus(id));
} // }
} }

View File

@ -1,117 +1,117 @@
package com.ruoyi.web.bst; //package com.ruoyi.web.bst;
//
import com.ruoyi.bst.withdraw.domain.Withdraw; //import com.ruoyi.bst.withdraw.domain.Withdraw;
import com.ruoyi.bst.withdraw.domain.WithdrawQuery; //import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
import com.ruoyi.bst.withdraw.domain.WithdrawVO; //import com.ruoyi.bst.withdraw.domain.WithdrawVO;
import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO; //import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
import com.ruoyi.bst.withdraw.service.WithdrawConverter; //import com.ruoyi.bst.withdraw.service.WithdrawConverter;
import com.ruoyi.bst.withdraw.service.WithdrawService; //import com.ruoyi.bst.withdraw.service.WithdrawService;
import com.ruoyi.common.annotation.Log; //import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; //import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; //import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.vo.UserVO; //import com.ruoyi.common.core.domain.vo.UserVO;
import com.ruoyi.common.core.page.TableDataInfo; //import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; //import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil; //import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.user.service.UserService; //import com.ruoyi.system.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; //import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; //import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; //import org.springframework.web.bind.annotation.*;
//
import javax.servlet.http.HttpServletResponse; //import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal; //import java.math.BigDecimal;
import java.util.List; //import java.util.List;
//
/** ///**
* 提现Controller // * 提现Controller
* // *
* @author ruoyi // * @author ruoyi
* @date 2025-04-07 // * @date 2025-04-07
*/ // */
@RestController //@RestController
@RequestMapping("/bst/withdraw") //@RequestMapping("/bst/withdraw")
public class WithdrawController extends BaseController //public class WithdrawController extends BaseController
{ //{
@Autowired // @Autowired
private WithdrawService withdrawService; // private WithdrawService withdrawService;
//
@Autowired // @Autowired
private UserService userService; // private UserService userService;
//
@Autowired // @Autowired
private WithdrawConverter withdrawConverter; // private WithdrawConverter withdrawConverter;
//
/** // /**
* 查询提现列表 // * 查询提现列表
*/ // */
@PreAuthorize("@ss.hasPermi('bst:withdraw:list')") // @PreAuthorize("@ss.hasPermi('bst:withdraw:list')")
@GetMapping("/list") // @GetMapping("/list")
public TableDataInfo list(WithdrawQuery query) // public TableDataInfo list(WithdrawQuery query)
{ // {
startPage(); // startPage();
startOrderBy(); // startOrderBy();
query.setScope(true); // query.setScope(true);
List<WithdrawVO> list = withdrawService.selectWithdrawList(query); // List<WithdrawVO> list = withdrawService.selectWithdrawList(query);
return getDataTable(list); // return getDataTable(list);
} // }
//
/** // /**
* 导出提现列表 // * 导出提现列表
*/ // */
@PreAuthorize("@ss.hasPermi('bst:withdraw:export')") // @PreAuthorize("@ss.hasPermi('bst:withdraw:export')")
@Log(title = "提现", businessType = BusinessType.EXPORT) // @Log(title = "提现", businessType = BusinessType.EXPORT)
@PostMapping("/export") // @PostMapping("/export")
public void export(HttpServletResponse response, WithdrawQuery query) // public void export(HttpServletResponse response, WithdrawQuery query)
{ // {
query.setScope(true); // query.setScope(true);
List<WithdrawVO> list = withdrawService.selectWithdrawList(query); // List<WithdrawVO> list = withdrawService.selectWithdrawList(query);
ExcelUtil<WithdrawVO> util = new ExcelUtil<WithdrawVO>(WithdrawVO.class); // ExcelUtil<WithdrawVO> util = new ExcelUtil<WithdrawVO>(WithdrawVO.class);
util.exportExcel(response, list, "提现数据"); // util.exportExcel(response, list, "提现数据");
} // }
//
/** // /**
* 获取提现详细信息 // * 获取提现详细信息
*/ // */
@PreAuthorize("@ss.hasPermi('bst:withdraw:query')") // @PreAuthorize("@ss.hasPermi('bst:withdraw:query')")
@GetMapping(value = "/{id}") // @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) // public AjaxResult getInfo(@PathVariable("id") Long id)
{ // {
return success(withdrawService.selectWithdrawById(id)); // return success(withdrawService.selectWithdrawById(id));
} // }
//
/** // /**
* 申请提现 // * 申请提现
*/ // */
@PreAuthorize("@ss.hasPermi('bst:withdraw:add')") // @PreAuthorize("@ss.hasPermi('bst:withdraw:add')")
@Log(title = "申请提现", businessType = BusinessType.INSERT) // @Log(title = "申请提现", businessType = BusinessType.INSERT)
@PostMapping // @PostMapping
public AjaxResult add(@RequestBody @Validated Withdraw withdraw) { // public AjaxResult add(@RequestBody @Validated Withdraw withdraw) {
// 若是不是系统管理员则无权给他人提现 // // 若是不是系统管理员则无权给他人提现
if (!isSysAdmin() || withdraw.getUserId() == null) { // if (!isSysAdmin() || withdraw.getUserId() == null) {
withdraw.setUserId(getUserId()); // withdraw.setUserId(getUserId());
} // }
return toAjax(withdrawService.insertWithdraw(withdraw)); // return toAjax(withdrawService.insertWithdraw(withdraw));
} // }
//
@PreAuthorize("@ss.hasPermi('bst:withdraw:add')") // @PreAuthorize("@ss.hasPermi('bst:withdraw:add')")
@Log(title = "查询提现服务费", businessType = BusinessType.OTHER) // @Log(title = "查询提现服务费", businessType = BusinessType.OTHER)
@GetMapping("/calcAmount") // @GetMapping("/calcAmount")
public AjaxResult calcAmount(BigDecimal amount, @RequestParam(required = false) Long userId) { // public AjaxResult calcAmount(BigDecimal amount, @RequestParam(required = false) Long userId) {
// 若是不是系统管理员则无权查询他人的提现服务费 // // 若是不是系统管理员则无权查询他人的提现服务费
if (!isSysAdmin() || userId == null) { // if (!isSysAdmin() || userId == null) {
userId = getUserId(); // userId = getUserId();
} // }
UserVO user = userService.selectUserById(userId); // UserVO user = userService.selectUserById(userId);
return success(withdrawConverter.calcAmount(user, amount)); // return success(withdrawConverter.calcAmount(user, amount));
} // }
//
@PreAuthorize("@ss.hasPermi('bst:withdraw:verify')") // @PreAuthorize("@ss.hasPermi('bst:withdraw:verify')")
@Log(title = "提现审核", businessType = BusinessType.VERIFY) // @Log(title = "提现审核", businessType = BusinessType.VERIFY)
@PutMapping("/verify") // @PutMapping("/verify")
public AjaxResult verify(@RequestBody @Validated WithdrawVerifyDTO dto) { // public AjaxResult verify(@RequestBody @Validated WithdrawVerifyDTO dto) {
dto.setVerifyId(getUserId()); // dto.setVerifyId(getUserId());
return toAjax(withdrawService.verify(dto)); // return toAjax(withdrawService.verify(dto));
} // }
//
} //}