...
|
...
|
@@ -26,6 +26,7 @@ import com.yohoufo.dal.order.*; |
|
|
import com.yohoufo.dal.order.model.*;
|
|
|
import com.yohoufo.dal.user.model.ZhiMaCert;
|
|
|
import com.yohoufo.order.common.EnterQuitEnum;
|
|
|
import com.yohoufo.order.event.EntrySellerRechargeEvent;
|
|
|
import com.yohoufo.order.event.InviteRecordEvent;
|
|
|
import com.yohoufo.order.model.request.PaymentRequest;
|
|
|
import com.yohoufo.order.model.response.PrepayResponse;
|
...
|
...
|
@@ -121,186 +122,16 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private SellerWallet processFirstTimeCharge(SellerWallet sw, OrderInfo orderInfo){
|
|
|
Long orderCode = orderInfo.getOrderCode();
|
|
|
BigDecimal amount = orderInfo.getAmount();
|
|
|
Integer uid = orderInfo.getUid();
|
|
|
|
|
|
ZhiMaCert cert = null;
|
|
|
try {
|
|
|
ApiResponse<?> resp = ufoServiceCaller.call("ufo.user.zhiMaCertInfo", ApiResponse.class, uid);
|
|
|
cert = (ZhiMaCert) resp.getData();
|
|
|
} catch (Exception e) {
|
|
|
CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "没有芝麻认证信息:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount);
|
|
|
logger.error("重新入驻首次充值保证金={},没有芝麻认证信息,uid={}", amount, uid);
|
|
|
return sw;
|
|
|
}
|
|
|
if(cert == null || StringUtils.isBlank(cert.getCertNo())) {
|
|
|
CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "芝麻认证信息有误:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount);
|
|
|
logger.error("重新入驻首次充值保证金={},没有芝麻认证信息有误,uid={}", amount, uid);
|
|
|
return sw;
|
|
|
}
|
|
|
String certNo = cert.getCertNo();
|
|
|
|
|
|
if (sw != null) {
|
|
|
logger.info("重新入驻首次充值保证金={},已入驻次数为,uid={}", amount, uid, sw.getJoinTimes());
|
|
|
if (sw.getStatus() == null || sw.getStatus() != 0) {
|
|
|
CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "入驻状态异常:uid=" + uid + ",充值订单号为:" + orderCode + ", 充值金额为:" + amount);
|
|
|
logger.error("重新入驻首次充值保证金={},发现入驻状态异常,uid={},times={}", amount, uid, sw.getJoinTimes());
|
|
|
return sw;
|
|
|
}
|
|
|
if (!canRejoin(uid, sw, cert)) {
|
|
|
CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "超过入最大驻次数:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount);
|
|
|
logger.error("重新入驻首次充值保证金={},发现已超过最大入驻次数,uid={},times={}", amount, uid, sw.getJoinTimes());
|
|
|
return sw;
|
|
|
}
|
|
|
// 更新钱包
|
|
|
logger.info("重新入驻首次充值保证金={},更新钱包信息,uid={}", amount, uid);
|
|
|
int exe = sellerWalletMapper.rejoin(uid, amount, null, TimeUtils.getTimeStampSecond(), sw.getJoinTimes() + 1);
|
|
|
if (exe == 0) {
|
|
|
CommonAlarmEventPublisher.publish("重新入驻修改钱包失败", "ufo.order.recharge", "更新钱包不成功:uid=" + uid + ",充值订单号为:" + orderCode + ", 充值金额为:" + amount+ ",钱包信息为:"+sw);
|
|
|
logger.info("重新入驻失败,首次充值保证金={},更新钱包信息失败,uid={}, 钱包信息={}", amount, uid, sw);
|
|
|
return sw;
|
|
|
}
|
|
|
// 数据清理
|
|
|
// 钱包明细
|
|
|
logger.info("重新入驻orderCode={},清理历史钱包明细数据,uid={}", orderCode, uid);
|
|
|
int clearCount = sellerWalletDetailMapper.clearUserHistoryData(uid);
|
|
|
logger.info("重新入驻orderCode={},清理历史钱包明细数据={},uid={}", orderCode, clearCount, uid);
|
|
|
// 充值信息
|
|
|
logger.info("重新入驻orderCode={},清理充值表数据,uid={}", orderCode, uid);
|
|
|
clearCount = entrySellerRechargeOrderMapper.clearUserHistoryData(uid, orderCode);
|
|
|
logger.info("重新入驻orderCode={},清理充值表数据={},uid={}", orderCode, clearCount, uid);
|
|
|
// 入驻信息
|
|
|
logger.info("重新入驻orderCode={},清理历史入驻表数据,uid={}", orderCode, uid);
|
|
|
clearCount = storedSellerService.removeStoredSeller(uid);
|
|
|
logger.info("重新入驻orderCode={},清理历史入驻表数据={},uid={}", orderCode, clearCount, uid);
|
|
|
|
|
|
} else {
|
|
|
// 首次充值,创建钱包信息
|
|
|
sw = new SellerWallet();
|
|
|
sw.setUid(uid);
|
|
|
sw.setAmount(amount);
|
|
|
sw.setLockAmount(BigDecimal.ZERO);
|
|
|
sw.setStatus(1);
|
|
|
sw.setType(1);
|
|
|
sw.setCreateTime(TimeUtils.getTimeStampSecond());
|
|
|
sw.setUpdateTime(0);
|
|
|
sw.setJoinTimes(0);
|
|
|
logger.info("首次充值后回调,处理总账表新增账号,bean={}", sw);
|
|
|
sellerWalletMapper.insert(sw);
|
|
|
logger.info("首次充值后回调,处理总账表新增账号成功,bean={}", sw);
|
|
|
|
|
|
// 首次入驻
|
|
|
InviteRecordEvent inviteRecordEvent = InviteRecordEvent.builder().uid(uid).orderCode(orderCode).eventType(EnterQuitEnum.ENTER).build();
|
|
|
EventBusPublisher.publishEvent(inviteRecordEvent);
|
|
|
}
|
|
|
addJoinHistory(uid, certNo);
|
|
|
return sw;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void processAfterPay(OrderInfo orderInfo) {
|
|
|
logger.info("充值后回调,处理processAfterPay,orderInfo={}", orderInfo);
|
|
|
Long orderCode = orderInfo.getOrderCode();
|
|
|
BigDecimal amount = orderInfo.getAmount();
|
|
|
Integer payment = orderInfo.getPayment();
|
|
|
tradeBillsService.addPayRechargeEnsureRecord(orderInfo.getUid(), orderCode, payment, orderInfo.getAmount());
|
|
|
|
|
|
BigDecimal beforeAmount = BigDecimal.ZERO;
|
|
|
BigDecimal beforeLockAmount = BigDecimal.ZERO;
|
|
|
|
|
|
BigDecimal afterAmount = BigDecimal.ZERO;
|
|
|
BigDecimal afterLockAmount = BigDecimal.ZERO;
|
|
|
|
|
|
Integer uid = orderInfo.getUid();
|
|
|
|
|
|
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
|
|
|
logger.info("充值后回调,处理总账表,orderCode={}", orderCode);
|
|
|
if (orderInfo.getType() == TYPE_FIRST_RECHARGE) {
|
|
|
sw = processFirstTimeCharge(sw, orderInfo);
|
|
|
afterAmount = amount;
|
|
|
} else {
|
|
|
// 修改钱包余额
|
|
|
if (sw == null) {
|
|
|
logger.error("充值保证金余额{},钱包不存在,uid={}", amount, uid);
|
|
|
CommonAlarmEventPublisher.publish("充值保证金余额失败", "ufo.order.recharge", "钱包不存在uid=" + uid + ",充值订单号为:" + orderCode +", 充值金额为:"+amount);
|
|
|
return;
|
|
|
}
|
|
|
if (sw.getStatus() == null || sw.getStatus() == 0) {
|
|
|
logger.error("充值保证金余额{},钱包不可用,uid={}", amount, uid);
|
|
|
CommonAlarmEventPublisher.publish("充值保证金余额失败", "ufo.order.recharge", "钱包不可用uid=" + uid + ",充值订单号为:" + orderCode +", 充值金额为:"+amount);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
beforeAmount = sw.getAmount();
|
|
|
beforeLockAmount = sw.getLockAmount();
|
|
|
EntrySellerType sellerType = sellerService.getEntrySellerType(uid);
|
|
|
if (sellerType == EntrySellerType.SPECIAL_SUPER) {
|
|
|
// 白名单:充入lock账户
|
|
|
sw.setLockAmount(amount);
|
|
|
sw.setAmount(null);
|
|
|
afterAmount = beforeAmount;
|
|
|
afterLockAmount = beforeLockAmount.add(amount);
|
|
|
} else {
|
|
|
sw.setLockAmount(null);
|
|
|
sw.setAmount(amount);
|
|
|
afterAmount = beforeAmount.add(amount);
|
|
|
afterLockAmount = beforeLockAmount;
|
|
|
}
|
|
|
|
|
|
sw.setUpdateTime(TimeUtils.getTimeStampSecond());
|
|
|
logger.info("后期充值,处理总账表增加余额,bean={}", sw);
|
|
|
if (sellerWalletMapper.addMoney(sw) == 0) {
|
|
|
logger.error("充值保证金余额{},更新表返回0,uid={}", amount, uid);
|
|
|
CommonAlarmEventPublisher.publish("充值保证金余额失败", "ufo.order.recharge", "更新表返回0,uid=" + uid + ",充值订单号为:" + orderCode +", 充值金额为:"+amount);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
logger.info("修改钱包表余额成功,orderCode={}", orderCode);
|
|
|
|
|
|
// 增加充值记录
|
|
|
SellerWalletDetail swd = new SellerWalletDetail();
|
|
|
swd.setOrderCode(orderCode);
|
|
|
swd.setType(1);
|
|
|
swd.setUid(uid);
|
|
|
swd.setWalletId(sw.getId());
|
|
|
swd.setAmount(amount);
|
|
|
swd.setIsBatch(0);
|
|
|
swd.setType(SellerWalletDetail.Type.RE_CHARGE.getValue());
|
|
|
swd.setCreateTime(TimeUtils.getTimeStampSecond());
|
|
|
swd.setUpdateTime(0);
|
|
|
swd.setAvailAmount(afterAmount);
|
|
|
swd.setLockAmount(afterLockAmount);
|
|
|
swd.setIsSet(1);
|
|
|
MerchantOrderAttachInfo att = new MerchantOrderAttachInfo();
|
|
|
att.setPayment(orderInfo.getPayment());
|
|
|
if (att != null) {
|
|
|
att.setType(SellerWalletDetail.Type.RE_CHARGE.getValue());
|
|
|
att.setTypeName(SellerWalletDetail.Type.RE_CHARGE.getName());
|
|
|
}
|
|
|
swd.setAttachValue(att==null?"":JSON.toJSONString(att));
|
|
|
logger.info("充值后,处理增加钱包明细,bean={}", swd);
|
|
|
sellerWalletDetailMapper.insert(swd);
|
|
|
logger.info("充值后,处理增加钱包明细成功,orderCode={}", orderCode);
|
|
|
|
|
|
// 身份升级、恢复等
|
|
|
BigDecimal allMoney = afterAmount.add(afterLockAmount);
|
|
|
logger.info("卖家{}此充值完成身份处理:剩余金额={},orderCode={}", allMoney, uid);
|
|
|
sellerDealAfterPay(uid, orderCode, allMoney);
|
|
|
EntrySellerRechargeEvent rechargeEvent = new EntrySellerRechargeEvent(orderInfo);
|
|
|
EventBusPublisher.publishEvent(rechargeEvent);
|
|
|
}
|
|
|
|
|
|
private void addJoinHistory(Integer uid, String certNo) {
|
|
|
try {
|
|
|
SellerJoinHistory history = new SellerJoinHistory();
|
|
|
history.setCertNo(certNo);
|
|
|
history.setUid(uid);
|
|
|
history.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
sellerJoinHistoryMapper.insert(history);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("增加入驻历史信息出错uid=" + uid + ",certNo=" + certNo, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public boolean canRejoin(Integer uid, SellerWallet sw, ZhiMaCert cert) {
|
|
|
if (sw == null) {
|
...
|
...
|
|