Merge remote-tracking branch 'origin/master' into dev

This commit is contained in:
墨大叔 2024-07-27 16:58:43 +08:00
commit 85402f8a7d
11 changed files with 179 additions and 57 deletions
smart-switch-service/src/main/java/com/ruoyi
smart-switch-web/src/main/java/com/ruoyi/web/controller/ss

View File

@ -11,4 +11,6 @@ public class DictTypeConstants {
public static final String TIME_UNIT = "time_unit"; public static final String TIME_UNIT = "time_unit";
// 设备服务费类型 // 设备服务费类型
public static final String SERVICE_TYPE = "service_type"; public static final String SERVICE_TYPE = "service_type";
// 提现打款方式
public static final String WITHDRAW_TYPE = "withdraw_type";
} }

View File

@ -187,6 +187,12 @@ public class TransactionBill extends BaseEntity implements Payable
@ApiModelProperty("服务费退款金额") @ApiModelProperty("服务费退款金额")
private BigDecimal refundServiceAmount; private BigDecimal refundServiceAmount;
@ApiModelProperty("支付凭证")
private String payPicture;
@ApiModelProperty("提现方式")
private String withdrawType;
/** /**
* 获取价格 * 获取价格
*/ */

View File

@ -0,0 +1,34 @@
package com.ruoyi.ss.transactionBill.domain.dto;
import com.ruoyi.common.constants.DictTypeConstants;
import com.ruoyi.system.valid.DictValid;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 提现审核DTO
* @author wjh
* 2024/7/27
*/
@Data
public class WithdrawApprovalDTO {
@ApiModelProperty("订单ID")
@NotNull(message = "订单ID不能为空")
private Long billId;
@ApiModelProperty("审核意见")
private String remark;
@ApiModelProperty("打款方式")
@NotBlank(message = "打款方式不能为空")
@DictValid(type = DictTypeConstants.WITHDRAW_TYPE, message = "非法的打款方式")
private String withdrawType;
@ApiModelProperty("支付凭证")
private String payPicture;
}

View File

