更新分成逻辑

This commit is contained in:
磷叶 2025-04-24 09:09:53 +08:00
parent 06adee38b8
commit cbbaf0a2e7
6 changed files with 54 additions and 5 deletions

View File

@ -149,4 +149,11 @@ public interface BonusMapper
* @return
*/
BigDecimal selectSumOfWaitAmount(@Param("query") BonusQuery query);
/**
* 根据业务类型和业务ID将分成更新为待分成状态
* @param bstType 业务类型
* @param bstId 业务ID
*/
int validByBst(@Param("bstType") String bstType, @Param("bstId") Long bstId);
}

View File

@ -256,12 +256,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<!-- validByBst -->
<update id="validByBst">
update bst_bonus bb
set bb.status = 'WAIT_DIVIDE',
bb.wait_amount = bb.wait_amount + bb.invalid_amount,
bb.invalid_amount = 0
where bb.bst_type = #{bstType}
and bb.bst_id = #{bstId}
and bb.status = 'INVALID'
and <include refid="checkAmount"/>
</update>
<update id="prepay">
update bst_bonus bb
<trim prefix="SET" suffixOverrides=",">
bb.wait_amount = bb.wait_amount + bb.invalid_amount,
bb.invalid_amount = 0,
bb.status = 'WAIT_DIVIDE',
<foreach open="bb.pre_pay_time = CASE id" collection="list" item="item" close="END,">
<choose>
<when test="item.prePayTime != null">
@ -278,7 +288,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.id}
</foreach>
and <include refid="checkAmount"/>
and bb.status = 'INVALID'
and bb.status = 'WAIT_DIVIDE'
</update>
<update id="pay">

View File

@ -83,6 +83,14 @@ public interface BonusService
*/
public int batchInsert(List<? extends Bonus> list);
/**
* 根据业务类型和业务ID将分成更新为待分成状态
* @param bstType 业务类型
* @param bstId 业务ID
*/
public boolean validByBst(BonusBstType bstType, Long bstId);
/**
* 预分成
* @param bstType 业务类型

View File

@ -178,6 +178,15 @@ public class BonusServiceImpl implements BonusService
return bonusMapper.batchInsert(list);
}
@Override
public boolean validByBst(BonusBstType bstType, Long bstId) {
if (bstType == null || bstId == null) {
return false;
}
bonusMapper.validByBst(bstType.getType(), bstId);
return true;
}
@Override
public boolean prepayByBst(BonusBstType bstType, Long bstId) {
if (bstType == null || bstId == null) {

View File

@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
import com.ruoyi.bst.bonus.domain.enums.BonusBstType;
import com.ruoyi.bst.bonus.service.BonusService;
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
import com.ruoyi.bst.device.domain.vo.DeviceIotVO;
import com.ruoyi.bst.device.service.DeviceIotService;
@ -41,6 +43,9 @@ public class OrderPayHandlerImpl implements PayHandler {
@Autowired
private DeviceIotService deviceIotService;
@Autowired
private BonusService bonusService;
// 支付成功后操作
@Override
public boolean onPaySuccess(PayVO pay) {
@ -71,10 +76,15 @@ public class OrderPayHandlerImpl implements PayHandler {
int rows = orderMapper.updateByQuery(data, query);
ServiceUtil.assertion(rows != 1, "更新ID为%s的订单失败", order.getId());
// 分成更新为待分成状态
boolean valid = bonusService.validByBst(BonusBstType.ORDER, order.getId());
ServiceUtil.assertion(!valid, "更新ID为%s的订单分成失败", order.getId());
// 开始使用订单设备
int start = orderDeviceService.start(orderDevice);
ServiceUtil.assertion(start != 1, "开始使用ID为%s的订单设备失败", orderDevice.getId());
// 解锁设备
DeviceIotVO unlock = deviceIotService.unlock(orderDevice.getDeviceId(), DeviceUnLockType.USER, "订单支付成功开锁:" + order.getNo(), false);
ServiceUtil.assertion(unlock.getDb() <= 0, "ID为%s的设备解锁失败", orderDevice.getDeviceId());

View File

@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.aliyun.core.utils.StringUtils;
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.OrderVO;
@ -130,8 +131,12 @@ public class OrderController extends BaseController
if (!orderValidator.canOperate(dto.getOrderId())) {
return error("您无权退款ID为" + dto.getOrderId() + "的订单");
}
String userName = getNickName();
dto.setUserId(getUserId());
dto.setUserName(getNickName());
dto.setUserName(userName);
if (StringUtils.isBlank(dto.getReason())) {
dto.setReason("管理员【" + userName + "】退款");
}
return toAjax(orderService.refund(dto));
}