Authored by LUOXC

Merge branch 'test6.9.10' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.10

# Conflicts:
#	order/src/main/java/com/yohoufo/order/service/impl/TradeBillsService.java
... ... @@ -15,8 +15,20 @@ public interface AppraiseOrderMetaMapper {
AppraiseOrderMeta selectByPrimaryKey(Integer id);
/**
* 只适用子订单,使用子订单查询
* @param condition
* @return
*/
AppraiseOrderMeta selectByOrderCode(AppraiseOrderMeta condition);
/**
* 适用于卖家鉴定订单 根据父订单查询
* @param condition
* @return
*/
List<AppraiseOrderMeta> selectAllByParentOrderCode(AppraiseOrderMeta condition);
List<AppraiseOrderMeta> selectByOrderCodeMetaKeys(@Param("orderCode") long orderCode,
@Param("metaKeys") Collection<String> metaKeys);
... ...
... ... @@ -147,6 +147,7 @@ public class AppraiseOrderPaymentService extends AbstractOrderPaymentService {
AppraiseOrderStatus.HAS_PAYED.getCode(),
AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode(),
AppraiseOrderStatus.JUDGE_PASS_WAIT_WAREHOUSE.getCode(),
AppraiseOrderStatus.CANCEL_BEFORE_DELIVER.getCode(),
AppraiseOrderStatus.SHAM_SEND_OUT.getCode(),
AppraiseOrderStatus.SEND_OUT_TIMEOUT.getCode()
);
... ...
... ... @@ -22,7 +22,7 @@ public class AppraiseExpressStageBuilder {
/**
* 平台确认收货
*
* 1卖家发货 == 2平台鉴定 点亮1
* 1卖家发货 == 2平台鉴定 点亮2
*/
private static final int DEPOSIT_PLATFORM_RECEIPT = 11;
... ...
... ... @@ -16,6 +16,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.order.common.*;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
... ... @@ -504,9 +505,9 @@ public class AppraiseService {
return apiResponse;
}
// 1.瑕疵,鉴定为假,虚假发货,质检不通过取消
// 1.鉴定为假,质检不通过
List<Integer> APPRAISE_FAIL_STATUS_CODE = Lists.newArrayList(AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.SHAM_SEND_OUT.getCode(), AppraiseOrderStatus.QUALITY_CHECK_FAKE.getCode());
AppraiseOrderStatus.QUALITY_CHECK_FAKE.getCode());
// 2.无法鉴定
List<Integer> CANNOT_APPRAISE_STATUS_CODE = Lists.newArrayList(
... ... @@ -588,9 +589,21 @@ public class AppraiseService {
// 子订单对应商品 1:1
AppraiseOrderGoods oneAppraiseOrderGood = appraiseOrderGoods.get(0);
inBoxFacade.sendInboxSmsWhenAppraiseFinished(uid, oneAppraiseOrderGood.getProductName(),
oneAppraiseOrderGood.getProductCode(),
wayBillCode);
if (APPRAISE_FAIL_STATUS_CODE.contains(appraiseOrder.getStatus())
|| APPRAISE_SUCCESS_STATUS_CODE.contains(appraiseOrder.getStatus())){
inBoxFacade.sendInboxSmsWhenAppraiseFinished(InboxBusinessTypeEnum.INBOX_DELIVERY_APPRAISE_FINISHED,
InboxBusinessTypeEnum.SMS_DELIVERY_APPRAISE_FINISHED,
uid, oneAppraiseOrderGood.getProductName(),
oneAppraiseOrderGood.getProductCode(),
wayBillCode);
}else if(CANNOT_APPRAISE_STATUS_CODE.contains(appraiseOrder.getStatus())){
inBoxFacade.sendInboxSmsWhenAppraiseFinished(InboxBusinessTypeEnum.INBOX_DELIVERY_CANNOT_APPRAISE,
InboxBusinessTypeEnum.SMS_DELIVERY_CANNOT_APPRAISE,
uid, oneAppraiseOrderGood.getProductName(),
oneAppraiseOrderGood.getProductCode(),
wayBillCode);
}
}
if (appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()) { // 鉴定寄存的订单,需要同步修改寄存表的状态
... ... @@ -1741,13 +1754,14 @@ public class AppraiseService {
List<Integer> skupList = buyerOrderGoodses.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
sellerOrderGoodsMapper.updateDeptNoBySkups(skupList, appraiseExpressInfoBo.getDepotNum());
expressRecordMapper.updateDeptNoByOrder(orderCodeList, EnumExpressType.EXPRESS_TYPE_1.getCode(), appraiseExpressInfoBo.getDepotNum());
productProxyService.setBatchDepotNum(skupList, appraiseExpressInfoBo.getDepotNum());
}
// 更新鉴定订单的鉴定室
appraiseOrderGoodsMapper.updateBatchDepotNo(orderCodeList, appraiseExpressInfoBo.getDepotNum());
expressRecordMapper.updateDeptNoByOrder(orderCodeList, EnumExpressType.EXPRESS_TYPE_1.getCode(), appraiseExpressInfoBo.getDepotNum());
}
}
... ...
... ... @@ -6,6 +6,7 @@ import com.yohobuy.ufo.model.ProductInfo;
import com.yohobuy.ufo.model.order.bo.DepositProductBo;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.constants.DepositSourceEnum;
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohobuy.ufo.model.response.StorageDataResp;
... ... @@ -15,11 +16,9 @@ import com.yohoufo.common.utils.AppVersion;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.StringUtil;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.DepositCodeMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.DepositCode;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.order.model.StorageDepositCount;
import com.yohoufo.dal.order.model.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -27,10 +26,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
... ... @@ -49,6 +47,9 @@ public class DepositHelpService {
@Autowired
private AppraiseOrderMapper appraiseOrderMapper;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
// 是否 24小时反馈时间 如果是则返回true
public boolean isFeedback(int depositRemainDay) {
return -1 * DepositOrderComputeResp.FEEDBACK_DAY <= depositRemainDay && depositRemainDay <= 0;
... ... @@ -249,4 +250,27 @@ public class DepositHelpService {
public String queryEarnestMoneyStatus(Integer status) {
return Integer.valueOf(AppraiseOrderStatus.CHECKING_FAKE.getCode()).equals(status) ? "已扣除" : "原路退还";
}
/**
* 获取入手价
* @param countInfoList
* @return
*/
public Map<Long, BuyerOrder> getOrderAmountMap(List<StorageDeposit> depositList) {
if (CollectionUtils.isEmpty(depositList)) {
return Maps.newHashMap();
}
Collection<Long> orderCodeList = depositList.stream()
.filter(item -> DepositSourceEnum.SOURCE_BUYER.getCode().equals(item.getSource())).map(StorageDeposit::getOrderCode).collect(Collectors.toList());
if (CollectionUtils.isEmpty(orderCodeList)) {
return Maps.newHashMap();
}
List<BuyerOrder> buyerGoodsList = buyerOrderMapper.selectByOrderCodes(orderCodeList, null);
Map<Long, BuyerOrder> buyerGoodsMap = buyerGoodsList.stream().map(Function.identity()).collect(Collectors.toMap(BuyerOrder::getOrderCode, Function.identity()));
return buyerGoodsMap;
}
}
... ...
... ... @@ -131,14 +131,13 @@ public class DepositServiceImpl implements DepositService {
}
// 召回或者到期退回的
List<StorageDeposit> depositList = storageDepositMapper.queryUserDopositBack(uid, (page - 1) * limit, limit);
List<BuyerOrder> buyerGoodsList = buyerOrderMapper.selectByOrderCodes(depositList.stream()
.filter(item -> DepositSourceEnum.SOURCE_BUYER.getCode().equals(item.getSource())).map(StorageDeposit::getOrderCode).collect(Collectors.toList()), null);
// 查询现货寄存订单的状态
Map<Long, String> appraiseOrderStatusMap = depositHelpService.queryAppraiseOrderStatus(depositList.stream()
.filter(item -> DepositOutTypeEnum.OUTTYPE_EXPIRED.getCode().equals(item.getOutType())).map(StorageDeposit::getOrderCode).collect(Collectors.toList()));
Map<Long, BuyerOrder> buyerGoodsMap = buyerGoodsList.stream().map(Function.identity()).collect(Collectors.toMap(BuyerOrder::getOrderCode, Function.identity()));
Map<Long, BuyerOrder> buyerGoodsMap = depositHelpService.getOrderAmountMap(depositList);
List<Integer> storageList = depositList.stream().map(StorageDeposit::getStorageId).collect(Collectors.toList());
... ...
... ... @@ -258,6 +258,7 @@ public class QiniuLiveRecordService {
resp.setProductId(item.getProductId());
resp.setProductPicUrl(null == orderVideoResp ? "" : orderVideoResp.getProductPicUrl());
resp.setAppraise_result(item.getAppraiseResult());
resp.setOrderCode(item.getOrderCode());
result.add(resp);
});
... ...
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);
}
}
... ...
... ... @@ -339,12 +339,13 @@ public class InBoxFacade extends BaseNoticeFacade{
* @param productCode
* @param wayBillCode
*/
public void sendInboxSmsWhenAppraiseFinished(int uid, String prdName, String productCode,String wayBillCode){
public void sendInboxSmsWhenAppraiseFinished(InboxBusinessTypeEnum inbox, InboxBusinessTypeEnum sms,
int uid, String prdName, String productCode,String wayBillCode){
try {
executorService.execute(() -> {
String params = buildParams(prdName, productCode);
InboxReqVO req = buildInboxReqVO(uid, params, InboxBusinessTypeEnum.INBOX_DELIVERY_APPRAISE_FINISHED);
InboxReqVO req = buildInboxReqVO(uid, params, inbox);
InBoxResponse resp = inBoxSDK.addInbox(req);
log.info("record sendInboxSmsWhenAppraiseFinished inbox msg, uid {}, prdName {}, wayBillCode {}, resp {}", uid, prdName, wayBillCode, resp);
... ... @@ -356,7 +357,7 @@ public class InBoxFacade extends BaseNoticeFacade{
return;
}
List<String> mobileList = Arrays.asList(phone);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_DELIVERY_APPRAISE_FINISHED.getContent(), prdName ,productCode,wayBillCode);
String content = getReplacedContent(sms.getContent(), prdName ,productCode,wayBillCode);
sendSmsService.smsSendByMobile(content, mobileList);
log.info("sendInboxSmsWhenAppraiseFinished sms content {}, mobileList {}", content, mobileList);
});
... ...
... ... @@ -6,10 +6,7 @@ import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.AppraiseOrderBo;
import com.yohobuy.ufo.model.order.bo.DepositOrderStatisticInfo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.req.*;
import com.yohobuy.ufo.model.order.resp.SellerDepositOrderComputeResp;
import com.yohobuy.ufo.model.order.resp.SellerDepositOrderSubmitResp;
... ... @@ -38,6 +35,7 @@ import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.handler.GoodsServiceRefundHandler;
... ... @@ -66,7 +64,7 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
@Autowired
private AppraiseOrderStorageMapper appraiseOrderStorageMapper;
private IExpressInfoService expressInfoService;
@Autowired
private SellerDepositOrderPrepareService sellerDepositOrderPrepareService;
... ... @@ -697,7 +695,7 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
case PLATFORM_APPRAISE_UNSURE:
unsureNum = cnt;
break;
case JUDGE_PASS:
case JUDGE_PASS_WAIT_WAREHOUSE:
passNum = cnt;
break;
case CHECKING_FAKE:
... ... @@ -758,6 +756,13 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
logger.info("detectAppraiseFinish event {},parentOrderCode {} PLATFORM_RECEIVE count {}", event, parentOrderCode, cnt);
if (cnt == 0){
int prows = platformFinishAppraiseGoods(parentOrderCode);
// 鉴定已经完成的物流信息
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.appraise_finished;
expressInfoService.saveOperateTransferExpressInfo(appraiseOrder.getUid(), orderCode ,expressType.getCode(),expressDataType,operateTransferCode);
logger.info("detectAppraiseFinish platformFinishReceiveGoods, orderCode {},parentOrderCode {} parent count {}",
orderCode, parentOrderCode, prows);
if (prows>0){
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.order.service.seller.deposit;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.bo.AppraiseOrderBo;
import com.yohoufo.order.BaseWebTest;
import com.yohoufo.order.event.OrderCancelEvent;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -20,4 +21,12 @@ public class SellerDepositOrderServiceTest extends BaseWebTest {
List<AppraiseOrderBo> list = sellerDepositOrderService.getSubOrderStatistic(orderCode);
System.out.println("in testGetSubOrderStatistic result" + JSONObject.toJSONString(list));
}
@Test
public void testcancelByTimeout(){
String json = "{\"orderCode\":36379748458307,\"payExpire\":10,\"retry\":0,\"uid\":500031424}";
OrderCancelEvent orderCancelEvent = JSONObject.parseObject(json, OrderCancelEvent.class);
sellerDepositOrderService.cancelByTimeout(orderCancelEvent);
}
}
... ...