...
|
...
|
@@ -2,6 +2,7 @@ package com.yohoufo.order.service; |
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -23,10 +24,12 @@ import com.yohoufo.common.caller.UfoServiceCaller; |
|
|
import com.yohoufo.common.utils.TimeUtils;
|
|
|
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
|
|
|
import com.yohoufo.dal.order.OrdersPayMapper;
|
|
|
import com.yohoufo.dal.order.OrdersPayRefundMapper;
|
|
|
import com.yohoufo.dal.order.SellerWalletDetailMapper;
|
|
|
import com.yohoufo.dal.order.SellerWalletMapper;
|
|
|
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
|
|
|
import com.yohoufo.dal.order.model.OrdersPay;
|
|
|
import com.yohoufo.dal.order.model.OrdersPayRefund;
|
|
|
import com.yohoufo.dal.order.model.SellerWallet;
|
|
|
import com.yohoufo.dal.order.model.SellerWalletDetail;
|
|
|
import com.yohoufo.order.common.Payment;
|
...
|
...
|
@@ -34,6 +37,7 @@ import com.yohoufo.order.model.request.PaymentRequest; |
|
|
import com.yohoufo.order.model.response.PrepayResponse;
|
|
|
import com.yohoufo.order.service.cache.CacheCleaner;
|
|
|
import com.yohoufo.order.service.cache.CacheKeyBuilder;
|
|
|
import com.yohoufo.order.service.impl.PaymentServiceImpl;
|
|
|
|
|
|
@Service
|
|
|
public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
|
...
|
...
|
@@ -52,12 +56,18 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
|
|
|
@Autowired
|
|
|
OrdersPayMapper ordersPayDao;
|
|
|
|
|
|
@Autowired
|
|
|
OrdersPayRefundMapper ordersPayRefundMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private CacheCleaner cacheCleaner;
|
|
|
|
|
|
@Autowired
|
|
|
UfoServiceCaller ufoServiceCaller;
|
|
|
|
|
|
@Autowired
|
|
|
PaymentServiceImpl paymentService;
|
|
|
|
|
|
/**
|
|
|
* 更新订单状态
|
...
|
...
|
@@ -305,10 +315,96 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
return changeEarnest(uid, money, "退还保证金");
|
|
|
}
|
|
|
|
|
|
// 支付保证金:明细记录+orders_pay记录
|
|
|
public void useEarnestAddWalletDetail(SellerWallet sw, List<OrderInfo> orderList) {
|
|
|
for(OrderInfo oi : orderList) {
|
|
|
SellerWalletDetail swd = addUseEarnestDetail(sw, oi.getOrderCode(), oi.getAmount());
|
|
|
addOrdersPay(swd);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 修改价格:明细记录+orders_pay金额修改
|
|
|
public void changePriceAddWalletDetail(SellerWallet sw, List<OrderInfo> orderList) {
|
|
|
for(OrderInfo oi : orderList) {
|
|
|
SellerWalletDetail swd = addChangePriceWalletDetail(sw, oi.getOrderCode(), oi.getAmount());
|
|
|
changePriceUpdateOrdersPay(swd);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 下架商品:明细记录+退款表记录
|
|
|
public void unshelveAddWalletDetail(SellerWallet sw, List<OrderInfo> orderList) {
|
|
|
for(OrderInfo oi : orderList) {
|
|
|
SellerWalletDetail swd = refundEarnestDetail(sw, oi.getOrderCode(), oi.getAmount());
|
|
|
addRefundRecord(swd, oi.getAmount());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 商家退出入驻,钱包清空+转账
|
|
|
public boolean returnAllEarnest(Integer uid, long orderCode, String alipayAccount) {
|
|
|
BigDecimal money = returnEarnest(uid, orderCode);
|
|
|
if (money == null) {
|
|
|
return false;
|
|
|
}
|
|
|
return paymentService.transAllEarnest(orderCode, uid, money, alipayAccount);
|
|
|
}
|
|
|
|
|
|
// 退还保证金
|
|
|
public SellerWalletDetail refundEarnestDetail(SellerWallet sw, long orderCode, BigDecimal amount) {
|
|
|
SellerWalletDetail swd = new SellerWalletDetail();
|
|
|
swd.setOrderCode(orderCode);
|
|
|
swd.setType(3); // 单笔退还
|
|
|
swd.setUid(sw.getUid());
|
|
|
swd.setWalletId(sw.getId());
|
|
|
swd.setAmount(amount);
|
|
|
swd.setCreateTime(TimeUtils.getTimeStampSecond());
|
|
|
logger.info("退还保证金,钱包明细记录,bean={}", swd);
|
|
|
sellerWalletDetailMapper.insert(swd);
|
|
|
logger.info("退还保证金,钱包明细记录成功,bean={}", swd);
|
|
|
return swd;
|
|
|
}
|
|
|
|
|
|
// 退出入驻:归还所有保证金 总账+明细
|
|
|
private BigDecimal returnEarnest(Integer uid, long orderCode) {
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理开始,uid={},orderCode={}", uid, orderCode);
|
|
|
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
|
|
|
|
|
|
if (sw == null) {
|
|
|
logger.error("退还所有保证金,钱包不存在,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.changeEarnest", "钱包不存在uid=" + uid);
|
|
|
return null;
|
|
|
}
|
|
|
BigDecimal amount = sw.getAmount();
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理,钱包信息={}", sw);
|
|
|
|
|
|
if (sw.getStatus() == null || sw.getStatus() == 0) {
|
|
|
logger.error("退还所有保证金{},钱包不可用,uid={}", amount, uid);
|
|
|
CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.changeEarnest", "钱包不可用uid=" + uid+", 退还金额为:"+amount);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
sw.setUpdateTime(TimeUtils.getTimeStampSecond());
|
|
|
if (sellerWalletMapper.returnMoney(sw) == 0) {
|
|
|
logger.error("退还所有证金失败,更新表返回0,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.changeEarnest", "更新表返回0,uid=" + uid + ", 退还金额为:"+ amount);
|
|
|
return null;
|
|
|
}
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理,余额扣除成功,钱包信息={}", sw);
|
|
|
// 增加充值记录
|
|
|
SellerWalletDetail swd = new SellerWalletDetail();
|
|
|
swd.setOrderCode(orderCode);
|
|
|
swd.setType(5);// 退还所有保证金
|
|
|
swd.setUid(uid);
|
|
|
swd.setWalletId(sw.getId());
|
|
|
swd.setAmount(amount);
|
|
|
swd.setCreateTime(TimeUtils.getTimeStampSecond());
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理,增加扣减明细,bean={}", swd);
|
|
|
sellerWalletDetailMapper.insert(swd);
|
|
|
|
|
|
return amount;
|
|
|
}
|
|
|
|
|
|
// 支付保证金:明细
|
|
|
public void addUseEarnestDetail(SellerWallet sw, BigDecimal money) {
|
|
|
long orderCode = 0;
|
|
|
BigDecimal amount = null;
|
|
|
private SellerWalletDetail addUseEarnestDetail(SellerWallet sw, long orderCode, BigDecimal amount) {
|
|
|
Integer uid = sw.getId();
|
|
|
SellerWalletDetail swd = new SellerWalletDetail();
|
|
|
swd.setOrderCode(orderCode);
|
...
|
...
|
@@ -320,63 +416,24 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
logger.info("支付保证金,钱包明细记录,bean={}", swd);
|
|
|
sellerWalletDetailMapper.insert(swd);
|
|
|
logger.info("支付保证金,钱包明细记录成功,bean={}", swd);
|
|
|
return swd;
|
|
|
}
|
|
|
|
|
|
// 退还保证金
|
|
|
public SellerWalletDetail refundEarnestDetail(SellerWallet sw, long orderCode, BigDecimal amount) {
|
|
|
|
|
|
// 修改价格支付保证金:明细
|
|
|
private SellerWalletDetail addChangePriceWalletDetail(SellerWallet sw, long orderCode, BigDecimal amount) {
|
|
|
Integer uid = sw.getId();
|
|
|
SellerWalletDetail swd = new SellerWalletDetail();
|
|
|
swd.setOrderCode(orderCode);
|
|
|
swd.setType(3); // 单笔退还
|
|
|
swd.setUid(sw.getUid());
|
|
|
swd.setType(4);
|
|
|
swd.setUid(uid);
|
|
|
swd.setWalletId(sw.getId());
|
|
|
swd.setAmount(amount);
|
|
|
swd.setCreateTime(TimeUtils.getTimeStampSecond());
|
|
|
logger.info("退还保证金,钱包明细记录,bean={}", swd);
|
|
|
logger.info("修改价格支付保证金,钱包明细记录,bean={}", swd);
|
|
|
sellerWalletDetailMapper.insert(swd);
|
|
|
logger.info("退还保证金,钱包明细记录成功,bean={}", swd);
|
|
|
logger.info("修改价格支付保证金,钱包明细记录成功,bean={}", swd);
|
|
|
return swd;
|
|
|
}
|
|
|
|
|
|
// 退出入驻:归还所有保证金 总账+明细
|
|
|
public BigDecimal returnEarnest(Integer uid, long orderCode) {
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理开始,uid={},orderCode={}", uid, orderCode);
|
|
|
|
|
|
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
|
|
|
|
|
|
if (sw == null) {
|
|
|
logger.error("退还所有保证金,钱包不存在,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.recharge", "钱包不存在uid=" + uid);
|
|
|
return null;
|
|
|
}
|
|
|
BigDecimal amount = sw.getAmount();
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理,钱包信息={}", sw);
|
|
|
|
|
|
if (sw.getStatus() == null || sw.getStatus() == 0) {
|
|
|
logger.error("退还所有保证金{},钱包不可用,uid={}", amount, uid);
|
|
|
CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.recharge", "钱包不可用uid=" + uid+", 退还金额为:"+amount);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
sw.setUpdateTime(TimeUtils.getTimeStampSecond());
|
|
|
if (sellerWalletMapper.returnMoney(sw) == 0) {
|
|
|
logger.error("退还所有证金失败,更新表返回0,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.recharge", "更新表返回0,uid=" + uid + ", 退还金额为:"+ amount);
|
|
|
return null;
|
|
|
}
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理,余额扣除成功,钱包信息={}", sw);
|
|
|
// 增加充值记录
|
|
|
SellerWalletDetail swd = new SellerWalletDetail();
|
|
|
swd.setOrderCode(orderCode);
|
|
|
swd.setType(5);// 退还所有保证金
|
|
|
swd.setUid(uid);
|
|
|
swd.setWalletId(sw.getId());
|
|
|
swd.setAmount(amount);
|
|
|
swd.setCreateTime(TimeUtils.getTimeStampSecond());
|
|
|
logger.info("商家退出,退还保证金,钱包归零处理,增加扣减明细,bean={}", swd);
|
|
|
sellerWalletDetailMapper.insert(swd);
|
|
|
|
|
|
return amount;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private SellerWallet changeEarnest(Integer uid, BigDecimal money, String message) {
|
|
|
logger.info("{}修改钱包表入口,uid={},money={}", message, uid, money);
|
...
|
...
|
@@ -385,17 +442,17 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
|
|
|
if (sw == null) {
|
|
|
logger.error(message + "失败,钱包不存在,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "钱包不存在uid=" + uid+", 金额为:"+money);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不存在uid=" + uid+", 金额为:"+money);
|
|
|
return null;
|
|
|
}
|
|
|
if (sw.getStatus() == null || sw.getStatus() == 0) {
|
|
|
logger.error(message + "{}失败,钱包不可用,uid={}", money, uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "钱包不可用uid=" + uid+", 金额为:"+money);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不可用uid=" + uid+", 金额为:"+money);
|
|
|
return null;
|
|
|
}
|
|
|
if (sw.getAmount().compareTo(money) < 0) {
|
|
|
logger.error(message + "{}失败,钱包余额不足,uid={}", money, uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "钱包余额不足uid=" + uid+", 金额为:"+money+", 账户余额为:"+sw.getAmount());
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包余额不足uid=" + uid+", 金额为:"+money+", 账户余额为:"+sw.getAmount());
|
|
|
return null;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -404,14 +461,14 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
logger.info("{}修改钱包表余额,bean={}", sw);
|
|
|
if (sellerWalletMapper.addMoney(sw) == 0) {
|
|
|
logger.error(message + "失败,(并发)更新表返回0,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "(并发)更新表返回0,uid=" + uid + ", 金额为:"+ money);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "(并发)更新表返回0,uid=" + uid + ", 金额为:"+ money);
|
|
|
return null;
|
|
|
}
|
|
|
logger.info("{}修改钱包表余额成功,bean={}", sw);
|
|
|
return sw;
|
|
|
}
|
|
|
|
|
|
public void addOrdersPay(SellerWalletDetail swd) {
|
|
|
private void addOrdersPay(SellerWalletDetail swd) {
|
|
|
// 增加支付记录
|
|
|
OrdersPay ordersPay = new OrdersPay();
|
|
|
ordersPay.setOrderCode(swd.getOrderCode());
|
...
|
...
|
@@ -430,7 +487,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
logger.info("增加支付记录orders_pay成功,orderCode={}", swd.getOrderCode());
|
|
|
}
|
|
|
|
|
|
public int changePriceUpdateOrdersPay(SellerWalletDetail swd) {
|
|
|
private int changePriceUpdateOrdersPay(SellerWalletDetail swd) {
|
|
|
// 增加支付记录
|
|
|
OrdersPay ordersPay = new OrdersPay();
|
|
|
ordersPay.setOrderCode(swd.getOrderCode());
|
...
|
...
|
@@ -447,4 +504,19 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private void addRefundRecord(SellerWalletDetail swd, BigDecimal amount) {
|
|
|
OrdersPayRefund newRecord = new OrdersPayRefund();
|
|
|
newRecord.setOrderCode(swd.getOrderCode());
|
|
|
newRecord.setRefundCode(Integer.toString(swd.getWalletId()));
|
|
|
newRecord.setAmount(amount);
|
|
|
newRecord.setStatus((byte) 0);
|
|
|
newRecord.setSerialNo(Integer.toString(swd.getId()));
|
|
|
newRecord.setOrderType(0);
|
|
|
int timeStamp = (int) (new Date().getTime() / 1000);
|
|
|
newRecord.setCreateTime(timeStamp);
|
|
|
newRecord.setUpdateTime(timeStamp);
|
|
|
logger.info("商品下架,添加退款记录,bean={}", newRecord);
|
|
|
ordersPayRefundMapper.insert(newRecord);
|
|
|
logger.info("商品下架,添加退款记录成功,orderCode={}", swd.getOrderCode());
|
|
|
}
|
|
|
} |
...
|
...
|
|