Authored by tanling

充值入驻增加重试

package com.yohoufo.order.event;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohoufo.common.alarm.Event;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EntrySellerRechargeEvent extends Event {
OrderInfo orderInfo;
}
... ...
package com.yohoufo.order.service;
import com.yohobuy.ufo.model.order.req.EntrySellerRecharge;
public interface IEntrySellerRechargeService {
/**
* 首次入驻
* @param entrySellerRecharge
*/
void firstEntry(EntrySellerRecharge entrySellerRecharge);
/**
* 重新入驻
* @param entrySellerRecharge
*/
void againEntry(EntrySellerRecharge entrySellerRecharge);
/**
* 充值
* @param entrySellerRecharge
*/
void recharge(EntrySellerRecharge entrySellerRecharge);
}
... ...
... ... @@ -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) {
... ...
package com.yohoufo.order.service.handler;
import com.alibaba.fastjson.JSON;
import com.github.rholder.retry.*;
import com.google.common.base.Predicates;
import com.yoho.core.config.ConfigReader;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.req.EntrySellerRecharge;
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
import com.yohoufo.dal.order.SellerJoinHistoryMapper;
import com.yohoufo.dal.order.SellerWalletDetailMapper;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.model.SellerJoinHistory;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.dal.order.model.SellerWalletDetail;
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.service.IEntrySellerRechargeService;
import com.yohoufo.order.service.IStoredSellerService;
import com.yohoufo.order.service.impl.TradeBillsService;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.utils.RetryerUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@Component
public class EntrySellerRechargeHandler implements IEventHandler<EntrySellerRechargeEvent> {
private final Logger logger = LoggerFactory.getLogger(getClass());
private static final int TYPE_FIRST_RECHARGE = 1;
@Autowired
private TradeBillsService tradeBillsService;
@Autowired
SellerService sellerService;
@Autowired
SellerWalletMapper sellerWalletMapper;
@Autowired
IEntrySellerRechargeService entrySellerRechargeService;
@Override
public void handle(EntrySellerRechargeEvent event) {
OrderInfo orderInfo = event.getOrderInfo();
logger.info("entry_seller_recharge,orderInfo: {}", orderInfo);
Long orderCode = orderInfo.getOrderCode();
BigDecimal amount = orderInfo.getAmount();
Integer payment = orderInfo.getPayment();
Integer uid = orderInfo.getUid();
tradeBillsService.addPayRechargeEnsureRecord(orderInfo.getUid(), orderCode, payment, orderInfo.getAmount());
EntrySellerRecharge entrySellerRecharge = new EntrySellerRecharge(uid, amount, orderCode, payment);
// 明确 充值场景
SellerEntryRecharge sellerEntryRecharge = getSellerEntryRecharge(orderInfo.getUid(), orderInfo.getType());
try{
RetryerUtils.getRetryer().call(()->{
switch(sellerEntryRecharge){
case FIRST_ENTRY:
logger.error("seller entry firstEntry {}", entrySellerRecharge);
entrySellerRechargeService.firstEntry(entrySellerRecharge);
break;
case AGAIN_ENTRY:
logger.error("seller entry againEntry {}", entrySellerRecharge);
entrySellerRechargeService.againEntry(entrySellerRecharge);
break;
case RECHARGE:
logger.error("seller entry recharge {}", entrySellerRecharge);
entrySellerRechargeService.recharge(entrySellerRecharge);
break;
default:
logger.error("seller entry recharge no type {}, {}, {}", uid, orderCode, amount);
break;
}
return true;
});
}catch (Exception e){
logger.error("entry seller recharge e {}", e);
return;
}
// 身份升级、恢复等
SellerWallet sellerWallet = sellerWalletMapper.selectByUidAndType(uid, 1);
BigDecimal allMoney = sellerWallet.getAmount().add(sellerWallet.getLockAmount());
logger.info("sellerDealAfterPay before leftMoney {}, uid {}", allMoney, uid);
sellerDealAfterPay(uid, orderCode, allMoney);
}
private SellerEntryRecharge getSellerEntryRecharge(int uid, int type) {
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
SellerEntryRecharge sellerEntryRecharge = null;
if (type == TYPE_FIRST_RECHARGE){
if (sw != null){
sellerEntryRecharge = SellerEntryRecharge.AGAIN_ENTRY;
}else{
sellerEntryRecharge = SellerEntryRecharge.FIRST_ENTRY;
}
}else{
sellerEntryRecharge = SellerEntryRecharge.RECHARGE;
}
return sellerEntryRecharge;
}
private void sellerDealAfterPay(Integer uid, long orderCode, BigDecimal allMoney) {
sellerService.processApply(uid, orderCode, allMoney);
}
private enum SellerEntryRecharge{
FIRST_ENTRY, AGAIN_ENTRY, RECHARGE
}
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSON;
import com.yoho.core.config.ConfigReader;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.req.EntrySellerRecharge;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
import com.yohoufo.dal.order.SellerJoinHistoryMapper;
import com.yohoufo.dal.order.SellerWalletDetailMapper;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.model.SellerJoinHistory;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.dal.order.model.SellerWalletDetail;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.order.common.EnterQuitEnum;
import com.yohoufo.order.event.InviteRecordEvent;
import com.yohoufo.order.service.IEntrySellerRechargeService;
import com.yohoufo.order.service.IStoredSellerService;
import com.yohoufo.order.service.seller.setting.SellerService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
@Service
@Transactional
public class EntrySellerRechargeServiceImpl implements IEntrySellerRechargeService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
SellerJoinHistoryMapper sellerJoinHistoryMapper;
@Autowired
SellerWalletDetailMapper sellerWalletDetailMapper;
@Autowired
UfoServiceCaller ufoServiceCaller;
@Autowired
EntrySellerRechargeOrderMapper entrySellerRechargeOrderMapper;
@Autowired
SellerWalletMapper sellerWalletMapper;
@Autowired
SellerService sellerService;
@Autowired
private ConfigReader configReader;
@Autowired
IStoredSellerService storedSellerService;
/**
* 充值
* @param entrySellerRecharge
*/
@Database(ForceMaster = true, DataSource = "ufo_order")
public void recharge(EntrySellerRecharge entrySellerRecharge){
int uid = entrySellerRecharge.getUid();
BigDecimal amount = entrySellerRecharge.getAmount();
long orderCode = entrySellerRecharge.getOrderCode();
int payment = entrySellerRecharge.getPayment();
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
if (sw == null){
logger.error("again_entry seller_wallet null ,uid={}", uid);
return;
}
// 1.更新钱包总表的数值
sellerWalletMapper.addMoney(buildRechargeSellerWallet(sw.getId(), uid, amount));
// 2.增加明细
addSellerWalletDetail(orderCode, uid, sw.getId(), amount, payment);
}
/**
* 重新入驻
* @param entrySellerRecharge
*/
@Database(ForceMaster = true, DataSource = "ufo_order")
public void againEntry(EntrySellerRecharge entrySellerRecharge){
int uid = entrySellerRecharge.getUid();
BigDecimal amount = entrySellerRecharge.getAmount();
long orderCode = entrySellerRecharge.getOrderCode();
int payment = entrySellerRecharge.getPayment();
// 1. 检查芝麻认证用户
String againEntryCertNo = geytZhiMaCertNo(uid);
if (StringUtils.isBlank(againEntryCertNo)){
logger.error("again_entry geytZhiMaCertNo null ,uid={}", uid);
return;
}
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
if (sw == null){
logger.error("again_entry seller_wallet null ,uid={}", uid);
return;
}
// 2.检查是否达到了 入驻上线
if (!canRejoin(uid, sw.getJoinTimes(), againEntryCertNo)){
logger.error("again_entry joinTimes maxTimes,uid: {},times: {}", uid, sw.getJoinTimes());
return;
}
// 3. 更新 钱包总表
int uptCnt = sellerWalletMapper.rejoin(uid, amount, null, TimeUtils.getTimeStampSecond(), sw.getJoinTimes() + 1);
if (uptCnt == 0){
logger.info("again_entry update seller_wallet uid: {}", uid);
return;
}
// 4. 清理上次入驻的数据
clearOldEntryData(orderCode, uid);
// 5. 增加入驻次数
addJoinHistory(uid, againEntryCertNo);
// 6. 增加明细
addSellerWalletDetail(orderCode, uid, sw.getId(), amount, payment);
}
/**
* 首次入驻
* @param entrySellerRecharge
*/
@Database(ForceMaster = true, DataSource = "ufo_order")
public void firstEntry(EntrySellerRecharge entrySellerRecharge){
int uid = entrySellerRecharge.getUid();
BigDecimal amount = entrySellerRecharge.getAmount();
long orderCode = entrySellerRecharge.getOrderCode();
int payment = entrySellerRecharge.getPayment();
// 1.检查是否是 芝麻认证的用户
String firstEntryCertNo = geytZhiMaCertNo(uid);
if (StringUtils.isBlank(firstEntryCertNo)){
logger.error("frist_entry geytZhiMaCertNo null uid: {}", uid);
return;
}
// 2. 增加钱包总表
SellerWallet sw = addSellerWallet(amount, uid);
// 3.入驻次数记录
addJoinHistory(uid, firstEntryCertNo);
// 4.增加明细
addSellerWalletDetail(orderCode, uid, sw.getId(), amount, payment);
// 附加: 首次入驻(邀请入驻返利)
InviteRecordEvent inviteRecordEvent = InviteRecordEvent.builder().uid(uid).orderCode(orderCode).eventType(EnterQuitEnum.ENTER).build();
EventBusPublisher.publishEvent(inviteRecordEvent);
}
private void clearOldEntryData(Long orderCode, Integer uid) {
// 钱包明细
sellerWalletDetailMapper.clearUserHistoryData(uid);
// 充值信息
entrySellerRechargeOrderMapper.clearUserHistoryData(uid, orderCode);
// 入驻信息
storedSellerService.removeStoredSeller(uid);
}
private String geytZhiMaCertNo(int uid){
ZhiMaCert cert = null;
try {
ApiResponse<?> resp = ufoServiceCaller.call("ufo.user.zhiMaCertInfo", ApiResponse.class, uid);
cert = (ZhiMaCert) resp.getData();
} catch (Exception e) {
logger.error("geytZhiMaCertNo uid {}", uid);
return null;
}
if(cert == null || StringUtils.isBlank(cert.getCertNo())) {
logger.error("geytZhiMaCertNo uid {}", uid);
return null;
}
return cert.getCertNo();
}
private SellerWallet addSellerWallet(BigDecimal amount, Integer uid) {
SellerWallet sw;// 首次充值,创建钱包信息
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);
sellerWalletMapper.insert(sw);
return sw;
}
private int getSellerMaxReJoinTimes() {
String rejoinMaxTimes = configReader.getString("ufo.seller.rejoinMaxTimes", "");
logger.info("getSellerMaxReJoinTimes,value={}", rejoinMaxTimes);
if (StringUtils.isBlank(rejoinMaxTimes)) {
return 0;
}
try {
return Integer.parseInt(rejoinMaxTimes.trim());
} catch (NumberFormatException e) {
return 0;
}
}
private boolean canRejoin(Integer uid, int sellerWalletJoinTimes, String certNo ) {
int maxReJoin = getSellerMaxReJoinTimes();
if (sellerWalletJoinTimes >= maxReJoin) {
return false;
}
return sellerJoinHistoryMapper.selectCountByCertNo(certNo) <= maxReJoin;
}
private void addJoinHistory(Integer uid, String certNo) {
SellerJoinHistory history = new SellerJoinHistory();
history.setCertNo(certNo);
history.setUid(uid);
history.setCreateTime((int) (System.currentTimeMillis() / 1000));
sellerJoinHistoryMapper.insert(history);
}
private int addSellerWalletDetail(long orderCode, int uid, int walletId, BigDecimal amount, int payment){
// 查询总表
SellerWallet sw = sellerWalletMapper.selectByPrimaryKey(walletId);
SellerWalletDetail swd = buildSellerWalletDetail(orderCode, uid, walletId, amount, sw.getAmount(), sw.getLockAmount(), payment);
return sellerWalletDetailMapper.insertSelective(swd);
}
private SellerWalletDetail buildSellerWalletDetail(long orderCode, int uid, int walletId, BigDecimal amount,
BigDecimal afterAmount, BigDecimal afterLockAmount, int payment){
// 增加充值记录
SellerWalletDetail swd = new SellerWalletDetail();
swd.setOrderCode(orderCode);
swd.setType(1);
swd.setUid(uid);
swd.setWalletId(walletId);
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(payment);
if (att != null) {
att.setType(SellerWalletDetail.Type.RE_CHARGE.getValue());
att.setTypeName(SellerWalletDetail.Type.RE_CHARGE.getName());
}
swd.setAttachValue(att==null?"": JSON.toJSONString(att));
return swd;
}
private SellerWallet buildRechargeSellerWallet(int sellerWalletId, int uid, BigDecimal amount){
SellerWallet sw = new SellerWallet();
sw.setId(sellerWalletId);
EntrySellerType sellerType = sellerService.getEntrySellerType(uid);
if (sellerType == EntrySellerType.SPECIAL_SUPER) {
// 白名单:充入lock账户
sw.setLockAmount(amount);
sw.setAmount(null);
} else {
sw.setLockAmount(null);
sw.setAmount(amount);
}
sw.setUpdateTime(TimeUtils.getTimeStampSecond());
return sw;
}
}
... ...