1
|
-package com.yohoufo.order.service.impl;
|
|
|
2
|
-
|
|
|
3
|
-import com.alibaba.fastjson.JSON;
|
|
|
4
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
5
|
-import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
|
|
|
6
|
-import com.yohoufo.common.utils.BigDecimalHelper;
|
|
|
7
|
-import com.yohoufo.common.utils.DateUtil;
|
|
|
8
|
-import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
|
|
|
9
|
-import com.yohoufo.dal.order.SellerOrderMetaMapper;
|
|
|
10
|
-import com.yohoufo.dal.order.TradeBillsMapper;
|
|
|
11
|
-import com.yohoufo.dal.order.model.AppraiseOrderMeta;
|
|
|
12
|
-import com.yohoufo.dal.order.model.SellerOrder;
|
|
|
13
|
-import com.yohoufo.dal.order.model.SellerOrderMeta;
|
|
|
14
|
-import com.yohoufo.dal.order.model.TradeBills;
|
|
|
15
|
-import com.yohobuy.ufo.model.order.common.Payment;
|
|
|
16
|
-import com.yohoufo.order.common.BillTradeStatus;
|
|
|
17
|
-import com.yohoufo.order.constants.MetaKey;
|
|
|
18
|
-import com.yohoufo.order.model.dto.SellerOrderComputeResult;
|
|
|
19
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
20
|
-import org.slf4j.Logger;
|
|
|
21
|
-import org.slf4j.LoggerFactory;
|
|
|
22
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
23
|
-import org.springframework.stereotype.Service;
|
|
|
24
|
-
|
|
|
25
|
-import java.math.BigDecimal;
|
|
|
26
|
-import java.util.List;
|
|
|
27
|
-import java.util.Objects;
|
|
|
28
|
-
|
|
|
29
|
-/**
|
|
|
30
|
- * Created by chenchao on 2018/10/10.
|
|
|
31
|
- */
|
|
|
32
|
-@Service
|
|
|
33
|
-public class TradeBillsService {
|
|
|
34
|
-
|
|
|
35
|
- final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
36
|
-
|
|
|
37
|
- @Autowired
|
|
|
38
|
- SellerOrderMetaMapper sellerOrderMetaMapper;
|
|
|
39
|
-
|
|
|
40
|
- @Autowired
|
|
|
41
|
- TradeBillsMapper tradeBillsMapper;
|
|
|
42
|
-
|
|
|
43
|
- @Autowired
|
|
|
44
|
- private ServiceOrderProcessor serviceOrderProcessor;
|
|
|
45
|
-
|
|
|
46
|
- @Autowired
|
|
|
47
|
- private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
|
|
|
48
|
-
|
|
|
49
|
- /**
|
|
|
50
|
- * 退保证金流水记录
|
|
|
51
|
- *
|
|
|
52
|
- * @param uid
|
|
|
53
|
- * @param skup
|
|
|
54
|
- * @param orderCode
|
|
|
55
|
- * @param payType
|
|
|
56
|
- * @param tradeStatus
|
|
|
57
|
- */
|
|
|
58
|
- public void backPayEnsureRecord(Integer uid,
|
|
|
59
|
- Integer skup,
|
|
|
60
|
- Long orderCode,
|
|
|
61
|
- Long paidOrderCode,
|
|
|
62
|
- Integer payType,
|
|
|
63
|
- Integer tradeStatus) {
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
- String computeResultVal = null;
|
|
|
67
|
-
|
|
|
68
|
- if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
|
|
|
69
|
- AppraiseOrderMeta feeCondition = new AppraiseOrderMeta();
|
|
|
70
|
- feeCondition.setOrderCode(orderCode);
|
|
|
71
|
- feeCondition.setMetaKey(MetaKey.SELLER_FEE);
|
|
|
72
|
- AppraiseOrderMeta feeMeta = appraiseOrderMetaMapper.selectByOrderCode(feeCondition);
|
|
|
73
|
- computeResultVal = Objects.nonNull(feeMeta) ? feeMeta.getMetaValue() : null;
|
|
|
74
|
- logger.info("in backPayEnsureRecord isGoodsServiceOrder orderCode {} computeResultVal {}", orderCode, computeResultVal);
|
|
|
75
|
- }else {
|
|
|
76
|
- SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, MetaKey.SELLER_FEE);
|
|
|
77
|
- computeResultVal = Objects.nonNull(meta) ? meta.getMetaValue() : null;
|
|
|
78
|
- logger.info("in backPayEnsureRecord buyerorder orderCode {} computeResultVal {}", orderCode, computeResultVal);
|
|
|
79
|
- }
|
|
|
80
|
-
|
|
|
81
|
- if (Objects.isNull(computeResultVal)) {
|
|
|
82
|
- logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup);
|
|
|
83
|
- return;
|
|
|
84
|
- }
|
|
|
85
|
- try{
|
|
|
86
|
- SellerOrderComputeResult socr = JSONObject.parseObject(computeResultVal, SellerOrderComputeResult.class);
|
|
|
87
|
- BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
88
|
- BigDecimal systemAmount = calSystemAmountByComputeResult(socr);
|
|
|
89
|
- backPayEnsureRecord0(uid, orderCode, paidOrderCode, payType, tradeStatus, earnestMoney, systemAmount);
|
|
|
90
|
-
|
|
|
91
|
- }catch (Exception ex){
|
|
|
92
|
- logger.error("backPayEnsureRecord error, uid {},orderCode {} computeResultVal {}",
|
|
|
93
|
- uid, orderCode, computeResultVal, ex);
|
|
|
94
|
- }
|
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
- }
|
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
- private void backPayEnsureRecord0(Integer uid,
|
|
|
101
|
- Long orderCode,
|
|
|
102
|
- Long paidOrderCode,
|
|
|
103
|
- Integer payType,
|
|
|
104
|
- Integer tradeStatus,
|
|
|
105
|
- BigDecimal earnestMoney,
|
|
|
106
|
- BigDecimal systemAmount
|
|
|
107
|
- ) {
|
|
|
108
|
- if (payType != null && Payment.WALLET.getCode() == payType) {
|
|
|
109
|
- return;
|
|
|
110
|
- }
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
- // 增加流水记录
|
|
|
114
|
- TradeBills record = new TradeBills();
|
|
|
115
|
- record.setUid(uid);
|
|
|
116
|
- record.setOrderCode(orderCode);
|
|
|
117
|
- record.setPaidOrderCode(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
118
|
- record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
119
|
- record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
120
|
- record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
121
|
- record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
122
|
- record.setAmount(earnestMoney);
|
|
|
123
|
- record.setSystemAmount(systemAmount);// 有货收入
|
|
|
124
|
- record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
125
|
- record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
126
|
- addTradeBills(record);
|
|
|
127
|
- }
|
|
|
128
|
-
|
|
|
129
|
-
|
|
|
130
|
- BigDecimal calSystemAmountByComputeResult(SellerOrderComputeResult socr){
|
|
|
131
|
- BigDecimal amount = BigDecimal.ZERO;
|
|
|
132
|
- try {
|
|
|
133
|
- BigDecimal rate = socr.getServiceFeeRate().getPayChannelRate();
|
|
|
134
|
- BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
135
|
- amount = BigDecimalHelper.halfUp(earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).negate());
|
|
|
136
|
- } catch (Exception e) {
|
|
|
137
|
- logger.warn("calSystemAmountByComputeResult fail SellerOrderComputeResult {}", socr);
|
|
|
138
|
- }
|
|
|
139
|
- return amount;
|
|
|
140
|
- }
|
|
|
141
|
-
|
|
|
142
|
- /**
|
|
|
143
|
- * 退付货款流水记录
|
|
|
144
|
- *
|
|
|
145
|
- * @param uid
|
|
|
146
|
- * @param sellerUid
|
|
|
147
|
- * @param skup
|
|
|
148
|
- * @param orderCode
|
|
|
149
|
- * @param payType
|
|
|
150
|
- * @param amount
|
|
|
151
|
- * @param tradeStatus
|
|
|
152
|
- */
|
|
|
153
|
- public void backPayBuyRecord(Integer uid, Integer sellerUid, Integer skup,
|
|
|
154
|
- Long orderCode, Long paidOrderCode, Integer payType, BigDecimal amount,
|
|
|
155
|
- Integer tradeStatus) {
|
|
|
156
|
-
|
|
|
157
|
- if (payType != null && Payment.WALLET.getCode() == payType) {
|
|
|
158
|
- return;
|
|
|
159
|
- }
|
|
|
160
|
-
|
|
|
161
|
- SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
|
|
162
|
- if (meta == null) {
|
|
|
163
|
- logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
164
|
- return;
|
|
|
165
|
- }
|
|
|
166
|
- // 增加流水记录
|
|
|
167
|
- TradeBills record = new TradeBills();
|
|
|
168
|
- record.setUid(uid);
|
|
|
169
|
- record.setOrderCode(orderCode);
|
|
|
170
|
- record.setPaidOrderCode(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
171
|
- record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
172
|
- record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
173
|
- record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
|
|
174
|
- record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
175
|
- record.setAmount(amount);
|
|
|
176
|
- try {
|
|
|
177
|
- JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
178
|
- BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
179
|
- BigDecimal samount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
180
|
- record.setSystemAmount(samount);// 有货收入
|
|
|
181
|
- } catch (Exception e) {
|
|
|
182
|
- logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
183
|
- // return;
|
|
|
184
|
- }
|
|
|
185
|
-
|
|
|
186
|
- record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
187
|
- record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
188
|
- addTradeBills(record);
|
|
|
189
|
- }
|
|
|
190
|
-
|
|
|
191
|
-
|
|
|
192
|
- public void addTradeBills(TradeBills record) {
|
|
|
193
|
- try {
|
|
|
194
|
- tradeBillsMapper.insert(record);
|
|
|
195
|
- } catch (Exception e) {
|
|
|
196
|
- logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
|
|
|
197
|
- alarm("记录流水到数据库出错", "ufo.order.addTradeBills",
|
|
|
198
|
- "流水信息:" + record.toString() + ",msg=" + e.getMessage());
|
|
|
199
|
- }
|
|
|
200
|
- }
|
|
|
201
|
-
|
|
|
202
|
- private void alarm(String name, String type, String content) {
|
|
|
203
|
- CommonAlarmEventPublisher.publish(name, type, content);
|
|
|
204
|
- }
|
|
|
205
|
-
|
|
|
206
|
- public double queryBuyerPenaltyAmount(Long orderCode){
|
|
|
207
|
- TradeBills condition = new TradeBills();
|
|
|
208
|
- condition.setOrderCode(orderCode);
|
|
|
209
|
- condition.setTradeType(3);
|
|
|
210
|
- List<TradeBills> tbs = tradeBillsMapper.selectByKeyProps(condition);
|
|
|
211
|
- double penaltyAmount = 0D;
|
|
|
212
|
- if (tbs != null && tbs.size() > 0){
|
|
|
213
|
- TradeBills ptb = tbs.get(0);
|
|
|
214
|
- penaltyAmount = ptb.getAmount() == null ? penaltyAmount : ptb.getAmount().doubleValue();
|
|
|
215
|
- }
|
|
|
216
|
- return penaltyAmount;
|
|
|
217
|
- }
|
|
|
218
|
-
|
|
|
219
|
- private Integer adaptPayType(Integer payment){
|
|
|
220
|
- // 流水记录表支付方式适配
|
|
|
221
|
- Integer recordPayment = payment;
|
|
|
222
|
- if (recordPayment != null) {
|
|
|
223
|
- if (recordPayment == 1) {
|
|
|
224
|
- recordPayment = 2;
|
|
|
225
|
- } else if (recordPayment == 2) {
|
|
|
226
|
- recordPayment = 1;
|
|
|
227
|
- }
|
|
|
228
|
- }
|
|
|
229
|
- return recordPayment;
|
|
|
230
|
- }
|
|
|
231
|
-
|
|
|
232
|
-
|
|
|
233
|
- /**
|
|
|
234
|
- * 支付货款流水记录
|
|
|
235
|
- * @param uid
|
|
|
236
|
- * @param sellerUid
|
|
|
237
|
- * @param skup
|
|
|
238
|
- * @param orderCode
|
|
|
239
|
- * @param payment
|
|
|
240
|
- * @param amount
|
|
|
241
|
- */
|
|
|
242
|
- public void addPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
243
|
- SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
|
|
244
|
- if (meta == null) {
|
|
|
245
|
- logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
246
|
- return;
|
|
|
247
|
- }
|
|
|
248
|
- Integer payType = adaptPayType(payment);
|
|
|
249
|
- // 增加流水记录
|
|
|
250
|
- TradeBills record = new TradeBills();
|
|
|
251
|
- record.setUid(uid);
|
|
|
252
|
- record.setOrderCode(orderCode);
|
|
|
253
|
- record.setPaidOrderCode(0L);
|
|
|
254
|
- record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
255
|
- record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
256
|
- record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
|
|
257
|
- record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
258
|
- record.setAmount(amount);
|
|
|
259
|
- try {
|
|
|
260
|
- JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
261
|
- BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
262
|
- amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
263
|
- } catch (Exception e) {
|
|
|
264
|
- logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
265
|
- return;
|
|
|
266
|
- }
|
|
|
267
|
-
|
|
|
268
|
- record.setSystemAmount(amount);// 有货收入
|
|
|
269
|
- record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
270
|
- record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
271
|
- addTradeBills(record);
|
|
|
272
|
- }
|
|
|
273
|
-
|
|
|
274
|
- /**
|
|
|
275
|
- * 支付保证金流水记录
|
|
|
276
|
- * @param uid
|
|
|
277
|
- * @param skup
|
|
|
278
|
- * @param orderCode
|
|
|
279
|
- * @param payment
|
|
|
280
|
- * @param amount
|
|
|
281
|
- */
|
|
|
282
|
- public void addPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
283
|
- SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee");
|
|
|
284
|
- if (meta == null) {
|
|
|
285
|
- logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup);
|
|
|
286
|
- return;
|
|
|
287
|
- }
|
|
|
288
|
- Integer payType = adaptPayType(payment);
|
|
|
289
|
- // 增加流水记录
|
|
|
290
|
- TradeBills record = new TradeBills();
|
|
|
291
|
- record.setUid(uid);
|
|
|
292
|
- record.setOrderCode(orderCode);
|
|
|
293
|
- record.setPaidOrderCode(0L);
|
|
|
294
|
- record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
295
|
- record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
296
|
- record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
297
|
- record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
298
|
- record.setAmount(amount);
|
|
|
299
|
- try {
|
|
|
300
|
- JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
301
|
- BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
302
|
- amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
303
|
- } catch (Exception e) {
|
|
|
304
|
- logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
305
|
- return;
|
|
|
306
|
- }
|
|
|
307
|
- record.setSystemAmount(amount);// 有货收入
|
|
|
308
|
- record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
309
|
- record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
310
|
- addTradeBills(record);
|
|
|
311
|
- }
|
|
|
312
|
-
|
|
|
313
|
- /**
|
|
|
314
|
- * 添加充值保证金流水
|
|
|
315
|
- * @param uid
|
|
|
316
|
- * @param orderCode
|
|
|
317
|
- * @param payment
|
|
|
318
|
- * @param amount
|
|
|
319
|
- */
|
|
|
320
|
- public void addPayRechargeEnsureRecord(Integer uid, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
321
|
-
|
|
|
322
|
- Integer payType = adaptPayType(payment);
|
|
|
323
|
- TradeBills record = new TradeBills();
|
|
|
324
|
- record.setUid(uid);
|
|
|
325
|
- record.setOrderCode(orderCode);
|
|
|
326
|
- record.setPaidOrderCode(0L);
|
|
|
327
|
- record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
328
|
- record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
329
|
- record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
330
|
- record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
331
|
- record.setAmount(amount);
|
|
|
332
|
- record.setSystemAmount(amount);// 有货收入
|
|
|
333
|
- record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
334
|
- record.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
335
|
- addTradeBills(record);
|
|
|
336
|
- }
|
|
|
337
|
-} |
1
|
+package com.yohoufo.order.service.impl;
|
|
|
2
|
+
|
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
5
|
+import com.yohobuy.ufo.model.order.common.Payment;
|
|
|
6
|
+import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
|
|
|
7
|
+import com.yohoufo.common.utils.BigDecimalHelper;
|
|
|
8
|
+import com.yohoufo.common.utils.DateUtil;
|
|
|
9
|
+import com.yohoufo.dal.order.SellerOrderMetaMapper;
|
|
|
10
|
+import com.yohoufo.dal.order.TradeBillsMapper;
|
|
|
11
|
+import com.yohoufo.dal.order.model.SellerOrderMeta;
|
|
|
12
|
+import com.yohoufo.dal.order.model.TradeBills;
|
|
|
13
|
+import com.yohoufo.order.common.BillTradeStatus;
|
|
|
14
|
+import com.yohoufo.order.constants.MetaKey;
|
|
|
15
|
+import com.yohoufo.order.model.dto.SellerOrderComputeResult;
|
|
|
16
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
17
|
+import org.slf4j.Logger;
|
|
|
18
|
+import org.slf4j.LoggerFactory;
|
|
|
19
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
20
|
+import org.springframework.stereotype.Service;
|
|
|
21
|
+
|
|
|
22
|
+import java.math.BigDecimal;
|
|
|
23
|
+import java.util.List;
|
|
|
24
|
+import java.util.Objects;
|
|
|
25
|
+
|
|
|
26
|
+/**
|
|
|
27
|
+ * Created by chenchao on 2018/10/10.
|
|
|
28
|
+ */
|
|
|
29
|
+@Service
|
|
|
30
|
+public class TradeBillsService {
|
|
|
31
|
+
|
|
|
32
|
+ final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
33
|
+
|
|
|
34
|
+ @Autowired
|
|
|
35
|
+ SellerOrderMetaMapper sellerOrderMetaMapper;
|
|
|
36
|
+
|
|
|
37
|
+ @Autowired
|
|
|
38
|
+ TradeBillsMapper tradeBillsMapper;
|
|
|
39
|
+
|
|
|
40
|
+ @Autowired
|
|
|
41
|
+ private ServiceOrderProcessor serviceOrderProcessor;
|
|
|
42
|
+
|
|
|
43
|
+
|
|
|
44
|
+ /**
|
|
|
45
|
+ * 退保证金流水记录
|
|
|
46
|
+ *
|
|
|
47
|
+ * @param uid
|
|
|
48
|
+ * @param skup
|
|
|
49
|
+ * @param orderCode
|
|
|
50
|
+ * @param payType
|
|
|
51
|
+ * @param tradeStatus
|
|
|
52
|
+ */
|
|
|
53
|
+ public void backPayEnsureRecord(Integer uid,
|
|
|
54
|
+ Integer skup,
|
|
|
55
|
+ Long orderCode,
|
|
|
56
|
+ Long paidOrderCode,
|
|
|
57
|
+ Integer payType,
|
|
|
58
|
+ Integer tradeStatus) {
|
|
|
59
|
+
|
|
|
60
|
+
|
|
|
61
|
+ String computeResultVal = null;
|
|
|
62
|
+
|
|
|
63
|
+ BigDecimal earnestMoney = null;
|
|
|
64
|
+ BigDecimal systemAmount = null;
|
|
|
65
|
+ if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
|
|
|
66
|
+ ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.isAppraiseOrder(orderCode);
|
|
|
67
|
+ if(!existenceNode.isExisted()){
|
|
|
68
|
+ return;
|
|
|
69
|
+ }
|
|
|
70
|
+ earnestMoney = existenceNode.getAppraiseOrder().getAmount();
|
|
|
71
|
+ systemAmount = earnestMoney.negate();
|
|
|
72
|
+ logger.info("in backPayEnsureRecord isGoodsServiceOrder orderCode {} earnestMoney {}", orderCode, computeResultVal);
|
|
|
73
|
+ }else {
|
|
|
74
|
+ SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, MetaKey.SELLER_FEE);
|
|
|
75
|
+ computeResultVal = Objects.nonNull(meta) ? meta.getMetaValue() : null;
|
|
|
76
|
+ logger.info("in backPayEnsureRecord buyerorder orderCode {} computeResultVal {}", orderCode, computeResultVal);
|
|
|
77
|
+ SellerOrderComputeResult socr = JSONObject.parseObject(computeResultVal, SellerOrderComputeResult.class);
|
|
|
78
|
+ earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
79
|
+ systemAmount = calSystemAmountByComputeResult(socr);
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ if (Objects.isNull(systemAmount) || Objects.isNull(systemAmount)) {
|
|
|
83
|
+ logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, orderCode {}", uid, orderCode);
|
|
|
84
|
+ return;
|
|
|
85
|
+ }
|
|
|
86
|
+ try{
|
|
|
87
|
+
|
|
|
88
|
+ backPayEnsureRecord0(uid, orderCode,paidOrderCode, payType, tradeStatus, earnestMoney, systemAmount);
|
|
|
89
|
+
|
|
|
90
|
+ }catch (Exception ex){
|
|
|
91
|
+ logger.error("backPayEnsureRecord error, uid {},orderCode {} computeResultVal {}",
|
|
|
92
|
+ uid, orderCode, computeResultVal, ex);
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+
|
|
|
96
|
+ }
|
|
|
97
|
+
|
|
|
98
|
+
|
|
|
99
|
+ private void backPayEnsureRecord0(Integer uid,
|
|
|
100
|
+ Long orderCode,
|
|
|
101
|
+ Long paidOrderCode,
|
|
|
102
|
+ Integer payType,
|
|
|
103
|
+ Integer tradeStatus,
|
|
|
104
|
+ BigDecimal earnestMoney,
|
|
|
105
|
+ BigDecimal systemAmount
|
|
|
106
|
+ ) {
|
|
|
107
|
+ if (payType != null && Payment.WALLET.getCode() == payType) {
|
|
|
108
|
+ return;
|
|
|
109
|
+ }
|
|
|
110
|
+
|
|
|
111
|
+
|
|
|
112
|
+ // 增加流水记录
|
|
|
113
|
+ TradeBills record = new TradeBills();
|
|
|
114
|
+ record.setUid(uid);
|
|
|
115
|
+ record.setOrderCode(orderCode);
|
|
|
116
|
+ record.setPaidOrderCode(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
117
|
+ record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
118
|
+ record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
119
|
+ record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
120
|
+ record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
121
|
+ record.setAmount(earnestMoney);
|
|
|
122
|
+ record.setSystemAmount(systemAmount);// 有货收入
|
|
|
123
|
+ record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
124
|
+ record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
125
|
+ addTradeBills(record);
|
|
|
126
|
+ }
|
|
|
127
|
+
|
|
|
128
|
+
|
|
|
129
|
+ BigDecimal calSystemAmountByComputeResult(SellerOrderComputeResult socr){
|
|
|
130
|
+ BigDecimal amount = BigDecimal.ZERO;
|
|
|
131
|
+ try {
|
|
|
132
|
+ BigDecimal rate = socr.getServiceFeeRate().getPayChannelRate();
|
|
|
133
|
+ BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
134
|
+ amount = BigDecimalHelper.halfUp(earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).negate());
|
|
|
135
|
+ } catch (Exception e) {
|
|
|
136
|
+ logger.warn("calSystemAmountByComputeResult fail SellerOrderComputeResult {}", socr);
|
|
|
137
|
+ }
|
|
|
138
|
+ return amount;
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
|
141
|
+ /**
|
|
|
142
|
+ * 退付货款流水记录
|
|
|
143
|
+ *
|
|
|
144
|
+ * @param uid
|
|
|
145
|
+ * @param sellerUid
|
|
|
146
|
+ * @param skup
|
|
|
147
|
+ * @param orderCode
|
|
|
148
|
+ * @param payType
|
|
|
149
|
+ * @param amount
|
|
|
150
|
+ * @param tradeStatus
|
|
|
151
|
+ */
|
|
|
152
|
+ public void backPayBuyRecord(Integer uid, Integer sellerUid, Integer skup,
|
|
|
153
|
+ Long orderCode, Long paidOrderCode, Integer payType, BigDecimal amount,
|
|
|
154
|
+ Integer tradeStatus) {
|
|
|
155
|
+
|
|
|
156
|
+ if (payType != null && Payment.WALLET.getCode() == payType) {
|
|
|
157
|
+ return;
|
|
|
158
|
+ }
|
|
|
159
|
+
|
|
|
160
|
+ SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
|
|
161
|
+ if (meta == null) {
|
|
|
162
|
+ logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
163
|
+ return;
|
|
|
164
|
+ }
|
|
|
165
|
+ // 增加流水记录
|
|
|
166
|
+ TradeBills record = new TradeBills();
|
|
|
167
|
+ record.setUid(uid);
|
|
|
168
|
+ record.setOrderCode(orderCode);
|
|
|
169
|
+ record.setPaidOrderCode(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
170
|
+ record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
171
|
+ record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
172
|
+ record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
|
|
173
|
+ record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
174
|
+ record.setAmount(amount);
|
|
|
175
|
+ try {
|
|
|
176
|
+ JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
177
|
+ BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
178
|
+ BigDecimal samount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
179
|
+ record.setSystemAmount(samount);// 有货收入
|
|
|
180
|
+ } catch (Exception e) {
|
|
|
181
|
+ logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
182
|
+ // return;
|
|
|
183
|
+ }
|
|
|
184
|
+
|
|
|
185
|
+ record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
186
|
+ record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
187
|
+ addTradeBills(record);
|
|
|
188
|
+ }
|
|
|
189
|
+
|
|
|
190
|
+
|
|
|
191
|
+ public void addTradeBills(TradeBills record) {
|
|
|
192
|
+ try {
|
|
|
193
|
+ tradeBillsMapper.insert(record);
|
|
|
194
|
+ } catch (Exception e) {
|
|
|
195
|
+ logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
|
|
|
196
|
+ alarm("记录流水到数据库出错", "ufo.order.addTradeBills",
|
|
|
197
|
+ "流水信息:" + record.toString() + ",msg=" + e.getMessage());
|
|
|
198
|
+ }
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+ private void alarm(String name, String type, String content) {
|
|
|
202
|
+ CommonAlarmEventPublisher.publish(name, type, content);
|
|
|
203
|
+ }
|
|
|
204
|
+
|
|
|
205
|
+ public double queryBuyerPenaltyAmount(Long orderCode){
|
|
|
206
|
+ TradeBills condition = new TradeBills();
|
|
|
207
|
+ condition.setOrderCode(orderCode);
|
|
|
208
|
+ condition.setTradeType(3);
|
|
|
209
|
+ List<TradeBills> tbs = tradeBillsMapper.selectByKeyProps(condition);
|
|
|
210
|
+ double penaltyAmount = 0D;
|
|
|
211
|
+ if (tbs != null && tbs.size() > 0){
|
|
|
212
|
+ TradeBills ptb = tbs.get(0);
|
|
|
213
|
+ penaltyAmount = ptb.getAmount() == null ? penaltyAmount : ptb.getAmount().doubleValue();
|
|
|
214
|
+ }
|
|
|
215
|
+ return penaltyAmount;
|
|
|
216
|
+ }
|
|
|
217
|
+
|
|
|
218
|
+ private Integer adaptPayType(Integer payment){
|
|
|
219
|
+ // 流水记录表支付方式适配
|
|
|
220
|
+ Integer recordPayment = payment;
|
|
|
221
|
+ if (recordPayment != null) {
|
|
|
222
|
+ if (recordPayment == 1) {
|
|
|
223
|
+ recordPayment = 2;
|
|
|
224
|
+ } else if (recordPayment == 2) {
|
|
|
225
|
+ recordPayment = 1;
|
|
|
226
|
+ }
|
|
|
227
|
+ }
|
|
|
228
|
+ return recordPayment;
|
|
|
229
|
+ }
|
|
|
230
|
+
|
|
|
231
|
+
|
|
|
232
|
+ /**
|
|
|
233
|
+ * 支付货款流水记录
|
|
|
234
|
+ * @param uid
|
|
|
235
|
+ * @param sellerUid
|
|
|
236
|
+ * @param skup
|
|
|
237
|
+ * @param orderCode
|
|
|
238
|
+ * @param payment
|
|
|
239
|
+ * @param amount
|
|
|
240
|
+ */
|
|
|
241
|
+ public void addPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
242
|
+ SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
|
|
243
|
+ if (meta == null) {
|
|
|
244
|
+ logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
245
|
+ return;
|
|
|
246
|
+ }
|
|
|
247
|
+ Integer payType = adaptPayType(payment);
|
|
|
248
|
+ // 增加流水记录
|
|
|
249
|
+ TradeBills record = new TradeBills();
|
|
|
250
|
+ record.setUid(uid);
|
|
|
251
|
+ record.setOrderCode(orderCode);
|
|
|
252
|
+ record.setPaidOrderCode(0L);
|
|
|
253
|
+ record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
254
|
+ record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
255
|
+ record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
|
|
256
|
+ record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
257
|
+ record.setAmount(amount);
|
|
|
258
|
+ try {
|
|
|
259
|
+ JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
260
|
+ BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
261
|
+ amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
262
|
+ } catch (Exception e) {
|
|
|
263
|
+ logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
264
|
+ return;
|
|
|
265
|
+ }
|
|
|
266
|
+
|
|
|
267
|
+ record.setSystemAmount(amount);// 有货收入
|
|
|
268
|
+ record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
269
|
+ record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
270
|
+ addTradeBills(record);
|
|
|
271
|
+ }
|
|
|
272
|
+
|
|
|
273
|
+ /**
|
|
|
274
|
+ * 支付保证金流水记录
|
|
|
275
|
+ * @param uid
|
|
|
276
|
+ * @param skup
|
|
|
277
|
+ * @param orderCode
|
|
|
278
|
+ * @param payment
|
|
|
279
|
+ * @param amount
|
|
|
280
|
+ */
|
|
|
281
|
+ public void addPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
282
|
+ SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee");
|
|
|
283
|
+ if (meta == null) {
|
|
|
284
|
+ logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup);
|
|
|
285
|
+ return;
|
|
|
286
|
+ }
|
|
|
287
|
+ Integer payType = adaptPayType(payment);
|
|
|
288
|
+ // 增加流水记录
|
|
|
289
|
+ TradeBills record = new TradeBills();
|
|
|
290
|
+ record.setUid(uid);
|
|
|
291
|
+ record.setOrderCode(orderCode);
|
|
|
292
|
+ record.setPaidOrderCode(0L);
|
|
|
293
|
+ record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
294
|
+ record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
295
|
+ record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
296
|
+ record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
297
|
+ record.setAmount(amount);
|
|
|
298
|
+ try {
|
|
|
299
|
+ JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
300
|
+ BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
301
|
+ amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
302
|
+ } catch (Exception e) {
|
|
|
303
|
+ logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
304
|
+ return;
|
|
|
305
|
+ }
|
|
|
306
|
+ record.setSystemAmount(amount);// 有货收入
|
|
|
307
|
+ record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
308
|
+ record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
309
|
+ addTradeBills(record);
|
|
|
310
|
+ }
|
|
|
311
|
+
|
|
|
312
|
+ /**
|
|
|
313
|
+ * 添加充值保证金流水
|
|
|
314
|
+ * @param uid
|
|
|
315
|
+ * @param orderCode
|
|
|
316
|
+ * @param payment
|
|
|
317
|
+ * @param amount
|
|
|
318
|
+ */
|
|
|
319
|
+ public void addPayRechargeEnsureRecord(Integer uid, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
320
|
+ Integer payType = adaptPayType(payment);
|
|
|
321
|
+ TradeBills record = new TradeBills();
|
|
|
322
|
+ record.setUid(uid);
|
|
|
323
|
+ record.setOrderCode(orderCode);
|
|
|
324
|
+ record.setPaidOrderCode(0L);
|
|
|
325
|
+ record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
326
|
+ record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
327
|
+ record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
328
|
+ record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
329
|
+ record.setAmount(amount);
|
|
|
330
|
+ record.setSystemAmount(amount);// 有货收入
|
|
|
331
|
+ record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
332
|
+ record.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
333
|
+ addTradeBills(record);
|
|
|
334
|
+ }
|
|
|
335
|
+} |