fix refund money bill record
Showing
1 changed file
with
71 additions
and
27 deletions
@@ -3,13 +3,18 @@ package com.yohoufo.order.service.impl; | @@ -3,13 +3,18 @@ package com.yohoufo.order.service.impl; | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
5 | import com.yohoufo.common.alarm.CommonAlarmEventPublisher; | 5 | import com.yohoufo.common.alarm.CommonAlarmEventPublisher; |
6 | +import com.yohoufo.common.utils.BigDecimalHelper; | ||
7 | +import com.yohoufo.dal.order.AppraiseOrderMetaMapper; | ||
6 | import com.yohoufo.dal.order.SellerOrderMetaMapper; | 8 | import com.yohoufo.dal.order.SellerOrderMetaMapper; |
7 | import com.yohoufo.dal.order.TradeBillsMapper; | 9 | import com.yohoufo.dal.order.TradeBillsMapper; |
10 | +import com.yohoufo.dal.order.model.AppraiseOrderMeta; | ||
8 | import com.yohoufo.dal.order.model.SellerOrder; | 11 | import com.yohoufo.dal.order.model.SellerOrder; |
9 | import com.yohoufo.dal.order.model.SellerOrderMeta; | 12 | import com.yohoufo.dal.order.model.SellerOrderMeta; |
10 | import com.yohoufo.dal.order.model.TradeBills; | 13 | import com.yohoufo.dal.order.model.TradeBills; |
11 | import com.yohobuy.ufo.model.order.common.Payment; | 14 | import com.yohobuy.ufo.model.order.common.Payment; |
12 | import com.yohoufo.order.common.BillTradeStatus; | 15 | import com.yohoufo.order.common.BillTradeStatus; |
16 | +import com.yohoufo.order.constants.MetaKey; | ||
17 | +import com.yohoufo.order.model.dto.SellerOrderComputeResult; | ||
13 | import org.slf4j.Logger; | 18 | import org.slf4j.Logger; |
14 | import org.slf4j.LoggerFactory; | 19 | import org.slf4j.LoggerFactory; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -33,6 +38,12 @@ public class TradeBillsService { | @@ -33,6 +38,12 @@ public class TradeBillsService { | ||
33 | @Autowired | 38 | @Autowired |
34 | TradeBillsMapper tradeBillsMapper; | 39 | TradeBillsMapper tradeBillsMapper; |
35 | 40 | ||
41 | + @Autowired | ||
42 | + private ServiceOrderProcessor serviceOrderProcessor; | ||
43 | + | ||
44 | + @Autowired | ||
45 | + private AppraiseOrderMetaMapper appraiseOrderMetaMapper; | ||
46 | + | ||
36 | /** | 47 | /** |
37 | * 退保证金流水记录 | 48 | * 退保证金流水记录 |
38 | * | 49 | * |
@@ -42,27 +53,59 @@ public class TradeBillsService { | @@ -42,27 +53,59 @@ public class TradeBillsService { | ||
42 | * @param payType | 53 | * @param payType |
43 | * @param tradeStatus | 54 | * @param tradeStatus |
44 | */ | 55 | */ |
45 | - public void backPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType, Integer tradeStatus) { | ||
46 | - backPayEnsureRecord(uid, skup, orderCode, payType, tradeStatus, null, null); | ||
47 | - } | 56 | + public void backPayEnsureRecord(Integer uid, |
57 | + Integer skup, | ||
58 | + Long orderCode, | ||
59 | + Integer payType, | ||
60 | + Integer tradeStatus) { | ||
48 | 61 | ||
49 | - public void backPayEnsureRecord(SellerOrder sellerOrder, Integer tradeStatus, BigDecimal backEarnestMoney, SellerOrderMeta meta) { | ||
50 | - backPayEnsureRecord(sellerOrder.getUid(), sellerOrder.getSkup(), sellerOrder.getOrderCode(), sellerOrder.getPayment(), tradeStatus, backEarnestMoney, meta); | ||
51 | - } | ||
52 | 62 | ||
53 | - private void backPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType, | ||
54 | - Integer tradeStatus, | ||
55 | - BigDecimal backEarnestMoney, SellerOrderMeta meta) { | ||
56 | - if (payType != null && Payment.WALLET.getCode() == payType) { | 63 | + String computeResultVal = null; |
64 | + | ||
65 | + if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){ | ||
66 | + AppraiseOrderMeta feeCondition = new AppraiseOrderMeta(); | ||
67 | + feeCondition.setOrderCode(orderCode); | ||
68 | + feeCondition.setMetaKey(MetaKey.SELLER_FEE); | ||
69 | + AppraiseOrderMeta feeMeta = appraiseOrderMetaMapper.selectByOrderCode(feeCondition); | ||
70 | + computeResultVal = Objects.nonNull(feeMeta) ? feeMeta.getMetaValue() : null; | ||
71 | + logger.info("in backPayEnsureRecord isGoodsServiceOrder orderCode {} computeResultVal {}", orderCode, computeResultVal); | ||
72 | + }else { | ||
73 | + SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, MetaKey.SELLER_FEE); | ||
74 | + computeResultVal = Objects.nonNull(meta) ? meta.getMetaValue() : null; | ||
75 | + logger.info("in backPayEnsureRecord buyerorder orderCode {} computeResultVal {}", orderCode, computeResultVal); | ||
76 | + } | ||
77 | + | ||
78 | + if (Objects.isNull(computeResultVal)) { | ||
79 | + logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup); | ||
57 | return; | 80 | return; |
58 | } | 81 | } |
59 | - if (Objects.isNull(meta)) { | ||
60 | - meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee"); | 82 | + try{ |
83 | + SellerOrderComputeResult socr = JSONObject.parseObject(computeResultVal, SellerOrderComputeResult.class); | ||
84 | + BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney(); | ||
85 | + BigDecimal systemAmount = calSystemAmountByComputeResult(socr); | ||
86 | + backPayEnsureRecord0(uid, orderCode, payType, tradeStatus, earnestMoney, systemAmount); | ||
87 | + | ||
88 | + }catch (Exception ex){ | ||
89 | + logger.error("backPayEnsureRecord error, uid {},orderCode {} computeResultVal {}", | ||
90 | + uid, orderCode, computeResultVal, ex); | ||
61 | } | 91 | } |
62 | - if (Objects.isNull(meta)) { | ||
63 | - logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup); | 92 | + |
93 | + | ||
94 | + } | ||
95 | + | ||
96 | + | ||
97 | + private void backPayEnsureRecord0(Integer uid, | ||
98 | + Long orderCode, | ||
99 | + Integer payType, | ||
100 | + Integer tradeStatus, | ||
101 | + BigDecimal earnestMoney, | ||
102 | + BigDecimal systemAmount | ||
103 | + ) { | ||
104 | + if (payType != null && Payment.WALLET.getCode() == payType) { | ||
64 | return; | 105 | return; |
65 | } | 106 | } |
107 | + | ||
108 | + | ||
66 | // 增加流水记录 | 109 | // 增加流水记录 |
67 | TradeBills record = new TradeBills(); | 110 | TradeBills record = new TradeBills(); |
68 | record.setUid(uid); | 111 | record.setUid(uid); |
@@ -71,25 +114,26 @@ public class TradeBillsService { | @@ -71,25 +114,26 @@ public class TradeBillsService { | ||
71 | record.setPayType(payType);// 1:支付宝; 2:微信 | 114 | record.setPayType(payType);// 1:支付宝; 2:微信 |
72 | record.setTradeType(1);//1:保证金;2:货款;3:补偿款 | 115 | record.setTradeType(1);//1:保证金;2:货款;3:补偿款 |
73 | record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出 | 116 | record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出 |
74 | - BigDecimal earnestMoney = backEarnestMoney; | ||
75 | - BigDecimal amount = BigDecimal.ZERO; | ||
76 | - try { | ||
77 | - JSONObject metavalue = JSON.parseObject(meta.getMetaValue()); | ||
78 | - BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate"); | ||
79 | - if (Objects.isNull(earnestMoney)) { | ||
80 | - earnestMoney = metavalue.getJSONObject("earnestMoney").getBigDecimal("earnestMoney"); | ||
81 | - } | ||
82 | - amount = earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP); | ||
83 | - } catch (Exception e) { | ||
84 | - logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage()); | ||
85 | - } | ||
86 | record.setAmount(earnestMoney); | 117 | record.setAmount(earnestMoney); |
87 | - record.setSystemAmount(amount);// 有货收入 | 118 | + record.setSystemAmount(systemAmount);// 有货收入 |
88 | record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结 | 119 | record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结 |
89 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); | 120 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); |
90 | addTradeBills(record); | 121 | addTradeBills(record); |
91 | } | 122 | } |
92 | 123 | ||
124 | + | ||
125 | + BigDecimal calSystemAmountByComputeResult(SellerOrderComputeResult socr){ | ||
126 | + BigDecimal amount = BigDecimal.ZERO; | ||
127 | + try { | ||
128 | + BigDecimal rate = socr.getServiceFeeRate().getPayChannelRate(); | ||
129 | + BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney(); | ||
130 | + amount = BigDecimalHelper.halfUp(earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).negate()); | ||
131 | + } catch (Exception e) { | ||
132 | + logger.warn("calSystemAmountByComputeResult fail SellerOrderComputeResult {}", socr); | ||
133 | + } | ||
134 | + return amount; | ||
135 | + } | ||
136 | + | ||
93 | /** | 137 | /** |
94 | * 退付货款流水记录 | 138 | * 退付货款流水记录 |
95 | * | 139 | * |
-
Please register or login to post a comment