...
|
...
|
@@ -3,13 +3,18 @@ package com.yohoufo.order.service.impl; |
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
|
|
|
import com.yohoufo.common.utils.BigDecimalHelper;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderMetaMapper;
|
|
|
import com.yohoufo.dal.order.TradeBillsMapper;
|
|
|
import com.yohoufo.dal.order.model.AppraiseOrderMeta;
|
|
|
import com.yohoufo.dal.order.model.SellerOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderMeta;
|
|
|
import com.yohoufo.dal.order.model.TradeBills;
|
|
|
import com.yohobuy.ufo.model.order.common.Payment;
|
|
|
import com.yohoufo.order.common.BillTradeStatus;
|
|
|
import com.yohoufo.order.constants.MetaKey;
|
|
|
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -33,6 +38,12 @@ public class TradeBillsService { |
|
|
@Autowired
|
|
|
TradeBillsMapper tradeBillsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceOrderProcessor serviceOrderProcessor;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
|
|
|
|
|
|
/**
|
|
|
* 退保证金流水记录
|
|
|
*
|
...
|
...
|
@@ -42,54 +53,88 @@ public class TradeBillsService { |
|
|
* @param payType
|
|
|
* @param tradeStatus
|
|
|
*/
|
|
|
public void backPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType, Integer tradeStatus) {
|
|
|
backPayEnsureRecord(uid, skup, orderCode, payType, tradeStatus, null, null);
|
|
|
}
|
|
|
public void backPayEnsureRecord(Integer uid,
|
|
|
Integer skup,
|
|
|
Long orderCode,
|
|
|
Integer payType,
|
|
|
Integer tradeStatus) {
|
|
|
|
|
|
public void backPayEnsureRecord(SellerOrder sellerOrder, Integer tradeStatus, BigDecimal backEarnestMoney, SellerOrderMeta meta) {
|
|
|
backPayEnsureRecord(sellerOrder.getUid(), sellerOrder.getSkup(), sellerOrder.getOrderCode(), sellerOrder.getPayment(), tradeStatus, backEarnestMoney, meta);
|
|
|
}
|
|
|
|
|
|
private void backPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType,
|
|
|
Integer tradeStatus,
|
|
|
BigDecimal backEarnestMoney, SellerOrderMeta meta) {
|
|
|
if (payType != null && Payment.WALLET.getCode() == payType) {
|
|
|
String computeResultVal = null;
|
|
|
|
|
|
if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
|
|
|
AppraiseOrderMeta feeCondition = new AppraiseOrderMeta();
|
|
|
feeCondition.setOrderCode(orderCode);
|
|
|
feeCondition.setMetaKey(MetaKey.SELLER_FEE);
|
|
|
AppraiseOrderMeta feeMeta = appraiseOrderMetaMapper.selectByOrderCode(feeCondition);
|
|
|
computeResultVal = Objects.nonNull(feeMeta) ? feeMeta.getMetaValue() : null;
|
|
|
logger.info("in backPayEnsureRecord isGoodsServiceOrder orderCode {} computeResultVal {}", orderCode, computeResultVal);
|
|
|
}else {
|
|
|
SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, MetaKey.SELLER_FEE);
|
|
|
computeResultVal = Objects.nonNull(meta) ? meta.getMetaValue() : null;
|
|
|
logger.info("in backPayEnsureRecord buyerorder orderCode {} computeResultVal {}", orderCode, computeResultVal);
|
|
|
}
|
|
|
|
|
|
if (Objects.isNull(computeResultVal)) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup);
|
|
|
return;
|
|
|
}
|
|
|
if (Objects.isNull(meta)) {
|
|
|
meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee");
|
|
|
try{
|
|
|
SellerOrderComputeResult socr = JSONObject.parseObject(computeResultVal, SellerOrderComputeResult.class);
|
|
|
BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
BigDecimal systemAmount = calSystemAmountByComputeResult(socr);
|
|
|
backPayEnsureRecord0(uid, orderCode, payType, tradeStatus, earnestMoney, systemAmount);
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
logger.error("backPayEnsureRecord error, uid {},orderCode {} computeResultVal {}",
|
|
|
uid, orderCode, computeResultVal, ex);
|
|
|
}
|
|
|
if (Objects.isNull(meta)) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private void backPayEnsureRecord0(Integer uid,
|
|
|
Long orderCode,
|
|
|
Integer payType,
|
|
|
Integer tradeStatus,
|
|
|
BigDecimal earnestMoney,
|
|
|
BigDecimal systemAmount
|
|
|
) {
|
|
|
if (payType != null && Payment.WALLET.getCode() == payType) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
// 增加流水记录
|
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(uid);
|
|
|
record.setOrderCode(orderCode);
|
|
|
record.setPaidOrderCode(0L);
|
|
|
record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
BigDecimal earnestMoney = backEarnestMoney;
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
try {
|
|
|
JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
if (Objects.isNull(earnestMoney)) {
|
|
|
earnestMoney = metavalue.getJSONObject("earnestMoney").getBigDecimal("earnestMoney");
|
|
|
}
|
|
|
amount = earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
}
|
|
|
record.setAmount(earnestMoney);
|
|
|
record.setSystemAmount(amount);// 有货收入
|
|
|
record.setSystemAmount(systemAmount);// 有货收入
|
|
|
record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
|
|
|
BigDecimal calSystemAmountByComputeResult(SellerOrderComputeResult socr){
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
try {
|
|
|
BigDecimal rate = socr.getServiceFeeRate().getPayChannelRate();
|
|
|
BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
amount = BigDecimalHelper.halfUp(earnestMoney.multiply(BigDecimal.ONE.subtract(rate)).negate());
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("calSystemAmountByComputeResult fail SellerOrderComputeResult {}", socr);
|
|
|
}
|
|
|
return amount;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退付货款流水记录
|
|
|
*
|
...
|
...
|
@@ -118,6 +163,7 @@ public class TradeBillsService { |
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(uid);
|
|
|
record.setOrderCode(orderCode);
|
|
|
record.setPaidOrderCode(0L);
|
|
|
record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
...
|
...
|
@@ -200,6 +246,7 @@ public class TradeBillsService { |
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(uid);
|
|
|
record.setOrderCode(orderCode);
|
|
|
record.setPaidOrderCode(0L);
|
|
|
record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
...
|
...
|
@@ -239,6 +286,7 @@ public class TradeBillsService { |
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(uid);
|
|
|
record.setOrderCode(orderCode);
|
|
|
record.setPaidOrderCode(0L);
|
|
|
record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
...
|
...
|
@@ -265,6 +313,7 @@ public class TradeBillsService { |
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(uid);
|
|
|
record.setOrderCode(orderCode);
|
|
|
record.setPaidOrderCode(0L);
|
|
|
record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
...
|
...
|
|