@ -18,7 +18,9 @@ public enum TransactionBillPayType {
WECHAT(1L, "微信支付", AccountType.WECHAT), WECHAT(1L, "微信支付", AccountType.WECHAT),
ALI(2L, "支付宝", AccountType.ALIPAY), ALI(2L, "支付宝", AccountType.ALIPAY),
BANK(3L, "银行卡", AccountType.BANK_CARD); BANK(3L, "银行卡", AccountType.BANK_CARD),
BALANCE(4L, "余额支付", null)
;
private final Long type; private final Long type;
private final String name; private final String name;

View File

@ -0,0 +1,20 @@
package com.ruoyi.ss.transactionBill.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author wjh
* 2024/7/27
*/
@Getter
@AllArgsConstructor
public enum WithdrawType {
ONLINE("1", "线上提现"),
OFFLINE("2", "线下提现");
private final String type;
private final String msg;
}

View File

@ -118,7 +118,7 @@ public interface TransactionBillMapper
* 提现成功 * 提现成功
* @param billId id * @param billId id
*/ */
int withdrawSuccess(Long billId); int withdrawSuccess(@Param("billId") Long billId, @Param("payTime")LocalDateTime payTime);
/** /**
* 提现失败 * 提现失败

View File

@ -46,6 +46,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
stb.refund_amount, stb.refund_amount,
stb.refund_mch_amount, stb.refund_mch_amount,
stb.refund_service_amount, stb.refund_service_amount,
stb.pay_picture,
stb.withdraw_type,
su.user_name as user_name, su.user_name as user_name,
su1.user_name as mch_name, su1.user_name as mch_name,
su1.phonenumber as mch_mobile su1.phonenumber as mch_mobile
@ -233,6 +235,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="refundAmount != null">refund_amount,</if> <if test="refundAmount != null">refund_amount,</if>
<if test="refundMchAmount != null">refund_mch_amount,</if> <if test="refundMchAmount != null">refund_mch_amount,</if>
<if test="refundServiceAmount != null">refund_service_amount,</if> <if test="refundServiceAmount != null">refund_service_amount,</if>
<if test="payPicture != null">pay_picture,</if>
<if test="withdrawType != null">withdraw_type,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="billNo != null">#{billNo},</if> <if test="billNo != null">#{billNo},</if>
@ -271,6 +275,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="refundAmount != null">#{refundAmount},</if> <if test="refundAmount != null">#{refundAmount},</if>
<if test="refundMchAmount != null">#{refundMchAmount},</if> <if test="refundMchAmount != null">#{refundMchAmount},</if>
<if test="refundServiceAmount != null">#{refundServiceAmount},</if> <if test="refundServiceAmount != null">#{refundServiceAmount},</if>
<if test="payPicture != null">#{payPicture},</if>
<if test="withdrawType != null">#{withdrawType},</if>
</trim> </trim>
</insert> </insert>
@ -326,6 +332,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="data.refundAmount != null">refund_amount = #{data.refundAmount},</if> <if test="data.refundAmount != null">refund_amount = #{data.refundAmount},</if>
<if test="data.refundMchAmount != null">refund_mch_amount = #{data.refundMchAmount},</if> <if test="data.refundMchAmount != null">refund_mch_amount = #{data.refundMchAmount},</if>
<if test="data.refundServiceAmount != null">refund_service_amount = #{data.refundServiceAmount},</if> <if test="data.refundServiceAmount != null">refund_service_amount = #{data.refundServiceAmount},</if>
<if test="data.payPicture != null">pay_picture = #{data.payPicture},</if>
<if test="data.withdrawType != null">withdraw_type = #{data.withdrawType},</if>
</sql> </sql>
<update id="updateByQuery"> <update id="updateByQuery">
@ -397,7 +405,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="withdrawSuccess"> <update id="withdrawSuccess">
update sm_transaction_bill update sm_transaction_bill
set status = '14' set status = '14',
pay_time = #{payTime}
where bill_id = #{billId} and status = '16' where bill_id = #{billId} and status = '16'
</update> </update>

View File

@ -6,9 +6,11 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.TransactionBillVo; import com.ruoyi.ss.transactionBill.domain.TransactionBillVo;
import com.ruoyi.ss.transactionBill.domain.bo.TransactionBillBO; import com.ruoyi.ss.transactionBill.domain.bo.TransactionBillBO;
import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO;
import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -125,17 +127,17 @@ public interface TransactionBillService
/** /**
* 提现审核通过 * 提现审核通过
* @param billId id *
* @param remark 审核意见 * @param dto id
*/ */
boolean passWithdraw(Long billId, String remark); boolean passWithdraw(WithdrawApprovalDTO dto);
/** /**
* 提现审核拒绝 * 提现审核拒绝
* @param billId id *
* @param remark 审核意见 * @param dto id
*/ */
boolean rejectWithdraw(Long billId, String remark); boolean rejectWithdraw(WithdrawApprovalDTO dto);
/** /**
* 提现打款 * 提现打款
@ -145,9 +147,11 @@ public interface TransactionBillService
/** /**
* 提现成功 * 提现成功
* @param billId id *
* @param billId id
* @param payTime
*/ */
void withdrawSuccess(Long billId); void withdrawSuccess(Long billId, LocalDateTime payTime);
/** /**
* 提现失败 * 提现失败

View File

@ -29,6 +29,7 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.TransactionBillVo; import com.ruoyi.ss.transactionBill.domain.TransactionBillVo;
import com.ruoyi.ss.transactionBill.domain.bo.TransactionBillBO; import com.ruoyi.ss.transactionBill.domain.bo.TransactionBillBO;
import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO;
import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO;
import com.ruoyi.ss.transactionBill.domain.enums.*; import com.ruoyi.ss.transactionBill.domain.enums.*;
import com.ruoyi.ss.transactionBill.mapper.TransactionBillMapper; import com.ruoyi.ss.transactionBill.mapper.TransactionBillMapper;
import com.ruoyi.ss.transactionBill.service.TransactionBillService; import com.ruoyi.ss.transactionBill.service.TransactionBillService;
@ -437,6 +438,7 @@ public class TransactionBillServiceImpl implements TransactionBillService {
bill.setAfterBalance(afterUser.getBalance()); bill.setAfterBalance(afterUser.getBalance());
bill.setAccountNo(accountNo); bill.setAccountNo(accountNo);
bill.setChannelId(data.getChannelId()); bill.setChannelId(data.getChannelId());
bill.setWithdrawType(WithdrawType.ONLINE.getType());
ServiceUtil.assertion(this.insertSmTransactionBill(bill) != 1, "提现申请失败"); ServiceUtil.assertion(this.insertSmTransactionBill(bill) != 1, "提现申请失败");
return bill.getBillNo(); return bill.getBillNo();
@ -448,41 +450,65 @@ public class TransactionBillServiceImpl implements TransactionBillService {
/** /**
* 提现审核通过 * 提现审核通过
* @param billId id *
* @param remark 审核意见 * @param dto id
*/ */
@Override @Override
@Transactional public boolean passWithdraw(WithdrawApprovalDTO dto) {
public boolean passWithdraw(Long billId, String remark) { ServiceUtil.assertion(dto.getBillId() == null, "提现申请ID不允许为空");
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.APPROVAL_WITHDRAW, dto.getBillId()), "该提现申请正在审核,请刷新后重试");
try { try {
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.APPROVAL_WITHDRAW, billId.toString()), "该提现申请正在审核,请刷新后重试"); transactionTemplate.execute(status -> {
int updateCount = this.approvalWithdraw(dto, TransactionBillStatus.WITHDRAW_PASSED);
ServiceUtil.assertion(updateCount != 1, "提现审核失败,请刷新后重试");
return updateCount;
});
int updateCount = transactionBillMapper.doPassWithdraw(billId, remark); this.payWithdraw(dto.getBillId());
ServiceUtil.assertion(updateCount != 1, "提现审核失败,请刷新后重试");
return true; return true;
} finally { } finally {
redisLock.unlock(RedisLockKey.APPROVAL_WITHDRAW, billId.toString()); redisLock.unlock(RedisLockKey.APPROVAL_WITHDRAW, dto.toString());
} }
} }
/**
* 审核操作
*/
private int approvalWithdraw(WithdrawApprovalDTO dto, TransactionBillStatus status) {
TransactionBill data = new TransactionBill();
data.setStatus(status.getStatus());
data.setRemark(dto.getRemark());
data.setPayPicture(dto.getPayPicture());
data.setWithdrawType(dto.getWithdrawType());
TransactionBillQuery query = new TransactionBillQuery();
query.setBillId(dto.getBillId());
query.setType(TransactionBillType.WITHDRAW.getType());
query.setStatus(TransactionBillStatus.WITHDRAW_APPROVING.getStatus());
return this.updateByQuery(data, query);
}
@Override @Override
@Transactional public boolean rejectWithdraw(WithdrawApprovalDTO dto) {
public boolean rejectWithdraw(Long billId, String remark) { ServiceUtil.assertion(dto.getBillId() == null, "提现申请ID不允许为空");
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.APPROVAL_WITHDRAW, dto.getBillId()), "该提现申请正在审核,请刷新后重试");
try { try {
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.APPROVAL_WITHDRAW, billId.toString()), "该提现申请正在审核,请刷新后重试"); transactionTemplate.execute(status -> {
// 审核
int updateCount = this.approvalWithdraw(dto, TransactionBillStatus.WITHDRAW_REJECTED);
ServiceUtil.assertion(updateCount != 1, "提现审核失败,请刷新后重试");
int updateCount = transactionBillMapper.doRejectWithdraw(billId, remark); // 返还客户余额
ServiceUtil.assertion(updateCount != 1, "提现审核失败,请刷新后重试"); TransactionBill bill = transactionBillMapper.selectSmTransactionBillByBillId(dto.getBillId());
ServiceUtil.assertion(bill == null || bill.getUserId() == null, "数据不存在");
userService.addBalance(bill.getUserId(), bill.getMoney(), "提现驳回");
// 返还客户余额 return updateCount;
TransactionBill bill = transactionBillMapper.selectSmTransactionBillByBillId(billId); });
ServiceUtil.assertion(bill == null || bill.getUserId() == null, "数据不存在");
userService.addBalance(bill.getUserId(), bill.getMoney(), "提现驳回");
return true; return true;
} finally { } finally {
redisLock.unlock(RedisLockKey.APPROVAL_WITHDRAW, billId.toString()); redisLock.unlock(RedisLockKey.APPROVAL_WITHDRAW, dto.toString());
} }
} }
@ -491,39 +517,59 @@ public class TransactionBillServiceImpl implements TransactionBillService {
* @param billId 提现单id * @param billId 提现单id
*/ */
@Override @Override
@Transactional
public boolean payWithdraw(Long billId) { public boolean payWithdraw(Long billId) {
ServiceUtil.assertion(billId == null, "参数错误提现打款id不允许为空"); ServiceUtil.assertion(billId == null, "参数错误提现打款id不允许为空");
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.PAY_WITHDRAW, billId), "该提现申请正在打款,请刷新后重试");
try { try {
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.PAY_WITHDRAW, billId.toString()), "该提现申请正在打款,请刷新后重试"); TransactionBillVo bill = transactionBillMapper.selectSmTransactionBillByBillId(billId);
TransactionBill bill = transactionBillMapper.selectSmTransactionBillByBillId(billId);
ServiceUtil.assertion(bill == null, "单据不存在"); ServiceUtil.assertion(bill == null, "单据不存在");
// 更新为打款中 transactionTemplate.execute(status -> {
int updateCount = transactionBillMapper.doPayWithdraw(billId); // 更新为打款中
ServiceUtil.assertion(updateCount != 1, "单据状态发生变化,请刷新后重试"); int updateCount = transactionBillMapper.doPayWithdraw(billId);
ServiceUtil.assertion(updateCount != 1, "单据状态发生变化,请刷新后重试");
// 发起打款 // 发起打款线上
if (TransactionBillPayType.WECHAT.getType().equals(bill.getChannelId())) { if (WithdrawType.ONLINE.getType().equals(bill.getWithdrawType())) {
InitiateBatchTransferResponse res = wxPayService.payWithdraw(billId); // 微信
log.debug(String.valueOf(res)); if (TransactionBillPayType.WECHAT.getType().equals(bill.getChannelId())) {
} else { InitiateBatchTransferResponse res = wxPayService.payWithdraw(billId);
throw new ServiceException("其他打款方式正在开发中"); log.debug(String.valueOf(res));
} } else {
throw new ServiceException("其他打款渠道正在开发中");
}
}
// 线下
else if(WithdrawType.OFFLINE.getType().equals(bill.getWithdrawType())) {
this.payWithdrawByOffline(bill);
} else {
throw new ServiceException("不支持的打款方式");
}
return updateCount;
});
return true; return true;
} finally { } finally {
redisLock.unlock(RedisLockKey.PAY_WITHDRAW, billId.toString()); redisLock.unlock(RedisLockKey.PAY_WITHDRAW, billId);
} }
} }
/**
* 线下打款
*/
private void payWithdrawByOffline(TransactionBillVo bill) {
this.withdrawSuccess(bill.getBillId(), LocalDateTime.now());
}
@Override @Override
@Transactional public void withdrawSuccess(Long billId, LocalDateTime payTime) {
public void withdrawSuccess(Long billId) { transactionTemplate.execute(status -> {
// 修改状态 // 修改状态
int updateCount = transactionBillMapper.withdrawSuccess(billId); int updateCount = transactionBillMapper.withdrawSuccess(billId, payTime);
ServiceUtil.assertion(updateCount != 1, "单据状态发生变化,请刷新后重试"); ServiceUtil.assertion(updateCount != 1, "单据状态发生变化,请刷新后重试");
return updateCount;
});
} }
@Override @Override

