Showing
1 changed file
with
59 additions
and
47 deletions
@@ -12,9 +12,9 @@ import com.yohoufo.dal.order.TradeBillsMapper; | @@ -12,9 +12,9 @@ import com.yohoufo.dal.order.TradeBillsMapper; | ||
12 | import com.yohoufo.dal.order.model.SellerOrderMeta; | 12 | import com.yohoufo.dal.order.model.SellerOrderMeta; |
13 | import com.yohoufo.dal.order.model.TradeBills; | 13 | import com.yohoufo.dal.order.model.TradeBills; |
14 | import com.yohoufo.order.common.BillTradeStatus; | 14 | import com.yohoufo.order.common.BillTradeStatus; |
15 | -import com.yohoufo.order.constants.MetaKey; | ||
16 | import com.yohoufo.order.event.BillLogEvent; | 15 | import com.yohoufo.order.event.BillLogEvent; |
17 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; | 16 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; |
17 | +import com.yohoufo.order.model.dto.ServiceFeeRate; | ||
18 | import com.yohoufo.order.repository.TradeBillsRepository; | 18 | import com.yohoufo.order.repository.TradeBillsRepository; |
19 | import com.yohoufo.order.service.seller.SellerOrderServiceDelegate; | 19 | import com.yohoufo.order.service.seller.SellerOrderServiceDelegate; |
20 | import org.apache.commons.lang3.ObjectUtils; | 20 | import org.apache.commons.lang3.ObjectUtils; |
@@ -76,12 +76,9 @@ public class TradeBillsService { | @@ -76,12 +76,9 @@ public class TradeBillsService { | ||
76 | systemAmount = earnestMoney.negate(); | 76 | systemAmount = earnestMoney.negate(); |
77 | logger.info("in backPayEnsureRecord isGoodsServiceOrder orderCode {} earnestMoney {}", orderCode, computeResultVal); | 77 | logger.info("in backPayEnsureRecord isGoodsServiceOrder orderCode {} earnestMoney {}", orderCode, computeResultVal); |
78 | }else { | 78 | }else { |
79 | - SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, MetaKey.SELLER_FEE); | ||
80 | - computeResultVal = Objects.nonNull(meta) ? meta.getMetaValue() : null; | ||
81 | - logger.info("in backPayEnsureRecord buyerorder orderCode {} computeResultVal {}", orderCode, computeResultVal); | ||
82 | - SellerOrderComputeResult socr = JSONObject.parseObject(computeResultVal, SellerOrderComputeResult.class); | 79 | + SellerOrderComputeResult socr = sellerOrderServiceDelegate.getSellerFeeService().getSellerOrderComputeResult(uid, skup); |
83 | earnestMoney = socr.getEarnestMoney().getEarnestMoney(); | 80 | earnestMoney = socr.getEarnestMoney().getEarnestMoney(); |
84 | - systemAmount = calSystemAmountByComputeResult(socr); | 81 | + systemAmount = calSystemAmountFromEarnMoney(socr); |
85 | } | 82 | } |
86 | 83 | ||
87 | if (Objects.isNull(systemAmount) || Objects.isNull(systemAmount)) { | 84 | if (Objects.isNull(systemAmount) || Objects.isNull(systemAmount)) { |
@@ -131,14 +128,14 @@ public class TradeBillsService { | @@ -131,14 +128,14 @@ public class TradeBillsService { | ||
131 | } | 128 | } |
132 | 129 | ||
133 | 130 | ||
134 | - BigDecimal calSystemAmountByComputeResult(SellerOrderComputeResult socr){ | 131 | + BigDecimal calSystemAmountFromEarnMoney(SellerOrderComputeResult socr){ |
135 | BigDecimal amount = BigDecimal.ZERO; | 132 | BigDecimal amount = BigDecimal.ZERO; |
136 | try { | 133 | try { |
137 | BigDecimal rate = socr.getServiceFeeRate().getPayChannelRate(); | 134 | BigDecimal rate = socr.getServiceFeeRate().getPayChannelRate(); |
138 | BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney(); | 135 | BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney(); |
139 | amount = BigDecimalHelper.halfUp(earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).negate()); | 136 | amount = BigDecimalHelper.halfUp(earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).negate()); |
140 | } catch (Exception e) { | 137 | } catch (Exception e) { |
141 | - logger.warn("calSystemAmountByComputeResult fail SellerOrderComputeResult {}", socr); | 138 | + logger.warn("calSystemAmountFromEarnMoney fail SellerOrderComputeResult {}", socr,e); |
142 | } | 139 | } |
143 | return amount; | 140 | return amount; |
144 | } | 141 | } |
@@ -161,10 +158,9 @@ public class TradeBillsService { | @@ -161,10 +158,9 @@ public class TradeBillsService { | ||
161 | if (payType != null && Payment.WALLET.getCode() == payType) { | 158 | if (payType != null && Payment.WALLET.getCode() == payType) { |
162 | return; | 159 | return; |
163 | } | 160 | } |
164 | - | ||
165 | - SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee"); | ||
166 | - if (meta == null) { | ||
167 | - logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup); | 161 | + SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService().getSellerOrderComputeResult(sellerUid,skup); |
162 | + if (computeResult == null) { | ||
163 | + logger.error("backPayBuyRecord fail, computeResult is null, selleruid = {}, skup={}", sellerUid, skup); | ||
168 | return; | 164 | return; |
169 | } | 165 | } |
170 | // 增加流水记录 | 166 | // 增加流水记录 |
@@ -177,16 +173,8 @@ public class TradeBillsService { | @@ -177,16 +173,8 @@ public class TradeBillsService { | ||
177 | record.setTradeType(2);//1:保证金;2:货款;3:补偿款 | 173 | record.setTradeType(2);//1:保证金;2:货款;3:补偿款 |
178 | record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出 | 174 | record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出 |
179 | record.setAmount(amount); | 175 | record.setAmount(amount); |
180 | - try { | ||
181 | - JSONObject metavalue = JSON.parseObject(meta.getMetaValue()); | ||
182 | - BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate"); | ||
183 | - BigDecimal samount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP); | ||
184 | - record.setSystemAmount(samount);// 有货收入 | ||
185 | - } catch (Exception e) { | ||
186 | - logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage()); | ||
187 | - // return; | ||
188 | - } | ||
189 | - | 176 | + BigDecimal systemAmount = calculateSystemAmount4Back(sellerUid,skup,amount,computeResult); |
177 | + record.setSystemAmount(systemAmount); | ||
190 | record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结 | 178 | record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结 |
191 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); | 179 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); |
192 | addTradeBills(record); | 180 | addTradeBills(record); |
@@ -277,14 +265,7 @@ public class TradeBillsService { | @@ -277,14 +265,7 @@ public class TradeBillsService { | ||
277 | */ | 265 | */ |
278 | public void addPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) { | 266 | public void addPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) { |
279 | 267 | ||
280 | - SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService() | ||
281 | - .getSellerOrderComputeResult(sellerUid, skup); | ||
282 | - PlatformFeeDto platformFee; | ||
283 | - if (computeResult == null || Objects.isNull(platformFee = computeResult.getPlatformFee())) { | ||
284 | - logger.error("addPayBuyRecord error,no computeResult of seller order in meta, orderCode {},selleruid {}, skup {}", | ||
285 | - orderCode, sellerUid, skup); | ||
286 | - return; | ||
287 | - } | 268 | + |
288 | Integer payType = adaptPayType(payment); | 269 | Integer payType = adaptPayType(payment); |
289 | // 增加流水记录 | 270 | // 增加流水记录 |
290 | TradeBills record = new TradeBills(); | 271 | TradeBills record = new TradeBills(); |
@@ -296,15 +277,54 @@ public class TradeBillsService { | @@ -296,15 +277,54 @@ public class TradeBillsService { | ||
296 | record.setTradeType(2);//1:保证金;2:货款;3:补偿款 | 277 | record.setTradeType(2);//1:保证金;2:货款;3:补偿款 |
297 | record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出 | 278 | record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出 |
298 | record.setAmount(amount); | 279 | record.setAmount(amount); |
299 | - | ||
300 | - | ||
301 | - BigDecimal systemAmount = platformFee.getServiceFee(); | 280 | + SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService() |
281 | + .getSellerOrderComputeResult(sellerUid, skup); | ||
282 | + ServiceFeeRate serviceFeeRate; | ||
283 | + if (computeResult == null || Objects.isNull(serviceFeeRate = computeResult.getServiceFeeRate())) { | ||
284 | + logger.error("addPayBuyRecord error,no computeResult of seller order in meta, orderCode {},selleruid {}, skup {}", | ||
285 | + orderCode, sellerUid, skup); | ||
286 | + } | ||
287 | + //计算平台留存 | ||
288 | + BigDecimal systemAmount = calculateSystemAmount(sellerUid,skup,amount, computeResult); | ||
302 | record.setSystemAmount(systemAmount);// 有货收入 | 289 | record.setSystemAmount(systemAmount);// 有货收入 |
303 | record.setTradeStatus(BillTradeStatus.SUCCESS.getCode()); | 290 | record.setTradeStatus(BillTradeStatus.SUCCESS.getCode()); |
304 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); | 291 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); |
305 | addTradeBills(record); | 292 | addTradeBills(record); |
306 | } | 293 | } |
307 | 294 | ||
295 | + | ||
296 | + /** | ||
297 | + * 扣除转账手续费后的留存金额 | ||
298 | + * @param uid | ||
299 | + * @param skup | ||
300 | + * @param amount | ||
301 | + * @param computeResult | ||
302 | + * @return | ||
303 | + */ | ||
304 | + private BigDecimal calculateSystemAmount(int uid, int skup, | ||
305 | + BigDecimal amount, SellerOrderComputeResult computeResult){ | ||
306 | + BigDecimal systemAount = null; | ||
307 | + try { | ||
308 | + BigDecimal rate = computeResult.getServiceFeeRate().getPayChannelRate(); | ||
309 | + systemAount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP); | ||
310 | + } catch (Exception e) { | ||
311 | + logger.error("calculateSystemAmount fail, uid is {}, skup is {}, err is {}", uid, skup, e); | ||
312 | + } | ||
313 | + return systemAount; | ||
314 | + } | ||
315 | + | ||
316 | + private BigDecimal calculateSystemAmount4Back(int uid, int skup, | ||
317 | + BigDecimal amount, SellerOrderComputeResult computeResult){ | ||
318 | + BigDecimal systemAount = null; | ||
319 | + try { | ||
320 | + BigDecimal rate = computeResult.getServiceFeeRate().getPayChannelRate(); | ||
321 | + systemAount = amount.multiply(BigDecimal.ONE.subtract(rate)).negate().setScale(2, BigDecimal.ROUND_HALF_UP); | ||
322 | + } catch (Exception e) { | ||
323 | + logger.error("calculateSystemAmount 4 back fail, uid is {}, skup is {}, err is {}", uid, skup, e); | ||
324 | + } | ||
325 | + return systemAount; | ||
326 | + } | ||
327 | + | ||
308 | /** | 328 | /** |
309 | * 支付保证金流水记录 | 329 | * 支付保证金流水记录 |
310 | * @param uid | 330 | * @param uid |
@@ -314,11 +334,7 @@ public class TradeBillsService { | @@ -314,11 +334,7 @@ public class TradeBillsService { | ||
314 | * @param amount | 334 | * @param amount |
315 | */ | 335 | */ |
316 | public void addPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) { | 336 | public void addPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) { |
317 | - SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee"); | ||
318 | - if (meta == null) { | ||
319 | - logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup); | ||
320 | - return; | ||
321 | - } | 337 | + |
322 | Integer payType = adaptPayType(payment); | 338 | Integer payType = adaptPayType(payment); |
323 | // 增加流水记录 | 339 | // 增加流水记录 |
324 | TradeBills record = new TradeBills(); | 340 | TradeBills record = new TradeBills(); |
@@ -330,15 +346,11 @@ public class TradeBillsService { | @@ -330,15 +346,11 @@ public class TradeBillsService { | ||
330 | record.setTradeType(1);//1:保证金;2:货款;3:补偿款 | 346 | record.setTradeType(1);//1:保证金;2:货款;3:补偿款 |
331 | record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出 | 347 | record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出 |
332 | record.setAmount(amount); | 348 | record.setAmount(amount); |
333 | - try { | ||
334 | - JSONObject metavalue = JSON.parseObject(meta.getMetaValue()); | ||
335 | - BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate"); | ||
336 | - amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP); | ||
337 | - } catch (Exception e) { | ||
338 | - logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage()); | ||
339 | - return; | ||
340 | - } | ||
341 | - record.setSystemAmount(amount);// 有货收入 | 349 | + |
350 | + SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService() | ||
351 | + .getSellerOrderComputeResult(uid, skup); | ||
352 | + BigDecimal systemAmount = calculateSystemAmount(uid, skup, amount, computeResult); | ||
353 | + record.setSystemAmount(systemAmount);// 有货收入 | ||
342 | record.setTradeStatus(BillTradeStatus.SUCCESS.getCode()); | 354 | record.setTradeStatus(BillTradeStatus.SUCCESS.getCode()); |
343 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); | 355 | record.setCreateTime((int) (System.currentTimeMillis() / 1000)); |
344 | addTradeBills(record); | 356 | addTradeBills(record); |
-
Please register or login to post a comment