Showing
9 changed files
with
268 additions
and
84 deletions
1 | package com.yohoufo.order.common; | 1 | package com.yohoufo.order.common; |
2 | 2 | ||
3 | +import java.util.Map; | ||
4 | + | ||
3 | /** | 5 | /** |
4 | * 1:鉴定通过(货款-->卖家 + 平台); | 6 | * 1:鉴定通过(货款-->卖家 + 平台); |
5 | * 2:鉴定不通过(保证金 --> 买家 + 平台); | 7 | * 2:鉴定不通过(保证金 --> 买家 + 平台); |
6 | * 3:有买家时卖家不卖了(保证金 --> 买家+ 平台) | 8 | * 3:有买家时卖家不卖了(保证金 --> 买家+ 平台) |
7 | * 4:超时发货(保证金 --> 买家 + 平台) | 9 | * 4:超时发货(保证金 --> 买家 + 平台) |
8 | * Created by chenchao on 2018/10/9. | 10 | * Created by chenchao on 2018/10/9. |
11 | + * 5:买家付款后[卖家未发货],取消订单(货款部分-->卖家); | ||
12 | + * 6:买家付款后[卖家已发货],取消订单(货款部分-->卖家); | ||
9 | */ | 13 | */ |
10 | public enum TransferCase { | 14 | public enum TransferCase { |
11 | 15 | ||
@@ -13,7 +17,9 @@ public enum TransferCase { | @@ -13,7 +17,9 @@ public enum TransferCase { | ||
13 | APPRAISE_SUCCESS(1), | 17 | APPRAISE_SUCCESS(1), |
14 | APPRAISE_FAIL(2), | 18 | APPRAISE_FAIL(2), |
15 | SELLER_PLAY_BUYER(3), | 19 | SELLER_PLAY_BUYER(3), |
16 | - DELIVER_TIME_OUT(4); | 20 | + DELIVER_TIME_OUT(4), |
21 | + BUYER_CANCEL_BEFORE_SELLER_DELIVER(5), | ||
22 | + BUYER_CANCEL_BEFORE_DEPOT_RECEIVE(6); | ||
17 | 23 | ||
18 | private int code; | 24 | private int code; |
19 | 25 | ||
@@ -24,4 +30,16 @@ public enum TransferCase { | @@ -24,4 +30,16 @@ public enum TransferCase { | ||
24 | public int getCode() { | 30 | public int getCode() { |
25 | return code; | 31 | return code; |
26 | } | 32 | } |
33 | + | ||
34 | + | ||
35 | + private static Map<Integer, TransferCase> cache; | ||
36 | + static { | ||
37 | + for(TransferCase tc: values()){ | ||
38 | + cache.put(tc.code, tc); | ||
39 | + } | ||
40 | + } | ||
41 | + | ||
42 | + public static TransferCase getTransferCase(Integer code){ | ||
43 | + return cache.get(code); | ||
44 | + } | ||
27 | } | 45 | } |
1 | package com.yohoufo.order.event; | 1 | package com.yohoufo.order.event; |
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.common.OrderStatus; | 3 | import com.yohobuy.ufo.model.order.common.OrderStatus; |
4 | +import com.yohoufo.common.alarm.Event; | ||
4 | import lombok.AllArgsConstructor; | 5 | import lombok.AllArgsConstructor; |
5 | import lombok.Data; | 6 | import lombok.Data; |
6 | import lombok.NoArgsConstructor; | 7 | import lombok.NoArgsConstructor; |
@@ -13,9 +14,16 @@ import lombok.experimental.Builder; | @@ -13,9 +14,16 @@ import lombok.experimental.Builder; | ||
13 | @Builder | 14 | @Builder |
14 | @NoArgsConstructor | 15 | @NoArgsConstructor |
15 | @AllArgsConstructor | 16 | @AllArgsConstructor |
16 | -public class BeforeDepotReceiveEvent extends BuyerCancelEvent { | 17 | +public class BeforeDepotReceiveEvent extends Event { |
18 | + private int buyerUid; | ||
19 | + | ||
20 | + private long orderCode; | ||
17 | 21 | ||
18 | private OrderStatus target; | 22 | private OrderStatus target; |
19 | 23 | ||
20 | private OrderStatus expected; | 24 | private OrderStatus expected; |
25 | + | ||
26 | + private int sellerUid; | ||
27 | + | ||
28 | + private int skup; | ||
21 | } | 29 | } |
1 | package com.yohoufo.order.event; | 1 | package com.yohoufo.order.event; |
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.common.OrderStatus; | 3 | import com.yohobuy.ufo.model.order.common.OrderStatus; |
4 | -import lombok.Data; | 4 | +import com.yohoufo.common.alarm.Event; |
5 | +import lombok.*; | ||
6 | +import lombok.experimental.Builder; | ||
5 | 7 | ||
6 | /** | 8 | /** |
7 | * Created by chao.chen on 2018/11/14. | 9 | * Created by chao.chen on 2018/11/14. |
8 | */ | 10 | */ |
9 | @Data | 11 | @Data |
12 | +@Builder | ||
13 | +@NoArgsConstructor | ||
14 | +@AllArgsConstructor | ||
15 | +public class BeforeSellerDeliverEvent extends Event { | ||
16 | + private int buyerUid; | ||
17 | + | ||
18 | + private long orderCode; | ||
10 | 19 | ||
11 | -public class BeforeSellerDeliverEvent extends BuyerCancelEvent { | ||
12 | private OrderStatus target; | 20 | private OrderStatus target; |
13 | 21 | ||
14 | private OrderStatus expected; | 22 | private OrderStatus expected; |
23 | + | ||
24 | + private int sellerUid; | ||
25 | + | ||
26 | + private int skup; | ||
15 | } | 27 | } |
1 | package com.yohoufo.order.model.request; | 1 | package com.yohoufo.order.model.request; |
2 | 2 | ||
3 | +import com.yohoufo.order.common.RefundCase; | ||
3 | import lombok.AllArgsConstructor; | 4 | import lombok.AllArgsConstructor; |
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | import lombok.NoArgsConstructor; | 6 | import lombok.NoArgsConstructor; |
@@ -25,4 +26,6 @@ public class PaymentRequest { | @@ -25,4 +26,6 @@ public class PaymentRequest { | ||
25 | private double refundAmount; | 26 | private double refundAmount; |
26 | 27 | ||
27 | private String openid; | 28 | private String openid; |
29 | + | ||
30 | + private RefundCase refundCase; | ||
28 | } | 31 | } |
order/src/main/java/com/yohoufo/order/service/handler/BuyerCancelCompensateComputeHandler.java
0 → 100644
1 | +package com.yohoufo.order.service.handler; | ||
2 | + | ||
3 | +import com.yohoufo.order.service.impl.OrderDynamicConfig; | ||
4 | +import org.springframework.stereotype.Component; | ||
5 | + | ||
6 | +import javax.annotation.Resource; | ||
7 | +import java.math.BigDecimal; | ||
8 | + | ||
9 | +/** | ||
10 | + * Created by chao.chen on 2018/11/16. | ||
11 | + */ | ||
12 | +@Component | ||
13 | +public class BuyerCancelCompensateComputeHandler { | ||
14 | + | ||
15 | + @Resource(name = "orderDynamicConfig") | ||
16 | + OrderDynamicConfig orderDynamicConfig; | ||
17 | + | ||
18 | + | ||
19 | + public BigDecimal calBeforeSellerDeliver(){ | ||
20 | + //todo 若后续改成动态配置时,需要实时计算 | ||
21 | + OrderDynamicConfig.BuyerCancelCompensateNode node = orderDynamicConfig.getBeforeSellerDeliverBCCN(); | ||
22 | + return node.getSellerGetMoney(); | ||
23 | + } | ||
24 | + | ||
25 | + public BigDecimal calBeforeDepotReceive(){ | ||
26 | + //todo 若后续改成动态配置时,需要实时计算 | ||
27 | + OrderDynamicConfig.BuyerCancelCompensateNode node = orderDynamicConfig.getBeforeDepotReceiveBCCN(); | ||
28 | + return node.getSellerGetMoney(); | ||
29 | + } | ||
30 | +} |
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | +import com.yohobuy.ufo.model.order.common.OrderStatus; | ||
4 | +import com.yohobuy.ufo.model.order.common.SkupStatus; | ||
5 | +import com.yohoufo.common.utils.DateUtil; | ||
6 | +import com.yohoufo.dal.order.BuyerOrderMapper; | ||
7 | +import com.yohoufo.dal.order.SellerOrderGoodsMapper; | ||
8 | +import com.yohoufo.dal.order.model.SellerOrderGoods; | ||
3 | import com.yohoufo.order.event.BeforeDepotReceiveEvent; | 9 | import com.yohoufo.order.event.BeforeDepotReceiveEvent; |
4 | import com.yohoufo.order.event.BeforeSellerDeliverEvent; | 10 | import com.yohoufo.order.event.BeforeSellerDeliverEvent; |
5 | import com.yohoufo.order.utils.LoggerUtils; | 11 | import com.yohoufo.order.utils.LoggerUtils; |
6 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | import org.springframework.beans.factory.annotation.Value; | 14 | import org.springframework.beans.factory.annotation.Value; |
8 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
9 | import org.springframework.web.bind.annotation.RequestParam; | 16 | import org.springframework.web.bind.annotation.RequestParam; |
@@ -20,19 +27,57 @@ public class BuyerOrderCancelService { | @@ -20,19 +27,57 @@ public class BuyerOrderCancelService { | ||
20 | @Resource(name = "orderDynamicConfig") | 27 | @Resource(name = "orderDynamicConfig") |
21 | private OrderDynamicConfig orderDynamicConfig; | 28 | private OrderDynamicConfig orderDynamicConfig; |
22 | 29 | ||
30 | + @Autowired | ||
31 | + private BuyerOrderMapper buyerOrderMapper; | ||
32 | + | ||
33 | + @Autowired | ||
34 | + private SellerOrderGoodsMapper sellerOrderGoodsMapper; | ||
35 | + | ||
23 | public void cancel(BeforeSellerDeliverEvent bsdEvent){ | 36 | public void cancel(BeforeSellerDeliverEvent bsdEvent){ |
24 | - Double compensate = orderDynamicConfig.getCOMPENSATE_BEFORE_SELLER_DELIVER(); | 37 | + OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeSellerDeliverBCCN(); |
38 | + | ||
25 | logger.info("in buyer cancel BeforeSellerDeliver, event {} compensate {}", bsdEvent, compensate); | 39 | logger.info("in buyer cancel BeforeSellerDeliver, event {} compensate {}", bsdEvent, compensate); |
40 | + int buyerUid = bsdEvent.getBuyerUid(); | ||
41 | + long orderCode = bsdEvent.getOrderCode(); | ||
42 | + OrderStatus target = bsdEvent.getTarget(); | ||
43 | + OrderStatus expected = bsdEvent.getExpected(); | ||
44 | + int currentTime = DateUtil.getCurrentTimeSecond(); | ||
45 | + int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expected.getCode(), target.getCode(), currentTime); | ||
46 | + if (rows>0) { | ||
47 | + int skup = bsdEvent.getSkup(); | ||
48 | + SellerOrderGoods targetGoods = new SellerOrderGoods(); | ||
49 | + targetGoods.setId(skup); | ||
50 | + targetGoods.setStatus(SkupStatus.BUYER_CANCEL_BEFORE_SELLER_DELIVER.getCode()); | ||
51 | + targetGoods.setExceptStatus(SkupStatus.SELL_OUT.getCode()); | ||
52 | + sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods); | ||
53 | + | ||
26 | //TODO 整个过程异步去执行(考虑退费依赖订单状态) | 54 | //TODO 整个过程异步去执行(考虑退费依赖订单状态) |
27 | //(退费)退保证金给卖家 | 55 | //(退费)退保证金给卖家 |
28 | //(转账)瓜分指定赔偿款给卖家和平台 | 56 | //(转账)瓜分指定赔偿款给卖家和平台 |
29 | //(退费)扣除赔偿款,计算剩余的货款,退给买家 | 57 | //(退费)扣除赔偿款,计算剩余的货款,退给买家 |
58 | + | ||
59 | + } | ||
30 | } | 60 | } |
31 | 61 | ||
32 | 62 | ||
33 | public void cancel(BeforeDepotReceiveEvent bdrEvent){ | 63 | public void cancel(BeforeDepotReceiveEvent bdrEvent){ |
34 | - Double compensate = orderDynamicConfig.getCOMPENSATE_BEFORE_DEPOT_RECEIVE(); | 64 | + OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeDepotReceiveBCCN(); |
35 | logger.info("in buyer cancel BeforeDepotReceive, event {} compensate {}", bdrEvent, compensate); | 65 | logger.info("in buyer cancel BeforeDepotReceive, event {} compensate {}", bdrEvent, compensate); |
66 | + | ||
67 | + OrderStatus target = bdrEvent.getTarget(); | ||
68 | + OrderStatus expected = bdrEvent.getExpected(); | ||
69 | + int buyerUid = bdrEvent.getBuyerUid(); | ||
70 | + long orderCode = bdrEvent.getOrderCode(); | ||
71 | + int currentTime = DateUtil.getCurrentTimeSecond(); | ||
72 | + int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expected.getCode(), target.getCode(), currentTime); | ||
73 | + if (rows>0) { | ||
74 | + int skup = bdrEvent.getSkup(); | ||
75 | + SellerOrderGoods targetGoods = new SellerOrderGoods(); | ||
76 | + targetGoods.setId(skup); | ||
77 | + targetGoods.setStatus(SkupStatus.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE.getCode()); | ||
78 | + targetGoods.setExceptStatus(SkupStatus.SELL_OUT.getCode()); | ||
79 | + sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods); | ||
80 | + | ||
36 | //TODO 整个过程异步去执行(考虑退费依赖订单状态) | 81 | //TODO 整个过程异步去执行(考虑退费依赖订单状态) |
37 | //(退费)退保证金给卖家 | 82 | //(退费)退保证金给卖家 |
38 | //(转账)瓜分指定赔偿款给卖家和平台 | 83 | //(转账)瓜分指定赔偿款给卖家和平台 |
@@ -40,6 +85,9 @@ public class BuyerOrderCancelService { | @@ -40,6 +85,9 @@ public class BuyerOrderCancelService { | ||
40 | } | 85 | } |
41 | 86 | ||
42 | 87 | ||
88 | + } | ||
89 | + | ||
90 | + | ||
43 | 91 | ||
44 | 92 | ||
45 | } | 93 | } |
@@ -143,21 +143,25 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | @@ -143,21 +143,25 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | ||
143 | cancelBeforePaid(orderRequest, node, expectStatus, targetStatus); | 143 | cancelBeforePaid(orderRequest, node, expectStatus, targetStatus); |
144 | break; | 144 | break; |
145 | case HAS_PAYED: | 145 | case HAS_PAYED: |
146 | + BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(), | ||
147 | + orderRequest.getOrderCode()); | ||
148 | + int skup = bog.getSkup(); | ||
146 | targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_SELLER_DELIVER; | 149 | targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_SELLER_DELIVER; |
147 | - BeforeSellerDeliverEvent bsde = new BeforeSellerDeliverEvent(); | ||
148 | - bsde.setUid(orderRequest.getUid()); | ||
149 | - bsde.setOrderCode(orderRequest.getOrderCode()); | ||
150 | - bsde.setExpected(expectStatus); | ||
151 | - bsde.setTarget(targetStatus); | 150 | + BeforeSellerDeliverEvent bsde = BeforeSellerDeliverEvent.builder() |
151 | + .buyerUid(orderRequest.getUid()).orderCode(orderRequest.getOrderCode()) | ||
152 | + .expected(expectStatus).target(targetStatus).skup(skup).sellerUid(buyerOrder.getSellerUid()) | ||
153 | + .build(); | ||
152 | buyerOrderCancelService.cancel(bsde); | 154 | buyerOrderCancelService.cancel(bsde); |
153 | break; | 155 | break; |
154 | case SELLER_SEND_OUT: | 156 | case SELLER_SEND_OUT: |
157 | + bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(), | ||
158 | + orderRequest.getOrderCode()); | ||
159 | + skup = bog.getSkup(); | ||
155 | targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE; | 160 | targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE; |
156 | - BeforeDepotReceiveEvent bdre = new BeforeDepotReceiveEvent(); | ||
157 | - bdre.setUid(orderRequest.getUid()); | ||
158 | - bdre.setOrderCode(orderRequest.getOrderCode()); | ||
159 | - bdre.setExpected(expectStatus); | ||
160 | - bdre.setTarget(targetStatus); | 161 | + BeforeDepotReceiveEvent bdre = BeforeDepotReceiveEvent.builder() |
162 | + .buyerUid(orderRequest.getUid()).orderCode(orderRequest.getOrderCode()) | ||
163 | + .expected(expectStatus).target(targetStatus).skup(skup).sellerUid(buyerOrder.getSellerUid()) | ||
164 | + .build(); | ||
161 | buyerOrderCancelService.cancel(bdre); | 165 | buyerOrderCancelService.cancel(bdre); |
162 | break; | 166 | break; |
163 | } | 167 | } |
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | +import com.yohoufo.common.utils.BigDecimalHelper; | ||
3 | import lombok.Data; | 4 | import lombok.Data; |
5 | +import lombok.Getter; | ||
6 | +import org.slf4j.Logger; | ||
7 | +import org.slf4j.LoggerFactory; | ||
4 | import org.springframework.beans.factory.annotation.Value; | 8 | import org.springframework.beans.factory.annotation.Value; |
5 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
6 | 10 | ||
11 | +import javax.annotation.PostConstruct; | ||
12 | +import java.math.BigDecimal; | ||
13 | + | ||
7 | /** | 14 | /** |
8 | * Created by chao.chen on 2018/11/15. | 15 | * Created by chao.chen on 2018/11/15. |
9 | */ | 16 | */ |
10 | @Component("orderDynamicConfig") | 17 | @Component("orderDynamicConfig") |
11 | -@Data | 18 | + |
12 | public class OrderDynamicConfig { | 19 | public class OrderDynamicConfig { |
13 | 20 | ||
14 | - @Value("${order.buyer.compensate.before_seller_deliver}") | ||
15 | - private Double COMPENSATE_BEFORE_SELLER_DELIVER; | 21 | + final private Logger logger = LoggerFactory.getLogger(getClass()); |
22 | + | ||
23 | + @Data | ||
24 | + public static class BuyerCancelCompensateNode{ | ||
25 | + /** | ||
26 | + * 卖家赔偿金额 | ||
27 | + */ | ||
28 | + private BigDecimal buyerCompensateMoney; | ||
29 | + /** | ||
30 | + * 卖家获取的赔偿金额 | ||
31 | + */ | ||
32 | + private BigDecimal sellerGetMoney; | ||
33 | + /** | ||
34 | + * 赔偿比例 | ||
35 | + */ | ||
36 | + private BigDecimal compensateRate; | ||
16 | 37 | ||
17 | - @Value("${order.buyer.compensate.before_depot_receive}") | ||
18 | - private Double COMPENSATE_BEFORE_DEPOT_RECEIVE; | 38 | + public BuyerCancelCompensateNode(BigDecimal buyerCompensateMoney, BigDecimal compensateRate) { |
39 | + this.buyerCompensateMoney = buyerCompensateMoney; | ||
40 | + this.compensateRate = compensateRate; | ||
41 | + this.sellerGetMoney = BigDecimalHelper.halfUp(buyerCompensateMoney.multiply(compensateRate)); | ||
42 | + } | ||
43 | + } | ||
19 | 44 | ||
45 | + /** | ||
46 | + * 卖家发货前 | ||
47 | + */ | ||
48 | + @Value("${order.buyer.cancelWhenSellerUnDelivery.money}") | ||
49 | + private String buyerCancelUnDelivery; | ||
50 | + @Value("${order.buyer.cancelWhenSellerUnDelivery.sellerGetMoneyRate}") | ||
51 | + private String sellerGetRateUnDelivery; | ||
52 | + /** | ||
53 | + * 卖家发货后 鉴定中心收货前 | ||
54 | + */ | ||
55 | + @Value("${order.buyer.cancelWhenSellerDelivery.money}") | ||
56 | + private String buyerCancelDelivery; | ||
57 | + @Value("${order.buyer.cancelWhenSellerDelivery.sellerGetMoneyRate}") | ||
58 | + private String sellerGetRateDelivery; | ||
20 | 59 | ||
21 | - public void set(OrderDynamicConfig config){ | ||
22 | - if (config == null){ | ||
23 | - return; | 60 | + /** |
61 | + * 卖家发货,买家赔偿金额 比例 ,卖家获取金额 | ||
62 | + */ | ||
63 | + @Getter | ||
64 | + private BuyerCancelCompensateNode beforeSellerDeliverBCCN; | ||
65 | + /** | ||
66 | + * 卖家未发货,买家赔偿金额 | ||
67 | + */ | ||
68 | + @Getter | ||
69 | + private BuyerCancelCompensateNode beforeDepotReceiveBCCN; | ||
70 | + | ||
71 | + | ||
72 | + @PostConstruct | ||
73 | + private void init() { | ||
74 | + BigDecimal buyerCancelUnDeliveryMoney , beforeSellerDeliverRate; | ||
75 | + BigDecimal buyerCancelDeliveryMoney, beforeDepotReceiveRate; | ||
76 | + try { | ||
77 | + buyerCancelDeliveryMoney = new BigDecimal(buyerCancelUnDelivery); | ||
78 | + beforeSellerDeliverRate = new BigDecimal( sellerGetRateUnDelivery); | ||
79 | + | ||
80 | + //包装结构时做格式化,之前请保留有效位 | ||
81 | + beforeSellerDeliverBCCN = new BuyerCancelCompensateNode(BigDecimalHelper.halfUp(buyerCancelDeliveryMoney), | ||
82 | + BigDecimalHelper.halfUp(beforeSellerDeliverRate) ); | ||
83 | + | ||
84 | + buyerCancelUnDeliveryMoney = new BigDecimal(buyerCancelDelivery); | ||
85 | + beforeDepotReceiveRate = new BigDecimal(sellerGetRateDelivery); | ||
86 | + beforeDepotReceiveBCCN = new BuyerCancelCompensateNode(buyerCancelUnDeliveryMoney, beforeDepotReceiveRate); | ||
87 | + } catch (Exception e) { | ||
88 | + logger.error("买家取消罚款金额相关参数配置错误!", e); | ||
89 | + throw new Error("买家取消罚款金额相关参数配置错误!"); | ||
90 | + } | ||
91 | + if (buyerCancelDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) { | ||
92 | + throw new Error("buyerCancelDeliveryMoney买家取消(货已寄出)罚款金额不能为负数"); | ||
24 | } | 93 | } |
25 | - if(config.COMPENSATE_BEFORE_SELLER_DELIVER>0D){ | ||
26 | - this.COMPENSATE_BEFORE_SELLER_DELIVER = config.COMPENSATE_BEFORE_SELLER_DELIVER; | 94 | + if (buyerCancelUnDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) { |
95 | + throw new Error("buyerCancelUnDeliveryMoney买家取消(货未寄出)罚款金额不能为负数"); | ||
27 | } | 96 | } |
28 | - if(config.COMPENSATE_BEFORE_DEPOT_RECEIVE>0D){ | ||
29 | - this.COMPENSATE_BEFORE_DEPOT_RECEIVE = config.COMPENSATE_BEFORE_DEPOT_RECEIVE; | 97 | + if (beforeDepotReceiveRate.compareTo(BigDecimal.ZERO) < 0 |
98 | + || beforeDepotReceiveRate.compareTo(BigDecimal.ONE) > 0) { | ||
99 | + throw new Error("sellerGetRateDeliveryMoney买家取消(货已寄出)卖家获得赔偿比率必须在[0,1]"); | ||
30 | } | 100 | } |
101 | + if (beforeSellerDeliverRate.compareTo(BigDecimal.ZERO) < 0 | ||
102 | + || beforeSellerDeliverRate.compareTo(BigDecimal.ONE) > 0) { | ||
103 | + throw new Error("sellerGetRateUnDeliveryMoney买家取消(货未寄出)卖家获得赔偿比率必须在[0,1]"); | ||
31 | } | 104 | } |
105 | + } | ||
106 | + | ||
32 | } | 107 | } |
@@ -17,6 +17,7 @@ import com.yohoufo.common.utils.TimeUtils; | @@ -17,6 +17,7 @@ import com.yohoufo.common.utils.TimeUtils; | ||
17 | import com.yohoufo.dal.order.*; | 17 | import com.yohoufo.dal.order.*; |
18 | import com.yohoufo.dal.order.model.*; | 18 | import com.yohoufo.dal.order.model.*; |
19 | import com.yohoufo.order.common.Payment; | 19 | import com.yohoufo.order.common.Payment; |
20 | +import com.yohoufo.order.common.TransferCase; | ||
20 | import com.yohoufo.order.constants.RefundContant; | 21 | import com.yohoufo.order.constants.RefundContant; |
21 | import com.yohoufo.order.model.PayQueryBo; | 22 | import com.yohoufo.order.model.PayQueryBo; |
22 | import com.yohoufo.order.model.PayRefundBo; | 23 | import com.yohoufo.order.model.PayRefundBo; |
@@ -29,6 +30,7 @@ import com.yohoufo.order.service.AbstractOrderPaymentService; | @@ -29,6 +30,7 @@ import com.yohoufo.order.service.AbstractOrderPaymentService; | ||
29 | import com.yohoufo.order.service.BuyerOrderPaymentService; | 30 | import com.yohoufo.order.service.BuyerOrderPaymentService; |
30 | import com.yohoufo.order.service.IPaymentService; | 31 | import com.yohoufo.order.service.IPaymentService; |
31 | import com.yohoufo.order.service.SellerOrderPaymentService; | 32 | import com.yohoufo.order.service.SellerOrderPaymentService; |
33 | +import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler; | ||
32 | import com.yohoufo.order.service.pay.AbstractPayService; | 34 | import com.yohoufo.order.service.pay.AbstractPayService; |
33 | import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; | 35 | import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; |
34 | import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService; | 36 | import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService; |
@@ -52,7 +54,18 @@ import javax.annotation.PostConstruct; | @@ -52,7 +54,18 @@ import javax.annotation.PostConstruct; | ||
52 | 54 | ||
53 | @Service | 55 | @Service |
54 | public class PaymentServiceImpl implements IPaymentService { | 56 | public class PaymentServiceImpl implements IPaymentService { |
57 | + public enum TargetUserType { | ||
58 | + buyer(1),seller(2); | ||
59 | + int code; | ||
55 | 60 | ||
61 | + TargetUserType(int code) { | ||
62 | + this.code = code; | ||
63 | + } | ||
64 | + | ||
65 | + public int getCode() { | ||
66 | + return code; | ||
67 | + } | ||
68 | + } | ||
56 | private static final Logger logger = LoggerUtils.getPayConfirmLogger(); | 69 | private static final Logger logger = LoggerUtils.getPayConfirmLogger(); |
57 | 70 | ||
58 | 71 | ||
@@ -104,19 +117,10 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -104,19 +117,10 @@ public class PaymentServiceImpl implements IPaymentService { | ||
104 | @Autowired | 117 | @Autowired |
105 | TradeBillsMapper tradeBillsMapper; | 118 | TradeBillsMapper tradeBillsMapper; |
106 | 119 | ||
107 | - @Value("${order.buyer.cancelWhenSellerDelivery.money}") | ||
108 | - private String buyerCancelDelivery; | ||
109 | - @Value("${order.buyer.cancelWhenSellerUnDelivery.money}") | ||
110 | - private String buyerCancelUnDelivery; | ||
111 | - @Value("${order.buyer.cancelWhenSellerDelivery.sellerGetMoneyRate}") | ||
112 | - private String sellerGetRateDelivery; | ||
113 | - @Value("${order.buyer.cancelWhenSellerUnDelivery.sellerGetMoneyRate}") | ||
114 | - private String sellerGetRateUnDelivery; | 120 | + @Autowired |
121 | + private BuyerCancelCompensateComputeHandler buyerCancelCompensateComputeHandler; | ||
122 | + | ||
115 | 123 | ||
116 | - private BigDecimal buyerCancelDeliveryMoney; | ||
117 | - private BigDecimal buyerCancelUnDeliveryMoney; | ||
118 | - private BigDecimal sellerGetRateDeliveryMoney; | ||
119 | - private BigDecimal sellerGetRateUnDeliveryMoney; | ||
120 | 124 | ||
121 | /** | 125 | /** |
122 | * 获取主场的订单service | 126 | * 获取主场的订单service |
@@ -418,6 +422,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -418,6 +422,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
418 | } | 422 | } |
419 | 423 | ||
420 | 424 | ||
425 | + | ||
421 | /** | 426 | /** |
422 | * <pre> | 427 | * <pre> |
423 | * 1:鉴定通过(货款-->卖家); | 428 | * 1:鉴定通过(货款-->卖家); |
@@ -433,18 +438,17 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -433,18 +438,17 @@ public class PaymentServiceImpl implements IPaymentService { | ||
433 | @Database(ForceMaster = true) | 438 | @Database(ForceMaster = true) |
434 | public void transferMon(TransferMoneyRequest request){ | 439 | public void transferMon(TransferMoneyRequest request){ |
435 | logger.info("transferMon转账开始,request = {}", request); | 440 | logger.info("transferMon转账开始,request = {}", request); |
436 | - | ||
437 | long buyerOrderCode = request.getBuyerOrderCode(); | 441 | long buyerOrderCode = request.getBuyerOrderCode(); |
438 | - int transferType = request.getType(); | ||
439 | - | ||
440 | logger.info("transferMon参数检查"); | 442 | logger.info("transferMon参数检查"); |
441 | // 订单号check | 443 | // 订单号check |
442 | - if (buyerOrderCode < 1) { | 444 | + if (buyerOrderCode < 1L) { |
443 | logger.warn("transferMonErr orderCode empty"); | 445 | logger.warn("transferMonErr orderCode empty"); |
444 | throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); | 446 | throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); |
445 | } | 447 | } |
446 | // 类型检查 | 448 | // 类型检查 |
447 | - if (transferType < 1 || transferType > 5) { | 449 | + int transferType = request.getType(); |
450 | + TransferCase transferCase = TransferCase.getTransferCase(transferType); | ||
451 | + if (transferCase == null) { | ||
448 | logger.warn("transferMonErr transferType invalid"); | 452 | logger.warn("transferMonErr transferType invalid"); |
449 | throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); | 453 | throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); |
450 | } | 454 | } |
@@ -470,8 +474,10 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -470,8 +474,10 @@ public class PaymentServiceImpl implements IPaymentService { | ||
470 | } | 474 | } |
471 | 475 | ||
472 | long sellerOrderCode = sellerOrder.getOrderCode(); | 476 | long sellerOrderCode = sellerOrder.getOrderCode(); |
473 | - Integer targetUserType = (transferType == 2 || transferType == 3) ? 1 : 2; | ||
474 | - Integer targetUid = targetUserType == 1 ? buyerOrder.getUid() : sellerOrder.getUid(); | 477 | + TargetUserType targetUserType = (transferType == TransferCase.APPRAISE_FAIL.getCode() |
478 | + || transferType == TransferCase.SELLER_PLAY_BUYER.getCode()) ? TargetUserType.buyer : TargetUserType.seller; | ||
479 | + //Integer targetUserType = (transferType == 2 || transferType == 3) ? 1 : 2; | ||
480 | + Integer targetUid = targetUserType == TargetUserType.buyer ? buyerOrder.getUid() : sellerOrder.getUid(); | ||
475 | 481 | ||
476 | if (targetUid == null || targetUid < 1) { | 482 | if (targetUid == null || targetUid < 1) { |
477 | logger.warn("transferMonErr uid {} 不合法", targetUid); | 483 | logger.warn("transferMonErr uid {} 不合法", targetUid); |
@@ -508,7 +514,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -508,7 +514,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
508 | TradeBills record = new TradeBills(); | 514 | TradeBills record = new TradeBills(); |
509 | record.setUid(targetUid); | 515 | record.setUid(targetUid); |
510 | record.setOrderCode(buyerOrderCode); | 516 | record.setOrderCode(buyerOrderCode); |
511 | - record.setUserType(targetUserType); | 517 | + record.setUserType(targetUserType.getCode()); |
512 | record.setPayType(1); | 518 | record.setPayType(1); |
513 | record.setTradeType(transferType == 1 ? 2 : 3); | 519 | record.setTradeType(transferType == 1 ? 2 : 3); |
514 | record.setIncomeOutcome(1); | 520 | record.setIncomeOutcome(1); |
@@ -520,7 +526,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -520,7 +526,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
520 | 526 | ||
521 | logger.info("transferMon插入初始化转账信息成功,接下来计算费用"); | 527 | logger.info("transferMon插入初始化转账信息成功,接下来计算费用"); |
522 | // 算费 | 528 | // 算费 |
523 | - BigDecimal transferAmount = calcTransferAmount(sellerOrder.getUid(), sellerOrder.getSkup(), transferType); | 529 | + BigDecimal transferAmount = calcTransferAmount(sellerOrder.getUid(), sellerOrder.getSkup(), transferCase); |
524 | logger.info("transferMon计算费用结果为 {}", transferAmount); | 530 | logger.info("transferMon计算费用结果为 {}", transferAmount); |
525 | if (transferAmount == null) { | 531 | if (transferAmount == null) { |
526 | logger.warn("transferMonErr transferMon计算费用结果为 null, 不合法的金额"); | 532 | logger.warn("transferMonErr transferMon计算费用结果为 null, 不合法的金额"); |
@@ -917,14 +923,21 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -917,14 +923,21 @@ public class PaymentServiceImpl implements IPaymentService { | ||
917 | addTradeBills(record); | 923 | addTradeBills(record); |
918 | } | 924 | } |
919 | 925 | ||
926 | + private BigDecimal getBuyerCancelBeforeSellerDeliver(){ | ||
927 | + //todo | ||
928 | + return buyerCancelCompensateComputeHandler.calBeforeSellerDeliver(); | ||
929 | + } | ||
930 | + private BigDecimal getBuyerCancelBeforeDepotReceive(){ | ||
931 | + //todo | ||
932 | + return buyerCancelCompensateComputeHandler.calBeforeDepotReceive(); | ||
933 | + } | ||
920 | 934 | ||
921 | - | ||
922 | - private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, int transferType) { | ||
923 | - if (transferType == 4) { | ||
924 | - return sellerGetRateUnDeliveryMoney; | 935 | + private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, TransferCase transferCase) { |
936 | + if (transferCase == TransferCase.BUYER_CANCEL_BEFORE_SELLER_DELIVER) { | ||
937 | + return getBuyerCancelBeforeSellerDeliver(); | ||
925 | } | 938 | } |
926 | - if (transferType == 5) { | ||
927 | - return sellerGetRateDeliveryMoney; | 939 | + if (transferCase == TransferCase.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE) { |
940 | + return getBuyerCancelBeforeDepotReceive(); | ||
928 | } | 941 | } |
929 | 942 | ||
930 | SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee"); | 943 | SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee"); |
@@ -940,7 +953,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -940,7 +953,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
940 | try { | 953 | try { |
941 | JSONObject metavalue = JSON.parseObject(meta.getMetaValue()); | 954 | JSONObject metavalue = JSON.parseObject(meta.getMetaValue()); |
942 | // 交易成功的情况 | 955 | // 交易成功的情况 |
943 | - if (transferType == 1) { | 956 | + if (transferCase == TransferCase.APPRAISE_SUCCESS) { |
944 | return metavalue.getBigDecimal("income"); | 957 | return metavalue.getBigDecimal("income"); |
945 | } | 958 | } |
946 | // (1-Y)*A | 959 | // (1-Y)*A |
@@ -1048,33 +1061,6 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -1048,33 +1061,6 @@ public class PaymentServiceImpl implements IPaymentService { | ||
1048 | CommonAlarmEventPublisher.publish(name, type, content); | 1061 | CommonAlarmEventPublisher.publish(name, type, content); |
1049 | } | 1062 | } |
1050 | 1063 | ||
1051 | - @PostConstruct | ||
1052 | - private void init() { | ||
1053 | - try { | ||
1054 | - buyerCancelDeliveryMoney = new BigDecimal(buyerCancelUnDelivery); | ||
1055 | - buyerCancelUnDeliveryMoney = new BigDecimal(buyerCancelUnDelivery); | ||
1056 | - sellerGetRateDeliveryMoney = buyerCancelDeliveryMoney.multiply(new BigDecimal(sellerGetRateDelivery)) | ||
1057 | - .setScale(2, BigDecimal.ROUND_HALF_DOWN); | ||
1058 | - sellerGetRateUnDeliveryMoney = buyerCancelUnDeliveryMoney.multiply(new BigDecimal(sellerGetRateUnDelivery)) | ||
1059 | - .setScale(2, BigDecimal.ROUND_HALF_DOWN); | ||
1060 | - } catch (Exception e) { | ||
1061 | - logger.error("买家取消罚款金额相关参数配置错误!", e); | ||
1062 | - throw new Error("买家取消罚款金额相关参数配置错误!"); | ||
1063 | - } | ||
1064 | - if (buyerCancelDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) { | ||
1065 | - throw new Error("buyerCancelDeliveryMoney买家取消(货已寄出)罚款金额不能为负数"); | ||
1066 | - } | ||
1067 | - if (buyerCancelUnDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) { | ||
1068 | - throw new Error("buyerCancelUnDeliveryMoney买家取消(货未寄出)罚款金额不能为负数"); | ||
1069 | - } | ||
1070 | - if (sellerGetRateDeliveryMoney.compareTo(BigDecimal.ZERO) < 0 | ||
1071 | - || sellerGetRateDeliveryMoney.compareTo(BigDecimal.ONE) > 0) { | ||
1072 | - throw new Error("sellerGetRateDeliveryMoney买家取消(货已寄出)卖家获得赔偿比率必须在[0,1]"); | ||
1073 | - } | ||
1074 | - if (sellerGetRateUnDeliveryMoney.compareTo(BigDecimal.ZERO) < 0 | ||
1075 | - || sellerGetRateUnDeliveryMoney.compareTo(BigDecimal.ONE) > 0) { | ||
1076 | - throw new Error("sellerGetRateUnDeliveryMoney买家取消(货未寄出)卖家获得赔偿比率必须在[0,1]"); | ||
1077 | - } | ||
1078 | - } | 1064 | + |
1079 | 1065 | ||
1080 | } | 1066 | } |
-
Please register or login to post a comment