mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-03 09:29:59 +08:00
交易分账 重构
This commit is contained in:
@@ -32,7 +32,7 @@ public class MemberAdapayRecord {
|
||||
private String paymentId;
|
||||
|
||||
/**
|
||||
* 汇付支付单号
|
||||
* 汇付支付单号(支付宝/微信 订单号)
|
||||
*/
|
||||
private String paymentOrderNo;
|
||||
|
||||
@@ -51,6 +51,11 @@ public class MemberAdapayRecord {
|
||||
*/
|
||||
private BigDecimal spendAmt;
|
||||
|
||||
/**
|
||||
* 冻结金额
|
||||
*/
|
||||
private BigDecimal freezeAmt;
|
||||
|
||||
/**
|
||||
* 剩余金额
|
||||
*/
|
||||
|
||||
@@ -760,15 +760,20 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
|
||||
未使用延时分账的一级运营商
|
||||
*/
|
||||
OrderSettleResult orderSettleResult = null;
|
||||
if (StringUtils.equals(delayMode, Constants.ADAPAY_PAY_MODE_DELAY)) {
|
||||
// 延迟商家订单处理逻辑
|
||||
orderSettleResult = delayMerchantOrderProcessingLogic(orderBasicInfo, adapayMemberAccount, appId);
|
||||
} else {
|
||||
// 不延迟商家订单处理逻辑 不使用延时分账的汇付商户,钱已经到基本账户中了,只需要退款就可以
|
||||
orderSettleResult = notDelayMerchantOrderProcessingLogic(orderBasicInfo, adapayMemberAccount, appId);
|
||||
// 记账 冻结金额
|
||||
|
||||
}
|
||||
|
||||
OrderSettleResult orderSettleResult = null;
|
||||
// if (StringUtils.equals(delayMode, Constants.ADAPAY_PAY_MODE_DELAY)) {
|
||||
// // 延迟商家订单处理逻辑
|
||||
// orderSettleResult = delayMerchantOrderProcessingLogic(orderBasicInfo, adapayMemberAccount, appId);
|
||||
// } else {
|
||||
// // 不延迟商家订单处理逻辑 不使用延时分账的汇付商户,钱已经到基本账户中了,只需要退款就可以
|
||||
// orderSettleResult = notDelayMerchantOrderProcessingLogic(orderBasicInfo, adapayMemberAccount, appId);
|
||||
// }
|
||||
|
||||
// 退款逻辑/需要退款的情况
|
||||
BigDecimal residue = orderBasicInfo.getRefundAmount();
|
||||
if (residue.compareTo(BigDecimal.ZERO) > 0) {
|
||||
@@ -787,6 +792,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
* 不延迟商家订单处理逻辑
|
||||
* 例如:希晓
|
||||
* 相当于已经分账完成了
|
||||
*
|
||||
* @param orderBasicInfo 订单信息
|
||||
* @param adapayMemberAccount 汇付用户信息
|
||||
* @param wechatAppId 小程序appId
|
||||
@@ -797,6 +803,26 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 冻结订单金额
|
||||
* 记一笔账,还没有到分账时间,把订单消费金额在支付单里冻结,退款的时候不能动这些钱
|
||||
*/
|
||||
private void freezeAmount(OrderBasicInfo orderBasicInfo) {
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
// 查询这笔订单的支付id/查询该笔订单的支付交易回调
|
||||
AdapayCallbackRecord adapayCallbackRecord = selectAdapayCallbackRecord(orderCode);
|
||||
|
||||
}
|
||||
|
||||
private AdapayCallbackRecord selectAdapayCallbackRecord(String orderCode) {
|
||||
AdapayCallbackRecord adapayCallbackRecord = adapayCallbackRecordService.selectByOrderCode(orderCode);
|
||||
if (adapayCallbackRecord == null) {
|
||||
logger.error("根据订单号:{}, 未查询到汇付支付回调信息", orderCode);
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CALLBACK_IS_NULL_ERROR);
|
||||
}
|
||||
return adapayCallbackRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟商家订单处理逻辑
|
||||
* 例如:举视以及下面的二级运营商
|
||||
@@ -1328,11 +1354,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
public OrderSettleResult doPaymentConfirmWithDelay(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) {
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
// 查询该笔订单的支付交易回调
|
||||
AdapayCallbackRecord adapayCallbackRecord = adapayCallbackRecordService.selectByOrderCode(orderCode);
|
||||
if (adapayCallbackRecord == null) {
|
||||
logger.error("根据订单号:{}, 未查询到汇付支付回调信息", orderCode);
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CALLBACK_IS_NULL_ERROR);
|
||||
}
|
||||
AdapayCallbackRecord adapayCallbackRecord = selectAdapayCallbackRecord(orderCode);
|
||||
// 支付id
|
||||
String paymentId = adapayCallbackRecord.getPaymentId();
|
||||
|
||||
@@ -2857,10 +2879,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
BigDecimal refundAmount = orderBasicInfo.getRefundAmount();
|
||||
|
||||
// 查到原汇付支付id
|
||||
AdapayCallbackRecord adapayCallbackRecord = adapayCallbackRecordService.selectByOrderCode(orderCode);
|
||||
if (adapayCallbackRecord == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CALLBACK_IS_NULL_ERROR);
|
||||
}
|
||||
AdapayCallbackRecord adapayCallbackRecord = selectAdapayCallbackRecord(orderCode);
|
||||
|
||||
// 获取appId
|
||||
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(orderBasicInfo.getMerchantId());
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<result column="pay_amt" jdbcType="DECIMAL" property="payAmt" />
|
||||
<result column="refund_amt" jdbcType="DECIMAL" property="refundAmt" />
|
||||
<result column="spend_amt" jdbcType="DECIMAL" property="spendAmt" />
|
||||
<result column="freeze_amt" jdbcType="DECIMAL" property="freezeAmt" />
|
||||
<result column="balance_amt" jdbcType="DECIMAL" property="balanceAmt" />
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
@@ -22,7 +23,8 @@
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, member_id, scenario_type, payment_id, payment_order_no, pay_amt, refund_amt,
|
||||
spend_amt, balance_amt, create_by, create_time, update_by, update_time, del_flag
|
||||
spend_amt, freeze_amt, balance_amt, create_by, create_time, update_by, update_time,
|
||||
del_flag
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
<!--@mbg.generated-->
|
||||
@@ -56,6 +58,9 @@
|
||||
<if test="spendAmt != null">
|
||||
spend_amt,
|
||||
</if>
|
||||
<if test="freezeAmt != null">
|
||||
freeze_amt,
|
||||
</if>
|
||||
<if test="balanceAmt != null">
|
||||
balance_amt,
|
||||
</if>
|
||||
@@ -97,6 +102,9 @@
|
||||
<if test="spendAmt != null">
|
||||
#{spendAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="freezeAmt != null">
|
||||
#{freezeAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="balanceAmt != null">
|
||||
#{balanceAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
@@ -142,6 +150,9 @@
|
||||
<if test="spendAmt != null">
|
||||
spend_amt = #{spendAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="freezeAmt != null">
|
||||
freeze_amt = #{freezeAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="balanceAmt != null">
|
||||
balance_amt = #{balanceAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
@@ -202,6 +213,11 @@
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.spendAmt,jdbcType=DECIMAL}
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="freeze_amt = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.freezeAmt,jdbcType=DECIMAL}
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="balance_amt = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.balanceAmt,jdbcType=DECIMAL}
|
||||
@@ -242,14 +258,15 @@
|
||||
<!--@mbg.generated-->
|
||||
insert into member_adapay_record
|
||||
(member_id, scenario_type, payment_id, payment_order_no, pay_amt, refund_amt, spend_amt,
|
||||
balance_amt, create_by, create_time, update_by, update_time, del_flag)
|
||||
freeze_amt, balance_amt, create_by, create_time, update_by, update_time, del_flag
|
||||
)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.memberId,jdbcType=VARCHAR}, #{item.scenarioType,jdbcType=VARCHAR}, #{item.paymentId,jdbcType=VARCHAR},
|
||||
#{item.paymentOrderNo,jdbcType=VARCHAR}, #{item.payAmt,jdbcType=DECIMAL}, #{item.refundAmt,jdbcType=DECIMAL},
|
||||
#{item.spendAmt,jdbcType=DECIMAL}, #{item.balanceAmt,jdbcType=DECIMAL}, #{item.createBy,jdbcType=VARCHAR},
|
||||
#{item.createTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP},
|
||||
#{item.delFlag,jdbcType=VARCHAR})
|
||||
#{item.spendAmt,jdbcType=DECIMAL}, #{item.freezeAmt,jdbcType=DECIMAL}, #{item.balanceAmt,jdbcType=DECIMAL},
|
||||
#{item.createBy,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=VARCHAR},
|
||||
#{item.updateTime,jdbcType=TIMESTAMP}, #{item.delFlag,jdbcType=VARCHAR})
|
||||
</foreach>
|
||||
</insert>
|
||||
<insert id="insertOrUpdate" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberAdapayRecord" useGeneratedKeys="true">
|
||||
@@ -266,6 +283,7 @@
|
||||
pay_amt,
|
||||
refund_amt,
|
||||
spend_amt,
|
||||
freeze_amt,
|
||||
balance_amt,
|
||||
create_by,
|
||||
create_time,
|
||||
@@ -285,6 +303,7 @@
|
||||
#{payAmt,jdbcType=DECIMAL},
|
||||
#{refundAmt,jdbcType=DECIMAL},
|
||||
#{spendAmt,jdbcType=DECIMAL},
|
||||
#{freezeAmt,jdbcType=DECIMAL},
|
||||
#{balanceAmt,jdbcType=DECIMAL},
|
||||
#{createBy,jdbcType=VARCHAR},
|
||||
#{createTime,jdbcType=TIMESTAMP},
|
||||
@@ -304,6 +323,7 @@
|
||||
pay_amt = #{payAmt,jdbcType=DECIMAL},
|
||||
refund_amt = #{refundAmt,jdbcType=DECIMAL},
|
||||
spend_amt = #{spendAmt,jdbcType=DECIMAL},
|
||||
freeze_amt = #{freezeAmt,jdbcType=DECIMAL},
|
||||
balance_amt = #{balanceAmt,jdbcType=DECIMAL},
|
||||
create_by = #{createBy,jdbcType=VARCHAR},
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
@@ -340,6 +360,9 @@
|
||||
<if test="spendAmt != null">
|
||||
spend_amt,
|
||||
</if>
|
||||
<if test="freezeAmt != null">
|
||||
freeze_amt,
|
||||
</if>
|
||||
<if test="balanceAmt != null">
|
||||
balance_amt,
|
||||
</if>
|
||||
@@ -385,6 +408,9 @@
|
||||
<if test="spendAmt != null">
|
||||
#{spendAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="freezeAmt != null">
|
||||
#{freezeAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="balanceAmt != null">
|
||||
#{balanceAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
@@ -430,6 +456,9 @@
|
||||
<if test="spendAmt != null">
|
||||
spend_amt = #{spendAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="freezeAmt != null">
|
||||
freeze_amt = #{freezeAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="balanceAmt != null">
|
||||
balance_amt = #{balanceAmt,jdbcType=DECIMAL},
|
||||
</if>
|
||||
@@ -477,7 +506,7 @@
|
||||
from member_adapay_record
|
||||
where del_flag = '0'
|
||||
and scenario_type = 'balance'
|
||||
and balance_amt > '0.00'
|
||||
and balance_amt > '0.00'
|
||||
and member_id = #{memberId,jdbcType=VARCHAR}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user