Commit 5783724c545c7d309d140604a9c58f497ef57371

Authored by fengliang
1 parent 8ddacaba

update:补充退费合计

etrade-order/src/main/java/com/diligrp/etrade/order/dao/OrderRefundMapper.java
... ... @@ -7,12 +7,13 @@ import com.diligrp.etrade.order.model.OrderRefund;
7 7 import org.apache.ibatis.annotations.Param;
8 8 import org.springframework.stereotype.Repository;
9 9  
  10 +import java.math.BigDecimal;
10 11 import java.util.List;
11 12 import java.util.Map;
12 13  
13 14 @Repository("orderRefundMapper")
14 15 public interface OrderRefundMapper extends MybatisMapperSupport {
15   - Map<String, Long> getRefundInfoBefore(@Param("orderId") Long orderId);
  16 + Map<String, BigDecimal> getRefundInfoBefore(@Param("orderId") Long orderId);
16 17  
17 18 Long insert(OrderRefund orderRefund);
18 19  
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/domain/OrderDto.java
... ... @@ -242,6 +242,8 @@ public class OrderDto {
242 242 /** 运费 */
243 243 private BigDecimal transportFee;
244 244  
  245 + private BigDecimal totalRefundAmount;
  246 +
245 247 public Integer getAchieveType() {
246 248 return achieveType;
247 249 }
... ... @@ -775,4 +777,12 @@ public class OrderDto {
775 777 public void setWayType(String wayType) {
776 778 this.wayType = wayType;
777 779 }
  780 +
  781 + public BigDecimal getTotalRefundAmount() {
  782 + return totalRefundAmount;
  783 + }
  784 +
  785 + public void setTotalRefundAmount(BigDecimal totalRefundAmount) {
  786 + this.totalRefundAmount = totalRefundAmount;
  787 + }
778 788 }
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/domain/OrderPageMessage.java
... ... @@ -25,6 +25,11 @@ public class OrderPageMessage&lt;T&gt; extends PageMessage&lt;T&gt; {
25 25 */
26 26 private BigDecimal totalTransferAmount;
27 27  
  28 + /**
  29 + * 总退款金额
  30 + */
  31 + private BigDecimal totalRefundAmount;
  32 +
28 33 public static <T> OrderPageMessage<T> success(Page<T> pageInfo) {
29 34 OrderPageMessage<T> page = new OrderPageMessage<>();
30 35 page.setCode(CODE_SUCCESS);
... ... @@ -66,4 +71,12 @@ public class OrderPageMessage&lt;T&gt; extends PageMessage&lt;T&gt; {
66 71 public void setTotalTransferAmount(BigDecimal totalTransferAmount) {
67 72 this.totalTransferAmount = totalTransferAmount;
68 73 }
  74 +
  75 + public BigDecimal getTotalRefundAmount() {
  76 + return totalRefundAmount;
  77 + }
  78 +
  79 + public void setTotalRefundAmount(BigDecimal totalRefundAmount) {
  80 + this.totalRefundAmount = totalRefundAmount;
  81 + }
69 82 }
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderQueryServiceImpl.java
... ... @@ -84,11 +84,13 @@ public class OrderQueryServiceImpl implements OrderQueryService {
84 84 if(map!=null){
85 85 success.setTotalAmount(map.get("totalAmount")==null?BigDecimal.ZERO:map.get("totalAmount").setScale(2, BigDecimal.ROUND_HALF_UP));
86 86 success.setTotalTransferAmount(map.get("totalTransferAmount")==null?BigDecimal.ZERO:map.get("totalTransferAmount").setScale(2, BigDecimal.ROUND_HALF_UP));
  87 + success.setTotalTransferAmount(map.get("totalRefundAmount")==null?BigDecimal.ZERO:map.get("totalRefundAmount").setScale(2, BigDecimal.ROUND_HALF_UP));
87 88 success.setTotalGoodsAmount(success.getTotalAmount().subtract(success.getTotalTransferAmount()).setScale(2, BigDecimal.ROUND_HALF_UP));
88 89 }else{
89 90 success.setTotalAmount(BigDecimal.ZERO);
90 91 success.setTotalTransferAmount(BigDecimal.ZERO);
91 92 success.setTotalGoodsAmount(BigDecimal.ZERO);
  93 + success.setTotalGoodsAmount(BigDecimal.ZERO);
92 94 }
93 95  
94 96 return success;
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderRefundServiceImpl.java
... ... @@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory;
31 31 import org.springframework.stereotype.Service;
32 32 import org.springframework.transaction.annotation.Transactional;
33 33  
  34 +import java.math.BigDecimal;
34 35 import java.math.RoundingMode;
35 36 import java.time.LocalDateTime;
36 37 import java.util.ArrayList;
... ... @@ -71,14 +72,14 @@ public class OrderRefundServiceImpl implements OrderRefundService {
71 72 return Message.failure(OrderErrorCode.PARAM_ERROR,"订单未支付");
72 73 }
73 74 //是否可退款效验
74   - Map<String,Long> oldMap = orderRefundMapper.getRefundInfoBefore(order.getId());
  75 + Map<String, BigDecimal> oldMap = orderRefundMapper.getRefundInfoBefore(order.getId());
75 76 Long refundAmount = refundDto.getRefundAmount().setScale(2, RoundingMode.HALF_UP).multiply(NumberTransform.ONE_HUNDERD).longValue();
76 77 if(oldMap!=null){
77   - if(oldMap.get("doing")!=null&&!oldMap.get("doing").equals(0L)){
  78 + if(oldMap.get("doing")!=null&&oldMap.get("doing").compareTo(BigDecimal.ZERO)!=0){
78 79 return Message.failure(OrderErrorCode.PARAM_ERROR,"有处理中的退款单据,请确定状态后,再操作");
79 80 }
80 81 Long AllRefundAmount = orderPayment.getPayAmount()-orderPayment.getPayDiscount();
81   - if(oldMap.get("success")!=null&&oldMap.get("success")> AllRefundAmount - refundAmount){
  82 + if(oldMap.get("success")!=null&& oldMap.get("success").compareTo(BigDecimal.ZERO)!=0 && oldMap.get("success").longValue() > AllRefundAmount - refundAmount){
82 83 return Message.failure(OrderErrorCode.PARAM_ERROR,"退款金额不能大于可退金额");
83 84 }
84 85 }
... ... @@ -240,6 +241,7 @@ public class OrderRefundServiceImpl implements OrderRefundService {
240 241 orderRefund.setOrderPaymentId(orderPayment.getId());
241 242 orderRefund.setCreateId(userTicket.getId());
242 243 orderRefund.setCreateName(userTicket.getRealName());
  244 + orderRefund.setCreatedTime(LocalDateTime.now());
243 245 return orderRefund;
244 246 }
245 247  
... ...
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/order/OrderMapper.xml
... ... @@ -60,6 +60,7 @@
60 60 <result column="achieve_state" jdbcType="INTEGER" property="achieveState" />
61 61 <result column="transport_fee" jdbcType="BIGINT" property="transportFee" />
62 62 <result column="stock_deduction_state" jdbcType="BIGINT" property="stockDeductionState" />
  63 + <result column="total_refund_amount" jdbcType="BIGINT" property="totalRefundAmount" />
63 64 </resultMap>
64 65 <sql id="Base_Column_List">
65 66 id, code, mapping_code, market_id, buyer_code, buyer_id,buyer_store_customer_id, buyer_name, buyer_account_id,
... ... @@ -69,7 +70,7 @@
69 70 pay_time, order_state, `state`, version, creater_id, creater, created_time, modifier_id,
70 71 modifier, modified_time, verify_ids, verifier,verify_state, verifier_time, cancel_id, cancel_name,
71 72 cancel_time, out_time,`source`,totle_seller_fee,district_id,district_name,sub_district_id,sub_district_name,location
72   - ,order_status,relation_id,achieve_type,achieve_address,achieve_state,transport_fee,stock_deduction_state
  73 + ,order_status,relation_id,achieve_type,achieve_address,achieve_state,transport_fee,stock_deduction_state,total_refund_amount
73 74 </sql>
74 75 <sql id="Dto_Column_List">
75 76 id,
... ... @@ -127,7 +128,9 @@
127 128 achieve_type,
128 129 achieve_address,
129 130 achieve_state,
130   - convert(transport_fee, decimal(20,2))/100 as transport_fee
  131 + convert(transport_fee, decimal(20,2))/100 as transport_fee,
  132 + convert(total_refund_amount, decimal(20,2))/100 as total_refund_amount
  133 +
131 134 </sql>
132 135 <insert id="saveOrder" parameterType="com.diligrp.etrade.order.model.Order" useGeneratedKeys="true" keyProperty="id" >
133 136 insert into `order` (id, code, mapping_code,
... ... @@ -216,7 +219,8 @@
216 219 achieve_type = #{achieveType,jdbcType=TINYINT},
217 220 achieve_address = #{achieveAddress,jdbcType=VARCHAR},
218 221 achieve_state = #{achieveState,jdbcType=TINYINT},
219   - transport_fee = #{transportFee,jdbcType=VARCHAR}
  222 + transport_fee = #{transportFee,jdbcType=VARCHAR},
  223 + total_refund_amount = #{totalRefundAmount}
220 224 where id = #{id,jdbcType=BIGINT} and version = #{version,jdbcType=BIGINT}
221 225 </update>
222 226  
... ... @@ -376,6 +380,9 @@
376 380 <if test="transportFee != null">
377 381 transport_fee = #{transportFee,jdbcType=VARCHAR},
378 382 </if>
  383 + <if test="totalRefundAmount != null">
  384 + total_refund_amount = #{totalRefundAmount},
  385 + </if>
379 386 </set>
380 387 where id = #{id,jdbcType=BIGINT} and version = #{version,jdbcType=INTEGER}
381 388 </update>
... ...
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/order/OrderQueryMapper.xml
... ... @@ -59,6 +59,7 @@
59 59 <result column="receiver_phone" jdbcType="VARCHAR" property="receiverPhone" />
60 60 <result column="address" jdbcType="VARCHAR" property="address" />
61 61 <result column="way_type" jdbcType="INTEGER" property="wayType" />
  62 + <result column="total_refund_amount" jdbcType="INTEGER" property="totalRefundAmount" />
62 63 </resultMap>
63 64 <sql id="Base_Column_List">
64 65 id, `code`, mapping_code, market_id, buyer_code, buyer_id,buyer_store_customer_id, buyer_name, buyer_account_id,
... ... @@ -67,7 +68,7 @@
67 68 totle_pay_amount, totle_paid_amount, totle_discount, totle_weight, order_type, pay_state,
68 69 pay_time, order_state, `state`, version, creater_id, creater, created_time, modifier_id,
69 70 modifier, modified_time, verify_ids, verifier, verifier_time,verify_state, cancel_id, cancel_name,
70   - cancel_time, out_time,`source`, achieve_type, achieve_state
  71 + cancel_time, out_time,`source`, achieve_type, achieve_state,total_refund_amount
71 72 </sql>
72 73 <sql id="Dto_Column_List">
73 74 id,
... ... @@ -125,7 +126,8 @@
125 126 location,
126 127 achieve_type,
127 128 achieve_state,
128   - transport_fee
  129 + transport_fee,
  130 + convert(total_refund_amount, decimal(20,2))/100 as total_refund_amount
129 131 </sql>
130 132 <select id="queryOrderStateNumber" resultType="com.diligrp.etrade.order.domain.OrderStateNumberDto"
131 133 parameterType="com.diligrp.etrade.order.domain.OrderQueryDto">
... ... @@ -189,6 +191,7 @@
189 191 convert(ord.totle_discount, decimal(20,2))/100 as totle_discount,
190 192 convert(ord.totle_weight, decimal(20,2))/1000 as totle_weight,
191 193 convert(ord.transport_fee, decimal(20,2))/100 as transport_fee,
  194 + convert(ord.total_refund_amount, decimal(20,2))/100 as total_refund_amount,
192 195 ord.order_type as order_type,
193 196 ord.pay_state as pay_state,
194 197 ord.pay_time as pay_time,
... ... @@ -596,7 +599,8 @@
596 599 parameterType="com.diligrp.etrade.order.domain.OrderQueryDto">
597 600 select
598 601 convert(sum(ord.totle_amount), decimal(20,2))/100 as totalAmount,
599   - convert(sum(ord.transport_fee), decimal(20,2))/100 as totalTransferAmount
  602 + convert(sum(ord.transport_fee), decimal(20,2))/100 as totalTransferAmount,
  603 + convert(sum(ord.total_refund_amount), decimal(20,2))/100 as totalRefundAmount
600 604 from `order` ord
601 605 left join order_delivery od on od.order_id = ord.id
602 606 <where>
... ...
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/resolver/WeChatPayRpcResolver.java
... ... @@ -109,7 +109,16 @@ public class WeChatPayRpcResolver {
109 109 weChatPayRefundDto.setNotifyUrl(backBaseUrl+weChatPayRefundDto.getNotifyUrl());
110 110 //组装headers
111 111 HttpHeaders prepareHeaders = creatHeader(weChatPayRefundDto.getMarketId().toString(), REFUND_STATE_INFO);
112   - Message<WeChatRefundBackDto> refundJsonObject = payRpc.refundHg(weChatPayRefundDto, prepareHeaders);
  112 + //Message<WeChatRefundBackDto> refundJsonObject = payRpc.refundHg(weChatPayRefundDto, prepareHeaders);
  113 + //退款发起模拟成功
  114 + Message<WeChatRefundBackDto> refundJsonObject = new Message<>();
  115 + refundJsonObject.setCode(200);
  116 + WeChatRefundBackDto weChatRefundBackDto = new WeChatRefundBackDto();
  117 + weChatRefundBackDto.setRefundId("123456789");
  118 + weChatRefundBackDto.setState(4);
  119 + weChatRefundBackDto.setMessage("退款成功");
  120 + refundJsonObject.setData(weChatRefundBackDto);
  121 + //退款发起模拟成功
113 122 if(!refundJsonObject.getCode().equals(200)){
114 123 log.info("退款发起成功:退款参数{},请求体头部为{},请求结果为{}",weChatPayRefundDto,prepareHeaders,refundJsonObject);
115 124 throw new PlatformServiceException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "退款失败:" + refundJsonObject.getMessage());
... ...