Authored by wujiexiang

求购订单退还,记录到trade_bills表中

... ... @@ -67,6 +67,9 @@ public class TradeBills {
private String payErrorCode;
//支付阶段,0:普通,1:定金
private int payLevel = 0;
/**
* suggest use new enum, define class as blow
* {@link com.yohoufo.order.common.BillTradeStatus}
... ...
... ... @@ -6,6 +6,7 @@
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="order_code" jdbcType="BIGINT" property="orderCode" />
<result column="paid_order_code" jdbcType="BIGINT" property="paidOrderCode" />
<result column="pay_level" jdbcType="TINYINT" property="payLevel" />
<result column="user_type" jdbcType="TINYINT" property="userType" />
<result column="pay_type" jdbcType="TINYINT" property="payType" />
<result column="trade_type" jdbcType="INTEGER" property="tradeType" />
... ... @@ -23,7 +24,7 @@
<result column="pay_error_code" jdbcType="VARCHAR" property="payErrorCode" />
</resultMap>
<sql id="Base_Column_List">
id,uid, order_code,paid_order_code, user_type,pay_type,trade_type,income_outcome,amount,system_amount,trade_status,create_time,
id,uid, order_code,paid_order_code,pay_level, user_type,pay_type,trade_type,income_outcome,amount,system_amount,trade_status,create_time,
deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name,pay_error_code
</sql>
... ... @@ -42,10 +43,10 @@
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.TradeBills" useGeneratedKeys="true">
insert into trade_bills (id, uid, order_code, paid_order_code, user_type,pay_type,trade_type,
insert into trade_bills (id, uid, order_code, paid_order_code,pay_level, user_type,pay_type,trade_type,
income_outcome,amount,system_amount,trade_status,create_time
,deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name,pay_error_code)
values (#{id},#{uid},#{orderCode},#{paidOrderCode},#{userType},#{payType},#{tradeType},
values (#{id},#{uid},#{orderCode},#{paidOrderCode},#{payLevel},#{userType},#{payType},#{tradeType},
#{incomeOutcome},#{amount},#{systemAmount},
#{tradeStatus},#{createTime},#{dealUid},#{dealStatus},
#{dealTime},#{dealRelateId},#{dealUserName},#{payErrorCode})
... ...
... ... @@ -7,5 +7,8 @@ public enum RefundCase {
SELLER_EARNEST_MONEY,
BUYER_GOODS_MONEY;
BUYER_GOODS_MONEY,
//求购定金
BID_DEPOSIT_MONEY;
}
... ...
... ... @@ -35,4 +35,6 @@ public class BillLogEvent extends Event{
BigDecimal amount;
Integer tradeStatus;
int payLevel;
}
... ...
... ... @@ -86,9 +86,6 @@ public abstract class AbstractBuyerOrderStateChanger<T extends RequestedStatusCh
protected CacheCleaner cacheCleaner;
@Autowired
protected IPaymentService paymentService;
@Autowired
protected ProductMapper productMapper;
@Autowired
... ...
... ... @@ -24,7 +24,7 @@ public class BillLogAsyncHandler implements IEventHandler<BillLogEvent> {
public void handle(BillLogEvent event) {
logger.info("in BillLogAsyncHandler.handle event {}", event);
switch (event.getRefundCase()){
switch (event.getRefundCase()) {
case SELLER_EARNEST_MONEY:
//Integer uid, Integer skup, Long orderCode, Integer payType, BigDecimal amount, Integer tradeStatus
tradeBillsService.backPayEnsureRecord(event);
... ... @@ -32,11 +32,14 @@ public class BillLogAsyncHandler implements IEventHandler<BillLogEvent> {
case BUYER_GOODS_MONEY:
//Integer uid, Integer sellerUid, Integer skup,
//Long orderCode, Integer payType, BigDecimal amount, Integer tradeStatus
tradeBillsService.backPayBuyRecord(event.getBuyerUid(), event.getSellerUid(), event.getSkup(), event.getOrderCode(),event.getPaidOrderCode(),
tradeBillsService.backPayBuyRecord(event.getBuyerUid(), event.getSellerUid(), event.getSkup(), event.getOrderCode(), event.getPaidOrderCode(),
event.getPayType(), event.getAmount(), event.getTradeStatus());
break;
case BID_DEPOSIT_MONEY:
//定金退款记录
tradeBillsService.backDepositPayBuyRecord(event.getBuyerUid(), event.getOrderCode(), event.getPaidOrderCode(),
event.getPayType(), event.getAmount(), event.getPayLevel(), event.getTradeStatus());
break;
}
... ...
... ... @@ -945,6 +945,7 @@ public class PaymentServiceImpl implements IPaymentService {
logger.info("{}, refund money is {}", logTag, tradeBills);
refundManager.create(orderCode, amount.doubleValue())
.withPaidOrderCode(tradeBills.getPaidOrderCode())
.withPayLevel(tradeBills.getPayLevel())
.withRefundPostHandler(context -> {
PayRefundBo refundBo = context.getResponse();
//退款申请成功
... ...
... ... @@ -184,6 +184,38 @@ public class TradeBillsService {
}
/**
* 定金退款流水记录
*
* @param uid
* @param orderCode
* @param payType
* @param amount
* @param tradeStatus
*/
public void backDepositPayBuyRecord(Integer uid, Long orderCode, Long paidOrderCode, Integer payType, BigDecimal amount, int payLevel, Integer tradeStatus) {
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(1);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
record.setAmount(amount);
record.setSystemAmount(amount.negate());
record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
record.setCreateTime((int) (System.currentTimeMillis() / 1000));
record.setPayLevel(payLevel);
addTradeBills(record);
}
public void addTradeBills(TradeBills record) {
try {
tradeBillsMapper.insert(record);
... ...
... ... @@ -7,14 +7,18 @@ import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.RequestedStatusChangeBuyerOrder;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.service.AbstractBuyerOrderStateChanger;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.PayRefundService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.LinkedHashMap;
... ... @@ -31,7 +35,7 @@ import static com.yohoufo.order.common.RefundCase.SELLER_EARNEST_MONEY;
public class BuyerOrderBidingCancelChanger extends AbstractBuyerOrderStateChanger<RequestedStatusChangeBuyerOrder> {
@Autowired
private IPaymentService paymentService;
private PayRefundService payRefundService;
/**
* @param statusChangeBuyerOrder
... ... @@ -65,17 +69,28 @@ public class BuyerOrderBidingCancelChanger extends AbstractBuyerOrderStateChange
private void refundDeposit(BuyerOrder buyerOrder) {
int uid = buyerOrder.getUid();
long orderCode = buyerOrder.getOrderCode();
//定金金额
double refundAmount = getDepositAmount(buyerOrder);
PaymentRequest paymentRequest = PaymentRequest.builder()
.uid(uid)
.refundCase(SELLER_EARNEST_MONEY)
.orderCode(orderCode)
.payLevel(OrderConstant.PAY_LEVEL_DEPOSIT)
.refundAmount(getDepositAmount(buyerOrder))
.refundAmount(refundAmount)
.refundattch(MerchantOrderAttachInfo.builder().type(SellerWalletDetail.Type.BID_DEPOSIT.getValue()).build())
.build();
val billLogEventBuilder = BillLogEvent.builder()
.buyerUid(uid)
.orderCode(orderCode)
.payType(buyerOrder.getPayment())
.refundCase(RefundCase.BID_DEPOSIT_MONEY)
.amount(BigDecimal.valueOf(refundAmount))
.payLevel(OrderConstant.PAY_LEVEL_DEPOSIT);
logger.info("[{}] refund deposit,paymentRequest:{}", orderCode, paymentRequest);
PayRefundBo payRefundBo = paymentService.refund(paymentRequest);
PayRefundBo payRefundBo = payRefundService.refund(paymentRequest, billLogEventBuilder);
logger.info("[{}] refund deposit end,result:{}", buyerOrder.getOrderCode(), payRefundBo);
}
... ...
... ... @@ -15,13 +15,15 @@ import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.bo.ActivityBo;
import com.yohoufo.order.model.bo.BidOrderMetaBo;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.PayRefundService;
import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
import com.yohoufo.order.service.proxy.BargainProxyService;
import com.yohoufo.order.service.proxy.BaseServiceCaller;
... ... @@ -32,11 +34,13 @@ import com.yohoufo.order.service.stats.impl.SellerOrderStatsEntry;
import com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.RetryerUtils;
import lombok.val;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
... ... @@ -78,7 +82,7 @@ public class BuyerOrderChangeBusinessPostProcessor {
private SellerService sellerService;
@Autowired
private IPaymentService paymentService;
private PayRefundService payRefundService;
@Autowired
private StatsConfigManager<SellerOrderStatsEntry, SellerOrderStatsConfiguration> statsConfigurationManager;
... ... @@ -319,17 +323,26 @@ public class BuyerOrderChangeBusinessPostProcessor {
private void refundBidDeposit(BuyerOrder buyerOrder) {
int uid = buyerOrder.getUid();
long orderCode = buyerOrder.getOrderCode();
double refundAmount = getDepositAmount(buyerOrder);
PaymentRequest paymentRequest = PaymentRequest.builder()
.uid(uid)
.refundCase(SELLER_EARNEST_MONEY)
.orderCode(orderCode)
.payLevel(OrderConstant.PAY_LEVEL_DEPOSIT)
.refundAmount(getDepositAmount(buyerOrder))
.refundAmount(refundAmount)
.refundattch(MerchantOrderAttachInfo.builder().type(SellerWalletDetail.Type.BID_DEPOSIT.getValue()).build())
.build();
val billLogEventBuilder = BillLogEvent.builder()
.buyerUid(uid)
.orderCode(orderCode)
.payType(buyerOrder.getPayment())
.refundCase(RefundCase.BID_DEPOSIT_MONEY)
.amount(BigDecimal.valueOf(refundAmount))
.payLevel(OrderConstant.PAY_LEVEL_DEPOSIT);
logger.info("[{}] refund deposit,paymentRequest:{}", orderCode, paymentRequest);
PayRefundBo payRefundBo = paymentService.refund(paymentRequest);
PayRefundBo payRefundBo = payRefundService.refund(paymentRequest, billLogEventBuilder);
logger.info("[{}] refund deposit end,result:{}", buyerOrder.getOrderCode(), payRefundBo);
}
... ...