View File

@ -45,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -273,7 +274,7 @@ public class WxPayService implements IWxPayService {
// 修改订单状态 // 修改订单状态
if (TransferBatchStatus.FINISHED.getStatus().equals(transferBatchGet.getBatchStatus())) { if (TransferBatchStatus.FINISHED.getStatus().equals(transferBatchGet.getBatchStatus())) {
// 提现成功 // 提现成功
transactionBillService.withdrawSuccess(bill.getBillId()); transactionBillService.withdrawSuccess(bill.getBillId(), LocalDateTime.now());
} else if (TransferBatchStatus.CLOSED.getStatus().equals(transferBatchGet.getBatchStatus())) { } else if (TransferBatchStatus.CLOSED.getStatus().equals(transferBatchGet.getBatchStatus())) {
// 提现失败 // 提现失败
transactionBillService.withdrawFailed(bill.getBillId()); transactionBillService.withdrawFailed(bill.getBillId());

View File

@ -1,15 +1,13 @@
package com.ruoyi.web.controller.ss; package com.ruoyi.web.controller.ss;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.ss.transactionBill.domain.bo.TransactionBillBO;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.TransactionBillVo; import com.ruoyi.ss.transactionBill.domain.TransactionBillVo;
import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO;
import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@ -124,18 +122,18 @@ public class SmTransactionBillController extends BaseController
@PreAuthorize("@ss.hasPermi('system:bill:approval')") @PreAuthorize("@ss.hasPermi('system:bill:approval')")
@PutMapping("/withdraw/pass") @PutMapping("/withdraw/pass")
@Log(title = "同意提现申请", businessType = BusinessType.UPDATE) @Log(title = "同意提现申请", businessType = BusinessType.UPDATE)
public AjaxResult passWithdraw(@RequestBody TransactionBillBO bo) public AjaxResult passWithdraw(@RequestBody @Validated WithdrawApprovalDTO dto)
{ {
return success(smTransactionBillService.passWithdraw(bo.getBillId(), bo.getRemark())); return success(smTransactionBillService.passWithdraw(dto));
} }
@ApiOperation("拒绝提现申请") @ApiOperation("拒绝提现申请")
@PreAuthorize("@ss.hasPermi('system:bill:approval')") @PreAuthorize("@ss.hasPermi('system:bill:approval')")
@PutMapping("/withdraw/reject") @PutMapping("/withdraw/reject")
@Log(title = "拒绝提现申请", businessType = BusinessType.UPDATE) @Log(title = "拒绝提现申请", businessType = BusinessType.UPDATE)
public AjaxResult rejectWithdraw(@RequestBody TransactionBillBO bo) public AjaxResult rejectWithdraw(@RequestBody @Validated WithdrawApprovalDTO dto)
{ {
return success(smTransactionBillService.rejectWithdraw(bo.getBillId(), bo.getRemark())); return success(smTransactionBillService.rejectWithdraw(dto));
} }
@ApiOperation("提现打款") @ApiOperation("提现打款")