下单充值余额并生成记录
This commit is contained in:
parent
054375ebc0
commit
3e86bb3018
|
@ -103,7 +103,7 @@ public interface BonusService
|
|||
* @param id 分成明细ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int payBonus(Long id);
|
||||
// public int payBonus(Long id);
|
||||
|
||||
/**
|
||||
* 进行分成打款指定时间之前的分成
|
||||
|
|
|
@ -78,6 +78,11 @@ public class BonusServiceImpl implements BonusService
|
|||
return this.selectOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BonusVO selectBonusById(Long id) {
|
||||
return BonusService.super.selectBonusById(id);
|
||||
}
|
||||
|
||||
private BonusVO selectOne(BonusQuery query) {
|
||||
PageHelper.startPage(1, 1);
|
||||
List<BonusVO> list = this.selectBonusList(query);
|
||||
|
@ -172,6 +177,11 @@ public class BonusServiceImpl implements BonusService
|
|||
return rows == list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int payBonus(BonusVO bonus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 预分成
|
||||
private int prepay(List<BonusVO> list) {
|
||||
if (CollectionUtils.isEmptyElement(list)) {
|
||||
|
@ -242,39 +252,39 @@ public class BonusServiceImpl implements BonusService
|
|||
return sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int payBonus(BonusVO bonus) {
|
||||
ServiceUtil.assertion(bonus == null, "待打款的分成不存在");
|
||||
ServiceUtil.assertion(!BonusStatus.canPay().contains(bonus.getStatus()), "ID为%s的分成当前状态不允许打款", bonus.getId());
|
||||
// @Override
|
||||
// public int payBonus(BonusVO bonus) {
|
||||
// ServiceUtil.assertion(bonus == null, "待打款的分成不存在");
|
||||
// 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 -> {
|
||||
// 更新分成状态为已分成
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int payBonus(Long id) {
|
||||
if (id == null) {
|
||||
return 0;
|
||||
}
|
||||
BonusVO bonus = this.selectBonusById(id);
|
||||
return this.payBonus(bonus);
|
||||
}
|
||||
// @Override
|
||||
// public int payBonus(Long id) {
|
||||
// if (id == null) {
|
||||
// return 0;
|
||||
// }
|
||||
// BonusVO bonus = this.selectBonusById(id);
|
||||
// return this.payBonus(bonus);
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.bst.changeRecord.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
@ -30,15 +31,15 @@ public class ChangeRecord extends BaseEntity
|
|||
|
||||
@Excel(name = "变动次数")
|
||||
@ApiModelProperty("变动次数")
|
||||
private Long number;
|
||||
private Integer number;
|
||||
|
||||
@Excel(name = "变动前次数")
|
||||
@ApiModelProperty("变动前次数")
|
||||
private Long beforeNum;
|
||||
private Integer beforeNum;
|
||||
|
||||
@Excel(name = "变动后次数")
|
||||
@ApiModelProperty("变动后次数")
|
||||
private Long afterNum;
|
||||
private Integer afterNum;
|
||||
|
||||
@Excel(name = "业务类型")
|
||||
@ApiModelProperty("业务类型")
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.bst.lightingNum.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
@ -30,6 +31,6 @@ public class LightingNum extends BaseEntity
|
|||
|
||||
@Excel(name = "爆灯次数")
|
||||
@ApiModelProperty("爆灯次数")
|
||||
private Long number;
|
||||
private Integer number;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.ruoyi.bst.lightingNum.mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import com.ruoyi.bst.lightingNum.domain.LightingNum;
|
||||
import com.ruoyi.bst.lightingNum.domain.LightingNumVO;
|
||||
import com.ruoyi.bst.lightingNum.domain.LightingNumQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
|
||||
/**
|
||||
* 爆灯次数列表Mapper接口
|
||||
|
@ -71,4 +73,14 @@ public interface LightingNumMapper
|
|||
* @return 结果
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<sql id="selectLightingNumVo">
|
||||
select
|
||||
id,
|
||||
user_id,
|
||||
store_id,
|
||||
number,
|
||||
create_time
|
||||
from bst_lighting_num
|
||||
bln.id,
|
||||
bln.user_id,
|
||||
bln.store_id,
|
||||
bln.number,
|
||||
bln.create_time
|
||||
from bst_lighting_num bln
|
||||
</sql>
|
||||
|
||||
<sql id="searchCondition">
|
||||
|
@ -41,6 +41,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where id = #{id}
|
||||
</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 into bst_lighting_num
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
@ -80,6 +86,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</foreach>
|
||||
</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 bst_lighting_num
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
|
|
|
@ -66,7 +66,7 @@ public class Order extends BaseEntity
|
|||
|
||||
@Excel(name = "套餐次数")
|
||||
@ApiModelProperty("套餐次数")
|
||||
private Long suitNum;
|
||||
private Integer suitNum;
|
||||
|
||||
@Excel(name = "套餐金额", readConverterExp = "单=位:元")
|
||||
@ApiModelProperty("套餐金额")
|
||||
|
|
|
@ -11,42 +11,23 @@ import java.util.List;
|
|||
public enum OrderStatus {
|
||||
|
||||
WAIT_PAY("WAIT_PAY", "待支付"),
|
||||
PROCESSING("PROCESSING", "进行中"),
|
||||
FINISHED("FINISHED", "已结束"),
|
||||
CANCELED("CANCELED", "已取消"),
|
||||
WAIT_VERIFY("WAIT_VERIFY", "待审核"),
|
||||
REJECTED("REJECTED", "已驳回"),
|
||||
REFUNDED("REFUNDED", "已退款");
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
|
||||
|
||||
// 允许支付的订单状态
|
||||
public static List<String> canPay() {
|
||||
return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY);
|
||||
}
|
||||
|
||||
// 正在使用中的订单状态
|
||||
public static List<String> inUse() {
|
||||
return CollectionUtils.map(OrderStatus::getCode, PROCESSING);
|
||||
}
|
||||
|
||||
// 可以支付成功的订单状态
|
||||
public static List<String> canPaySuccess() {
|
||||
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() {
|
||||
return CollectionUtils.map(OrderStatus::getCode, WAIT_PAY);
|
||||
|
@ -56,14 +37,5 @@ public enum OrderStatus {
|
|||
public static List<String> canCancelPay() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public interface OrderMapper
|
|||
* @param id 订单列表主键
|
||||
* @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);
|
||||
|
||||
OrderVO selectOrderByBstId(@Param("bstId") Long bstId);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="selectOrderById" parameterType="Long" resultMap="OrderResult">
|
||||
<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>
|
||||
<!-- selectIdByQuery -->
|
||||
|
||||
|
|
|
@ -108,4 +108,5 @@ public interface OrderService
|
|||
*/
|
||||
public int cancelOrder(Long id, String remark);
|
||||
|
||||
OrderVO selectOrderByBstId(Long bstId);
|
||||
}
|
||||
|
|
|
@ -11,10 +11,13 @@ import com.ruoyi.bst.model.service.ModelService;
|
|||
import com.ruoyi.bst.order.domain.Order;
|
||||
import com.ruoyi.bst.order.domain.bo.OrderCreateBO;
|
||||
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.service.OrderConverter;
|
||||
import com.ruoyi.bst.order.service.OrderService;
|
||||
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.service.SuitService;
|
||||
import com.ruoyi.bst.userApp.domain.UserAppVO;
|
||||
|
@ -57,6 +60,8 @@ public class OrderConverterImpl implements OrderConverter{
|
|||
|
||||
@Autowired
|
||||
private ModelService modelService;
|
||||
@Autowired
|
||||
private StoreService storeService;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -117,16 +122,29 @@ public class OrderConverterImpl implements OrderConverter{
|
|||
order.setUserId(user.getUserId());
|
||||
}
|
||||
|
||||
// 套餐信息
|
||||
// 套餐店铺信息
|
||||
SuitVO suit = bo.getSuit();
|
||||
if (suit != null) {
|
||||
StoreVO store = storeService.selectStoreById(suit.getStoreId());
|
||||
if (store != null) {
|
||||
order.setStoreName(store.getStoreName());
|
||||
}
|
||||
order.setStoreId(suit.getStoreId());
|
||||
order.setSuitId(suit.getSuitId());
|
||||
order.setSuitName(suit.getSuitName());
|
||||
order.setPayAmount(suit.getRechargeAmount());
|
||||
order.setSuitAmount(suit.getRechargeAmount());
|
||||
order.setSuitNum(suit.getLightingNums());
|
||||
}
|
||||
|
||||
// 价格信息
|
||||
OrderPrePriceVO prePrice = bo.getPrePrice();
|
||||
if (prePrice != null) {
|
||||
order.setPayAmount(prePrice.getPayAmount());
|
||||
}
|
||||
|
||||
// 订单状态
|
||||
order.setStatus(OrderStatus.WAIT_PAY.getCode());
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -232,6 +232,11 @@ public class OrderServiceImpl implements OrderService
|
|||
return result == null ? 0 : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderVO selectOrderByBstId(Long bstId) {
|
||||
return orderMapper.selectOrderByBstId(bstId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderVO selectOrderByNo(String no, boolean scope) {
|
||||
if (StringUtils.isBlank(no)) {
|
||||
|
|
|
@ -54,6 +54,7 @@ public class OrderValidatorImpl implements OrderValidator{
|
|||
// 价格
|
||||
OrderPrePriceVO prePrice = bo.getPrePrice();
|
||||
ServiceUtil.assertion(prePrice == null, "价格计算失败");
|
||||
|
||||
// 是否和前端传输的价格一致
|
||||
boolean priceEquals = OrderUtil.isEquals(prePrice, dto.getPrice());
|
||||
ServiceUtil.assertion(!priceEquals, "当前价格已发生变化,请刷新后重新下单");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.bst.pay.domain.enums;
|
||||
|
||||
import com.ruoyi.bst.order.service.impl.OrderPayHandler;
|
||||
import com.ruoyi.bst.pay.interfaces.PayHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
@ -15,7 +16,7 @@ import java.util.stream.Collectors;
|
|||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PayBstType {
|
||||
ORDER("1", "订单", null);
|
||||
ORDER("1", "订单", OrderPayHandler.class);
|
||||
|
||||
private final String type;
|
||||
private final String msg;
|
||||
|
|
|
@ -175,6 +175,12 @@ public class PayServiceImpl implements PayService {
|
|||
int update = this.updateChannelNo(pay.getNo(), vo.getPayParams());
|
||||
ServiceUtil.assertion(update != 1, "更新渠道订单号失败");
|
||||
|
||||
// 3秒后。支付成功
|
||||
// 开发测试用,正式环境需要删除
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
this.handleSuccess(pay.getNo(), LocalDateTime.now());
|
||||
}, 3, TimeUnit.SECONDS);
|
||||
|
||||
return vo;
|
||||
});
|
||||
} finally {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class Suit extends BaseEntity
|
|||
@ApiModelProperty("爆灯次数")
|
||||
@NotNull(message = "爆灯次数不能为空",groups = {ValidGroup.Create.class})
|
||||
@Min(value = 0,message = "爆灯次数不能为负数")
|
||||
private Long lightingNums;
|
||||
private Integer lightingNums;
|
||||
|
||||
@Excel(name = "套餐名称")
|
||||
@ApiModelProperty("套餐名称")
|
||||
|
|
|
@ -1,70 +1,70 @@
|
|||
package com.ruoyi.bst.withdraw.service;
|
||||
|
||||
import com.ruoyi.bst.withdraw.domain.Withdraw;
|
||||
import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
|
||||
import com.ruoyi.bst.withdraw.domain.WithdrawVO;
|
||||
import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提现Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-04-07
|
||||
*/
|
||||
public interface WithdrawService
|
||||
{
|
||||
/**
|
||||
* 查询提现
|
||||
*
|
||||
* @param id 提现主键
|
||||
* @return 提现
|
||||
*/
|
||||
public WithdrawVO selectWithdrawById(Long id);
|
||||
|
||||
/**
|
||||
* 查询提现列表
|
||||
*
|
||||
* @param withdraw 提现
|
||||
* @return 提现集合
|
||||
*/
|
||||
public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw);
|
||||
|
||||
/**
|
||||
* 新增提现
|
||||
*
|
||||
* @param withdraw 提现
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertWithdraw(Withdraw withdraw);
|
||||
|
||||
/**
|
||||
* 修改提现
|
||||
*
|
||||
* @param withdraw 提现
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateWithdraw(Withdraw withdraw);
|
||||
|
||||
/**
|
||||
* 批量删除提现
|
||||
*
|
||||
* @param ids 需要删除的提现主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteWithdrawByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除提现信息
|
||||
*
|
||||
* @param id 提现主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteWithdrawById(Long id);
|
||||
|
||||
/**
|
||||
* 提现审核
|
||||
*/
|
||||
int verify(WithdrawVerifyDTO dto);
|
||||
}
|
||||
//package com.ruoyi.bst.withdraw.service;
|
||||
//
|
||||
//import com.ruoyi.bst.withdraw.domain.Withdraw;
|
||||
//import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
|
||||
//import com.ruoyi.bst.withdraw.domain.WithdrawVO;
|
||||
//import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * 提现Service接口
|
||||
// *
|
||||
// * @author ruoyi
|
||||
// * @date 2025-04-07
|
||||
// */
|
||||
//public interface WithdrawService
|
||||
//{
|
||||
// /**
|
||||
// * 查询提现
|
||||
// *
|
||||
// * @param id 提现主键
|
||||
// * @return 提现
|
||||
// */
|
||||
// public WithdrawVO selectWithdrawById(Long id);
|
||||
//
|
||||
// /**
|
||||
// * 查询提现列表
|
||||
// *
|
||||
// * @param withdraw 提现
|
||||
// * @return 提现集合
|
||||
// */
|
||||
// public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw);
|
||||
//
|
||||
// /**
|
||||
// * 新增提现
|
||||
// *
|
||||
// * @param withdraw 提现
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int insertWithdraw(Withdraw withdraw);
|
||||
//
|
||||
// /**
|
||||
// * 修改提现
|
||||
// *
|
||||
// * @param withdraw 提现
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int updateWithdraw(Withdraw withdraw);
|
||||
//
|
||||
// /**
|
||||
// * 批量删除提现
|
||||
// *
|
||||
// * @param ids 需要删除的提现主键集合
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteWithdrawByIds(Long[] ids);
|
||||
//
|
||||
// /**
|
||||
// * 删除提现信息
|
||||
// *
|
||||
// * @param id 提现主键
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteWithdrawById(Long id);
|
||||
//
|
||||
// /**
|
||||
// * 提现审核
|
||||
// */
|
||||
// int verify(WithdrawVerifyDTO dto);
|
||||
//}
|
||||
|
|
|
@ -1,226 +1,226 @@
|
|||
package com.ruoyi.bst.withdraw.service.impl;
|
||||
|
||||
import com.ruoyi.bst.account.domain.AccountVO;
|
||||
import com.ruoyi.bst.account.domain.enums.AccountType;
|
||||
import com.ruoyi.bst.account.service.AccountService;
|
||||
import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType;
|
||||
import com.ruoyi.bst.withdraw.domain.Withdraw;
|
||||
import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
|
||||
import com.ruoyi.bst.withdraw.domain.WithdrawVO;
|
||||
import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
|
||||
import com.ruoyi.bst.withdraw.domain.enums.WithdrawStatus;
|
||||
import com.ruoyi.bst.withdraw.domain.vo.WithdrawAmountVO;
|
||||
import com.ruoyi.bst.withdraw.mapper.WithdrawMapper;
|
||||
import com.ruoyi.bst.withdraw.service.WithdrawConverter;
|
||||
import com.ruoyi.bst.withdraw.service.WithdrawService;
|
||||
import com.ruoyi.common.core.domain.vo.UserVO;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.MathUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.SnowFlakeUtil;
|
||||
import com.ruoyi.system.user.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提现Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-04-07
|
||||
*/
|
||||
@Service
|
||||
public class WithdrawServiceImpl implements WithdrawService
|
||||
{
|
||||
@Autowired
|
||||
private WithdrawMapper withdrawMapper;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private WithdrawConverter withdrawConverter;
|
||||
|
||||
@Autowired
|
||||
private AccountService accountService;
|
||||
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
|
||||
/**
|
||||
* 查询提现
|
||||
*
|
||||
* @param id 提现主键
|
||||
* @return 提现
|
||||
*/
|
||||
@Override
|
||||
public WithdrawVO selectWithdrawById(Long id)
|
||||
{
|
||||
return withdrawMapper.selectWithdrawById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询提现列表
|
||||
*
|
||||
* @param withdraw 提现
|
||||
* @return 提现
|
||||
*/
|
||||
@Override
|
||||
public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw)
|
||||
{
|
||||
return withdrawMapper.selectWithdrawList(withdraw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增提现
|
||||
*
|
||||
* @param withdraw 提现
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertWithdraw(Withdraw withdraw) {
|
||||
// 获取用户信息
|
||||
UserVO user = userService.selectUserById(withdraw.getUserId());
|
||||
ServiceUtil.assertion(user == null, "ID为%s的用户不存在", withdraw.getUserId());
|
||||
// 获取账户信息
|
||||
AccountVO account = accountService.selectAccountById(withdraw.getAccountId());
|
||||
ServiceUtil.assertion(account == null, "ID为%s的收款账户不存在", withdraw.getAccountId());
|
||||
|
||||
// 获取金额
|
||||
WithdrawAmountVO amountVo = withdrawConverter.calcAmount(user, withdraw.getAmount());
|
||||
ServiceUtil.assertion(amountVo == null, "计算金额出错");
|
||||
// 校验金额
|
||||
ServiceUtil.assertion(!MathUtils.equals(amountVo.getServiceCharge(), withdraw.getServiceCharge()), "服务费金额发生变化,请刷新后重试");
|
||||
ServiceUtil.assertion(!MathUtils.equals(amountVo.getAmount(), withdraw.getArrivalAmount()), "到账金额发生变化,请刷新后重试");
|
||||
ServiceUtil.assertion(MathUtils.smallerThan(withdraw.getAmount(), amountVo.getMinAmount()), "提现金额不允许小于最低金额:%s", amountVo.getMinAmount());
|
||||
ServiceUtil.assertion(MathUtils.biggerThan(withdraw.getAmount(), amountVo.getMaxAmount()), "提现金额不允许大于最高金额:%s", amountVo.getMaxAmount());
|
||||
|
||||
// 组装提现数据
|
||||
Withdraw data = new Withdraw();
|
||||
// 基础
|
||||
data.setUserId(withdraw.getUserId());
|
||||
data.setCreateTime(DateUtils.getNowDate());
|
||||
data.setNo(String.valueOf(SnowFlakeUtil.newId()));
|
||||
data.setStatus(WithdrawStatus.WAIT_VERIFY.getCode());
|
||||
// 账户
|
||||
data.setAccountId(withdraw.getAccountId());
|
||||
data.setAccountType(account.getType());
|
||||
data.setAccountNo(account.getNo());
|
||||
data.setAccountName(account.getName());
|
||||
data.setAccountMobile(account.getMobile());
|
||||
data.setAccountIdCard(account.getIdCard());
|
||||
data.setBankName(account.getBankName());
|
||||
data.setBankCardName(account.getBankCardName());
|
||||
data.setBankType(account.getBankType());
|
||||
// 金额
|
||||
data.setServiceType(amountVo.getType());
|
||||
data.setServiceCharge(amountVo.getServiceCharge());
|
||||
data.setServicePoint(amountVo.getPoint());
|
||||
data.setAmount(withdraw.getAmount());
|
||||
data.setArrivalAmount(amountVo.getAmount());
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
int rows = withdrawMapper.insertWithdraw(data);
|
||||
|
||||
if (rows > 0) {
|
||||
// 扣减用户余额
|
||||
int sub = userService.subtractBalance(data.getUserId(), data.getAmount(), BalanceLogBstType.WITHDRAW, data.getId(), "提现申请:" + data.getNo(), true);
|
||||
ServiceUtil.assertion(sub != 1, "扣减用户余额失败,请检查余额是否充足");
|
||||
}
|
||||
|
||||
return rows;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改提现
|
||||
*
|
||||
* @param withdraw 提现
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateWithdraw(Withdraw withdraw)
|
||||
{
|
||||
return withdrawMapper.updateWithdraw(withdraw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除提现
|
||||
*
|
||||
* @param ids 需要删除的提现主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteWithdrawByIds(Long[] ids)
|
||||
{
|
||||
return withdrawMapper.deleteWithdrawByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除提现信息
|
||||
*
|
||||
* @param id 提现主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteWithdrawById(Long id)
|
||||
{
|
||||
return withdrawMapper.deleteWithdrawById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int verify(WithdrawVerifyDTO dto) {
|
||||
WithdrawVO withdraw = selectWithdrawById(dto.getId());
|
||||
ServiceUtil.assertion(withdraw == null, "待审核的提现不存在");
|
||||
ServiceUtil.assertion(!WithdrawStatus.canVerify().contains(withdraw.getStatus()), "ID为%s的提现当前状态不允许审核", dto.getId());
|
||||
|
||||
boolean pass = dto.getPass() != null && dto.getPass();
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
Withdraw data = new Withdraw();
|
||||
if (pass) {
|
||||
if (AccountType.offline().contains(withdraw.getAccountType())) {
|
||||
data.setStatus(WithdrawStatus.SUCCESS.getCode());
|
||||
} else {
|
||||
data.setStatus(WithdrawStatus.PAYING.getCode());
|
||||
}
|
||||
} else {
|
||||
data.setStatus(WithdrawStatus.REJECTED.getCode());
|
||||
}
|
||||
data.setVerifyUserId(dto.getVerifyId());
|
||||
data.setVerifyTime(LocalDateTime.now());
|
||||
data.setVerifyRemark(dto.getRemark());
|
||||
WithdrawQuery query = new WithdrawQuery();
|
||||
query.setId(dto.getId());
|
||||
query.setStatusList(WithdrawStatus.canVerify());
|
||||
int rows = withdrawMapper.updateByQuery(data, query);
|
||||
|
||||
if (rows > 0 ) {
|
||||
if (WithdrawStatus.PAYING.getCode().equals(data.getStatus())) {
|
||||
// TODO 支付中,线上提现打款
|
||||
throw new ServiceException("暂未开通线上提现打款");
|
||||
} else if (WithdrawStatus.REJECTED.getCode().equals(data.getStatus())) {
|
||||
// 驳回,恢复用户余额
|
||||
int add = userService.addBalance(
|
||||
withdraw.getUserId(),
|
||||
withdraw.getAmount(),
|
||||
BalanceLogBstType.WITHDRAW,
|
||||
withdraw.getId(),
|
||||
"提现驳回:" + withdraw.getNo()
|
||||
);
|
||||
ServiceUtil.assertion(add != 1, "恢复用户余额失败");
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
}
|
||||
|
||||
}
|
||||
//package com.ruoyi.bst.withdraw.service.impl;
|
||||
//
|
||||
//import com.ruoyi.bst.account.domain.AccountVO;
|
||||
//import com.ruoyi.bst.account.domain.enums.AccountType;
|
||||
//import com.ruoyi.bst.account.service.AccountService;
|
||||
//import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType;
|
||||
//import com.ruoyi.bst.withdraw.domain.Withdraw;
|
||||
//import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
|
||||
//import com.ruoyi.bst.withdraw.domain.WithdrawVO;
|
||||
//import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
|
||||
//import com.ruoyi.bst.withdraw.domain.enums.WithdrawStatus;
|
||||
//import com.ruoyi.bst.withdraw.domain.vo.WithdrawAmountVO;
|
||||
//import com.ruoyi.bst.withdraw.mapper.WithdrawMapper;
|
||||
//import com.ruoyi.bst.withdraw.service.WithdrawConverter;
|
||||
//import com.ruoyi.bst.withdraw.service.WithdrawService;
|
||||
//import com.ruoyi.common.core.domain.vo.UserVO;
|
||||
//import com.ruoyi.common.exception.ServiceException;
|
||||
//import com.ruoyi.common.utils.DateUtils;
|
||||
//import com.ruoyi.common.utils.MathUtils;
|
||||
//import com.ruoyi.common.utils.ServiceUtil;
|
||||
//import com.ruoyi.common.utils.SnowFlakeUtil;
|
||||
//import com.ruoyi.system.user.service.UserService;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.transaction.support.TransactionTemplate;
|
||||
//
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * 提现Service业务层处理
|
||||
// *
|
||||
// * @author ruoyi
|
||||
// * @date 2025-04-07
|
||||
// */
|
||||
//@Service
|
||||
//public class WithdrawServiceImpl implements WithdrawService
|
||||
//{
|
||||
// @Autowired
|
||||
// private WithdrawMapper withdrawMapper;
|
||||
//
|
||||
// @Autowired
|
||||
// private UserService userService;
|
||||
//
|
||||
// @Autowired
|
||||
// private WithdrawConverter withdrawConverter;
|
||||
//
|
||||
// @Autowired
|
||||
// private AccountService accountService;
|
||||
//
|
||||
// @Autowired
|
||||
// private TransactionTemplate transactionTemplate;
|
||||
//
|
||||
// /**
|
||||
// * 查询提现
|
||||
// *
|
||||
// * @param id 提现主键
|
||||
// * @return 提现
|
||||
// */
|
||||
// @Override
|
||||
// public WithdrawVO selectWithdrawById(Long id)
|
||||
// {
|
||||
// return withdrawMapper.selectWithdrawById(id);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 查询提现列表
|
||||
// *
|
||||
// * @param withdraw 提现
|
||||
// * @return 提现
|
||||
// */
|
||||
// @Override
|
||||
// public List<WithdrawVO> selectWithdrawList(WithdrawQuery withdraw)
|
||||
// {
|
||||
// return withdrawMapper.selectWithdrawList(withdraw);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 新增提现
|
||||
// *
|
||||
// * @param withdraw 提现
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int insertWithdraw(Withdraw withdraw) {
|
||||
// // 获取用户信息
|
||||
// UserVO user = userService.selectUserById(withdraw.getUserId());
|
||||
// ServiceUtil.assertion(user == null, "ID为%s的用户不存在", withdraw.getUserId());
|
||||
// // 获取账户信息
|
||||
// AccountVO account = accountService.selectAccountById(withdraw.getAccountId());
|
||||
// ServiceUtil.assertion(account == null, "ID为%s的收款账户不存在", withdraw.getAccountId());
|
||||
//
|
||||
// // 获取金额
|
||||
// WithdrawAmountVO amountVo = withdrawConverter.calcAmount(user, withdraw.getAmount());
|
||||
// ServiceUtil.assertion(amountVo == null, "计算金额出错");
|
||||
// // 校验金额
|
||||
// ServiceUtil.assertion(!MathUtils.equals(amountVo.getServiceCharge(), withdraw.getServiceCharge()), "服务费金额发生变化,请刷新后重试");
|
||||
// ServiceUtil.assertion(!MathUtils.equals(amountVo.getAmount(), withdraw.getArrivalAmount()), "到账金额发生变化,请刷新后重试");
|
||||
// ServiceUtil.assertion(MathUtils.smallerThan(withdraw.getAmount(), amountVo.getMinAmount()), "提现金额不允许小于最低金额:%s", amountVo.getMinAmount());
|
||||
// ServiceUtil.assertion(MathUtils.biggerThan(withdraw.getAmount(), amountVo.getMaxAmount()), "提现金额不允许大于最高金额:%s", amountVo.getMaxAmount());
|
||||
//
|
||||
// // 组装提现数据
|
||||
// Withdraw data = new Withdraw();
|
||||
// // 基础
|
||||
// data.setUserId(withdraw.getUserId());
|
||||
// data.setCreateTime(DateUtils.getNowDate());
|
||||
// data.setNo(String.valueOf(SnowFlakeUtil.newId()));
|
||||
// data.setStatus(WithdrawStatus.WAIT_VERIFY.getCode());
|
||||
// // 账户
|
||||
// data.setAccountId(withdraw.getAccountId());
|
||||
// data.setAccountType(account.getType());
|
||||
// data.setAccountNo(account.getNo());
|
||||
// data.setAccountName(account.getName());
|
||||
// data.setAccountMobile(account.getMobile());
|
||||
// data.setAccountIdCard(account.getIdCard());
|
||||
// data.setBankName(account.getBankName());
|
||||
// data.setBankCardName(account.getBankCardName());
|
||||
// data.setBankType(account.getBankType());
|
||||
// // 金额
|
||||
// data.setServiceType(amountVo.getType());
|
||||
// data.setServiceCharge(amountVo.getServiceCharge());
|
||||
// data.setServicePoint(amountVo.getPoint());
|
||||
// data.setAmount(withdraw.getAmount());
|
||||
// data.setArrivalAmount(amountVo.getAmount());
|
||||
// Integer result = transactionTemplate.execute(status -> {
|
||||
// int rows = withdrawMapper.insertWithdraw(data);
|
||||
//
|
||||
// if (rows > 0) {
|
||||
// // 扣减用户余额
|
||||
// int sub = userService.subtractBalance(data.getUserId(), data.getAmount(), BalanceLogBstType.WITHDRAW, data.getId(), "提现申请:" + data.getNo(), true);
|
||||
// ServiceUtil.assertion(sub != 1, "扣减用户余额失败,请检查余额是否充足");
|
||||
// }
|
||||
//
|
||||
// return rows;
|
||||
// });
|
||||
//
|
||||
// return result == null ? 0 : result;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改提现
|
||||
// *
|
||||
// * @param withdraw 提现
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int updateWithdraw(Withdraw withdraw)
|
||||
// {
|
||||
// return withdrawMapper.updateWithdraw(withdraw);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 批量删除提现
|
||||
// *
|
||||
// * @param ids 需要删除的提现主键
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int deleteWithdrawByIds(Long[] ids)
|
||||
// {
|
||||
// return withdrawMapper.deleteWithdrawByIds(ids);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除提现信息
|
||||
// *
|
||||
// * @param id 提现主键
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int deleteWithdrawById(Long id)
|
||||
// {
|
||||
// return withdrawMapper.deleteWithdrawById(id);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int verify(WithdrawVerifyDTO dto) {
|
||||
// WithdrawVO withdraw = selectWithdrawById(dto.getId());
|
||||
// ServiceUtil.assertion(withdraw == null, "待审核的提现不存在");
|
||||
// ServiceUtil.assertion(!WithdrawStatus.canVerify().contains(withdraw.getStatus()), "ID为%s的提现当前状态不允许审核", dto.getId());
|
||||
//
|
||||
// boolean pass = dto.getPass() != null && dto.getPass();
|
||||
//
|
||||
// Integer result = transactionTemplate.execute(status -> {
|
||||
// Withdraw data = new Withdraw();
|
||||
// if (pass) {
|
||||
// if (AccountType.offline().contains(withdraw.getAccountType())) {
|
||||
// data.setStatus(WithdrawStatus.SUCCESS.getCode());
|
||||
// } else {
|
||||
// data.setStatus(WithdrawStatus.PAYING.getCode());
|
||||
// }
|
||||
// } else {
|
||||
// data.setStatus(WithdrawStatus.REJECTED.getCode());
|
||||
// }
|
||||
// data.setVerifyUserId(dto.getVerifyId());
|
||||
// data.setVerifyTime(LocalDateTime.now());
|
||||
// data.setVerifyRemark(dto.getRemark());
|
||||
// WithdrawQuery query = new WithdrawQuery();
|
||||
// query.setId(dto.getId());
|
||||
// query.setStatusList(WithdrawStatus.canVerify());
|
||||
// int rows = withdrawMapper.updateByQuery(data, query);
|
||||
//
|
||||
// if (rows > 0 ) {
|
||||
// if (WithdrawStatus.PAYING.getCode().equals(data.getStatus())) {
|
||||
// // TODO 支付中,线上提现打款
|
||||
// throw new ServiceException("暂未开通线上提现打款");
|
||||
// } else if (WithdrawStatus.REJECTED.getCode().equals(data.getStatus())) {
|
||||
// // 驳回,恢复用户余额
|
||||
// int add = userService.addBalance(
|
||||
// withdraw.getUserId(),
|
||||
// withdraw.getAmount(),
|
||||
// BalanceLogBstType.WITHDRAW,
|
||||
// withdraw.getId(),
|
||||
// "提现驳回:" + withdraw.getNo()
|
||||
// );
|
||||
// ServiceUtil.assertion(add != 1, "恢复用户余额失败");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return rows;
|
||||
// });
|
||||
//
|
||||
// return result == null ? 0 : result;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
|||
import java.util.List;
|
||||
|
||||
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.vo.UserVO;
|
||||
import com.ruoyi.system.user.domain.UserQuery;
|
||||
|
@ -235,15 +236,15 @@ public interface UserService
|
|||
public UserVO selectByAppOpenId(Long appId, String openId);
|
||||
|
||||
/**
|
||||
* 增加余额
|
||||
* 增加爆灯次数
|
||||
* @param userId 用户ID
|
||||
* @param amount 金额
|
||||
* @param bstType 业务类型
|
||||
* @param bstId 业务ID
|
||||
* @param number 次数
|
||||
* @param reason 原因
|
||||
* @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);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 减少余额
|
||||
|
|
|
@ -12,6 +12,13 @@ import javax.validation.Validator;
|
|||
import com.ruoyi.bst.balanceLog.domain.BalanceLog;
|
||||
import com.ruoyi.bst.balanceLog.domain.enums.BalanceLogBstType;
|
||||
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.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -100,6 +107,10 @@ public class UserServiceImpl implements UserService
|
|||
|
||||
@Autowired
|
||||
private BalanceLogService balanceLogService;
|
||||
@Autowired
|
||||
private LightingNumMapper lightingNumMapper;
|
||||
@Autowired
|
||||
private ChangeRecordMapper changeRecordMapper;
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
|
@ -684,41 +695,57 @@ public class UserServiceImpl implements UserService
|
|||
}
|
||||
|
||||
@Override
|
||||
public int addBalance(Long userId, BigDecimal amount, BalanceLogBstType bstType, Long bstId, String reason) {
|
||||
if (userId == null || amount == null ) {
|
||||
public int addLightingNum(Long userId, Long storeId , Integer number, String reason) {
|
||||
if (userId == null || number == null ) {
|
||||
return 0;
|
||||
}
|
||||
// 如果金额为0,则不进行任何操作
|
||||
if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
// 如果次数为0,则不进行任何操作
|
||||
if (number == 0) {
|
||||
return 1;
|
||||
}
|
||||
// 如果金额为负数,则抛出异常
|
||||
ServiceUtil.assertion(amount.compareTo(BigDecimal.ZERO) < 0, "增加的金额不能为负数");
|
||||
ServiceUtil.assertion(number < 0, "增加的次数不能为负数");
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 查询用户余额,并锁定
|
||||
BigDecimal balance = userMapper.selectBalanceForUpdate(userId);
|
||||
if (balance == null) {
|
||||
balance = BigDecimal.ZERO;
|
||||
// 查询用户爆灯次数,并锁定
|
||||
Integer lightingNumber = lightingNumMapper.selectLightingNumberForUpdate(userId);
|
||||
if (lightingNumber == null) {
|
||||
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) {
|
||||
BalanceLog log = new BalanceLog();
|
||||
log.setUserId(userId);
|
||||
log.setAmount(amount);
|
||||
log.setBeforeBalance(balance);
|
||||
log.setAfterBalance(balance.add(amount));
|
||||
log.setBstType(bstType.getCode());
|
||||
log.setBstId(bstId);
|
||||
log.setReason(reason);
|
||||
int logInsert = balanceLogService.insertBalanceLog(log);
|
||||
ChangeRecord record = new ChangeRecord();
|
||||
record.setUserId(userId);
|
||||
record.setStoreId(userId);
|
||||
record.setNumber(lightingNumber);
|
||||
if (lightingNumber == 0){
|
||||
record.setBeforeNum(0);
|
||||
}else {
|
||||
record.setBeforeNum(lightingNumber-number);
|
||||
}
|
||||
record.setAfterNum(lightingNumber+number);
|
||||
record.setReason(reason);
|
||||
record.setCreateTime(DateUtils.getNowDate());
|
||||
int logInsert = changeRecordMapper.insertChangeRecord(record);
|
||||
ServiceUtil.assertion(logInsert != 1, "新增余额日志失败");
|
||||
}
|
||||
|
||||
return rows;
|
||||
});
|
||||
|
||||
|
|
|
@ -89,14 +89,14 @@ public class BonusController extends BaseController
|
|||
// return success(list);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 支付分成
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('bst:bonus:pay')")
|
||||
@PutMapping("/pay")
|
||||
@Log(title = "支付分成", businessType = BusinessType.OTHER)
|
||||
public AjaxResult pay(Long id) {
|
||||
return success(bonusService.payBonus(id));
|
||||
}
|
||||
// /**
|
||||
// * 支付分成
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('bst:bonus:pay')")
|
||||
// @PutMapping("/pay")
|
||||
// @Log(title = "支付分成", businessType = BusinessType.OTHER)
|
||||
// public AjaxResult pay(Long id) {
|
||||
// return success(bonusService.payBonus(id));
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -1,117 +1,117 @@
|
|||
package com.ruoyi.web.bst;
|
||||
|
||||
import com.ruoyi.bst.withdraw.domain.Withdraw;
|
||||
import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
|
||||
import com.ruoyi.bst.withdraw.domain.WithdrawVO;
|
||||
import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
|
||||
import com.ruoyi.bst.withdraw.service.WithdrawConverter;
|
||||
import com.ruoyi.bst.withdraw.service.WithdrawService;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.vo.UserVO;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.user.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提现Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-04-07
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/bst/withdraw")
|
||||
public class WithdrawController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private WithdrawService withdrawService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private WithdrawConverter withdrawConverter;
|
||||
|
||||
/**
|
||||
* 查询提现列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('bst:withdraw:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(WithdrawQuery query)
|
||||
{
|
||||
startPage();
|
||||
startOrderBy();
|
||||
query.setScope(true);
|
||||
List<WithdrawVO> list = withdrawService.selectWithdrawList(query);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出提现列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('bst:withdraw:export')")
|
||||
@Log(title = "提现", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, WithdrawQuery query)
|
||||
{
|
||||
query.setScope(true);
|
||||
List<WithdrawVO> list = withdrawService.selectWithdrawList(query);
|
||||
ExcelUtil<WithdrawVO> util = new ExcelUtil<WithdrawVO>(WithdrawVO.class);
|
||||
util.exportExcel(response, list, "提现数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提现详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('bst:withdraw:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(withdrawService.selectWithdrawById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请提现
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('bst:withdraw:add')")
|
||||
@Log(title = "申请提现", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody @Validated Withdraw withdraw) {
|
||||
// 若是不是系统管理员,则无权给他人提现
|
||||
if (!isSysAdmin() || withdraw.getUserId() == null) {
|
||||
withdraw.setUserId(getUserId());
|
||||
}
|
||||
return toAjax(withdrawService.insertWithdraw(withdraw));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('bst:withdraw:add')")
|
||||
@Log(title = "查询提现服务费", businessType = BusinessType.OTHER)
|
||||
@GetMapping("/calcAmount")
|
||||
public AjaxResult calcAmount(BigDecimal amount, @RequestParam(required = false) Long userId) {
|
||||
// 若是不是系统管理员,则无权查询他人的提现服务费
|
||||
if (!isSysAdmin() || userId == null) {
|
||||
userId = getUserId();
|
||||
}
|
||||
UserVO user = userService.selectUserById(userId);
|
||||
return success(withdrawConverter.calcAmount(user, amount));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('bst:withdraw:verify')")
|
||||
@Log(title = "提现审核", businessType = BusinessType.VERIFY)
|
||||
@PutMapping("/verify")
|
||||
public AjaxResult verify(@RequestBody @Validated WithdrawVerifyDTO dto) {
|
||||
dto.setVerifyId(getUserId());
|
||||
return toAjax(withdrawService.verify(dto));
|
||||
}
|
||||
|
||||
}
|
||||
//package com.ruoyi.web.bst;
|
||||
//
|
||||
//import com.ruoyi.bst.withdraw.domain.Withdraw;
|
||||
//import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
|
||||
//import com.ruoyi.bst.withdraw.domain.WithdrawVO;
|
||||
//import com.ruoyi.bst.withdraw.domain.dto.WithdrawVerifyDTO;
|
||||
//import com.ruoyi.bst.withdraw.service.WithdrawConverter;
|
||||
//import com.ruoyi.bst.withdraw.service.WithdrawService;
|
||||
//import com.ruoyi.common.annotation.Log;
|
||||
//import com.ruoyi.common.core.controller.BaseController;
|
||||
//import com.ruoyi.common.core.domain.AjaxResult;
|
||||
//import com.ruoyi.common.core.domain.vo.UserVO;
|
||||
//import com.ruoyi.common.core.page.TableDataInfo;
|
||||
//import com.ruoyi.common.enums.BusinessType;
|
||||
//import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
//import com.ruoyi.system.user.service.UserService;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.security.access.prepost.PreAuthorize;
|
||||
//import org.springframework.validation.annotation.Validated;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * 提现Controller
|
||||
// *
|
||||
// * @author ruoyi
|
||||
// * @date 2025-04-07
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("/bst/withdraw")
|
||||
//public class WithdrawController extends BaseController
|
||||
//{
|
||||
// @Autowired
|
||||
// private WithdrawService withdrawService;
|
||||
//
|
||||
// @Autowired
|
||||
// private UserService userService;
|
||||
//
|
||||
// @Autowired
|
||||
// private WithdrawConverter withdrawConverter;
|
||||
//
|
||||
// /**
|
||||
// * 查询提现列表
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('bst:withdraw:list')")
|
||||
// @GetMapping("/list")
|
||||
// public TableDataInfo list(WithdrawQuery query)
|
||||
// {
|
||||
// startPage();
|
||||
// startOrderBy();
|
||||
// query.setScope(true);
|
||||
// List<WithdrawVO> list = withdrawService.selectWithdrawList(query);
|
||||
// return getDataTable(list);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 导出提现列表
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('bst:withdraw:export')")
|
||||
// @Log(title = "提现", businessType = BusinessType.EXPORT)
|
||||
// @PostMapping("/export")
|
||||
// public void export(HttpServletResponse response, WithdrawQuery query)
|
||||
// {
|
||||
// query.setScope(true);
|
||||
// List<WithdrawVO> list = withdrawService.selectWithdrawList(query);
|
||||
// ExcelUtil<WithdrawVO> util = new ExcelUtil<WithdrawVO>(WithdrawVO.class);
|
||||
// util.exportExcel(response, list, "提现数据");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取提现详细信息
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('bst:withdraw:query')")
|
||||
// @GetMapping(value = "/{id}")
|
||||
// public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
// {
|
||||
// return success(withdrawService.selectWithdrawById(id));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 申请提现
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('bst:withdraw:add')")
|
||||
// @Log(title = "申请提现", businessType = BusinessType.INSERT)
|
||||
// @PostMapping
|
||||
// public AjaxResult add(@RequestBody @Validated Withdraw withdraw) {
|
||||
// // 若是不是系统管理员,则无权给他人提现
|
||||
// if (!isSysAdmin() || withdraw.getUserId() == null) {
|
||||
// withdraw.setUserId(getUserId());
|
||||
// }
|
||||
// return toAjax(withdrawService.insertWithdraw(withdraw));
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("@ss.hasPermi('bst:withdraw:add')")
|
||||
// @Log(title = "查询提现服务费", businessType = BusinessType.OTHER)
|
||||
// @GetMapping("/calcAmount")
|
||||
// public AjaxResult calcAmount(BigDecimal amount, @RequestParam(required = false) Long userId) {
|
||||
// // 若是不是系统管理员,则无权查询他人的提现服务费
|
||||
// if (!isSysAdmin() || userId == null) {
|
||||
// userId = getUserId();
|
||||
// }
|
||||
// UserVO user = userService.selectUserById(userId);
|
||||
// return success(withdrawConverter.calcAmount(user, amount));
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("@ss.hasPermi('bst:withdraw:verify')")
|
||||
// @Log(title = "提现审核", businessType = BusinessType.VERIFY)
|
||||
// @PutMapping("/verify")
|
||||
// public AjaxResult verify(@RequestBody @Validated WithdrawVerifyDTO dto) {
|
||||
// dto.setVerifyId(getUserId());
|
||||
// return toAjax(withdrawService.verify(dto));
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
Loading…
Reference in New Issue
Block a user