|
|
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.common.utils.DateUtil;
|
|
|
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.apache.commons.lang3.ObjectUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* Created by chenchao on 2018/10/10.
|
|
|
*/
|
|
|
@Service
|
|
|
public class TradeBillsService {
|
|
|
|
|
|
final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
@Autowired
|
|
|
SellerOrderMetaMapper sellerOrderMetaMapper;
|
|
|
|
|
|
@Autowired
|
|
|
TradeBillsMapper tradeBillsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceOrderProcessor serviceOrderProcessor;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
|
|
|
|
|
|
/**
|
|
|
* 退保证金流水记录
|
|
|
*
|
|
|
* @param uid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payType
|
|
|
* @param tradeStatus
|
|
|
*/
|
|
|
public void backPayEnsureRecord(Integer uid,
|
|
|
Integer skup,
|
|
|
Long orderCode,
|
|
|
Long paidOrderCode,
|
|
|
Integer payType,
|
|
|
Integer tradeStatus) {
|
|
|
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
try{
|
|
|
SellerOrderComputeResult socr = JSONObject.parseObject(computeResultVal, SellerOrderComputeResult.class);
|
|
|
BigDecimal earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
BigDecimal systemAmount = calSystemAmountByComputeResult(socr);
|
|
|
backPayEnsureRecord0(uid, orderCode, paidOrderCode, payType, tradeStatus, earnestMoney, systemAmount);
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
logger.error("backPayEnsureRecord error, uid {},orderCode {} computeResultVal {}",
|
|
|
uid, orderCode, computeResultVal, ex);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private void backPayEnsureRecord0(Integer uid,
|
|
|
Long orderCode,
|
|
|
Long paidOrderCode,
|
|
|
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(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
record.setAmount(earnestMoney);
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退付货款流水记录
|
|
|
*
|
|
|
* @param uid
|
|
|
* @param sellerUid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payType
|
|
|
* @param amount
|
|
|
* @param tradeStatus
|
|
|
*/
|
|
|
public void backPayBuyRecord(Integer uid, Integer sellerUid, Integer skup,
|
|
|
Long orderCode, Long paidOrderCode, Integer payType, BigDecimal amount,
|
|
|
Integer tradeStatus) {
|
|
|
|
|
|
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);
|
|
|
return;
|
|
|
}
|
|
|
// 增加流水记录
|
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(uid);
|
|
|
record.setOrderCode(orderCode);
|
|
|
record.setPaidOrderCode(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
|
|
|
public void addTradeBills(TradeBills record) {
|
|
|
try {
|
|
|
tradeBillsMapper.insert(record);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
|
|
|
alarm("记录流水到数据库出错", "ufo.order.addTradeBills",
|
|
|
"流水信息:" + record.toString() + ",msg=" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void alarm(String name, String type, String content) {
|
|
|
CommonAlarmEventPublisher.publish(name, type, content);
|
|
|
}
|
|
|
|
|
|
public double queryBuyerPenaltyAmount(Long orderCode){
|
|
|
TradeBills condition = new TradeBills();
|
|
|
condition.setOrderCode(orderCode);
|
|
|
condition.setTradeType(3);
|
|
|
List<TradeBills> tbs = tradeBillsMapper.selectByKeyProps(condition);
|
|
|
double penaltyAmount = 0D;
|
|
|
if (tbs != null && tbs.size() > 0){
|
|
|
TradeBills ptb = tbs.get(0);
|
|
|
penaltyAmount = ptb.getAmount() == null ? penaltyAmount : ptb.getAmount().doubleValue();
|
|
|
}
|
|
|
return penaltyAmount;
|
|
|
}
|
|
|
|
|
|
private Integer adaptPayType(Integer payment){
|
|
|
// 流水记录表支付方式适配
|
|
|
Integer recordPayment = payment;
|
|
|
if (recordPayment != null) {
|
|
|
if (recordPayment == 1) {
|
|
|
recordPayment = 2;
|
|
|
} else if (recordPayment == 2) {
|
|
|
recordPayment = 1;
|
|
|
}
|
|
|
}
|
|
|
return recordPayment;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 支付货款流水记录
|
|
|
* @param uid
|
|
|
* @param sellerUid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payment
|
|
|
* @param amount
|
|
|
*/
|
|
|
public void addPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
|
|
if (meta == null) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
return;
|
|
|
}
|
|
|
Integer payType = adaptPayType(payment);
|
|
|
// 增加流水记录
|
|
|
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:补偿款
|
|
|
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);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付保证金流水记录
|
|
|
* @param uid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payment
|
|
|
* @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();
|
|
|
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(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);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加充值保证金流水
|
|
|
* @param uid
|
|
|
* @param orderCode
|
|
|
* @param payment
|
|
|
* @param amount
|
|
|
*/
|
|
|
public void addPayRechargeEnsureRecord(Integer uid, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
|
|
|
Integer payType = adaptPayType(payment);
|
|
|
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(2);// 1:用户收入; 2:用户支出
|
|
|
record.setAmount(amount);
|
|
|
record.setSystemAmount(amount);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
} |
|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yohobuy.ufo.model.order.common.Payment;
|
|
|
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
|
|
|
import com.yohoufo.common.utils.BigDecimalHelper;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.SellerOrderMetaMapper;
|
|
|
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.model.dto.SellerOrderComputeResult;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* Created by chenchao on 2018/10/10.
|
|
|
*/
|
|
|
@Service
|
|
|
public class TradeBillsService {
|
|
|
|
|
|
final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
@Autowired
|
|
|
SellerOrderMetaMapper sellerOrderMetaMapper;
|
|
|
|
|
|
@Autowired
|
|
|
TradeBillsMapper tradeBillsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceOrderProcessor serviceOrderProcessor;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 退保证金流水记录
|
|
|
*
|
|
|
* @param uid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payType
|
|
|
* @param tradeStatus
|
|
|
*/
|
|
|
public void backPayEnsureRecord(Integer uid,
|
|
|
Integer skup,
|
|
|
Long orderCode,
|
|
|
Long paidOrderCode,
|
|
|
Integer payType,
|
|
|
Integer tradeStatus) {
|
|
|
|
|
|
|
|
|
String computeResultVal = null;
|
|
|
|
|
|
BigDecimal earnestMoney = null;
|
|
|
BigDecimal systemAmount = null;
|
|
|
if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
|
|
|
ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.isAppraiseOrder(orderCode);
|
|
|
if(!existenceNode.isExisted()){
|
|
|
return;
|
|
|
}
|
|
|
earnestMoney = existenceNode.getAppraiseOrder().getAmount();
|
|
|
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);
|
|
|
earnestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
systemAmount = calSystemAmountByComputeResult(socr);
|
|
|
}
|
|
|
|
|
|
if (Objects.isNull(systemAmount) || Objects.isNull(systemAmount)) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, orderCode {}", uid, orderCode);
|
|
|
return;
|
|
|
}
|
|
|
try{
|
|
|
|
|
|
backPayEnsureRecord0(uid, orderCode,paidOrderCode, payType, tradeStatus, earnestMoney, systemAmount);
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
logger.error("backPayEnsureRecord error, uid {},orderCode {} computeResultVal {}",
|
|
|
uid, orderCode, computeResultVal, ex);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private void backPayEnsureRecord0(Integer uid,
|
|
|
Long orderCode,
|
|
|
Long paidOrderCode,
|
|
|
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(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
record.setUserType(2);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
|
|
|
record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
|
|
|
record.setAmount(earnestMoney);
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退付货款流水记录
|
|
|
*
|
|
|
* @param uid
|
|
|
* @param sellerUid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payType
|
|
|
* @param amount
|
|
|
* @param tradeStatus
|
|
|
*/
|
|
|
public void backPayBuyRecord(Integer uid, Integer sellerUid, Integer skup,
|
|
|
Long orderCode, Long paidOrderCode, Integer payType, BigDecimal amount,
|
|
|
Integer tradeStatus) {
|
|
|
|
|
|
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);
|
|
|
return;
|
|
|
}
|
|
|
// 增加流水记录
|
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(uid);
|
|
|
record.setOrderCode(orderCode);
|
|
|
record.setPaidOrderCode(ObjectUtils.defaultIfNull(paidOrderCode, 0L));
|
|
|
record.setUserType(1);// 1:买家uid; 2:卖家uid
|
|
|
record.setPayType(payType);// 1:支付宝; 2:微信
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
|
|
|
public void addTradeBills(TradeBills record) {
|
|
|
try {
|
|
|
tradeBillsMapper.insert(record);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
|
|
|
alarm("记录流水到数据库出错", "ufo.order.addTradeBills",
|
|
|
"流水信息:" + record.toString() + ",msg=" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void alarm(String name, String type, String content) {
|
|
|
CommonAlarmEventPublisher.publish(name, type, content);
|
|
|
}
|
|
|
|
|
|
public double queryBuyerPenaltyAmount(Long orderCode){
|
|
|
TradeBills condition = new TradeBills();
|
|
|
condition.setOrderCode(orderCode);
|
|
|
condition.setTradeType(3);
|
|
|
List<TradeBills> tbs = tradeBillsMapper.selectByKeyProps(condition);
|
|
|
double penaltyAmount = 0D;
|
|
|
if (tbs != null && tbs.size() > 0){
|
|
|
TradeBills ptb = tbs.get(0);
|
|
|
penaltyAmount = ptb.getAmount() == null ? penaltyAmount : ptb.getAmount().doubleValue();
|
|
|
}
|
|
|
return penaltyAmount;
|
|
|
}
|
|
|
|
|
|
private Integer adaptPayType(Integer payment){
|
|
|
// 流水记录表支付方式适配
|
|
|
Integer recordPayment = payment;
|
|
|
if (recordPayment != null) {
|
|
|
if (recordPayment == 1) {
|
|
|
recordPayment = 2;
|
|
|
} else if (recordPayment == 2) {
|
|
|
recordPayment = 1;
|
|
|
}
|
|
|
}
|
|
|
return recordPayment;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 支付货款流水记录
|
|
|
* @param uid
|
|
|
* @param sellerUid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payment
|
|
|
* @param amount
|
|
|
*/
|
|
|
public void addPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
|
|
if (meta == null) {
|
|
|
logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
|
|
|
return;
|
|
|
}
|
|
|
Integer payType = adaptPayType(payment);
|
|
|
// 增加流水记录
|
|
|
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:补偿款
|
|
|
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);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付保证金流水记录
|
|
|
* @param uid
|
|
|
* @param skup
|
|
|
* @param orderCode
|
|
|
* @param payment
|
|
|
* @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();
|
|
|
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(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);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加充值保证金流水
|
|
|
* @param uid
|
|
|
* @param orderCode
|
|
|
* @param payment
|
|
|
* @param amount
|
|
|
*/
|
|
|
public void addPayRechargeEnsureRecord(Integer uid, Long orderCode, Integer payment, BigDecimal amount) {
|
|
|
Integer payType = adaptPayType(payment);
|
|
|
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(2);// 1:用户收入; 2:用户支出
|
|
|
record.setAmount(amount);
|
|
|
record.setSystemAmount(amount);// 有货收入
|
|
|
record.setTradeStatus(BillTradeStatus.SUCCESS.getCode());
|
|
|
record.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
addTradeBills(record);
|
|
|
}
|
|
|
} |
...
|
...
|
|