临时提交
This commit is contained in:
parent
08c4ddecdc
commit
612abfc322
|
@ -9,7 +9,7 @@ public class TmTradeInfo {
|
|||
/**
|
||||
* 太米系统流水Id
|
||||
*/
|
||||
private Integer id;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 第三方内部流水号
|
||||
|
|
|
@ -9,7 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="checkAmount">
|
||||
bb.invalid_amount + bb.wait_amount + bb.payed_amount + bb.refund_amount = bb.amount
|
||||
bb.wait_amount + bb.payed_amount + bb.refund_amount = bb.amount
|
||||
</sql>
|
||||
|
||||
<sql id="selectBonusVo">
|
||||
|
@ -277,7 +277,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and bb.status = 'INVALID'
|
||||
and <include refid="checkAmount"/>
|
||||
</update>
|
||||
|
||||
|
||||
<update id="prepay">
|
||||
update bst_bonus bb
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
|
@ -301,9 +301,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
bb.status = 'WAIT_DIVIDE',
|
||||
bb.wait_amount = bb.wait_amount + bb.invalid_amount,
|
||||
bb.invalid_amount = 0
|
||||
<foreach open="bb.wait_amount = CASE id" collection="list" item="item" close="END,">
|
||||
<choose>
|
||||
<when test="item.waitAmount != null">
|
||||
WHEN #{item.id} THEN #{item.waitAmount}
|
||||
</when>
|
||||
<otherwise>
|
||||
WHEN #{item.id} THEN bb.wait_amount
|
||||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
<foreach open="bb.amount = CASE id" collection="list" item="item" close="END,">
|
||||
<choose>
|
||||
<when test="item.amount != null">
|
||||
WHEN #{item.id} THEN #{item.amount}
|
||||
</when>
|
||||
<otherwise>
|
||||
WHEN #{item.id} THEN bb.amount
|
||||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
bb.status = 'WAIT_DIVIDE'
|
||||
</trim>
|
||||
where bb.id in
|
||||
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||
|
|
|
@ -95,9 +95,11 @@ public interface BonusService {
|
|||
*
|
||||
* @param bstType 业务类型
|
||||
* @param bstId 业务ID
|
||||
* @param totalAmount 总金额
|
||||
* @param waitTime 待分成的时间
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean prepayByBst(BonusBstType bstType, Long bstId, LocalDateTime waitTime);
|
||||
public boolean prepayByBst(BonusBstType bstType, Long bstId, BigDecimal totalAmount, LocalDateTime waitTime);
|
||||
|
||||
/**
|
||||
* 分成打款
|
||||
|
|
|
@ -79,7 +79,6 @@ public class BonusConverterImpl implements BonusConverter {
|
|||
bonus.setBstType(BonusBstType.ORDER.getType());
|
||||
bonus.setBstId(order.getId());
|
||||
bonus.setStatus(BonusStatus.INVALID.getStatus());
|
||||
bonus.setInvalidAmount(bonus.getAmount());
|
||||
bonus.setToBalance(true);
|
||||
bonus.setAreaId(order.getAreaId());
|
||||
if (channel != null) {
|
||||
|
|
|
@ -182,7 +182,7 @@ public class BonusServiceImpl implements BonusService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean prepayByBst(BonusBstType bstType, Long bstId, LocalDateTime waitTime) {
|
||||
public boolean prepayByBst(BonusBstType bstType, Long bstId, BigDecimal totalAmount, LocalDateTime waitTime) {
|
||||
if (bstType == null || bstId == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -192,16 +192,19 @@ public class BonusServiceImpl implements BonusService {
|
|||
query.setBstType(bstType.getType());
|
||||
query.setBstId(bstId);
|
||||
List<BonusVO> list = this.selectBonusList(query);
|
||||
int rows = prepay(list, waitTime);
|
||||
int rows = prepay(list, totalAmount, waitTime);
|
||||
return rows == list.size();
|
||||
}
|
||||
|
||||
// 预分成
|
||||
private int prepay(List<BonusVO> list, LocalDateTime waitTime) {
|
||||
private int prepay(List<BonusVO> list, BigDecimal totalAmount, LocalDateTime waitTime) {
|
||||
if (CollectionUtils.isEmptyElement(list)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 计算分成金额
|
||||
BonusUtil.partAmount(list, totalAmount);
|
||||
|
||||
// 获取用户列表
|
||||
List<UserVO> userList = userService.selectByIds(list.stream()
|
||||
.filter(item -> BonusArrivalType.userList().contains(item.getArrivalType()))
|
||||
|
@ -210,6 +213,7 @@ public class BonusServiceImpl implements BonusService {
|
|||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
for (BonusVO bonus : list) {
|
||||
bonus.setWaitAmount(bonus.getAmount());
|
||||
bonus.setWaitTime(waitTime);
|
||||
// 设置预计分成时间
|
||||
if (BonusArrivalType.userList().contains(bonus.getArrivalType())) {
|
||||
|
|
|
@ -134,6 +134,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="query.locationType != null and query.locationType != ''">and bd.location_type = #{query.locationType}</if>
|
||||
<if test="query.orderDeviceId != null">and bd.order_device_id = #{query.orderDeviceId}</if>
|
||||
<if test="query.modelEnableSeat != null">and bm.enable_seat = #{query.modelEnableSeat}</if>
|
||||
<if test="query.softwareVersion != null">and bd.software_version like concat('%', #{query.softwareVersion}, '%')</if>
|
||||
<if test="query.keyword != null and query.keyword != ''">
|
||||
and (
|
||||
bd.sn like concat('%', #{query.keyword}, '%')
|
||||
|
|
|
@ -54,28 +54,28 @@ public class Order extends BaseEntity {
|
|||
@ApiModelProperty("支付金额")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
@Excel(name = "订单总金额")
|
||||
@ApiModelProperty("订单总金额")
|
||||
@Excel(name = "应收总金额")
|
||||
@ApiModelProperty("应收总金额")
|
||||
private BigDecimal totalFee;
|
||||
|
||||
@Excel(name = "押金")
|
||||
@ApiModelProperty("押金")
|
||||
private BigDecimal depositFee;
|
||||
|
||||
@Excel(name = "调度费")
|
||||
@ApiModelProperty("调度费(停车点外)")
|
||||
@Excel(name = "应收调度费")
|
||||
@ApiModelProperty("应收调度费(停车点外)")
|
||||
private BigDecimal dispatchFee;
|
||||
|
||||
@Excel(name = "管理费")
|
||||
@ApiModelProperty("管理费(运营区外)")
|
||||
@Excel(name = "应收管理费")
|
||||
@ApiModelProperty("应收管理费(运营区外)")
|
||||
private BigDecimal manageFee;
|
||||
|
||||
@Excel(name = "骑行费")
|
||||
@ApiModelProperty("骑行费")
|
||||
@Excel(name = "应收骑行费")
|
||||
@ApiModelProperty("应收骑行费")
|
||||
private BigDecimal ridingFee;
|
||||
|
||||
@Excel(name = "车损费")
|
||||
@ApiModelProperty("车损费")
|
||||
@Excel(name = "应收车损费")
|
||||
@ApiModelProperty("应收车损费")
|
||||
private BigDecimal deductionFee;
|
||||
|
||||
@Excel(name = "备注")
|
||||
|
@ -190,6 +190,9 @@ public class Order extends BaseEntity {
|
|||
@ApiModelProperty("审核备注")
|
||||
private String verifyRemark;
|
||||
|
||||
@ApiModelProperty("实收金额")
|
||||
private BigDecimal actualAmount;
|
||||
|
||||
@Excel(name = "实收骑行费")
|
||||
@ApiModelProperty("实收骑行费")
|
||||
private BigDecimal actualRidingFee;
|
||||
|
|
|
@ -71,10 +71,6 @@ public class OrderVO extends Order implements IotDevice {
|
|||
@ApiModelProperty("管理员退款金额")
|
||||
private BigDecimal payAdminRefund;
|
||||
|
||||
// 实收金额 = 最小值(支付金额,结算金额) - 退款金额 - 退款中金额
|
||||
@ApiModelProperty("实收金额")
|
||||
private BigDecimal actualAmount;
|
||||
|
||||
// 剩余可抵扣押金
|
||||
@ApiModelProperty("剩余可抵扣押金")
|
||||
private BigDecimal depositDeductRemain;
|
||||
|
|
|
@ -60,12 +60,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
bo.actual_dispatch_fee,
|
||||
bo.actual_manage_fee,
|
||||
bo.actual_deduction_fee,
|
||||
bo.actual_amount,
|
||||
bo.suit_deposit_deduction,
|
||||
bo.version,
|
||||
bo.pay_type,
|
||||
bo.deposit_deduction_amount,
|
||||
bo.ride_pay_id,
|
||||
<include refid="actualAmount"/> as actual_amount,
|
||||
<include refid="depositCanDeductRemain"/> as deposit_deduct_remain,
|
||||
ba.name as area_name,
|
||||
su.nick_name as user_name,
|
||||
|
@ -264,6 +264,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="payType != null and payType != ''">pay_type,</if>
|
||||
<if test="depositDeductionAmount != null">deposit_deduction_amount,</if>
|
||||
<if test="ridePayId != null">ride_pay_id,</if>
|
||||
<if test="actualAmount != null">actual_amount,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="no != null and no != ''">#{no},</if>
|
||||
|
@ -315,6 +316,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="payType != null and payType != ''">#{payType},</if>
|
||||
<if test="depositDeductionAmount != null">#{depositDeductionAmount},</if>
|
||||
<if test="ridePayId != null">#{ridePayId},</if>
|
||||
<if test="actualAmount != null">#{actualAmount},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -376,6 +378,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="data.payType != null and data.payType != ''">pay_type = #{data.payType},</if>
|
||||
<if test="data.depositDeductionAmount != null">deposit_deduction_amount = #{data.depositDeductionAmount},</if>
|
||||
<if test="data.ridePayId != null">ride_pay_id = #{data.ridePayId},</if>
|
||||
<if test="data.actualAmount != null">actual_amount = #{data.actualAmount},</if>
|
||||
</sql>
|
||||
|
||||
<delete id="deleteOrderById" parameterType="Long">
|
||||
|
@ -484,7 +487,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select
|
||||
bo.area_id,
|
||||
ba.name as area_name,
|
||||
sum(if(bo.status = 'PROCESSING', 0, <include refid="actualAmount"/>)) as actual_amount,
|
||||
sum(bo.actual_amount) as actual_amount,
|
||||
count(bo.id) as `count`,
|
||||
sum(if(bo.status = 'PROCESSING', 1, 0)) as processing_count
|
||||
from <include refid="searchTables"/>
|
||||
|
|
|
@ -6,7 +6,6 @@ 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;
|
||||
|
@ -85,10 +84,6 @@ 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());
|
||||
|
|
|
@ -255,7 +255,6 @@ public class OrderServiceImpl implements OrderService {
|
|||
ServiceUtil.assertion(dto == null || dto.getDeviceId() == null, "参数错误");
|
||||
|
||||
// 加锁,防止设备重复下单
|
||||
// TODO 可以考虑加锁60秒,存储车辆、用户ID,60秒内只允许同一个用户下单。
|
||||
Long lockKey = dto.getDeviceId();
|
||||
boolean lock = redisLock.lock(RedisLockKey.ORDER_CREATE, lockKey);
|
||||
ServiceUtil.assertion(!lock, "当前车辆使用的人太多了,请稍后再试");
|
||||
|
@ -457,6 +456,11 @@ public class OrderServiceImpl implements OrderService {
|
|||
int finish = orderDeviceService.finish(orderDevice, dto.getPicture(), inParkingVO);
|
||||
ServiceUtil.assertion(finish != 1, "结束ID为%s的订单设备失败", orderDevice.getId());
|
||||
|
||||
// 自动押金抵扣
|
||||
if (order.getSuitDepositDeduction() != null && order.getSuitDepositDeduction()) {
|
||||
this.autoDeduct(order);
|
||||
}
|
||||
|
||||
// 设备上锁(必须放最后,因为会操作设备)
|
||||
DeviceIotVO lock = deviceIotService.lock(orderDevice.getDeviceId(), isAdmin,
|
||||
"订单结束上锁:" + orderDevice.getOrderNo(), dto.getRequiredIot());
|
||||
|
@ -466,10 +470,6 @@ public class OrderServiceImpl implements OrderService {
|
|||
return rows;
|
||||
});
|
||||
|
||||
if (order.getSuitDepositDeduction() != null && order.getSuitDepositDeduction()) {
|
||||
this.autoDeduct(order);
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
@ -540,14 +540,14 @@ public class OrderServiceImpl implements OrderService {
|
|||
}
|
||||
|
||||
// 处理订单完成
|
||||
private void handleFinished(OrderVO order) {
|
||||
private void handleFinished(Long orderId) {
|
||||
// 预分成
|
||||
boolean bonus = this.prepayBonus(order.getId());
|
||||
ServiceUtil.assertion(!bonus, "ID为%s的订单预分成失败", order.getId());
|
||||
boolean bonus = this.prepayBonus(orderId);
|
||||
ServiceUtil.assertion(!bonus, "ID为%s的订单预分成失败", orderId);
|
||||
|
||||
// 剩余金额退款
|
||||
int refund = this.refundRemainAmount(order);
|
||||
ServiceUtil.assertion(refund != 1, "ID为%s的订单退还剩余金额失败", order.getId());
|
||||
int refund = this.refundRemainAmount(orderId);
|
||||
ServiceUtil.assertion(refund != 1, "ID为%s的订单退还剩余金额失败", orderId);
|
||||
}
|
||||
|
||||
// 设置订单费用
|
||||
|
@ -573,7 +573,8 @@ public class OrderServiceImpl implements OrderService {
|
|||
order.setActualManageFee(MathUtils.min(remain, order.getManageFee()));
|
||||
}
|
||||
|
||||
private int refundRemainAmount(OrderVO order) {
|
||||
private int refundRemainAmount(Long orderId) {
|
||||
OrderVO order = selectOrderById(orderId);
|
||||
if (order == null) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -696,7 +697,6 @@ public class OrderServiceImpl implements OrderService {
|
|||
@Override
|
||||
public int refund(OrderRefundDTO dto) {
|
||||
OrderVO order = this.selectOrderById(dto.getOrderId());
|
||||
|
||||
return this.refund(order, dto.getAmount(), dto.getReason(), dto.getUserId(), dto.getUserName(), dto.getType());
|
||||
}
|
||||
|
||||
|
@ -858,7 +858,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
|
||||
// 订单结束操作
|
||||
if (pass) {
|
||||
this.handleFinished(order);
|
||||
this.handleFinished(order.getId());
|
||||
}
|
||||
|
||||
return rows;
|
||||
|
@ -873,7 +873,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
if (order == null) {
|
||||
return false;
|
||||
}
|
||||
return bonusService.prepayByBst(BonusBstType.ORDER, orderId, order.getEndTime());
|
||||
return bonusService.prepayByBst(BonusBstType.ORDER, orderId, order.getActualAmount(), order.getEndTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -990,7 +990,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
|
||||
// 订单结束操作
|
||||
if (OrderStatus.FINISHED.getCode().equals(data.getStatus())) {
|
||||
this.handleFinished(order);
|
||||
this.handleFinished(order.getId());
|
||||
}
|
||||
|
||||
return rows;
|
||||
|
|
Loading…
Reference in New Issue
Block a user