Showing
8 changed files
with
30 additions
and
198 deletions
@@ -7,51 +7,10 @@ import java.util.List; | @@ -7,51 +7,10 @@ import java.util.List; | ||
7 | 7 | ||
8 | public interface OrdersPayRefundMapper { | 8 | public interface OrdersPayRefundMapper { |
9 | 9 | ||
10 | - /** | ||
11 | - * This method was generated by MyBatis Generator. | ||
12 | - * This method corresponds to the database table orders_pay_refund | ||
13 | - * | ||
14 | - * @mbggenerated | ||
15 | - */ | ||
16 | int insert(OrdersPayRefund record); | 10 | int insert(OrdersPayRefund record); |
17 | 11 | ||
18 | - /** | ||
19 | - * This method was generated by MyBatis Generator. | ||
20 | - * This method corresponds to the database table orders_pay_refund | ||
21 | - * | ||
22 | - * @mbggenerated | ||
23 | - */ | ||
24 | - int insertSelective(OrdersPayRefund record); | ||
25 | - | ||
26 | - /** | ||
27 | - * This method was generated by MyBatis Generator. | ||
28 | - * This method corresponds to the database table orders_pay_refund | ||
29 | - * | ||
30 | - * @mbggenerated | ||
31 | - */ | ||
32 | - OrdersPayRefund selectByPrimaryKey(Integer id); | ||
33 | - | ||
34 | - /** | ||
35 | - * This method was generated by MyBatis Generator. | ||
36 | - * This method corresponds to the database table orders_pay_refund | ||
37 | - * | ||
38 | - * @mbggenerated | ||
39 | - */ | ||
40 | - int updateByPrimaryKeySelective(OrdersPayRefund record); | ||
41 | - | ||
42 | - /** | ||
43 | - * This method was generated by MyBatis Generator. | ||
44 | - * This method corresponds to the database table orders_pay_refund | ||
45 | - * | ||
46 | - * @mbggenerated | ||
47 | - */ | ||
48 | - int updateByPrimaryKey(OrdersPayRefund record); | ||
49 | - | ||
50 | //根据订单号获取退款记录 | 12 | //根据订单号获取退款记录 |
51 | - List<OrdersPayRefund> selectByOrderCode(long orderCode); | ||
52 | - | ||
53 | - //查看部分退款记录是否存在 | ||
54 | - //OrdersPayRefund selectByRefundOrderCode(@Param("refundOrderCode") String refundOrderCode); | 13 | + List<OrdersPayRefund> selectByOrderCode(Long orderCode); |
55 | 14 | ||
56 | //查看部分退款记录是否存在 -- (新) | 15 | //查看部分退款记录是否存在 -- (新) |
57 | OrdersPayRefund selectByRefundCode(@Param("refundCode") String refundCode); | 16 | OrdersPayRefund selectByRefundCode(@Param("refundCode") String refundCode); |
@@ -26,6 +26,8 @@ public class TradeBills { | @@ -26,6 +26,8 @@ public class TradeBills { | ||
26 | 26 | ||
27 | private Long orderCode; | 27 | private Long orderCode; |
28 | 28 | ||
29 | + private Long paidOrderCode; | ||
30 | + | ||
29 | //1:买家uid; 2:卖家uid | 31 | //1:买家uid; 2:卖家uid |
30 | private Integer userType; | 32 | private Integer userType; |
31 | 33 | ||
@@ -64,11 +66,11 @@ public class TradeBills { | @@ -64,11 +66,11 @@ public class TradeBills { | ||
64 | private Integer dealRelateId = 0; | 66 | private Integer dealRelateId = 0; |
65 | 67 | ||
66 | @Deprecated | 68 | @Deprecated |
67 | - public static enum Status { | 69 | + public enum Status { |
68 | 70 | ||
69 | TRANSFER_WAITING(90); | 71 | TRANSFER_WAITING(90); |
70 | 72 | ||
71 | - private Status(int code) { | 73 | + Status(int code) { |
72 | this.code = code; | 74 | this.code = code; |
73 | } | 75 | } |
74 | private int code; | 76 | private int code; |
@@ -2,10 +2,6 @@ | @@ -2,10 +2,6 @@ | ||
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
3 | <mapper namespace="com.yohoufo.dal.order.OrdersPayRefundMapper" > | 3 | <mapper namespace="com.yohoufo.dal.order.OrdersPayRefundMapper" > |
4 | <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.OrdersPayRefund" > | 4 | <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.OrdersPayRefund" > |
5 | - <!-- | ||
6 | - WARNING - @mbggenerated | ||
7 | - This element is automatically generated by MyBatis Generator, do not modify. | ||
8 | - --> | ||
9 | <id column="id" property="id" jdbcType="INTEGER" /> | 5 | <id column="id" property="id" jdbcType="INTEGER" /> |
10 | <result column="order_code" property="orderCode" jdbcType="BIGINT" /> | 6 | <result column="order_code" property="orderCode" jdbcType="BIGINT" /> |
11 | <result column="serial_no" property="serialNo" jdbcType="VARCHAR" /> | 7 | <result column="serial_no" property="serialNo" jdbcType="VARCHAR" /> |
@@ -16,23 +12,8 @@ | @@ -16,23 +12,8 @@ | ||
16 | <result column="refund_code" property="refundCode" jdbcType="VARCHAR" /> | 12 | <result column="refund_code" property="refundCode" jdbcType="VARCHAR" /> |
17 | </resultMap> | 13 | </resultMap> |
18 | <sql id="Base_Column_List" > | 14 | <sql id="Base_Column_List" > |
19 | - <!-- | ||
20 | - WARNING - @mbggenerated | ||
21 | - This element is automatically generated by MyBatis Generator, do not modify. | ||
22 | - --> | ||
23 | - id, order_code, serial_no, amount, status, | ||
24 | - create_time, update_time | 15 | + id, order_code, serial_no, amount, status, create_time, update_time, refund_code |
25 | </sql> | 16 | </sql> |
26 | - <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | ||
27 | - <!-- | ||
28 | - WARNING - @mbggenerated | ||
29 | - This element is automatically generated by MyBatis Generator, do not modify. | ||
30 | - --> | ||
31 | - select | ||
32 | - <include refid="Base_Column_List" /> | ||
33 | - from orders_pay_refund | ||
34 | - where id = #{id,jdbcType=INTEGER} | ||
35 | - </select> | ||
36 | 17 | ||
37 | <select id="selectByOrderCode" resultMap="BaseResultMap" parameterType="java.lang.Long" > | 18 | <select id="selectByOrderCode" resultMap="BaseResultMap" parameterType="java.lang.Long" > |
38 | select | 19 | select |
@@ -50,113 +31,11 @@ | @@ -50,113 +31,11 @@ | ||
50 | </select> | 31 | </select> |
51 | 32 | ||
52 | <insert id="insert" parameterType="com.yohoufo.dal.order.model.OrdersPayRefund" > | 33 | <insert id="insert" parameterType="com.yohoufo.dal.order.model.OrdersPayRefund" > |
53 | - <!-- | ||
54 | - WARNING - @mbggenerated | ||
55 | - This element is automatically generated by MyBatis Generator, do not modify. | ||
56 | - --> | ||
57 | - insert into orders_pay_refund (id, order_code, | ||
58 | - serial_no, amount, | ||
59 | - status, create_time, | ||
60 | - update_time, refund_code, order_type) | 34 | + insert into orders_pay_refund (id, order_code, serial_no, amount, status, create_time, update_time, refund_code, order_type) |
61 | values (#{id,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT}, | 35 | values (#{id,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT}, |
62 | #{serialNo,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL}, | 36 | #{serialNo,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL}, |
63 | #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, | 37 | #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, |
64 | #{updateTime,jdbcType=INTEGER}, #{refundCode,jdbcType=VARCHAR}, #{orderType,jdbcType=INTEGER}) | 38 | #{updateTime,jdbcType=INTEGER}, #{refundCode,jdbcType=VARCHAR}, #{orderType,jdbcType=INTEGER}) |
65 | </insert> | 39 | </insert> |
66 | - <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPayRefund" > | ||
67 | - <!-- | ||
68 | - WARNING - @mbggenerated | ||
69 | - This element is automatically generated by MyBatis Generator, do not modify. | ||
70 | - --> | ||
71 | - insert into orders_pay_refund | ||
72 | - <trim prefix="(" suffix=")" suffixOverrides="," > | ||
73 | - <if test="id != null" > | ||
74 | - id, | ||
75 | - </if> | ||
76 | - <if test="orderCode != null" > | ||
77 | - order_code, | ||
78 | - </if> | ||
79 | - <if test="serialNo != null" > | ||
80 | - serial_no, | ||
81 | - </if> | ||
82 | - <if test="amount != null" > | ||
83 | - amount, | ||
84 | - </if> | ||
85 | - <if test="status != null" > | ||
86 | - status, | ||
87 | - </if> | ||
88 | - <if test="createTime != null" > | ||
89 | - create_time, | ||
90 | - </if> | ||
91 | - <if test="updateTime != null" > | ||
92 | - update_time, | ||
93 | - </if> | ||
94 | - </trim> | ||
95 | - <trim prefix="values (" suffix=")" suffixOverrides="," > | ||
96 | - <if test="id != null" > | ||
97 | - #{id,jdbcType=INTEGER}, | ||
98 | - </if> | ||
99 | - <if test="orderCode != null" > | ||
100 | - #{orderCode,jdbcType=BIGINT}, | ||
101 | - </if> | ||
102 | - <if test="serialNo != null" > | ||
103 | - #{serialNo,jdbcType=VARCHAR}, | ||
104 | - </if> | ||
105 | - <if test="amount != null" > | ||
106 | - #{amount,jdbcType=DECIMAL}, | ||
107 | - </if> | ||
108 | - <if test="status != null" > | ||
109 | - #{status,jdbcType=TINYINT}, | ||
110 | - </if> | ||
111 | - <if test="createTime != null" > | ||
112 | - #{createTime,jdbcType=INTEGER}, | ||
113 | - </if> | ||
114 | - <if test="updateTime != null" > | ||
115 | - #{updateTime,jdbcType=INTEGER}, | ||
116 | - </if> | ||
117 | - </trim> | ||
118 | - </insert> | ||
119 | - <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.OrdersPayRefund" > | ||
120 | - <!-- | ||
121 | - WARNING - @mbggenerated | ||
122 | - This element is automatically generated by MyBatis Generator, do not modify. | ||
123 | - --> | ||
124 | - update orders_pay_refund | ||
125 | - <set > | ||
126 | - <if test="orderCode != null" > | ||
127 | - order_code = #{orderCode,jdbcType=BIGINT}, | ||
128 | - </if> | ||
129 | - <if test="serialNo != null" > | ||
130 | - serial_no = #{serialNo,jdbcType=VARCHAR}, | ||
131 | - </if> | ||
132 | - <if test="amount != null" > | ||
133 | - amount = #{amount,jdbcType=DECIMAL}, | ||
134 | - </if> | ||
135 | - <if test="status != null" > | ||
136 | - status = #{status,jdbcType=TINYINT}, | ||
137 | - </if> | ||
138 | - <if test="createTime != null" > | ||
139 | - create_time = #{createTime,jdbcType=INTEGER}, | ||
140 | - </if> | ||
141 | - <if test="updateTime != null" > | ||
142 | - update_time = #{updateTime,jdbcType=INTEGER}, | ||
143 | - </if> | ||
144 | - </set> | ||
145 | - where id = #{id,jdbcType=INTEGER} | ||
146 | - </update> | ||
147 | - <update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.OrdersPayRefund" > | ||
148 | - <!-- | ||
149 | - WARNING - @mbggenerated | ||
150 | - This element is automatically generated by MyBatis Generator, do not modify. | ||
151 | - --> | ||
152 | - update orders_pay_refund | ||
153 | - set | ||
154 | - order_code = #{orderCode,jdbcType=BIGINT}, | ||
155 | - serial_no = #{serialNo,jdbcType=VARCHAR}, | ||
156 | - amount = #{amount,jdbcType=DECIMAL}, | ||
157 | - status = #{status,jdbcType=TINYINT}, | ||
158 | - create_time = #{createTime,jdbcType=INTEGER}, | ||
159 | - update_time = #{updateTime,jdbcType=INTEGER} | ||
160 | - where id = #{id,jdbcType=INTEGER} | ||
161 | - </update> | 40 | + |
162 | </mapper> | 41 | </mapper> |
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | <id column="id" jdbcType="INTEGER" property="id" /> | 5 | <id column="id" jdbcType="INTEGER" property="id" /> |
6 | <result column="uid" jdbcType="INTEGER" property="uid" /> | 6 | <result column="uid" jdbcType="INTEGER" property="uid" /> |
7 | <result column="order_code" jdbcType="BIGINT" property="orderCode" /> | 7 | <result column="order_code" jdbcType="BIGINT" property="orderCode" /> |
8 | + <result column="paid_order_code" jdbcType="BIGINT" property="paidOrderCode" /> | ||
8 | <result column="user_type" jdbcType="TINYINT" property="userType" /> | 9 | <result column="user_type" jdbcType="TINYINT" property="userType" /> |
9 | <result column="pay_type" jdbcType="TINYINT" property="payType" /> | 10 | <result column="pay_type" jdbcType="TINYINT" property="payType" /> |
10 | <result column="trade_type" jdbcType="INTEGER" property="tradeType" /> | 11 | <result column="trade_type" jdbcType="INTEGER" property="tradeType" /> |
@@ -21,7 +22,7 @@ | @@ -21,7 +22,7 @@ | ||
21 | <result column="deal_user_name" jdbcType="VARCHAR" property="dealUserName" /> | 22 | <result column="deal_user_name" jdbcType="VARCHAR" property="dealUserName" /> |
22 | </resultMap> | 23 | </resultMap> |
23 | <sql id="Base_Column_List"> | 24 | <sql id="Base_Column_List"> |
24 | - id,uid, order_code, user_type,pay_type,trade_type,income_outcome,amount,system_amount,trade_status,create_time,deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name | 25 | + id,uid, order_code,paid_order_code, user_type,pay_type,trade_type,income_outcome,amount,system_amount,trade_status,create_time,deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name |
25 | </sql> | 26 | </sql> |
26 | 27 | ||
27 | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | 28 | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> |
@@ -39,10 +40,10 @@ | @@ -39,10 +40,10 @@ | ||
39 | </select> | 40 | </select> |
40 | 41 | ||
41 | <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.TradeBills" useGeneratedKeys="true"> | 42 | <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.TradeBills" useGeneratedKeys="true"> |
42 | - insert into trade_bills (id, uid, order_code, user_type,pay_type,trade_type, | 43 | + insert into trade_bills (id, uid, order_code, paid_order_code, user_type,pay_type,trade_type, |
43 | income_outcome,amount,system_amount,trade_status,create_time | 44 | income_outcome,amount,system_amount,trade_status,create_time |
44 | ,deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name) | 45 | ,deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name) |
45 | - values (#{id},#{uid},#{orderCode},#{userType},#{payType},#{tradeType}, | 46 | + values (#{id},#{uid},#{orderCode},#{paidOrderCode},#{userType},#{payType},#{tradeType}, |
46 | #{incomeOutcome},#{amount},#{systemAmount}, | 47 | #{incomeOutcome},#{amount},#{systemAmount}, |
47 | #{tradeStatus},#{createTime},#{dealUid},#{dealStatus},#{dealTime},#{dealRelateId},#{dealUserName}) | 48 | #{tradeStatus},#{createTime},#{dealUid},#{dealStatus},#{dealTime},#{dealRelateId},#{dealUserName}) |
48 | </insert> | 49 | </insert> |
@@ -129,9 +129,10 @@ public class PaymentController { | @@ -129,9 +129,10 @@ public class PaymentController { | ||
129 | */ | 129 | */ |
130 | @RequestMapping(value = "/erp/order/refund") | 130 | @RequestMapping(value = "/erp/order/refund") |
131 | public ApiResponse refund(@RequestParam(name = "orderCode") long orderCode, | 131 | public ApiResponse refund(@RequestParam(name = "orderCode") long orderCode, |
132 | + @RequestParam(name = "paidOrderCode",required = false) Long paidOrderCode, | ||
132 | @RequestParam(name = "refundAmount") double refundAmount){ | 133 | @RequestParam(name = "refundAmount") double refundAmount){ |
133 | 134 | ||
134 | - PaymentRequest request = PaymentRequest.builder().orderCode(orderCode).refundAmount(refundAmount).build(); | 135 | + PaymentRequest request = PaymentRequest.builder().orderCode(orderCode).paidOrderCode(paidOrderCode).refundAmount(refundAmount).build(); |
135 | logger.info("ufo.order.refund {}", request); | 136 | logger.info("ufo.order.refund {}", request); |
136 | PayRefundBo payRefundBo = paymentService.refund(request); | 137 | PayRefundBo payRefundBo = paymentService.refund(request); |
137 | 138 |
@@ -115,7 +115,7 @@ public class RefundManager { | @@ -115,7 +115,7 @@ public class RefundManager { | ||
115 | } | 115 | } |
116 | 116 | ||
117 | // 确认状态是已支付, 存在支付状态 | 117 | // 确认状态是已支付, 存在支付状态 |
118 | - AbstractOrderPaymentService orderPaymentService = orderPaymentServiceFactory.get(orderCode); | 118 | + AbstractOrderPaymentService orderPaymentService = orderPaymentServiceFactory.get(paidOrderCode); |
119 | OrderInfo orderInfo = orderPaymentService.getOrderInfo(orderCode); | 119 | OrderInfo orderInfo = orderPaymentService.getOrderInfo(orderCode); |
120 | 120 | ||
121 | if (!orderPaymentService.canRefund(orderInfo)) { | 121 | if (!orderPaymentService.canRefund(orderInfo)) { |
@@ -125,7 +125,7 @@ public class RefundManager { | @@ -125,7 +125,7 @@ public class RefundManager { | ||
125 | 125 | ||
126 | // 获取支付成功记录 | 126 | // 获取支付成功记录 |
127 | OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(paidOrderCode, orderInfo.getUid()); | 127 | OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(paidOrderCode, orderInfo.getUid()); |
128 | - if (ordersPay == null || ordersPay.getAmount() == null) { | 128 | + if (Objects.isNull(ordersPay) || Objects.isNull(ordersPay.getAmount())) { |
129 | log.warn("refund paid record not exist.orderCode is {}", orderCode); | 129 | log.warn("refund paid record not exist.orderCode is {}", orderCode); |
130 | throw new ServiceException(ServiceError.ORDER_HAS_NOT_PAID); | 130 | throw new ServiceException(ServiceError.ORDER_HAS_NOT_PAID); |
131 | } | 131 | } |
@@ -137,6 +137,9 @@ public class RefundManager { | @@ -137,6 +137,9 @@ public class RefundManager { | ||
137 | throw new ServiceException(ServiceError.ORDER_REFUND_OVER_TOTAL_AMOUNT); | 137 | throw new ServiceException(ServiceError.ORDER_REFUND_OVER_TOTAL_AMOUNT); |
138 | } | 138 | } |
139 | 139 | ||
140 | + throwServiceExceptionIf(Objects.isNull(orderInfo.getPayment()), | ||
141 | + exceptionMessage.apply("退款渠道不存在")); | ||
142 | + | ||
140 | // 退款 | 143 | // 退款 |
141 | AbstractPayService payService = payServiceFactory.getPayService(orderInfo.getPayment()); | 144 | AbstractPayService payService = payServiceFactory.getPayService(orderInfo.getPayment()); |
142 | throwServiceExceptionIf(Objects.isNull(payService), | 145 | throwServiceExceptionIf(Objects.isNull(payService), |
@@ -144,6 +147,9 @@ public class RefundManager { | @@ -144,6 +147,9 @@ public class RefundManager { | ||
144 | 147 | ||
145 | PayRefundBo payRefundBo = buildRefundRequest(orderInfo, ordersPay); | 148 | PayRefundBo payRefundBo = buildRefundRequest(orderInfo, ordersPay); |
146 | 149 | ||
150 | + throwServiceExceptionIf(Objects.nonNull(ordersPayRefundMapper.selectByRefundCode(payRefundBo.getRefundOrderCode())), | ||
151 | + exceptionMessage.apply("已经退款成功过")); | ||
152 | + | ||
147 | RefundContext context = new RefundContext(); | 153 | RefundContext context = new RefundContext(); |
148 | context.orderInfo = orderInfo; | 154 | context.orderInfo = orderInfo; |
149 | context.ordersPay = ordersPay; | 155 | context.ordersPay = ordersPay; |
@@ -167,7 +173,7 @@ public class RefundManager { | @@ -167,7 +173,7 @@ public class RefundManager { | ||
167 | payRefundBo.setPayOrderCode(ordersPay.getPayOrderCode()); | 173 | payRefundBo.setPayOrderCode(ordersPay.getPayOrderCode()); |
168 | payRefundBo.setAmount(refundAmount); | 174 | payRefundBo.setAmount(refundAmount); |
169 | payRefundBo.setOrderTotalFee(ordersPay.getAmount().doubleValue()); | 175 | payRefundBo.setOrderTotalFee(ordersPay.getAmount().doubleValue()); |
170 | - payRefundBo.setRefundOrderCode(String.valueOf(orderCode) + ordersPay.getId()); | 176 | + payRefundBo.setRefundOrderCode(String.valueOf(orderCode)); |
171 | payRefundBo.setUid(ordersPay.getUid()); | 177 | payRefundBo.setUid(ordersPay.getUid()); |
172 | payRefundBo.setOrderCreateTime(orderInfo.getCreateTime()); | 178 | payRefundBo.setOrderCreateTime(orderInfo.getCreateTime()); |
173 | payRefundBo.setAttach(refundAttach); | 179 | payRefundBo.setAttach(refundAttach); |
@@ -203,17 +209,15 @@ public class RefundManager { | @@ -203,17 +209,15 @@ public class RefundManager { | ||
203 | // 钱包支付或其他渠道支付成功,添加退款申请成功的记录 | 209 | // 钱包支付或其他渠道支付成功,添加退款申请成功的记录 |
204 | if (Payment.WALLET.getCode() == context.orderInfo.getPayment().intValue() | 210 | if (Payment.WALLET.getCode() == context.orderInfo.getPayment().intValue() |
205 | || context.response.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS) { | 211 | || context.response.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS) { |
206 | - recordPayRefund(context.response); | 212 | + recordPayRefund(context.ordersPay, context.response); |
207 | } | 213 | } |
208 | 214 | ||
209 | } | 215 | } |
210 | 216 | ||
211 | /** | 217 | /** |
212 | * 数据库记录退款申请 | 218 | * 数据库记录退款申请 |
213 | - * | ||
214 | - * @param refundBo | ||
215 | */ | 219 | */ |
216 | - private void recordPayRefund(PayRefundBo refundBo) { | 220 | + private void recordPayRefund(OrdersPay ordersPay, PayRefundBo refundBo) { |
217 | log.info("refund record, refundOrderCode: {}, serialNo: {}", refundBo.getRefundOrderCode(), refundBo.getSerialNo()); | 221 | log.info("refund record, refundOrderCode: {}, serialNo: {}", refundBo.getRefundOrderCode(), refundBo.getSerialNo()); |
218 | // 一个订单号,只能退款一次? | 222 | // 一个订单号,只能退款一次? |
219 | OrdersPayRefund refundRecord = ordersPayRefundMapper.selectByRefundCode(refundBo.getRefundOrderCode()); | 223 | OrdersPayRefund refundRecord = ordersPayRefundMapper.selectByRefundCode(refundBo.getRefundOrderCode()); |
@@ -223,7 +227,7 @@ public class RefundManager { | @@ -223,7 +227,7 @@ public class RefundManager { | ||
223 | } | 227 | } |
224 | 228 | ||
225 | OrdersPayRefund newRecord = new OrdersPayRefund(); | 229 | OrdersPayRefund newRecord = new OrdersPayRefund(); |
226 | - newRecord.setOrderCode(Long.valueOf(refundBo.getOrderCode())); | 230 | + newRecord.setOrderCode(ordersPay.getOrderCode()); |
227 | newRecord.setRefundCode(refundBo.getRefundOrderCode()); | 231 | newRecord.setRefundCode(refundBo.getRefundOrderCode()); |
228 | newRecord.setAmount(BigDecimal.valueOf(refundBo.getAmount())); | 232 | newRecord.setAmount(BigDecimal.valueOf(refundBo.getAmount())); |
229 | newRecord.setStatus((byte) 0); | 233 | newRecord.setStatus((byte) 0); |
@@ -411,6 +411,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -411,6 +411,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
411 | public PayRefundBo refund(PaymentRequest request) { | 411 | public PayRefundBo refund(PaymentRequest request) { |
412 | 412 | ||
413 | return refundManager.create(request.getOrderCode(), request.getRefundAmount()) | 413 | return refundManager.create(request.getOrderCode(), request.getRefundAmount()) |
414 | + .withPaidOrderCode(request.getPaidOrderCode()) | ||
414 | .withRefundAttach(request.getRefundattch()) | 415 | .withRefundAttach(request.getRefundattch()) |
415 | .refund(); | 416 | .refund(); |
416 | 417 | ||
@@ -852,24 +853,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -852,24 +853,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
852 | try { | 853 | try { |
853 | logger.info("{}, refund money is {}", logTag, tradeBills); | 854 | logger.info("{}, refund money is {}", logTag, tradeBills); |
854 | refundManager.create(orderCode, amount.doubleValue()) | 855 | refundManager.create(orderCode, amount.doubleValue()) |
855 | - .withRefundPreHandler(context -> { | ||
856 | - OrderInfo orderInfo = context.getOrderInfo(); | ||
857 | - Function<Object, String> exceptionMessage = appendMessage -> String.format("订单[%s],%s!", orderCode, appendMessage); | ||
858 | - | ||
859 | - // 获取支付成功记录 | ||
860 | - OrdersPay ordersPay = context.getOrdersPay(); | ||
861 | - throwServiceExceptionIf(Objects.isNull(ordersPay) || Objects.isNull(ordersPay.getAmount()) || Objects.isNull(ordersPay.getPayment()), | ||
862 | - exceptionMessage.apply("尚未支付")); | ||
863 | - | ||
864 | - throwServiceExceptionIf(CollectionUtils.isNotEmpty(ordersPayRefundMapper.selectByOrderCode(orderCode)), | ||
865 | - exceptionMessage.apply("已经退款成功过")); | ||
866 | - | ||
867 | - throwServiceExceptionIf(ordersPay.getAmount().compareTo(amount) < 0, | ||
868 | - exceptionMessage.apply("退款金额大于支付金额")); | ||
869 | - | ||
870 | - throwServiceExceptionIf(Objects.isNull(orderInfo.getPayment()), | ||
871 | - exceptionMessage.apply("退款渠道不存在")); | ||
872 | - }) | 856 | + .withPaidOrderCode(tradeBills.getPaidOrderCode()) |
873 | .withRefundPostHandler(context -> { | 857 | .withRefundPostHandler(context -> { |
874 | PayRefundBo refundBo = context.getResponse(); | 858 | PayRefundBo refundBo = context.getResponse(); |
875 | //退款申请成功 | 859 | //退款申请成功 |
-
Please register or login to post a comment