Merge branch 'dev_order_6.8.6' into test6.8.6
Showing
10 changed files
with
341 additions
and
200 deletions
@@ -15,7 +15,7 @@ import com.yohoufo.dal.order.model.SellerOrder; | @@ -15,7 +15,7 @@ import com.yohoufo.dal.order.model.SellerOrder; | ||
15 | import com.yohoufo.order.model.request.OrderListRequest; | 15 | import com.yohoufo.order.model.request.OrderListRequest; |
16 | import com.yohoufo.order.model.request.OrderRequest; | 16 | import com.yohoufo.order.model.request.OrderRequest; |
17 | import com.yohoufo.order.model.response.OrderSubmitResp; | 17 | import com.yohoufo.order.model.response.OrderSubmitResp; |
18 | -import com.yohoufo.order.service.handler.SellerOrderComputeHandler; | 18 | +import com.yohoufo.order.service.impl.OrderDynamicConfig; |
19 | import com.yohoufo.order.service.impl.SellerOrderService; | 19 | import com.yohoufo.order.service.impl.SellerOrderService; |
20 | import com.yohoufo.order.service.impl.SellerService; | 20 | import com.yohoufo.order.service.impl.SellerService; |
21 | import com.yohoufo.order.service.impl.SkupListService; | 21 | import com.yohoufo.order.service.impl.SkupListService; |
@@ -44,7 +44,7 @@ public class SellerOrderController { | @@ -44,7 +44,7 @@ public class SellerOrderController { | ||
44 | private SellerOrderService sellerOrderService; | 44 | private SellerOrderService sellerOrderService; |
45 | 45 | ||
46 | @Autowired | 46 | @Autowired |
47 | - private SellerOrderComputeHandler sellerOrderComputeHandler; | 47 | + protected OrderDynamicConfig orderDynamicConfig; |
48 | 48 | ||
49 | @Autowired | 49 | @Autowired |
50 | private SellerService sellerService; | 50 | private SellerService sellerService; |
@@ -211,7 +211,7 @@ public class SellerOrderController { | @@ -211,7 +211,7 @@ public class SellerOrderController { | ||
211 | @ResponseBody | 211 | @ResponseBody |
212 | public ApiResponse getEarnestMoneyRange(){ | 212 | public ApiResponse getEarnestMoneyRange(){ |
213 | return new ApiResponse.ApiResponseBuilder() | 213 | return new ApiResponse.ApiResponseBuilder() |
214 | - .data(sellerOrderComputeHandler.getEarnestMoneyrange()) | 214 | + .data(orderDynamicConfig.getEMR()) |
215 | .message("get EarnestMoneyrange success").build(); | 215 | .message("get EarnestMoneyrange success").build(); |
216 | } | 216 | } |
217 | 217 | ||
@@ -231,7 +231,8 @@ public class SellerOrderController { | @@ -231,7 +231,8 @@ public class SellerOrderController { | ||
231 | public ApiResponse batchChangePrice(@RequestParam(name = "uid", required = true)int uid, | 231 | public ApiResponse batchChangePrice(@RequestParam(name = "uid", required = true)int uid, |
232 | @RequestParam(name = "price", required = true)String price, | 232 | @RequestParam(name = "price", required = true)String price, |
233 | @RequestParam(name = "batchNo", required = true)String batchNo, | 233 | @RequestParam(name = "batchNo", required = true)String batchNo, |
234 | - @RequestParam(name = "skupList", required = true)String skupList | 234 | + @RequestParam(name = "skupList", required = true)String skupList, |
235 | + @RequestParam(name="skupType", defaultValue = DEFAULT_SKUP_TYPE, required = false) Integer skupType | ||
235 | 236 | ||
236 | ) throws GatewayException { | 237 | ) throws GatewayException { |
237 | 238 | ||
@@ -241,6 +242,7 @@ public class SellerOrderController { | @@ -241,6 +242,7 @@ public class SellerOrderController { | ||
241 | req.setShowPriceError(true); | 242 | req.setShowPriceError(true); |
242 | req.setBatchNo(batchNo); | 243 | req.setBatchNo(batchNo); |
243 | req.setSkupList(skupList); | 244 | req.setSkupList(skupList); |
245 | + req.setSkupType(skupType); | ||
244 | logger.info("in ufo.sellerOrder.batchChangePrice, req {}", req); | 246 | logger.info("in ufo.sellerOrder.batchChangePrice, req {}", req); |
245 | BatchChangePriceResp result = sellerOrderService.batchChangePrice(req); | 247 | BatchChangePriceResp result = sellerOrderService.batchChangePrice(req); |
246 | 248 | ||
@@ -269,7 +271,8 @@ public class SellerOrderController { | @@ -269,7 +271,8 @@ public class SellerOrderController { | ||
269 | @RequestParam(name="price", required = true)String price, | 271 | @RequestParam(name="price", required = true)String price, |
270 | @RequestParam(name = "batchNo", required = false)String batchNo, | 272 | @RequestParam(name = "batchNo", required = false)String batchNo, |
271 | @RequestParam(name = "skupList", required = false)String skupList, | 273 | @RequestParam(name = "skupList", required = false)String skupList, |
272 | - @RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException { | 274 | + @RequestParam(name="num", defaultValue = "1", required = false)int num, |
275 | + @RequestParam(name="skupType", defaultValue = DEFAULT_SKUP_TYPE, required = false) Integer skupType) throws GatewayException { | ||
273 | 276 | ||
274 | BatchChangePriceReq req = new BatchChangePriceReq(); | 277 | BatchChangePriceReq req = new BatchChangePriceReq(); |
275 | req.setStorageId(storage_id); | 278 | req.setStorageId(storage_id); |
@@ -278,6 +281,7 @@ public class SellerOrderController { | @@ -278,6 +281,7 @@ public class SellerOrderController { | ||
278 | req.setBatchNo(batchNo); | 281 | req.setBatchNo(batchNo); |
279 | req.setSkupList(skupList); | 282 | req.setSkupList(skupList); |
280 | req.setShowPriceError(false); | 283 | req.setShowPriceError(false); |
284 | + req.setSkupType(skupType); | ||
281 | logger.info("in ufo.sellerOrder.computeChangePrice, req {}", req); | 285 | logger.info("in ufo.sellerOrder.computeChangePrice, req {}", req); |
282 | SoldPrdComputeBo computeBo = sellerOrderService.computeChangePrice(req); | 286 | SoldPrdComputeBo computeBo = sellerOrderService.computeChangePrice(req); |
283 | return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build(); | 287 | return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build(); |
@@ -303,7 +307,9 @@ public class SellerOrderController { | @@ -303,7 +307,9 @@ public class SellerOrderController { | ||
303 | @RequestParam(name = "old_price") BigDecimal old_price, | 307 | @RequestParam(name = "old_price") BigDecimal old_price, |
304 | @RequestParam(name = "new_price") String new_price, | 308 | @RequestParam(name = "new_price") String new_price, |
305 | @RequestParam(name = "product_id") int product_id, | 309 | @RequestParam(name = "product_id") int product_id, |
306 | - @RequestParam(name = "num") int num) throws GatewayException { | 310 | + @RequestParam(name = "num") int num, |
311 | + @RequestParam(name="skupType", defaultValue = DEFAULT_SKUP_TYPE, required = false) Integer skupType | ||
312 | + ) throws GatewayException { | ||
307 | SellerBatchChangeReq req = new SellerBatchChangeReq(); | 313 | SellerBatchChangeReq req = new SellerBatchChangeReq(); |
308 | req.setStorageId(storage_id); | 314 | req.setStorageId(storage_id); |
309 | req.setUid(uid); | 315 | req.setUid(uid); |
@@ -312,6 +318,7 @@ public class SellerOrderController { | @@ -312,6 +318,7 @@ public class SellerOrderController { | ||
312 | req.setProductId(product_id); | 318 | req.setProductId(product_id); |
313 | req.setNum(num); | 319 | req.setNum(num); |
314 | req.setShowPriceError(false); | 320 | req.setShowPriceError(false); |
321 | + req.setSkupType(skupType); | ||
315 | logger.info("in ufo.sellerOrder.computeAdjustPrice, req {}", req); | 322 | logger.info("in ufo.sellerOrder.computeAdjustPrice, req {}", req); |
316 | try { | 323 | try { |
317 | SoldPrdComputeBo computeBo = sellerOrderService.computeAdjustPrice(req); | 324 | SoldPrdComputeBo computeBo = sellerOrderService.computeAdjustPrice(req); |
1 | package com.yohoufo.order.service.handler; | 1 | package com.yohoufo.order.service.handler; |
2 | 2 | ||
3 | -import com.yohoufo.common.utils.BigDecimalHelper; | ||
4 | import com.yohoufo.order.model.dto.EarnestMoney; | 3 | import com.yohoufo.order.model.dto.EarnestMoney; |
5 | -import com.yohoufo.order.model.dto.PlatformFeeDto; | ||
6 | -import com.yohoufo.order.model.dto.SellerOrderComputeResult; | ||
7 | import com.yohoufo.order.model.dto.ServiceFeeRate; | 4 | import com.yohoufo.order.model.dto.ServiceFeeRate; |
8 | -import com.yohoufo.order.utils.LoggerUtils; | ||
9 | -import org.slf4j.Logger; | ||
10 | -import org.slf4j.LoggerFactory; | ||
11 | -import org.springframework.beans.factory.annotation.Value; | 5 | +import com.yohoufo.order.service.seller.AbsSellerOrderComputeHandler; |
6 | +import com.yohoufo.order.service.seller.OrderComputeHandler; | ||
12 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
13 | 8 | ||
14 | -import javax.annotation.PostConstruct; | ||
15 | import java.math.BigDecimal; | 9 | import java.math.BigDecimal; |
16 | 10 | ||
17 | /** | 11 | /** |
18 | * Created by chenchao on 2018/9/14. | 12 | * Created by chenchao on 2018/9/14. |
19 | */ | 13 | */ |
20 | @Component | 14 | @Component |
21 | -public class SellerOrderComputeHandler { | ||
22 | - | ||
23 | - private Logger logger = LoggerUtils.getSellerOrderLogger(); | ||
24 | - | ||
25 | - @Value("${order.seller.earnestmoney.min:28}") | ||
26 | - private double earnestmoney_min; | ||
27 | - @Value("${order.seller.earnestmoney.max:200}") | ||
28 | - private double earnestmoney_max; | ||
29 | - private BigDecimal[] EARNESTMONEYRANGE = new BigDecimal[2]; | ||
30 | - | ||
31 | - @Value("${order.seller.appraiseFee:5}") | ||
32 | - private Double appraiseFee; | ||
33 | - /** | ||
34 | - * 有货包装费(暂定5元) | ||
35 | - */ | ||
36 | - @Value("${order.seller.packageFee:5}") | ||
37 | - private Double packageFee ; | ||
38 | - | ||
39 | - @Value("${order.seller.goodsPaymentRate}") | ||
40 | - private Double goodsPaymentRate = 0.05D; | ||
41 | - | ||
42 | - @Value("${order.seller.earnestMoneyRate}") | ||
43 | - private Double earnestMoneyRate = 0.20D; | ||
44 | - | ||
45 | - @Value("${order.seller.payChannelRate}") | ||
46 | - private Double payChannelRate = 0.006D; | ||
47 | - | ||
48 | - @PostConstruct | ||
49 | - public void init(){ | ||
50 | - EARNESTMONEYRANGE[0] = new BigDecimal(earnestmoney_min); | ||
51 | - EARNESTMONEYRANGE[1] = new BigDecimal(earnestmoney_max); | ||
52 | - } | ||
53 | - | ||
54 | - public BigDecimal[] getEarnestMoneyrange(){ | ||
55 | - return EARNESTMONEYRANGE; | ||
56 | - } | ||
57 | - | ||
58 | - public SellerOrderComputeResult compute(BigDecimal prdPrice){ | ||
59 | - | ||
60 | - //保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200)) | ||
61 | - EarnestMoney earnestMoney = calEarnestMoney(prdPrice); | ||
62 | - //init fee rate | ||
63 | - ServiceFeeRate serviceFeeRate = new ServiceFeeRate(); | ||
64 | - serviceFeeRate.setGoodsPaymentRate(new BigDecimal(goodsPaymentRate).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||
65 | - serviceFeeRate.setEarnestMoneyRate(new BigDecimal(earnestMoneyRate).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||
66 | - serviceFeeRate.setPayChannelRate(new BigDecimal(payChannelRate).setScale(4, BigDecimal.ROUND_HALF_UP)); | ||
67 | - // | ||
68 | - PlatformFeeDto platformFeeDto = calPlatformFee(prdPrice, serviceFeeRate.getGoodsPaymentRate()); | ||
69 | - BigDecimal bankTransferFee = calBankTransferFee(prdPrice, serviceFeeRate.getPayChannelRate()); | ||
70 | - logger.info("in SellerOrder Compute, prdPrice {}, platformFee {}, bankTransferFee {}", | ||
71 | - prdPrice, platformFeeDto, bankTransferFee); | ||
72 | - BigDecimal income = calIncome(prdPrice, platformFeeDto.getTotal(), bankTransferFee); | ||
73 | - //set | ||
74 | - SellerOrderComputeResult result = new SellerOrderComputeResult(); | ||
75 | - result.setEarnestMoney(earnestMoney); | ||
76 | - result.setPlatformFee(platformFeeDto); | ||
77 | - result.setIncome(halfUp(income)); | ||
78 | - //TODO 根据配置文件 | ||
79 | - result.setServiceFeeRate(serviceFeeRate); | ||
80 | - result.setBankTransferfee(bankTransferFee); | ||
81 | - return result; | ||
82 | - } | ||
83 | - | ||
84 | - private BigDecimal calBankTransferFee(BigDecimal prdPrice, BigDecimal payServiceFeeRate){ | ||
85 | - //支付渠道转账费率(0.6%) | ||
86 | - return halfUp(prdPrice.multiply(payServiceFeeRate)); | ||
87 | - } | ||
88 | - | ||
89 | - /** | ||
90 | - * (1-X-Z)*B-D-E * | ||
91 | - B:货款(卖家发布商品自行输入); | ||
92 | - D:有货鉴定费(暂定5元); | ||
93 | - E:有货包装费(暂定5元); | ||
94 | - X:货款抽成(暂定5%,后期可调整,上线初期为0,后期活动可根据活动进行减免,每个卖家可收费不一样); | ||
95 | - Z:支付渠道费,调用银联支付接口时实时扣款(支付宝0.55%、微信均为0.6%,统一对用户收取0.6%,前期优惠策略可暂定0) | ||
96 | - * @param prdPrice | ||
97 | - * @param platformFee | ||
98 | - * @return | ||
99 | - */ | ||
100 | - private BigDecimal calIncome(BigDecimal prdPrice,BigDecimal platformFee,BigDecimal bankTransferFee){ | ||
101 | - return prdPrice.subtract(platformFee).subtract(bankTransferFee); | ||
102 | - } | ||
103 | - | ||
104 | - public Double getAppraiseFee() { | ||
105 | - return appraiseFee; | ||
106 | - } | ||
107 | - | ||
108 | - public Double getPackageFee() { | ||
109 | - return packageFee; | ||
110 | - } | ||
111 | - | ||
112 | - /** | ||
113 | - * 通过相加得出的数据 | ||
114 | - * 服务费参与计算后需要考虑精度问题(四舍五入) | ||
115 | - * @return | ||
116 | - */ | ||
117 | - private PlatformFeeDto calPlatformFee(BigDecimal price, BigDecimal goodsServiceRate){ | ||
118 | - PlatformFeeDto platformFee = new PlatformFeeDto(); | ||
119 | - BigDecimal appraiseFee = new BigDecimal(getAppraiseFee()); | ||
120 | - BigDecimal packageFee = new BigDecimal(getPackageFee()); | ||
121 | - BigDecimal serviceFee = price.multiply(goodsServiceRate); | ||
122 | - | ||
123 | - platformFee.setAppraiseFee(halfUp(appraiseFee)); | ||
124 | - platformFee.setPackageFee(halfUp(packageFee)); | ||
125 | - BigDecimal total = appraiseFee.add(packageFee).add(serviceFee); | ||
126 | - | ||
127 | - platformFee.setTotal(halfUp(total)); | ||
128 | - platformFee.setServiceFee(halfUp(serviceFee)); | ||
129 | - return platformFee; | ||
130 | - } | 15 | +public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler { |
131 | 16 | ||
132 | /** | 17 | /** |
133 | * 相对独立 不涉及到计算其他费用 | 18 | * 相对独立 不涉及到计算其他费用 |
134 | * @param prdPrice | 19 | * @param prdPrice |
135 | * @return | 20 | * @return |
136 | */ | 21 | */ |
137 | - private EarnestMoney calEarnestMoney(BigDecimal prdPrice){ | 22 | + protected EarnestMoney calEarnestMoney(BigDecimal prdPrice){ |
23 | + BigDecimal[] EARNEST_MONEY_RANGE = orderDynamicConfig.getEMR(); | ||
138 | EarnestMoney earnestMoney = new EarnestMoney(); | 24 | EarnestMoney earnestMoney = new EarnestMoney(); |
139 | - | 25 | + //TODO earnestMoney.rate 需要调整为动态可配 |
140 | BigDecimal real = halfUp(prdPrice.multiply(earnestMoney.getRate())); | 26 | BigDecimal real = halfUp(prdPrice.multiply(earnestMoney.getRate())); |
141 | - final BigDecimal min = EARNESTMONEYRANGE[0] == null ? earnestMoney.getMin() : EARNESTMONEYRANGE[0]; | ||
142 | - final BigDecimal max = EARNESTMONEYRANGE[1] == null ? earnestMoney.getMax() : EARNESTMONEYRANGE[1]; | ||
143 | - if(real.subtract(min).doubleValue() < 0D){ | ||
144 | - real = min; | ||
145 | - } | ||
146 | - if (real.subtract(max).doubleValue() > 0D){ | ||
147 | - real = max; | ||
148 | - } | 27 | + final BigDecimal min = EARNEST_MONEY_RANGE[0] == null ? earnestMoney.getMin() : EARNEST_MONEY_RANGE[0]; |
28 | + final BigDecimal max = EARNEST_MONEY_RANGE[1] == null ? earnestMoney.getMax() : EARNEST_MONEY_RANGE[1]; | ||
29 | + real = calCrossWithThreshold(min, max, real); | ||
149 | earnestMoney.setMin(min); | 30 | earnestMoney.setMin(min); |
150 | earnestMoney.setMax(max); | 31 | earnestMoney.setMax(max); |
151 | earnestMoney.setEarnestMoney(real); | 32 | earnestMoney.setEarnestMoney(real); |
152 | return earnestMoney; | 33 | return earnestMoney; |
153 | } | 34 | } |
154 | 35 | ||
155 | - private BigDecimal halfUp(BigDecimal fee){ | ||
156 | - return BigDecimalHelper.halfUp(fee); | 36 | + |
37 | + | ||
38 | + | ||
39 | + | ||
40 | + @Override | ||
41 | + protected ServiceFeeRate buildServiceFeeRate() { | ||
42 | + ServiceFeeRate serviceFeeRate = orderDynamicConfig.getServiceFeeRate(); | ||
43 | + return serviceFeeRate; | ||
157 | } | 44 | } |
45 | + | ||
46 | + | ||
158 | } | 47 | } |
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 com.yohoufo.common.utils.BigDecimalHelper; |
4 | +import com.yohoufo.order.model.dto.ServiceFeeRate; | ||
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | import lombok.Getter; | 6 | import lombok.Getter; |
6 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
@@ -14,12 +15,40 @@ import java.math.BigDecimal; | @@ -14,12 +15,40 @@ import java.math.BigDecimal; | ||
14 | /** | 15 | /** |
15 | * Created by chao.chen on 2018/11/15. | 16 | * Created by chao.chen on 2018/11/15. |
16 | */ | 17 | */ |
17 | -@Component("orderDynamicConfig") | ||
18 | - | 18 | +@Component |
19 | public class OrderDynamicConfig { | 19 | public class OrderDynamicConfig { |
20 | 20 | ||
21 | final private Logger logger = LoggerFactory.getLogger(getClass()); | 21 | final private Logger logger = LoggerFactory.getLogger(getClass()); |
22 | 22 | ||
23 | + @Value("${order.seller.earnestmoney.min:28}") | ||
24 | + protected double earnestmoney_min; | ||
25 | + | ||
26 | + @Value("${order.seller.earnestmoney.max:200}") | ||
27 | + protected double earnestmoney_max; | ||
28 | + /** | ||
29 | + * 货款抽成费率 | ||
30 | + */ | ||
31 | + @Value("${order.seller.goodsPaymentRate}") | ||
32 | + private Double goodsPaymentRate = 0.05D; | ||
33 | + | ||
34 | + /** | ||
35 | + * 保证金抽成费率 | ||
36 | + */ | ||
37 | + @Value("${order.seller.earnestMoneyRate}") | ||
38 | + private Double earnestMoneyRate = 0.20D; | ||
39 | + | ||
40 | + /** | ||
41 | + * (主要是第三方,支付宝 or 微信)支付渠道手续费率 | ||
42 | + */ | ||
43 | + @Value("${order.seller.payChannelRate}") | ||
44 | + private Double payChannelRate = 0.006D; | ||
45 | + | ||
46 | + /** | ||
47 | + * 保证金上下限阈值 | ||
48 | + */ | ||
49 | + private BigDecimal[] EARNEST_MONEY_RANGE = new BigDecimal[2]; | ||
50 | + | ||
51 | + | ||
23 | @Data | 52 | @Data |
24 | public static class BuyerCancelCompensateNode{ | 53 | public static class BuyerCancelCompensateNode{ |
25 | /** | 54 | /** |
@@ -70,40 +99,30 @@ public class OrderDynamicConfig { | @@ -70,40 +99,30 @@ public class OrderDynamicConfig { | ||
70 | */ | 99 | */ |
71 | private BuyerCancelCompensateNode beforeDepotReceiveBCCN; | 100 | private BuyerCancelCompensateNode beforeDepotReceiveBCCN; |
72 | 101 | ||
102 | + @Getter | ||
103 | + private ServiceFeeRate serviceFeeRate; | ||
73 | 104 | ||
74 | - | 105 | + @PostConstruct |
75 | private void init() { | 106 | private void init() { |
76 | - BigDecimal buyerCancelUnDeliveryMoney , beforeSellerDeliverRate; | ||
77 | - BigDecimal buyerCancelDeliveryMoney, beforeDepotReceiveRate; | ||
78 | - try { | ||
79 | - buyerCancelDeliveryMoney = new BigDecimal(buyerCancelUnDelivery); | ||
80 | - beforeSellerDeliverRate = new BigDecimal( sellerGetRateUnDelivery); | ||
81 | - | ||
82 | - //包装结构时做格式化,之前请保留有效位 | ||
83 | - beforeSellerDeliverBCCN = new BuyerCancelCompensateNode(BigDecimalHelper.halfUp(buyerCancelDeliveryMoney), | ||
84 | - BigDecimalHelper.halfUp(beforeSellerDeliverRate) ); | ||
85 | - | ||
86 | - buyerCancelUnDeliveryMoney = new BigDecimal(buyerCancelDelivery); | ||
87 | - beforeDepotReceiveRate = new BigDecimal(sellerGetRateDelivery); | ||
88 | - beforeDepotReceiveBCCN = new BuyerCancelCompensateNode(buyerCancelUnDeliveryMoney, beforeDepotReceiveRate); | ||
89 | - } catch (Exception e) { | ||
90 | - logger.error("买家取消罚款金额相关参数配置错误!", e); | ||
91 | - throw new Error("买家取消罚款金额相关参数配置错误!"); | ||
92 | - } | ||
93 | - if (buyerCancelDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) { | ||
94 | - throw new Error("buyerCancelDeliveryMoney买家取消(货已寄出)罚款金额不能为负数"); | ||
95 | - } | ||
96 | - if (buyerCancelUnDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) { | ||
97 | - throw new Error("buyerCancelUnDeliveryMoney买家取消(货未寄出)罚款金额不能为负数"); | ||
98 | - } | ||
99 | - if (beforeDepotReceiveRate.compareTo(BigDecimal.ZERO) < 0 | ||
100 | - || beforeDepotReceiveRate.compareTo(BigDecimal.ONE) > 0) { | ||
101 | - throw new Error("sellerGetRateDeliveryMoney买家取消(货已寄出)卖家获得赔偿比率必须在[0,1]"); | ||
102 | - } | ||
103 | - if (beforeSellerDeliverRate.compareTo(BigDecimal.ZERO) < 0 | ||
104 | - || beforeSellerDeliverRate.compareTo(BigDecimal.ONE) > 0) { | ||
105 | - throw new Error("sellerGetRateUnDeliveryMoney买家取消(货未寄出)卖家获得赔偿比率必须在[0,1]"); | ||
106 | - } | 107 | + EARNEST_MONEY_RANGE[0] = new BigDecimal(earnestmoney_min); |
108 | + EARNEST_MONEY_RANGE[1] = new BigDecimal(earnestmoney_max); | ||
109 | + | ||
110 | + // | ||
111 | + //ServiceFeeRate buildServiceFeeRate() { | ||
112 | + serviceFeeRate = new ServiceFeeRate(); | ||
113 | + serviceFeeRate.setGoodsPaymentRate(new BigDecimal(goodsPaymentRate).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||
114 | + serviceFeeRate.setEarnestMoneyRate(new BigDecimal(earnestMoneyRate).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||
115 | + serviceFeeRate.setPayChannelRate(new BigDecimal(payChannelRate).setScale(4, BigDecimal.ROUND_HALF_UP)); | ||
107 | } | 116 | } |
108 | 117 | ||
118 | + | ||
119 | + | ||
120 | + /** | ||
121 | + * | ||
122 | + * EMR : EarnestMoneyRange | ||
123 | + * @return | ||
124 | + */ | ||
125 | + public BigDecimal[] getEMR(){ | ||
126 | + return EARNEST_MONEY_RANGE; | ||
127 | + } | ||
109 | } | 128 | } |
@@ -6,6 +6,7 @@ import com.yoho.error.ServiceError; | @@ -6,6 +6,7 @@ import com.yoho.error.ServiceError; | ||
6 | import com.yoho.error.exception.ServiceException; | 6 | import com.yoho.error.exception.ServiceException; |
7 | import com.yohobuy.ufo.model.order.bo.*; | 7 | import com.yohobuy.ufo.model.order.bo.*; |
8 | import com.yohobuy.ufo.model.order.common.*; | 8 | import com.yohobuy.ufo.model.order.common.*; |
9 | +import com.yohobuy.ufo.model.order.constants.SkupType; | ||
9 | import com.yohobuy.ufo.model.order.req.*; | 10 | import com.yohobuy.ufo.model.order.req.*; |
10 | import com.yohobuy.ufo.model.order.resp.*; | 11 | import com.yohobuy.ufo.model.order.resp.*; |
11 | import com.yohoufo.common.alarm.EventBusPublisher; | 12 | import com.yohoufo.common.alarm.EventBusPublisher; |
@@ -47,6 +48,8 @@ import com.yohoufo.order.service.impl.visitor.UserCancelCase; | @@ -47,6 +48,8 @@ import com.yohoufo.order.service.impl.visitor.UserCancelCase; | ||
47 | import com.yohoufo.order.service.proxy.InBoxFacade; | 48 | import com.yohoufo.order.service.proxy.InBoxFacade; |
48 | import com.yohoufo.order.service.proxy.ProductProxyService; | 49 | import com.yohoufo.order.service.proxy.ProductProxyService; |
49 | import com.yohoufo.order.service.proxy.UserProxyService; | 50 | import com.yohoufo.order.service.proxy.UserProxyService; |
51 | +import com.yohoufo.order.service.seller.OrderComputeHandler; | ||
52 | +import com.yohoufo.order.service.seller.OrderComputeProvider; | ||
50 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; | 53 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; |
51 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; | 54 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; |
52 | import com.yohoufo.order.utils.LoggerUtils; | 55 | import com.yohoufo.order.utils.LoggerUtils; |
@@ -77,7 +80,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -77,7 +80,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
77 | private SellerOrderGoodsMapper sellerOrderGoodsMapper; | 80 | private SellerOrderGoodsMapper sellerOrderGoodsMapper; |
78 | 81 | ||
79 | @Autowired | 82 | @Autowired |
80 | - private SellerOrderComputeHandler computeHandler; | 83 | + private OrderComputeProvider orderComputeProvider; |
81 | 84 | ||
82 | @Autowired | 85 | @Autowired |
83 | private OrderCodeGenerator orderCodeGenerator; | 86 | private OrderCodeGenerator orderCodeGenerator; |
@@ -167,7 +170,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -167,7 +170,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
167 | tips = ex.getErrorMessage(); | 170 | tips = ex.getErrorMessage(); |
168 | } | 171 | } |
169 | boolean isSuper = sellerService.isSuperEntrySeller(uid); | 172 | boolean isSuper = sellerService.isSuperEntrySeller(uid); |
170 | - SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, salePrice, isSuper); | 173 | + SkupType skupType = SkupType.getSkupType(req.getSkupType()); |
174 | + SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, salePrice, isSuper, skupType); | ||
171 | spc.setTips(tips); | 175 | spc.setTips(tips); |
172 | return spc; | 176 | return spc; |
173 | } | 177 | } |
@@ -508,7 +512,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -508,7 +512,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
508 | } | 512 | } |
509 | } | 513 | } |
510 | 514 | ||
511 | - private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num, BigDecimal prdPrice, boolean isSuper){ | 515 | + private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num, |
516 | + BigDecimal prdPrice, boolean isSuper, | ||
517 | + SkupType skupType){ | ||
518 | + OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType); | ||
512 | SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice); | 519 | SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice); |
513 | /** | 520 | /** |
514 | * 验证是否是入驻商家 | 521 | * 验证是否是入驻商家 |
1 | package com.yohoufo.order.service.impl.processor; | 1 | package com.yohoufo.order.service.impl.processor; |
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.common.OrderStatus; | 3 | import com.yohobuy.ufo.model.order.common.OrderStatus; |
4 | +import com.yohobuy.ufo.model.order.constants.SkupType; | ||
4 | import com.yohobuy.ufo.model.order.req.SellerBaseChangeReq; | 5 | import com.yohobuy.ufo.model.order.req.SellerBaseChangeReq; |
5 | import com.yohoufo.common.exception.GatewayException; | 6 | import com.yohoufo.common.exception.GatewayException; |
6 | import com.yohoufo.common.exception.UfoServiceException; | 7 | import com.yohoufo.common.exception.UfoServiceException; |
@@ -14,9 +15,10 @@ import com.yohoufo.dal.order.model.SellerOrderGoods; | @@ -14,9 +15,10 @@ import com.yohoufo.dal.order.model.SellerOrderGoods; | ||
14 | import com.yohoufo.order.model.dto.ChangePricePrepareDTO; | 15 | import com.yohoufo.order.model.dto.ChangePricePrepareDTO; |
15 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; | 16 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; |
16 | import com.yohoufo.order.model.dto.SkupDto; | 17 | import com.yohoufo.order.model.dto.SkupDto; |
17 | -import com.yohoufo.order.service.handler.SellerOrderComputeHandler; | ||
18 | import com.yohoufo.order.service.impl.SellerService; | 18 | import com.yohoufo.order.service.impl.SellerService; |
19 | import com.yohoufo.order.service.proxy.ProductProxyService; | 19 | import com.yohoufo.order.service.proxy.ProductProxyService; |
20 | +import com.yohoufo.order.service.seller.OrderComputeHandler; | ||
21 | +import com.yohoufo.order.service.seller.OrderComputeProvider; | ||
20 | import com.yohoufo.order.utils.LoggerUtils; | 22 | import com.yohoufo.order.utils.LoggerUtils; |
21 | import org.apache.commons.collections.CollectionUtils; | 23 | import org.apache.commons.collections.CollectionUtils; |
22 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
@@ -48,7 +50,7 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | @@ -48,7 +50,7 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | ||
48 | private SellerOrderPrepareProcessor sellerOrderPrepareProcessor; | 50 | private SellerOrderPrepareProcessor sellerOrderPrepareProcessor; |
49 | 51 | ||
50 | @Autowired | 52 | @Autowired |
51 | - private SellerOrderComputeHandler computeHandler; | 53 | + private OrderComputeProvider orderComputeProvider; |
52 | 54 | ||
53 | @Autowired | 55 | @Autowired |
54 | private PriceComputePrepareProcessor priceComputePrepareProcessor; | 56 | private PriceComputePrepareProcessor priceComputePrepareProcessor; |
@@ -68,20 +70,6 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | @@ -68,20 +70,6 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | ||
68 | throw new UfoServiceException(400, "您不是入驻商家"); | 70 | throw new UfoServiceException(400, "您不是入驻商家"); |
69 | } | 71 | } |
70 | 72 | ||
71 | -// String skupList = req.getSkupList(); | ||
72 | -// if (StringUtils.isBlank(skupList)){ | ||
73 | -// logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req); | ||
74 | -// throw new UfoServiceException(400, "参数[skupList]为空"); | ||
75 | -// } | ||
76 | - //考虑到并发,需要进行过滤,将不是出售中状态的skup排除掉; | ||
77 | - //不做过滤导致后面的数量 扣费检查都可能不对 | ||
78 | -// List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(skupList); | ||
79 | -// List<Integer> needChangePriceSkupList = skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList()); | ||
80 | - //check batch no | ||
81 | -// Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req); | ||
82 | - | ||
83 | - | ||
84 | - | ||
85 | //检查是否有买家下单,返回的是可售 待买家付款的skup | 73 | //检查是否有买家下单,返回的是可售 待买家付款的skup |
86 | Map<Integer, SkupDto> skupOfSalingMap = checkExistWaitingBuyerPay(req); | 74 | Map<Integer, SkupDto> skupOfSalingMap = checkExistWaitingBuyerPay(req); |
87 | 75 | ||
@@ -93,9 +81,6 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | @@ -93,9 +81,6 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | ||
93 | int sampleSkup = sampleSkupDto.getSkup(); | 81 | int sampleSkup = sampleSkupDto.getSkup(); |
94 | SellerOrderGoods sampleSog = sampleSkupDto.getSellerOrderGoods(); | 82 | SellerOrderGoods sampleSog = sampleSkupDto.getSellerOrderGoods(); |
95 | BigDecimal preSalePrice = sampleSog.getGoodsPrice(); | 83 | BigDecimal preSalePrice = sampleSog.getGoodsPrice(); |
96 | -// if (preSalePrice.compareTo(salePrice) == 0){ | ||
97 | -// throw new UfoServiceException(401, "前后价格没有变化"); | ||
98 | -// } | ||
99 | 84 | ||
100 | SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup); | 85 | SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup); |
101 | BigDecimal sourceEM = sellerOrder.getEarnestMoney(); | 86 | BigDecimal sourceEM = sellerOrder.getEarnestMoney(); |
@@ -110,6 +95,8 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | @@ -110,6 +95,8 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh | ||
110 | tips = ex.getErrorMessage(); | 95 | tips = ex.getErrorMessage(); |
111 | } | 96 | } |
112 | // compute every fee from price | 97 | // compute every fee from price |
98 | + SkupType skupType = SkupType.getSkupType(req.getSkupType()); | ||
99 | + OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType); | ||
113 | SellerOrderComputeResult computeResult = computeHandler.compute(salePrice); | 100 | SellerOrderComputeResult computeResult = computeHandler.compute(salePrice); |
114 | int num = skupMap.size(); | 101 | int num = skupMap.size(); |
115 | //作为入驻商户 检查钱包 | 102 | //作为入驻商户 检查钱包 |
@@ -2,11 +2,13 @@ package com.yohoufo.order.service.impl.processor; | @@ -2,11 +2,13 @@ package com.yohoufo.order.service.impl.processor; | ||
2 | 2 | ||
3 | import com.yoho.error.ServiceError; | 3 | import com.yoho.error.ServiceError; |
4 | import com.yoho.error.exception.ServiceException; | 4 | import com.yoho.error.exception.ServiceException; |
5 | +import com.yohobuy.ufo.model.GoodsSize; | ||
5 | import com.yohobuy.ufo.model.order.bo.GoodsInfo; | 6 | import com.yohobuy.ufo.model.order.bo.GoodsInfo; |
6 | import com.yohobuy.ufo.model.order.common.SellerWalletType; | 7 | import com.yohobuy.ufo.model.order.common.SellerWalletType; |
7 | import com.yohobuy.ufo.model.order.constants.OrderConstant; | 8 | import com.yohobuy.ufo.model.order.constants.OrderConstant; |
8 | import com.yohobuy.ufo.model.order.constants.SkupType; | 9 | import com.yohobuy.ufo.model.order.constants.SkupType; |
9 | import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq; | 10 | import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq; |
11 | +import com.yohobuy.ufo.model.order.vo.AddressInfo; | ||
10 | import com.yohobuy.ufo.model.response.StorageDataResp; | 12 | import com.yohobuy.ufo.model.response.StorageDataResp; |
11 | import com.yohoufo.common.exception.GatewayException; | 13 | import com.yohoufo.common.exception.GatewayException; |
12 | import com.yohoufo.common.exception.UfoServiceException; | 14 | import com.yohoufo.common.exception.UfoServiceException; |
@@ -14,15 +16,14 @@ import com.yohoufo.common.utils.AddressUtil; | @@ -14,15 +16,14 @@ import com.yohoufo.common.utils.AddressUtil; | ||
14 | import com.yohoufo.common.utils.BigDecimalHelper; | 16 | import com.yohoufo.common.utils.BigDecimalHelper; |
15 | import com.yohoufo.dal.order.SellerWalletMapper; | 17 | import com.yohoufo.dal.order.SellerWalletMapper; |
16 | import com.yohoufo.dal.order.model.SellerWallet; | 18 | import com.yohoufo.dal.order.model.SellerWallet; |
17 | -import com.yohobuy.ufo.model.order.vo.AddressInfo; | ||
18 | import com.yohoufo.order.model.SellerOrderContext; | 19 | import com.yohoufo.order.model.SellerOrderContext; |
19 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; | 20 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; |
20 | -import com.yohoufo.order.service.handler.SellerOrderComputeHandler; | ||
21 | import com.yohoufo.order.service.proxy.ProductProxyService; | 21 | import com.yohoufo.order.service.proxy.ProductProxyService; |
22 | import com.yohoufo.order.service.proxy.UserProxyService; | 22 | import com.yohoufo.order.service.proxy.UserProxyService; |
23 | +import com.yohoufo.order.service.seller.OrderComputeHandler; | ||
24 | +import com.yohoufo.order.service.seller.OrderComputeProvider; | ||
23 | import com.yohoufo.order.utils.AddressHelper; | 25 | import com.yohoufo.order.utils.AddressHelper; |
24 | import com.yohoufo.order.utils.LoggerUtils; | 26 | import com.yohoufo.order.utils.LoggerUtils; |
25 | -import com.yohobuy.ufo.model.GoodsSize; | ||
26 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
27 | import org.springframework.beans.factory.annotation.Autowired; | 28 | import org.springframework.beans.factory.annotation.Autowired; |
28 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
@@ -45,7 +46,7 @@ public class SellerOrderPrepareProcessor { | @@ -45,7 +46,7 @@ public class SellerOrderPrepareProcessor { | ||
45 | private ProductProxyService productProxyService; | 46 | private ProductProxyService productProxyService; |
46 | 47 | ||
47 | @Autowired | 48 | @Autowired |
48 | - private SellerOrderComputeHandler computeHandler; | 49 | + private OrderComputeProvider orderComputeProvider; |
49 | 50 | ||
50 | @Autowired | 51 | @Autowired |
51 | private SellerWalletMapper sellerWalletMapper; | 52 | private SellerWalletMapper sellerWalletMapper; |
@@ -137,16 +138,17 @@ public class SellerOrderPrepareProcessor { | @@ -137,16 +138,17 @@ public class SellerOrderPrepareProcessor { | ||
137 | }catch (UfoServiceException ex){ | 138 | }catch (UfoServiceException ex){ |
138 | context.setPriceOverFlowTips( ex.getErrorMessage()); | 139 | context.setPriceOverFlowTips( ex.getErrorMessage()); |
139 | } | 140 | } |
140 | - | 141 | + // |
142 | + SkupType skupType = SkupType.getSkupType(req.getSkupType()); | ||
143 | + context.setSkupType(skupType); | ||
141 | // compute every fee from price | 144 | // compute every fee from price |
145 | + OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType); | ||
142 | SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice()); | 146 | SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice()); |
143 | checkIncome(storageId, computeResult.getIncome()); | 147 | checkIncome(storageId, computeResult.getIncome()); |
144 | log.info("in buildSellerOrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId, | 148 | log.info("in buildSellerOrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId, |
145 | goodsInfo.getPrice(), computeResult); | 149 | goodsInfo.getPrice(), computeResult); |
146 | context.setSellerOrderComputeResult(computeResult); | 150 | context.setSellerOrderComputeResult(computeResult); |
147 | - // | ||
148 | - SkupType skupType = SkupType.getSkupType(req.getSkupType()); | ||
149 | - context.setSkupType(skupType); | 151 | + |
150 | return context; | 152 | return context; |
151 | } | 153 | } |
152 | 154 | ||
@@ -303,6 +305,8 @@ public class SellerOrderPrepareProcessor { | @@ -303,6 +305,8 @@ public class SellerOrderPrepareProcessor { | ||
303 | goodsInfo.setStorageNum(storageNum); | 305 | goodsInfo.setStorageNum(storageNum); |
304 | 306 | ||
305 | // compute every fee from price | 307 | // compute every fee from price |
308 | + SkupType skupType = SkupType.IN_STOCK; | ||
309 | + OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType); | ||
306 | SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice()); | 310 | SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice()); |
307 | log.info("in buildImportPrdCxt , uid {}, storageId {}, price {}, computeResult {}", uid, storageId, | 311 | log.info("in buildImportPrdCxt , uid {}, storageId {}, price {}, computeResult {}", uid, storageId, |
308 | goodsInfo.getPrice(), computeResult); | 312 | goodsInfo.getPrice(), computeResult); |
1 | +package com.yohoufo.order.service.seller; | ||
2 | + | ||
3 | +import com.yohoufo.common.utils.BigDecimalHelper; | ||
4 | +import com.yohoufo.order.model.dto.EarnestMoney; | ||
5 | +import com.yohoufo.order.model.dto.PlatformFeeDto; | ||
6 | +import com.yohoufo.order.model.dto.SellerOrderComputeResult; | ||
7 | +import com.yohoufo.order.model.dto.ServiceFeeRate; | ||
8 | +import com.yohoufo.order.service.impl.OrderDynamicConfig; | ||
9 | +import com.yohoufo.order.utils.LoggerUtils; | ||
10 | +import org.slf4j.Logger; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +import org.springframework.beans.factory.annotation.Value; | ||
13 | + | ||
14 | +import java.math.BigDecimal; | ||
15 | + | ||
16 | +/** | ||
17 | + * Created by chao.chen on 2019/2/1. | ||
18 | + */ | ||
19 | +public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandler{ | ||
20 | + | ||
21 | + protected Logger logger = LoggerUtils.getSellerOrderLogger(); | ||
22 | + | ||
23 | + | ||
24 | + @Autowired | ||
25 | + protected OrderDynamicConfig orderDynamicConfig; | ||
26 | + /** | ||
27 | + * 鉴定费 | ||
28 | + */ | ||
29 | + @Value("${order.seller.appraiseFee:5}") | ||
30 | + private Double appraiseFee; | ||
31 | + /** | ||
32 | + * 有货包装费(暂定5元) | ||
33 | + */ | ||
34 | + @Value("${order.seller.packageFee:5}") | ||
35 | + private Double packageFee ; | ||
36 | + | ||
37 | + @Override | ||
38 | + public SellerOrderComputeResult compute(BigDecimal prdPrice){ | ||
39 | + | ||
40 | + //保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200)) | ||
41 | + EarnestMoney earnestMoney = calEarnestMoney(prdPrice); | ||
42 | + //init fee rate | ||
43 | + ServiceFeeRate serviceFeeRate = buildServiceFeeRate(); | ||
44 | + PlatformFeeDto platformFeeDto = calPlatformFee(prdPrice, serviceFeeRate); | ||
45 | + BigDecimal bankTransferFee = calBankTransferFee(prdPrice, serviceFeeRate.getPayChannelRate()); | ||
46 | + logger.info("in SellerOrder Compute, prdPrice {}, platformFee {}, bankTransferFee {}", | ||
47 | + prdPrice, platformFeeDto, bankTransferFee); | ||
48 | + BigDecimal income = calIncome(prdPrice, platformFeeDto.getTotal(), bankTransferFee); | ||
49 | + //set | ||
50 | + SellerOrderComputeResult result = new SellerOrderComputeResult(); | ||
51 | + result.setEarnestMoney(earnestMoney); | ||
52 | + result.setPlatformFee(platformFeeDto); | ||
53 | + result.setIncome(halfUp(income)); | ||
54 | + //TODO 根据配置文件 | ||
55 | + result.setServiceFeeRate(serviceFeeRate); | ||
56 | + result.setBankTransferfee(bankTransferFee); | ||
57 | + return result; | ||
58 | + } | ||
59 | + | ||
60 | + protected BigDecimal calCrossWithThreshold(BigDecimal min, BigDecimal max, BigDecimal calByRate){ | ||
61 | + if(calByRate.compareTo(min) < 0){ | ||
62 | + calByRate = min; | ||
63 | + } | ||
64 | + if (calByRate.compareTo(max) > 0){ | ||
65 | + calByRate = max; | ||
66 | + } | ||
67 | + return calByRate; | ||
68 | + } | ||
69 | + | ||
70 | + protected BigDecimal halfUp(BigDecimal fee){ | ||
71 | + return BigDecimalHelper.halfUp(fee); | ||
72 | + } | ||
73 | + | ||
74 | + protected abstract EarnestMoney calEarnestMoney(BigDecimal prdPrice); | ||
75 | + | ||
76 | + | ||
77 | + /** | ||
78 | + * (1-X-Z)*B-D-E * | ||
79 | + B:货款(卖家发布商品自行输入); | ||
80 | + D:有货鉴定费(暂定5元); | ||
81 | + E:有货包装费(暂定5元); | ||
82 | + X:货款抽成(暂定5%,后期可调整,上线初期为0,后期活动可根据活动进行减免,每个卖家可收费不一样); | ||
83 | + Z:支付渠道费,调用银联支付接口时实时扣款(支付宝0.55%、微信均为0.6%,统一对用户收取0.6%,前期优惠策略可暂定0) | ||
84 | + * @param prdPrice | ||
85 | + * @param platformFee | ||
86 | + * @return | ||
87 | + */ | ||
88 | + protected BigDecimal calIncome(BigDecimal prdPrice, BigDecimal platformFee, BigDecimal bankTransferFee){ | ||
89 | + return prdPrice.subtract(platformFee).subtract(bankTransferFee); | ||
90 | + } | ||
91 | + | ||
92 | + protected BigDecimal calBankTransferFee(BigDecimal prdPrice, BigDecimal payServiceFeeRate){ | ||
93 | + //支付渠道转账费率(0.6%) | ||
94 | + return halfUp(prdPrice.multiply(payServiceFeeRate)); | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * 通过相加得出的数据 | ||
99 | + * 服务费参与计算后需要考虑精度问题(四舍五入) | ||
100 | + * @return | ||
101 | + */ | ||
102 | + protected PlatformFeeDto calPlatformFee(BigDecimal price, ServiceFeeRate serviceFeeRate){ | ||
103 | + BigDecimal goodsServiceRate = serviceFeeRate.getGoodsPaymentRate(); | ||
104 | + | ||
105 | + | ||
106 | + PlatformFeeDto platformFee = new PlatformFeeDto(); | ||
107 | + | ||
108 | + BigDecimal appraiseFee = new BigDecimal(getAppraiseFee()); | ||
109 | + BigDecimal packageFee = new BigDecimal(getPackageFee()); | ||
110 | + BigDecimal serviceFee = price.multiply(goodsServiceRate); | ||
111 | + | ||
112 | + platformFee.setAppraiseFee(halfUp(appraiseFee)); | ||
113 | + platformFee.setPackageFee(halfUp(packageFee)); | ||
114 | + BigDecimal total = appraiseFee.add(packageFee).add(serviceFee); | ||
115 | + | ||
116 | + platformFee.setTotal(halfUp(total)); | ||
117 | + platformFee.setServiceFee(halfUp(serviceFee)); | ||
118 | + return platformFee; | ||
119 | + } | ||
120 | + | ||
121 | + public Double getAppraiseFee() { | ||
122 | + return appraiseFee; | ||
123 | + } | ||
124 | + | ||
125 | + public Double getPackageFee() { | ||
126 | + return packageFee; | ||
127 | + } | ||
128 | + | ||
129 | + protected abstract ServiceFeeRate buildServiceFeeRate(); | ||
130 | +} |
1 | +package com.yohoufo.order.service.seller; | ||
2 | + | ||
3 | +import com.yohoufo.order.model.dto.SellerOrderComputeResult; | ||
4 | + | ||
5 | +import java.math.BigDecimal; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by chao.chen on 2019/2/1. | ||
9 | + */ | ||
10 | +public interface OrderComputeHandler { | ||
11 | + | ||
12 | + | ||
13 | + SellerOrderComputeResult compute(BigDecimal prdPrice); | ||
14 | +} |
1 | +package com.yohoufo.order.service.seller; | ||
2 | + | ||
3 | +import com.yohobuy.ufo.model.order.constants.SkupType; | ||
4 | +import com.yohoufo.order.utils.LoggerUtils; | ||
5 | +import org.apache.commons.collections.CollectionUtils; | ||
6 | +import org.slf4j.Logger; | ||
7 | +import org.springframework.beans.BeansException; | ||
8 | +import org.springframework.context.ApplicationContext; | ||
9 | +import org.springframework.context.ApplicationContextAware; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import java.util.ArrayList; | ||
13 | +import java.util.List; | ||
14 | +import java.util.Map; | ||
15 | + | ||
16 | +/** | ||
17 | + * Created by chao.chen on 2019/2/1. | ||
18 | + */ | ||
19 | +@Service | ||
20 | +public class OrderComputeProvider implements ApplicationContextAware { | ||
21 | + private final Logger logger = LoggerUtils.getSellerOrderLogger(); | ||
22 | + | ||
23 | + private Map<String, OrderComputeHandler> cache; | ||
24 | + | ||
25 | + public OrderComputeHandler findBySkupType(SkupType skupType){ | ||
26 | + OrderComputeHandler och = cache.get(skupType.orderComputeHandlerClzName()); | ||
27 | + logger.info("in findBySkupType skupType {} OrderComputeHandler {}", skupType, och); | ||
28 | + return och; | ||
29 | + } | ||
30 | + | ||
31 | + @Override | ||
32 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
33 | + Map<String, OrderComputeHandler> allOCHMap = applicationContext.getBeansOfType(OrderComputeHandler.class); | ||
34 | + cache = allOCHMap; | ||
35 | + //check | ||
36 | + SkupType[] sta = SkupType.values(); | ||
37 | + List<SkupType> errorST = new ArrayList<>(sta.length); | ||
38 | + for(SkupType st : sta){ | ||
39 | + if(null == findBySkupType(st)){ | ||
40 | + errorST.add(st); | ||
41 | + logger.warn("init check SkupType.orderComputeHandlerClzName set error SkupType {}", st); | ||
42 | + } | ||
43 | + } | ||
44 | + if (CollectionUtils.isNotEmpty(errorST)){ | ||
45 | + throw new Error("SkupType.orderComputeHandlerClzName incorrect"); | ||
46 | + } | ||
47 | + } | ||
48 | +} |
order/src/main/java/com/yohoufo/order/service/seller/SellerAdvanceOrderComputeHandler.java
0 → 100644
1 | +package com.yohoufo.order.service.seller; | ||
2 | + | ||
3 | +import com.yohoufo.order.model.dto.EarnestMoney; | ||
4 | +import com.yohoufo.order.model.dto.ServiceFeeRate; | ||
5 | +import org.springframework.stereotype.Component; | ||
6 | + | ||
7 | +import java.math.BigDecimal; | ||
8 | + | ||
9 | +/** | ||
10 | + * Created by chao.chen on 2019/2/1. | ||
11 | + */ | ||
12 | +@Component | ||
13 | +public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler { | ||
14 | + @Override | ||
15 | + protected EarnestMoney calEarnestMoney(BigDecimal prdPrice) { | ||
16 | + //TODO 根据配置(来自于数据库或缓存 zk ,某一种数据存储方式) | ||
17 | + EarnestMoney earnestMoney = new EarnestMoney(); | ||
18 | + earnestMoney.setPrdSalePrice(prdPrice); | ||
19 | + | ||
20 | + //TODO earnestMoney.rate 需要调整为动态可配 | ||
21 | + BigDecimal real = halfUp(prdPrice.multiply(new BigDecimal(0.08D))); | ||
22 | + final BigDecimal min = new BigDecimal(56); | ||
23 | + final BigDecimal max = new BigDecimal(438); | ||
24 | + real = calCrossWithThreshold(min, max, real); | ||
25 | + earnestMoney.setMin(min); | ||
26 | + earnestMoney.setMax(max); | ||
27 | + earnestMoney.setEarnestMoney(real); | ||
28 | + return earnestMoney; | ||
29 | + } | ||
30 | + | ||
31 | + @Override | ||
32 | + protected ServiceFeeRate buildServiceFeeRate() { | ||
33 | + ServiceFeeRate serviceFeeRate = orderDynamicConfig.getServiceFeeRate(); | ||
34 | + return serviceFeeRate; | ||
35 | + } | ||
36 | +} |
-
Please register or login to post a comment