...
|
...
|
@@ -12,9 +12,9 @@ import com.yohoufo.dal.order.TradeBillsMapper; |
|
|
import com.yohoufo.dal.order.model.SellerOrderMeta;
|
|
|
import com.yohoufo.dal.order.model.TradeBills;
|
|
|
import com.yohoufo.order.common.BillTradeStatus;
|
|
|
import com.yohoufo.order.constants.MetaKey;
|
|
|
import com.yohoufo.order.event.BillLogEvent;
|
|
|
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
|
|
|
import com.yohoufo.order.model.dto.ServiceFeeRate;
|
|
|
import com.yohoufo.order.repository.TradeBillsRepository;
|
|
|
import com.yohoufo.order.service.seller.SellerOrderServiceDelegate;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
...
|
...
|
@@ -76,12 +76,9 @@ public class TradeBillsService { |
|
|
systemAmount = earnestMoney.negate();
|
|
|
logger.info("in backPayEnsureRecord isGoodsServiceOrder orderCode {} earnestMoney {}", 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);
|
|
|
SellerOrderComputeResult socr = JSONObject.parseObject(computeResultVal, SellerOrderComputeResult.class);
|
|
|
SellerOrderComputeResult socr = sellerOrderServiceDelegate.getSellerFeeService().getSellerOrderComputeResult(uid, skup);
|
|
|
earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
systemAmount = calSystemAmountByComputeResult(socr);
|
|
|
systemAmount = calSystemAmountFromEarnMoney(socr);
|
|
|
}
|
|
|
|
|
|
if (Objects.isNull(systemAmount) || Objects.isNull(systemAmount)) {
|
...
|
...
|
@@ -131,14 +128,14 @@ public class TradeBillsService { |
|
|
}
|
|
|
|
|
|
|
|
|
BigDecimal calSystemAmountByComputeResult(SellerOrderComputeResult socr){
|
|
|
BigDecimal calSystemAmountFromEarnMoney(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);
|
|
|
logger.warn("calSystemAmountFromEarnMoney fail SellerOrderComputeResult {}", socr,e);
|
|
|
}
|
|
|
return amount;
|
|
|
}
|
...
|
...
|
@@ -161,10 +158,9 @@ public class TradeBillsService { |
|
|
if (payType != null && Payment.WALLET.getCode() == payType) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
|
|
if (meta == null) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService().getSellerOrderComputeResult(sellerUid,skup);
|
|
|
if (computeResult == null) {
|
|
|
logger.error("backPayBuyRecord fail, computeResult is null, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
return;
|
|
|
}
|
|
|
// 增加流水记录
|
...
|
...
|
@@ -177,16 +173,8 @@ public class TradeBillsService { |
|
|
record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
|
|
record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
record.setAmount(amount);
|
|
|
try {
|
|
|
JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
BigDecimal samount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
record.setSystemAmount(samount);// 有货收入
|
|
|
} catch (Exception e) {
|
|
|
logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
// return;
|
|
|
}
|
|
|
|
|
|
BigDecimal systemAmount = calculateSystemAmount4Back(sellerUid,skup,amount,computeResult);
|
|
|
record.setSystemAmount(systemAmount);
|
|
|
record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
...
|
...
|
@@ -277,14 +265,7 @@ public class TradeBillsService { |
|
|
*/
|
|
|
public void addPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
|
|
|
SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService()
|
|
|
.getSellerOrderComputeResult(sellerUid, skup);
|
|
|
PlatformFeeDto platformFee;
|
|
|
if (computeResult == null || Objects.isNull(platformFee = computeResult.getPlatformFee())) {
|
|
|
logger.error("addPayBuyRecord error,no computeResult of seller order in meta, orderCode {},selleruid {}, skup {}",
|
|
|
orderCode, sellerUid, skup);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Integer payType = adaptPayType(payment);
|
|
|
// 增加流水记录
|
|
|
TradeBills record = new TradeBills();
|
...
|
...
|
@@ -296,15 +277,54 @@ public class TradeBillsService { |
|
|
record.setTradeType(2);//1:保证金;2:货款;3:补偿款
|
|
|
record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
record.setAmount(amount);
|
|
|
|
|
|
|
|
|
BigDecimal systemAmount = platformFee.getServiceFee();
|
|
|
SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService()
|
|
|
.getSellerOrderComputeResult(sellerUid, skup);
|
|
|
ServiceFeeRate serviceFeeRate;
|
|
|
if (computeResult == null || Objects.isNull(serviceFeeRate = computeResult.getServiceFeeRate())) {
|
|
|
logger.error("addPayBuyRecord error,no computeResult of seller order in meta, orderCode {},selleruid {}, skup {}",
|
|
|
orderCode, sellerUid, skup);
|
|
|
}
|
|
|
//计算平台留存
|
|
|
BigDecimal systemAmount = calculateSystemAmount(sellerUid,skup,amount, computeResult);
|
|
|
record.setSystemAmount(systemAmount);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 扣除转账手续费后的留存金额
|
|
|
* @param uid
|
|
|
* @param skup
|
|
|
* @param amount
|
|
|
* @param computeResult
|
|
|
* @return
|
|
|
*/
|
|
|
private BigDecimal calculateSystemAmount(int uid, int skup,
|
|
|
BigDecimal amount, SellerOrderComputeResult computeResult){
|
|
|
BigDecimal systemAount = null;
|
|
|
try {
|
|
|
BigDecimal rate = computeResult.getServiceFeeRate().getPayChannelRate();
|
|
|
systemAount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("calculateSystemAmount fail, uid is {}, skup is {}, err is {}", uid, skup, e);
|
|
|
}
|
|
|
return systemAount;
|
|
|
}
|
|
|
|
|
|
private BigDecimal calculateSystemAmount4Back(int uid, int skup,
|
|
|
BigDecimal amount, SellerOrderComputeResult computeResult){
|
|
|
BigDecimal systemAount = null;
|
|
|
try {
|
|
|
BigDecimal rate = computeResult.getServiceFeeRate().getPayChannelRate();
|
|
|
systemAount = amount.multiply(BigDecimal.ONE.subtract(rate)).negate().setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("calculateSystemAmount 4 back fail, uid is {}, skup is {}, err is {}", uid, skup, e);
|
|
|
}
|
|
|
return systemAount;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付保证金流水记录
|
|
|
* @param uid
|
...
|
...
|
@@ -314,11 +334,7 @@ public class TradeBillsService { |
|
|
* @param amount
|
|
|
*/
|
|
|
public void addPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee");
|
|
|
if (meta == null) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Integer payType = adaptPayType(payment);
|
|
|
// 增加流水记录
|
|
|
TradeBills record = new TradeBills();
|
...
|
...
|
@@ -330,15 +346,11 @@ public class TradeBillsService { |
|
|
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
|
|
|
record.setAmount(amount);
|
|
|
try {
|
|
|
JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
|
|
|
amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
|
|
|
return;
|
|
|
}
|
|
|
record.setSystemAmount(amount);// 有货收入
|
|
|
|
|
|
SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService()
|
|
|
.getSellerOrderComputeResult(uid, skup);
|
|
|
BigDecimal systemAmount = calculateSystemAmount(uid, skup, amount, computeResult);
|
|
|
record.setSystemAmount(systemAmount);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
...
|
...
|
|