...
|
...
|
@@ -10,6 +10,7 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo; |
|
|
import com.yohobuy.ufo.model.order.common.EntrySellerType;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
|
|
|
import com.yohobuy.ufo.model.order.resp.PageResp;
|
|
|
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
|
|
|
import com.yohoufo.common.utils.TimeUtils;
|
...
|
...
|
@@ -24,6 +25,7 @@ import com.yohoufo.order.service.impl.SellerService; |
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
...
|
...
|
@@ -32,6 +34,7 @@ import java.util.ArrayList; |
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
|
...
|
...
|
@@ -62,7 +65,23 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
|
|
|
@Autowired
|
|
|
IStoredSellerService storedSellerService;
|
|
|
|
|
|
|
|
|
//@Value("${order.seller.tip.publishMoneyTip:保证金余额不足}")
|
|
|
private String publishMoneyTip = "保证金余额不足";
|
|
|
|
|
|
//@Value("${order.seller.tip.publishFunctionTip:请充值后进行正常上架/下架}")
|
|
|
private String publishFunctionTip = "请充值后进行正常上架/下架";
|
|
|
|
|
|
//@Value("${order.seller.tip.canSaleMoneyTip:保证金余额低于}")
|
|
|
private String canSaleMoneyTip = "保证金余额低于";
|
|
|
|
|
|
//@Value("${order.seller.tip.canSaleFunctionTip:平台下架您所有出售中的商品}")
|
|
|
private String canSaleFunctionTip = "平台下架您所有出售中的商品";
|
|
|
|
|
|
//@Value("${order.seller.tip.recoverTip:充值 ¥{} 恢复超级商家权限}")
|
|
|
private String recoverTip = "充值 ¥{} 恢复超级商家权限";
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 更新订单状态
|
|
|
* @param orderInfo
|
...
|
...
|
@@ -83,21 +102,16 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
@Override
|
|
|
public void processAfterPay(OrderInfo orderInfo) {
|
|
|
logger.info("充值后回调,处理processAfterPay,orderInfo={}", orderInfo);
|
|
|
// 首次充值,调用认证成功接口
|
|
|
if (orderInfo.getType() == TYPE_FIRST_RECHARGE) {
|
|
|
try {
|
|
|
logger.info("首次充值后回调,调用商家入驻接口,uid={}", orderInfo.getUid());
|
|
|
storedSellerService.addUserAsStoredSeller(orderInfo.getUid());
|
|
|
} catch (Exception e) {
|
|
|
logger.error("首次充值后回调,商家入驻接口失败,uid={}, msg={}", orderInfo.getUid(), e.getMessage());
|
|
|
CommonAlarmEventPublisher.publish("商家入驻失败", "ufo.user.addUserAsStoredSeller", "首次充值后回调,商家入驻接口失败:uid=" + orderInfo.getUid() + ",充值订单号为:" + orderInfo.getOrderCode() + ",err="+ e.getMessage());
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
BigDecimal amount = orderInfo.getAmount();
|
|
|
|
|
|
BigDecimal beforeAmount = BigDecimal.ZERO;
|
|
|
BigDecimal beforeLockAmount = BigDecimal.ZERO;
|
|
|
|
|
|
BigDecimal afterAmount = BigDecimal.ZERO;
|
|
|
BigDecimal afterLockAmount = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
|
SellerWallet sw = sellerWalletMapper.selectByUidAndType(orderInfo.getUid(), 1);
|
|
|
logger.info("充值后回调,处理总账表,orderCode={}", orderInfo.getOrderCode());
|
|
|
if (orderInfo.getType() == TYPE_FIRST_RECHARGE) {
|
...
|
...
|
@@ -118,6 +132,9 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
logger.info("首次充值后回调,处理总账表新增账号,bean={}", sw);
|
|
|
sellerWalletMapper.insert(sw);
|
|
|
logger.info("首次充值后回调,处理总账表新增账号成功,bean={}", sw);
|
|
|
|
|
|
afterAmount = orderInfo.getAmount();
|
|
|
|
|
|
} else {
|
|
|
// 修改钱包余额
|
|
|
if (sw == null) {
|
...
|
...
|
@@ -130,10 +147,25 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
CommonAlarmEventPublisher.publish("充值保证金余额失败", "ufo.order.recharge", "钱包不可用uid=" + orderInfo.getUid() + ",充值订单号为:" + orderInfo.getOrderCode()+", 充值金额为:"+amount);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
beforeAmount = sw.getAmount();
|
|
|
beforeLockAmount = sw.getLockAmount();
|
|
|
sw.setLockAmount(null);
|
|
|
sw.setAmount(orderInfo.getAmount());
|
|
|
EntrySellerType sellerType = sellerService.getEntrySellerType(orderInfo.getUid());
|
|
|
if (sellerType == EntrySellerType.SPECIAL_SUPER) {
|
|
|
// 白名单:充入lock账户
|
|
|
sw.setLockAmount(orderInfo.getAmount());
|
|
|
sw.setAmount(null);
|
|
|
|
|
|
afterAmount = beforeAmount;
|
|
|
afterLockAmount = beforeLockAmount.add(orderInfo.getAmount());
|
|
|
} else {
|
|
|
sw.setLockAmount(null);
|
|
|
sw.setAmount(orderInfo.getAmount());
|
|
|
|
|
|
afterAmount = beforeAmount.add(orderInfo.getAmount());
|
|
|
afterLockAmount = beforeLockAmount;
|
|
|
}
|
|
|
|
|
|
sw.setUpdateTime(TimeUtils.getTimeStampSecond());
|
|
|
logger.info("后期充值,处理总账表增加余额,bean={}", sw);
|
|
|
if (sellerWalletMapper.addMoney(sw) == 0) {
|
...
|
...
|
@@ -155,13 +187,8 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
swd.setType(SellerWalletDetail.Type.RE_CHARGE.getValue());
|
|
|
swd.setCreateTime(TimeUtils.getTimeStampSecond());
|
|
|
swd.setUpdateTime(0);
|
|
|
if (orderInfo.getType() == TYPE_FIRST_RECHARGE) {
|
|
|
swd.setAvailAmount(orderInfo.getAmount());
|
|
|
swd.setLockAmount(BigDecimal.ZERO);
|
|
|
} else {
|
|
|
swd.setAvailAmount(orderInfo.getAmount().add(beforeAmount));
|
|
|
swd.setLockAmount(beforeLockAmount);
|
|
|
}
|
|
|
swd.setAvailAmount(afterAmount);
|
|
|
swd.setLockAmount(afterLockAmount);
|
|
|
swd.setIsSet(1);
|
|
|
MerchantOrderAttachInfo att = new MerchantOrderAttachInfo();
|
|
|
att.setPayment(orderInfo.getPayment());
|
...
|
...
|
@@ -173,10 +200,16 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
logger.info("充值后,处理增加钱包明细,bean={}", swd);
|
|
|
sellerWalletDetailMapper.insert(swd);
|
|
|
logger.info("充值后,处理增加钱包明细成功,orderCode={}", orderInfo.getOrderCode());
|
|
|
|
|
|
|
|
|
// 身份升级、恢复等
|
|
|
logger.info("卖家{}此充值完成身份处理:{},orderCode={}", orderInfo.getUid());
|
|
|
sellerDealAfterPay(orderInfo.getUid(), orderInfo.getOrderCode(), afterAmount.add(afterLockAmount));
|
|
|
}
|
|
|
|
|
|
|
|
|
private void sellerDealAfterPay(Integer uid, long orderCode, BigDecimal allMoney) {
|
|
|
sellerService.processApply(uid, orderCode, allMoney);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单是否是待支付状态
|
|
|
* @param orderInfo
|
...
|
...
|
@@ -334,11 +367,34 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
StoredSeller storedSeller =storedSellerService.getValidStoredSeller(uid);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("all", sw.getAmount().add(sw.getLockAmount()).setScale(2).toString());
|
|
|
BigDecimal allMoney = sw.getAmount().add(sw.getLockAmount());
|
|
|
|
|
|
Map<EntrySellerType, EntryThreshold> map = sellerService.getEntryThreshold();
|
|
|
EntryThreshold sp = map.get(EntrySellerType.SUPER_ENTRY);
|
|
|
// 查配置、超级卖家门槛金额
|
|
|
BigDecimal superMoney = sp.getPrepaymentAmount();
|
|
|
BigDecimal lackOfMoneyAsSuper = BigDecimal.ZERO;
|
|
|
if (allMoney.compareTo(superMoney) < 0) {
|
|
|
lackOfMoneyAsSuper = superMoney.subtract(allMoney);
|
|
|
}
|
|
|
result.put("all", allMoney.setScale(2).toString());
|
|
|
result.put("lackOfMoneyAsSuper", lackOfMoneyAsSuper.setScale(2).toString());
|
|
|
// 查配置、超级卖家门不能发布商品的金额
|
|
|
BigDecimal publishMinMoney = sp.getGoodsOnOffShelveAmount();
|
|
|
result.put("locked", sw.getLockAmount().setScale(2).toString());
|
|
|
result.put("avail", sw.getAmount().setScale(2).toString());
|
|
|
result.put("entryTime", (storedSeller == null || storedSeller.getEnterTime() < 1) ? ""
|
|
|
: sdf.format(1000L * storedSeller.getEnterTime()));
|
|
|
result.put("publishMoneyTip", publishMoneyTip + publishMinMoney.toString());
|
|
|
// TODO 查询用户权限状态
|
|
|
boolean logoGray = allMoney.compareTo(publishMinMoney) < 0;
|
|
|
result.put("logoGray", logoGray);
|
|
|
result.put("publishFunctionTip", publishFunctionTip);
|
|
|
// 查配置、超级卖家门不能发布商品的金额
|
|
|
BigDecimal canSaleMoney = sp.getHiddenGoodsAmount();
|
|
|
result.put("canSaleMoneyTip", canSaleMoneyTip + canSaleMoney.toString());
|
|
|
result.put("canSaleFunctionTip", canSaleFunctionTip);
|
|
|
result.put("recoverTip", recoverTip.replace("{}", lackOfMoneyAsSuper.toString()));
|
|
|
return new com.yohoufo.common.ApiResponse(200, "查询成功", result);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -388,9 +444,25 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
}
|
|
|
|
|
|
// 升级超级卖家:账号资金移动处理
|
|
|
public int changeWalletToSuperSeller(Integer uid) {
|
|
|
return sellerWalletMapper.changeAllMoneyToAvail(uid, DateUtil.getCurrentTimeSecond());
|
|
|
}
|
|
|
// *后期需要再次调用,清理残留
|
|
|
public int changeWalletToSuperSeller(Integer uid) {
|
|
|
logger.info("uid={}, 超级卖家:账号资金移动处理", uid);
|
|
|
// 使用钱包余额,支付保证金
|
|
|
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
|
|
|
logger.info("uid={}, 超级卖家:账号资金移动处理前账户={}", uid, sw);
|
|
|
if (sw == null) {
|
|
|
logger.error("超级卖家:账号资金移动处理失败,钱包不存在,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish("超级卖家:账号资金移动处理失败", "ufo.order.changeWalletToSuperSeller", "钱包不存在,uid=" + uid);
|
|
|
return 0;
|
|
|
}
|
|
|
if (sw.getStatus() == null || sw.getStatus() == 0) {
|
|
|
CommonAlarmEventPublisher.publish("超级卖家:账号资金移动处理失败", "ufo.order.changeWalletToSuperSeller", "钱包不可用,uid=" + uid);
|
|
|
return 0;
|
|
|
}
|
|
|
int result = sellerWalletMapper.changeAllMoneyToAvail(uid, DateUtil.getCurrentTimeSecond());
|
|
|
logger.info("uid={}, 超级卖家:账号资金移动处理结果={}", uid, result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 支付保证金:总账修改
|
|
|
public SellerWallet useEarnest(Integer uid, BigDecimal money, MerchantOrderAttachInfo attach) {
|
...
|
...
|
@@ -580,33 +652,33 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
private SellerWallet changeEarnest(Integer uid, BigDecimal money, long orderCode, MerchantOrderAttachInfo attach, SellerWalletDetail.Type type) {
|
|
|
BigDecimal money2 = money.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
if (money2.compareTo(money) != 0) {
|
|
|
logger.warn("{}修改钱包表入口,uid={},金额超出两位小数(自动截取) money={}, money2={}", type.getName(), uid, money, money2);
|
|
|
logger.warn("{}修改钱包表入口,orderCode={},uid={},金额超出两位小数(自动截取) money={}, money2={}", type.getName(), orderCode, uid, money, money2);
|
|
|
money = money2;
|
|
|
}
|
|
|
logger.info("{}修改钱包表入口,uid={},money={}", type.getName(), uid, money);
|
|
|
logger.info("{}修改钱包表入口,orderCode={},uid={},money={}", type.getName(), orderCode, orderCode, uid, money);
|
|
|
String message = type.getName();
|
|
|
// 使用钱包余额,支付保证金
|
|
|
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
|
|
|
logger.info("{}修改钱包表入口,uid={},钱包={}", type.getName(), uid, sw);
|
|
|
logger.info("{}修改钱包表入口,orderCode={},uid={},钱包={}", type.getName(), orderCode, uid, sw);
|
|
|
if (sw == null) {
|
|
|
logger.error(message + "失败,钱包不存在,uid={}", uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不存在uid=" + uid+", 金额为:"+money);
|
|
|
logger.error(message + "失败,钱包不存在,orderCode={},uid={}", orderCode, uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不存在,orderCode="+orderCode+",uid=" + uid+", 金额为:"+money);
|
|
|
return null;
|
|
|
}
|
|
|
if (sw.getStatus() == null || sw.getStatus() == 0) {
|
|
|
logger.error(message + "{}失败,钱包不可用,uid={}", money, uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不可用uid=" + uid+", 金额为:"+money);
|
|
|
logger.error(message + "{}失败,钱包不可用,orderCode={},uid={}", money, orderCode, uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不可用,orderCode="+orderCode+",uid=" + uid+", 金额为:"+money);
|
|
|
return null;
|
|
|
}
|
|
|
if ((type == SellerWalletDetail.Type.PUBLISH || type == SellerWalletDetail.Type.ADD_PRICE) && sw.getAmount().compareTo(money) < 0) {
|
|
|
logger.error(message + "{}失败,钱包余额不足,uid={}", money, uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包余额不足uid=" + uid+", 金额为:"+money+", 账户余额为:"+sw.getAmount());
|
|
|
logger.error(message + "{}失败,钱包余额不足,orderCode={},uid={}", money, orderCode, uid);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包余额不足,orderCode="+orderCode+",uid=" + uid+", 金额为:"+money+", 账户余额为:"+sw.getAmount());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
BigDecimal beforeAvailAmount = sw.getAmount();
|
|
|
BigDecimal beforeLockAmount = sw.getLockAmount();
|
|
|
logger.info("{}修改钱包,uid={},金额计算后:beforeAvailAmount={}, beforeLockAmount={}", type.getName(), uid, beforeAvailAmount, beforeLockAmount);
|
|
|
logger.info("{}修改钱包,orderCode={},uid={},金额计算后:beforeAvailAmount={}, beforeLockAmount={}", type.getName(), orderCode, uid, beforeAvailAmount, beforeLockAmount);
|
|
|
BigDecimal availAmount = null;
|
|
|
BigDecimal lockAmount = null;
|
|
|
BigDecimal tradeAmount = null;
|
...
|
...
|
@@ -618,7 +690,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
availAmount = money.multiply(new BigDecimal("-1"));
|
|
|
lockAmount = money;
|
|
|
tradeAmount = availAmount;
|
|
|
logger.info("{}修改钱包,uid={},减去保证金场合:", type.getName(), uid);
|
|
|
logger.info("{}修改钱包,orderCode={},uid={},减去保证金场合:", type.getName(), orderCode, uid);
|
|
|
} else if (type == SellerWalletDetail.Type.SELLER_OFF
|
|
|
|| type == SellerWalletDetail.Type.SYSTEM_OFF
|
|
|
|| type == SellerWalletDetail.Type.APPRAISE_OK
|
...
|
...
|
@@ -628,7 +700,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
availAmount = money;
|
|
|
lockAmount = money.multiply(new BigDecimal("-1"));
|
|
|
tradeAmount = money;
|
|
|
logger.info("{}修改钱包,uid={},增加保证金场合:", type.getName(), uid);
|
|
|
logger.info("{}修改钱包,orderCode={},uid={},增加保证金场合:", type.getName(), orderCode, uid);
|
|
|
} else if (type == SellerWalletDetail.Type.SELLER_CANCEL
|
|
|
|| type == SellerWalletDetail.Type.SELLER_OVER_TIME
|
|
|
|| type == SellerWalletDetail.Type.APPRAISE_FAIL
|
...
|
...
|
@@ -637,16 +709,16 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
// 如果是超级卖家
|
|
|
sellerType = sellerService.getEntrySellerType(uid);
|
|
|
boolean isSuper = (sellerType != null && sellerType == EntrySellerType.SUPER_ENTRY);
|
|
|
logger.info("{}修改钱包,uid={},处罚保证金场合:获取身份超级卖家:{}", type.getName(), uid, sellerType);
|
|
|
logger.info("{}修改钱包,orderCode={},uid={},处罚保证金场合:获取身份超级卖家:{}", type.getName(), orderCode, uid, sellerType);
|
|
|
if (isSuper) {
|
|
|
availAmount = money.multiply(new BigDecimal("-1"));
|
|
|
} else {
|
|
|
lockAmount = money.multiply(new BigDecimal("-1"));
|
|
|
}
|
|
|
tradeAmount = lockAmount;
|
|
|
logger.info("{}修改钱包,uid={},处罚保证金场合:", type.getName(), uid);
|
|
|
logger.info("{}修改钱包,orderCode={},uid={},处罚保证金场合:", type.getName(), orderCode, uid);
|
|
|
}
|
|
|
logger.info("{}修改钱包,uid={},金额计算后:availAmount={}, lockAmount={}, tradeAmount={}", type.getName(), uid, availAmount, lockAmount, tradeAmount);
|
|
|
logger.info("{}修改钱包,orderCode={},uid={},金额计算后:availAmount={}, lockAmount={}, tradeAmount={}", type.getName(), orderCode, uid, availAmount, lockAmount, tradeAmount);
|
|
|
sw.setAmount(availAmount);
|
|
|
sw.setLockAmount(lockAmount);
|
|
|
sw.setUpdateTime(TimeUtils.getTimeStampSecond());
|
...
|
...
|
@@ -674,8 +746,8 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
}
|
|
|
|
|
|
if(needLogErrAndReturn) {
|
|
|
logger.error(message + "失败,(余额不足或钱包不可用)更新表返回0,bean={}", sw);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.walletPunishment", "用户:" + uid + ",(余额不足货钱包不可用),更新表返回 0,bean为:"+ sw);
|
|
|
logger.error(message + "失败,(余额不足或钱包不可用)更新表返回0,orderCode={},bean={}", orderCode, sw);
|
|
|
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.walletPunishment", "用户:" + uid + ",(余额不足货钱包不可用),更新表返回 0,orderCode="+orderCode+",bean为:"+ sw);
|
|
|
return null;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -698,7 +770,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
|
|
swd.setAttachValue(attach==null?"":JSON.toJSONString(attach));
|
|
|
swd.setAvailAmount(availAmount == null ? beforeAvailAmount : beforeAvailAmount.add(availAmount));
|
|
|
swd.setLockAmount(lockAmount == null ? beforeLockAmount : beforeLockAmount.add(lockAmount));
|
|
|
logger.info("{}修改钱包,uid={},明细availAmount={}, beforeAvailAmount={}, beforeLockAmount={}, lockAmount={}", type.getName(), uid, availAmount, beforeAvailAmount, beforeLockAmount, lockAmount);
|
|
|
logger.info("{}修改钱包,orderCode={},uid={},明细availAmount={}, beforeAvailAmount={}, beforeLockAmount={}, lockAmount={}", type.getName(), orderCode, uid, availAmount, beforeAvailAmount, beforeLockAmount, lockAmount);
|
|
|
swd.setIsSet(0);
|
|
|
/////////////////////////
|
|
|
logger.info("增加钱包明细汇总记录,bean={}", swd);
|
...
|
...
|
|