Authored by TANLING

卖家权限&level变更

Showing 32 changed files with 1756 additions and 783 deletions
... ... @@ -16,6 +16,8 @@ public interface SellerEnterApplyMapper {
int updateByPrimaryKey(SellerEnterApply record);
int updateStatusByUidOrderCode(SellerEnterApply record);
/**
* UOCET => uid & order_code & enter_type
* @param condition
... ...
... ... @@ -132,4 +132,16 @@
status = #{status,jdbcType=SMALLINT}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateStatusByUidOrderCode" parameterType="com.yohoufo.dal.order.model.SellerEnterApply">
update seller_enter_apply set
status = #{status,jdbcType=SMALLINT},
update_time = #{updateTime,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER} and
order_code = #{orderCode,jdbcType=BIGINT}
and status = 0
</update>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.controller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
import com.yohoufo.order.event.EntrySellerRechargeEvent;
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
... ... @@ -8,6 +16,7 @@ import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
... ... @@ -49,4 +58,44 @@ public class OrderHelpController {
.build();
}
@Autowired
private EntrySellerRechargeOrderMapper entrySellerRechargeOrderMapper;
@RequestMapping(value = "/recharge")
public void test(@RequestParam(value = "uid") int uid,
@RequestParam(value = "orderCode") long orderCode){
EntrySellerRechargeOrder buyerOrder = entrySellerRechargeOrderMapper.selectByOrderCode(orderCode);
if (buyerOrder == null){
throw new ServiceException(ServiceError.ORDER_NULL);
}
OrderInfo orderInfo = buildOrderInfo(buyerOrder);
EntrySellerRechargeEvent rechargeEvent = new EntrySellerRechargeEvent(orderInfo);
EventBusPublisher.publishEvent(rechargeEvent);
}
private OrderInfo buildOrderInfo(EntrySellerRechargeOrder order) {
OrderInfo orderInfo = OrderInfo.builder()
.id(order.getId())
.uid(order.getUid())
.orderCode(order.getOrderCode())
.payment(order.getPayment())
.status(order.getStatus())
.amount(order.getAmount())
.createTime(order.getCreateTime())
.orderCodeType(OrderCodeType.BUYER_TYPE)
.sourceStatus(order.getStatus())
.payExpireTime(30)
.type(order.getType())
.build();
return orderInfo;
}
}
... ...
... ... @@ -399,7 +399,7 @@ public class PaymentController {
@RequestParam(name = "sellerOrderCode") long sellerOrderCode,
@RequestParam(name = "type") int type){
paymentService.transferMon(new TransferMoneyRequest(buyerOrderCode, sellerOrderCode, type));
return new ApiResponse.ApiResponseBuilder().code(200).data("").message("分账成功").buildSellerBo();
return new ApiResponse.ApiResponseBuilder().code(200).data("").message("分账成功").sellerBo();
}*/
... ...
... ... @@ -139,21 +139,18 @@ public class SellerController {
/**
* 入驻的普通卖家当钱包金额满足5000,可以直接申请为超级卖家
* 废弃,前台不允许直接升级成(商家入驻PLUS)
* @param uid
* @return
*/
@RequestMapping(params = "method=ufo.seller.applySuperEnter")
@ResponseBody
@Deprecated
public ApiResponse applySuperEnter(@RequestParam("uid") Integer uid) {
logger.info("enter ufo.seller.applySuperEnter uid {}", uid);
Boolean data = sellerService.applySuperEnter(uid);
String msg = "升级超级卖家";
if (data){
msg += "成功";
}else{
msg += "失败";
}
return new ApiResponse.ApiResponseBuilder().data(data).code(200).message(msg).build();
throw new UfoServiceException(403, "商家入驻全新升级,请更新app体验!");
}
@RequestMapping(params = "method=ufo.order.isSurperEntrySeller")
... ...
package com.yohoufo.order.controller;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.IStoredSellerDepositService;
... ... @@ -33,6 +34,11 @@ public class StoredSellerDepositController {
@ResponseBody
public ApiResponse depositPreStore(ShoppingRequest shoppingRequest) {
logger.info("in ufo.StoredSellerDepositController.depositPreStore, shoppingRequest {}", shoppingRequest);
// 前台升级成 入驻商家PLUS的入口关闭,接口直接异常
if (shoppingRequest.getAsSuper() == 1){
throw new UfoServiceException(403, "商家入驻全新升级,请更新app体验!");
}
OrderSubmitResponse orderSubmitResponse=storedSellerDepositService.depositPreStore(shoppingRequest);
return new ApiResponse.ApiResponseBuilder().code(200).data(orderSubmitResponse).message("预存保证金订单生成,请支付").build();
}
... ... @@ -45,6 +51,12 @@ public class StoredSellerDepositController {
@ResponseBody
public ApiResponse depositRecharge(ShoppingRequest shoppingRequest) {
logger.info("in ufo.StoredSellerDepositController.depositRecharge, shoppingRequest {}",shoppingRequest);
// 前台升级成 入驻商家PLUS的入口关闭,接口直接异常
if (shoppingRequest.getAsSuper() == 1){
throw new UfoServiceException(403, "商家入驻全新升级,请更新app体验!");
}
OrderSubmitResponse orderSubmitResponse=storedSellerDepositService.depositRecharge(shoppingRequest);
return new ApiResponse.ApiResponseBuilder().data(orderSubmitResponse).code(200).message("保证金充值订单生成,请支付").build();
}
... ...
... ... @@ -4,6 +4,7 @@ import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.req.SellerReq;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.order.service.IStoredSellerDepositService;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.setting.SellerWrapper;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -32,7 +33,7 @@ public class ErpSellerController {
@IgnoreSession
@RequestMapping("/isNormalSuper")
public Boolean isNormalSuper(@RequestBody SellerReq sellerReq){
logger.info("in isNormalSuper req {}", sellerReq);
logger.info("in isEntryPlus req {}", sellerReq);
if (Objects.isNull(sellerReq)){
return false;
}
... ... @@ -49,7 +50,7 @@ public class ErpSellerController {
return null;
}
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
logger.info("erp invoke getSellerWithAuth,req {},sellerBo {}", sellerReq, sellerBo);
return sellerBo;
}
... ... @@ -61,4 +62,17 @@ public class ErpSellerController {
logger.info("in detectEntryLevel,req {}", req);
sellerService.processAfterWalletChange(req.getUid());
}
@Autowired
IStoredSellerDepositService sellerDepositService;
@IgnoreSignature
@IgnoreSession
@RequestMapping("/applyEntryPlush")
public void applyEntryPlush(@RequestBody SellerReq req){
logger.info("in applyEntryPlush,req {}", req);
sellerDepositService.applyEntryPlush(req.getUid());
}
}
... ...
... ... @@ -40,6 +40,7 @@ public class ShoppingRequest {
private String amount;
@Deprecated
private int asSuper;
/**
... ...
... ... @@ -10,4 +10,11 @@ public interface IStoredSellerDepositService {
OrderSubmitResponse depositRecharge(ShoppingRequest shoppingRequest);
void quitStoredSellerAndReturnDeposit(Integer uid);
/**
* 将普通入驻升级成入驻PLUS
* @param uid
*/
public void applyEntryPlush(int uid);
}
... ...
... ... @@ -148,10 +148,10 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
return sellerJoinHistoryMapper.selectCountByCertNo(cert.getCertNo()) <= maxReJoin;
}
private void sellerDealAfterPay(Integer uid, long orderCode, BigDecimal allMoney) {
sellerService.processApply(uid, orderCode, allMoney);
}
// private void sellerDealAfterPay(Integer uid, long orderCode, BigDecimal allMoney) {
// sellerService.processApply(uid, orderCode, allMoney);
// }
//
/**
* 订单是否是待支付状态
* @param orderInfo
... ... @@ -332,7 +332,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
BigDecimal allMoney = sw.getAmount().add(sw.getLockAmount());
SellerWrapper sellerWrapper = sellerService.getBaseSellerWrapper(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
Map<EntrySellerType, EntryThreshold> map = sellerService.getEntryThreshold();
EntryThreshold sp = map.get(EntrySellerType.SUPER_ENTRY);
// 查配置、超级卖家门槛金额
... ... @@ -676,7 +676,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
}
private boolean isSuperWithoutLock(int uid){
SellerWrapper sellerWrapper = sellerService.getBaseSellerWrapper(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
return SellerHelper.isSuper(sellerBo.getEntrySellerType());
}
... ...
package com.yohoufo.order.service.handler;
import com.alibaba.fastjson.JSON;
import com.github.rholder.retry.*;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import com.google.common.eventbus.Subscribe;
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.common.EntrySellerDepositType;
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.proxy.UserProxyService;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.utils.RetryerUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -38,16 +22,16 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.List;
@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;
... ... @@ -62,130 +46,156 @@ public class EntrySellerRechargeHandler implements IEventHandler<EntrySellerRech
IEntrySellerRechargeService entrySellerRechargeService;
@Autowired
UfoServiceCaller ufoServiceCaller;
UserProxyService userProxyService;
List<AbstractPaySuccessPostProcessor> paySuccessPostProcessors = Lists.newArrayList();
@Autowired
SellerAuthorityChangeHandler authorityChangeHandler;
@PostConstruct
public void init() {
paySuccessPostProcessors.add(new FirstEntryAbstractPaySuccessPostProcessor());
paySuccessPostProcessors.add(new AgainEntryAbstractPaySuccessPostProcessor());
paySuccessPostProcessors.add(new RechargeAbstractPaySuccessPostProcessor());
}
@Override
@Subscribe
public void handle(EntrySellerRechargeEvent event) {
OrderInfo orderInfo = event.getOrderInfo();
paySuccessPostProcessors.stream().filter(x->x.isMatchedScene(event.getOrderInfo())).findFirst().ifPresent(x->x.handle(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 = EntrySellerRecharge.builder().amount(amount)
.orderCode(orderCode)
.uid(uid)
.payment(payment).build();
// 明确 充值场景
SellerEntryRecharge sellerEntryRecharge = getSellerEntryRecharge(orderInfo.getUid(), orderInfo.getType());
private abstract class AbstractPaySuccessPostProcessor {
try{
RetryerUtils.getRetryer().call(()->{
switch(sellerEntryRecharge){
public void handle(OrderInfo orderInfo){
case FIRST_ENTRY:
// 插入一条流水
tradeBillsService.addPayRechargeEnsureRecord(orderInfo.getUid(), orderInfo.getOrderCode(), orderInfo.getPayment(), orderInfo.getAmount());
// 1.检查是否是 芝麻认证的用户
String firstEntryCertNo = geytZhiMaCertNo(uid);
// 更新钱包
try{
RetryerUtils.getRetryer().call(()-> updateWalletWhenRecharge(orderInfo));
}catch (Exception e){
logger.error("entry seller recharge orderInfo {}, e {}",orderInfo, e);
return;
}
if (StringUtils.isBlank(firstEntryCertNo)){
logger.error("frist_entry geytZhiMaCertNo null uid: {}", uid);
return true;
}
// 升级商家的功能
authorityChangeHandler.changerAuthority(orderInfo.getUid(), orderInfo.getOrderCode());
entrySellerRecharge.setCertNo(firstEntryCertNo);
entrySellerRechargeService.firstEntry(entrySellerRecharge);
break;
}
case AGAIN_ENTRY:
protected abstract boolean updateWalletWhenRecharge(OrderInfo orderInfo);
/**
* 适用场景法
* @param orderInfo
* @return
*/
protected abstract boolean isMatchedScene(OrderInfo orderInfo);
// 1.检查是否是 芝麻认证的用户
String againEntryCertNo = geytZhiMaCertNo(uid);
}
if (StringUtils.isBlank(againEntryCertNo)){
logger.error("again entry geytZhiMaCertNo null uid: {}", uid);
return true;
}
entrySellerRecharge.setCertNo(againEntryCertNo);
class FirstEntryAbstractPaySuccessPostProcessor extends AbstractPaySuccessPostProcessor {
entrySellerRechargeService.againEntry(entrySellerRecharge);
@Override
protected boolean updateWalletWhenRecharge(OrderInfo orderInfo) {
break;
EntrySellerRecharge entrySellerRecharge = EntrySellerRecharge.builder().amount(orderInfo.getAmount())
.orderCode(orderInfo.getOrderCode())
.uid(orderInfo.getUid())
.payment(orderInfo.getPayment()).build();
case RECHARGE:
logger.error("seller entry recharge {}", entrySellerRecharge);
entrySellerRechargeService.recharge(entrySellerRecharge);
// 1.检查是否是 芝麻认证的用户
ZhiMaCert zhiMaCert = userProxyService.getRealNameInfo(orderInfo.getUid());
break;
default:
logger.error("seller entry recharge no type {}, {}, {}", uid, orderCode, amount);
break;
if (zhiMaCert == null || StringUtils.isBlank(zhiMaCert.getCertNo())){
logger.error("frist_entry geytZhiMaCertNo null uid: {}", orderInfo.getUid());
return true;
}
}
entrySellerRecharge.setCertNo(zhiMaCert.getCertNo());
entrySellerRechargeService.firstEntry(entrySellerRecharge);
return true;
});
}catch (Exception e){
logger.error("entry seller recharge orderInfo {}, e {}",orderInfo, e);
return;
}
return true;
}
// 身份升级、恢复等
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);
@Override
protected boolean isMatchedScene(OrderInfo orderInfo) {
if (orderInfo.getType() == EntrySellerDepositType.PRE_STORE.getType()){
SellerWallet sw = sellerWalletMapper.selectByUidAndType(orderInfo.getUid(), 1);
if (sw == null){
return true;
}
}
return false;
}
}
private SellerEntryRecharge getSellerEntryRecharge(int uid, int type) {
class AgainEntryAbstractPaySuccessPostProcessor extends AbstractPaySuccessPostProcessor {
if (type == TYPE_FIRST_RECHARGE){
@Override
protected boolean updateWalletWhenRecharge(OrderInfo orderInfo) {
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
if (sw != null){
return SellerEntryRecharge.AGAIN_ENTRY;
}else{
return SellerEntryRecharge.FIRST_ENTRY;
EntrySellerRecharge entrySellerRecharge = EntrySellerRecharge.builder().amount(orderInfo.getAmount())
.orderCode(orderInfo.getOrderCode())
.uid(orderInfo.getUid())
.payment(orderInfo.getPayment()).build();
// 1.检查是否是 芝麻认证的用户
ZhiMaCert zhiMaCert = userProxyService.getRealNameInfo(orderInfo.getUid());
if (zhiMaCert == null || StringUtils.isBlank(zhiMaCert.getCertNo())){
logger.error("again_entry geytZhiMaCertNo null uid: {}", orderInfo.getUid());
return true;
}
}else{
return SellerEntryRecharge.RECHARGE;
}
}
entrySellerRecharge.setCertNo(zhiMaCert.getCertNo());
private void sellerDealAfterPay(Integer uid, long orderCode, BigDecimal allMoney) {
sellerService.processApply(uid, orderCode, allMoney);
}
entrySellerRechargeService.againEntry(entrySellerRecharge);
return true;
}
private enum SellerEntryRecharge{
FIRST_ENTRY, AGAIN_ENTRY, RECHARGE
@Override
protected boolean isMatchedScene(OrderInfo orderInfo) {
if (orderInfo.getType() == EntrySellerDepositType.PRE_STORE.getType()){
SellerWallet sw = sellerWalletMapper.selectByUidAndType(orderInfo.getUid(), 1);
if (sw != null){
return true;
}
}
return false;
}
}
private String geytZhiMaCertNo(int uid){
class RechargeAbstractPaySuccessPostProcessor extends AbstractPaySuccessPostProcessor {
@Override
protected boolean updateWalletWhenRecharge(OrderInfo orderInfo) {
EntrySellerRecharge entrySellerRecharge = EntrySellerRecharge.builder().amount(orderInfo.getAmount())
.orderCode(orderInfo.getOrderCode())
.uid(orderInfo.getUid())
.payment(orderInfo.getPayment()).build();
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;
logger.error("seller entry recharge {}", entrySellerRecharge);
entrySellerRechargeService.recharge(entrySellerRecharge);
return true;
}
if(cert == null || StringUtils.isBlank(cert.getCertNo())) {
logger.error("geytZhiMaCertNo uid {}", uid);
return null;
@Override
protected boolean isMatchedScene(OrderInfo orderInfo) {
return orderInfo.getType() == EntrySellerDepositType.RECHARGE.getType();
}
return cert.getCertNo();
}
}
... ...
package com.yohoufo.order.service.handler;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.enums.StoredSellerStatusEnum;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.bo.SellerLevelFuncBo;
import com.yohobuy.ufo.model.order.common.EntrySellerDepositType;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.SellerEnterApplyStatus;
import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.UfoInfluxdbEvent;
import com.yohoufo.common.alarm.UfoInfluxdbVo;
import com.yohoufo.common.constant.InfluxdbFieldEnum;
import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
import com.yohoufo.common.constant.InfluxdbTagEnum;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
import com.yohoufo.dal.order.SellerEnterApplyMapper;
import com.yohoufo.dal.order.StoredSellerMapper;
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
import com.yohoufo.dal.order.model.SellerEnterApply;
import com.yohoufo.dal.order.model.StoredSeller;
import com.yohoufo.order.common.EnterQuitEnum;
import com.yohoufo.order.event.SellerEnterTypeChangeEvent;
import com.yohoufo.order.service.IStoredSellerService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.seller.setting.AuthLevelChgeSupport;
import com.yohoufo.order.service.seller.setting.EntrySellerWalletChangers;
import com.yohoufo.order.service.seller.setting.SellerEnterApplyService;
import com.yohoufo.order.service.seller.setting.SellerWrapper;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 场景:
* 卖家充值成功的支付回调
* ①卖家类型发生变化
* 1.非入驻==>普通入驻
* 2.普通入驻==>入驻PLUS[目前只能通过后台升级]
* ②仅仅是充值,卖家的level发生变化
*/
@Component
public class SellerAuthorityChangeHandler implements ApplicationContextAware {
private static final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private StoredSellerMapper storedSellerMapper;
@Autowired
private AuthLevelChgeSupport authLevelChgeSupport;
// 卖家类型对应的处理
private List<AuthorityChaneHandler> authorityChaneHandlers = Lists.newArrayList();
/**
* 以下两种场景:
* 1.未入驻 ==> 普通入驻
* 2.入驻PLUS因为充值,level发生改变
* @param uid
* @param orderCode
*/
public void changerAuthority(int uid, long orderCode){
SellerWrapper sellerWrapper = authLevelChgeSupport.getSellerWrapper(uid);
authorityChaneHandlers.stream().filter(x->x.isMatchedScene(sellerWrapper, orderCode)).findFirst().ifPresent(x->x.handle(sellerWrapper, orderCode));
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, AuthorityChaneHandler> chaneHandlerMap = applicationContext.getBeansOfType(AuthorityChaneHandler.class);
authorityChaneHandlers.addAll(chaneHandlerMap.values());
}
private abstract class AuthorityChaneHandler{
abstract EntrySellerType getTargetSellerType();
abstract boolean isMatchedScene(SellerWrapper sellerWrapper, long orderCode);
abstract void handle(SellerWrapper sellerWrapper, long orderCode);
@Autowired
AuthLevelChgeSupport levelChangeSupport;
@Autowired
IStoredSellerService storedSellerService;
@Autowired
SellerEnterApplyService sellerEnterApplyService;
}
@Component
class NoEntryToCommonAuthorityChaneHandler extends AuthorityChaneHandler{
@Override
EntrySellerType getTargetSellerType() {
return EntrySellerType.COMMON;
}
@Override
public boolean isMatchedScene(SellerWrapper sellerWrapper, long orderCode) {
SellerEnterApply sellerEnterApply = sellerEnterApplyService.getSellerEntryApply(sellerWrapper.getUid(), orderCode);
if (sellerEnterApply == null){
return false;
}
StoredSeller storedSeller = sellerWrapper.getStoredSeller();
SellerBo sellerBo = sellerWrapper.sellerBo();
// 未入驻 && 申请前状态一致 && 目标类型是普通入驻
if ((Objects.isNull(storedSeller) || storedSeller.getValidStatus().equals(StoredSellerStatusEnum.quit.getId()))
&& Objects.equals(sellerEnterApply.getPreEnterType(), sellerBo.getEntrySellerType().getCode())
&& Objects.equals(sellerEnterApply.getEnterType(), getTargetSellerType().getCode())){
return true;
}
return false;
}
@Override
void handle(SellerWrapper sellerWrapper, long orderCode) {
int uid = sellerWrapper.getUid();
logger.info("NoEntryToCommonAuthorityChaneHandler uid {}, orderCode {}", uid, orderCode);
// 1.更新申请记录的状态
sellerEnterApplyService.passApply(sellerWrapper.getUid(), orderCode);
EntrySellerType targeType = getTargetSellerType();
SellerLevelFuncBo shouldLevelBo = levelChangeSupport.getShouldLevel(uid, targeType);
if (shouldLevelBo == null){
return;
}
// 2.更新stored_seller
storedSellerService.addUserAsStoredSeller(uid, targeType, shouldLevelBo);
// 3.触发卖家订单统计数据变更(卖家阶梯扣点)
EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder()
.setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addTag(InfluxdbTagEnum.TAG_TYPE, targeType.getCode() == EntrySellerType.COMMON.getCode() ? 2 : 3)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录 2代表普通入驻 3 代表超级卖家入驻
}
}
@Component
class CommonToPlusAuthorityChaneHandler extends AuthorityChaneHandler{
@Autowired
private MerchantOrderPaymentService merchantOrderPaymentService;
@Override
EntrySellerType getTargetSellerType() {
return EntrySellerType.SUPER_ENTRY;
}
@Override
boolean isMatchedScene(SellerWrapper sellerWrapper, long orderCode) {
StoredSeller storedSeller = sellerWrapper.getStoredSeller();
// 未入驻
if (Objects.isNull(storedSeller)){
return false;
}
// 普通入驻的状态
EntrySellerType entrySellerType = EntrySellerType.of(storedSeller.getEntryType());
return entrySellerType == EntrySellerType.COMMON
&& (Objects.nonNull(storedSeller) && storedSeller.getValidStatus().equals(StoredSellerStatusEnum.entered.getId()));
}
@Override
void handle(SellerWrapper sellerWrapper, long orderCode) {
int uid = sellerWrapper.getUid();
logger.info("CommonToPlusAuthorityChaneHandler uid {}, orderCode {}", uid, orderCode);
sellerEnterApplyService.passApply(uid, orderCode);
EntrySellerType targeType = EntrySellerType.SUPER_ENTRY;
SellerLevelFuncBo shouldLevelBo = levelChangeSupport.getShouldLevel(uid, targeType);
if (shouldLevelBo == null){
return;
}
storedSellerService.updateEnterSeller(uid, targeType, shouldLevelBo);
merchantOrderPaymentService.changeWalletToSuperSeller(uid); // 占有保证金释放
//触发卖家订单统计数据变更(卖家阶梯扣点)
EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder()
.setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addTag(InfluxdbTagEnum.TAG_TYPE, 1)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录 1 代表升级
}
}
@Component
class LevelChangeAuthorityChaneHandler extends AuthorityChaneHandler{
@Override
EntrySellerType getTargetSellerType() {
return null;
}
@Autowired
EntrySellerRechargeOrderMapper entrySellerRechargeOrderMapper;
@Override
public boolean isMatchedScene(SellerWrapper sellerWrapper, long orderCode) {
// 充值的场景
EntrySellerRechargeOrder entrySellerRechargeOrder = entrySellerRechargeOrderMapper.selectByOrderCodeUid(orderCode, sellerWrapper.getUid());
if (entrySellerRechargeOrder != null && entrySellerRechargeOrder.getType() == EntrySellerDepositType.RECHARGE.getType()){
return true;
}
return false;
}
@Autowired
EntrySellerWalletChangers entrySellerWalletChangers;
@Override
void handle(SellerWrapper sellerWrapper, long orderCode) {
logger.info("LevelChangeAuthorityChaneHandler uid {}, orderCode {}", sellerWrapper.getUid(), orderCode);
entrySellerWalletChangers.recharge(sellerWrapper.getUid());
}
}
}
... ...
... ... @@ -18,17 +18,14 @@ import com.yohobuy.ufo.model.order.vo.OrderGoodsInfo;
import com.yohobuy.ufo.model.order.vo.OrderGoodsListVo;
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.response.ProductDetailResp;
import com.yohobuy.ufo.model.response.StorageCheckResp;
import com.yohobuy.ufo.model.response.StorageInfoResp;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.StringUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.BillTradeStatus;
import com.yohoufo.order.common.TradeType;
import com.yohoufo.order.model.dto.*;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.service.IErpFastDeliveryService;
import com.yohoufo.order.service.handler.SellerDecrPriceTaskHandler;
import com.yohoufo.order.service.handler.SellerDownShelfTaskHandler;
... ... @@ -433,7 +430,7 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
// 3.检查批量上架权限
sellerWrapper = sellerWrapper.attachSellerLevelFunc((sw)->sellerFuncService.getSellerLevelFunc(sw));
sellerAuthCheckService.checkAuth(sellerWrapper.buildSellerBo(), null, SellerFuncEnum.BATCH_PUBLISH);
sellerAuthCheckService.checkAuth(sellerWrapper.sellerBo(), null, SellerFuncEnum.BATCH_PUBLISH);
// 4.检查货号&尺寸 --> storageId
Map<String, StorageCheckResp> storageMap = getCheckStorageMap(req);
... ... @@ -557,7 +554,7 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
public SellerWrapper checkFastDeliveryAuth(int uid){
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
if (!sellerBo.isFastDeliverySuper()){
logger.warn("checkFastDeliveryAuth not legal super, uid {} ", uid);
throw new UfoServiceException(501, "用户权限不合法!");
... ...
... ... @@ -1459,7 +1459,7 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
private boolean isHKLargeSettlementSuper(int uid) {
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
SellerBo sellerBo;
if (sellerWrapper != null && Objects.nonNull(sellerBo = sellerWrapper.buildSellerBo())) {
if (sellerWrapper != null && Objects.nonNull(sellerBo = sellerWrapper.sellerBo())) {
if (sellerBo.isLargeSettlementSuper()) {
return true;
}
... ...
... ... @@ -40,9 +40,6 @@ import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
import com.yohoufo.order.service.handler.SellerDecrPriceTaskHandler;
import com.yohoufo.order.service.handler.SellerDownShelfTaskHandler;
import com.yohoufo.order.service.handler.SellerIncrPriceTaskHandler;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
... ... @@ -51,7 +48,6 @@ import com.yohoufo.order.service.seller.SellerOrderCancelService;
import com.yohoufo.order.service.seller.SellerOrderServiceDelegate;
import com.yohoufo.order.service.seller.SkupBatchService;
import com.yohoufo.order.service.seller.processor.*;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.setting.SellerWrapper;
import com.yohoufo.order.service.seller.support.SellerOrderContextFactory;
import com.yohoufo.order.service.support.CouponSupport;
... ... @@ -280,7 +276,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
protectPublish(req);
int uid = req.getUid();
SellerWrapper sellerWrapper = sellerOrderServiceDelegate.getSellerService().getFullDimensionSeller(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
if (sellerBo.isLargeSettlementSuper()){
log.warn("publishPrd user is overseas ,uid {}", uid);
throw new UfoServiceException(400, "海外卖家暂时不支持出售");
... ... @@ -673,7 +669,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
}
skupDetailRKBs.add(CacheKeyBuilder.sellerOrderDetailKey(sog));
}
log.info("buildSellerBo detail cache group keys {}", keys);
log.info("sellerBo detail cache group keys {}", keys);
return skupDetailRKBs;
}
... ...
... ... @@ -32,6 +32,7 @@ import com.yohoufo.order.service.IStoredSellerDepositService;
import com.yohoufo.order.service.IStoredSellerService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.cache.StoredSellerCacheService;
import com.yohoufo.order.service.handler.SellerAuthorityChangeHandler;
import com.yohoufo.order.service.proxy.SellerNoticeFacade;
import com.yohoufo.order.service.seller.SkupService;
import com.yohoufo.order.service.seller.setting.SellerEnterApplyService;
... ... @@ -112,7 +113,7 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
if (uid==null||uid <= 0){
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
BigDecimal amount = getValidMoney(shoppingRequest.getAmount());
if (amount==null||amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new UfoServiceException(400, "金额不合法,预存金额必须大于0");
... ... @@ -159,9 +160,9 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
int num = entrySellerRechargeOrderMapper.insert(entrySellerRechargeOrder);
logger.info("enter StoredSellerDepositServiceImpl depositRecharge end save entrySellerRechargeOrder {} ,num {}",entrySellerRechargeOrder,num);
if (shoppingRequest.getAsSuper() == 1) {
markAsSuper(orderCode, uid, EntrySellerType.SUPER_ENTRY);
}
// if (shoppingRequest.getAsSuper() == 1) {
// markAsSuper(orderCode, uid, EntrySellerType.SUPER_ENTRY);
// }
// 返回结果
return OrderSubmitResponse.builder().orderCode(orderCode).paymentStatus(OrderConstant.N_STR).build();
... ... @@ -183,7 +184,7 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
if (amount==null||amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new UfoServiceException(400, "金额不合法,预存金额必须大于0");
}
if (!merchantOrderPaymentService.canRejoin(uid, null, null)) {
throw new UfoServiceException(400, "入驻次数已经达到上限!");
}
... ... @@ -230,17 +231,46 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
int num = entrySellerRechargeOrderMapper.insert(entrySellerRechargeOrder);
logger.info("enter StoredSellerDepositServiceImpl depositPreStore end save entrySellerRechargeOrder {} ,num {}",entrySellerRechargeOrder,num);
if (shoppingRequest.getAsSuper() == 1) {
markAsSuper(orderCode, uid, EntrySellerType.SUPER_ENTRY);
} else {
// if (shoppingRequest.getAsSuper() == 1) {
// markAsSuper(orderCode, uid, EntrySellerType.SUPER_ENTRY);
// } else {
markAsSuper(orderCode, uid, EntrySellerType.COMMON);
}
// }
// 返回结果
return OrderSubmitResponse.builder().orderCode(orderCode).paymentStatus(OrderConstant.N_STR).build();
}
@Autowired
SellerAuthorityChangeHandler sellerAuthorityChangeHandler;
/**
* 将普通入驻升级成入驻PLUS
* @param uid
*/
public void applyEntryPlush(int uid){
if (uid <= 0){
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
if(!storedSellerService.isStoredSeller(uid)){
throw new UfoServiceException(400,"该用户不是入驻商家,不可升级入驻PLUS!");
}
// 生成订单号
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE);
// 生成一条商家等级升级记录
markAsSuper(orderCode, uid, EntrySellerType.SUPER_ENTRY);
sellerAuthorityChangeHandler.changerAuthority(uid, orderCode);
}
private void markAsSuper(long orderCode, Integer uid, EntrySellerType sellerType) {
sellerEnterApplyService.applySuperEntry(uid, orderCode, sellerType);
}
... ... @@ -253,7 +283,7 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
public void quitStoredSellerAndReturnDeposit(Integer uid){
logger.info("StoredSellerServiceImpl quitStoredSeller enter uid is {} ",uid);
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
if (sellerBo.isLargeSettlementSuper()){
logger.warn("quitStoredSellerAndReturnDeposit user is overseas ,uid {}", uid);
throw new UfoServiceException(400, "海外卖家暂时不支持退出");
... ...
... ... @@ -159,7 +159,10 @@ public class TransferService {
SellerOrder sellerOrder = transferMoneyModel.getSellerOrder();
Integer targetUid = transferMoneyModel.getTargetUid();
boolean needUserApplyCash = ufoOrderPayConfigReader.transferNeedUserApplyCash();
// 更新钱包
penaltyEarnestIfWalletSellerOrder(request.getPenaltyEarnestFunction(), request.getSwdType(), sellerOrder);
// 创建转账单
TransferBill transferBill = transferMoneyModel.newTransferBill()
.withLogTag(logTag)
... ...
... ... @@ -11,6 +11,7 @@ import com.yoho.service.model.request.UserAddressReqBO;
import com.yoho.service.model.social.response.UserInfoRspBO;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.order.convert.AddressInfoConvertor;
... ... @@ -49,6 +50,9 @@ public class UserProxyService extends AbsProxyService{
private String uicUrl;
@Autowired
UfoServiceCaller ufoServiceCaller;
@Autowired
private IStoredSellerService storeSellerService;
/**
* 获取用户信息
... ... @@ -243,4 +247,6 @@ public class UserProxyService extends AbsProxyService{
}
return null;
}
}
... ...
... ... @@ -61,7 +61,7 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S
if (CollectionUtils.isNotEmpty(importPrds = req.getProductList())){
Integer uid = importPrds.get(0).getUid();
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
//check seller entry type
if (!checkSellerEntryType(sellerBo)){
logger.warn("in ImportPublishExcutor.publish not legal super, uid {} ", uid);
... ... @@ -117,7 +117,7 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S
SellerWrapper sellerWrapper = node.getSellerWrapper();
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder()
.sellerUid(uid)
.sellerBo(sellerWrapper.buildSellerBo())
.sellerBo(sellerWrapper.sellerBo())
.fjr(fjr).sellerWallet(null).build();
EventBusPublisher.publishEvent(bpte);
return fjr;
... ...
... ... @@ -92,7 +92,7 @@ public class NEGChangePricePublishProcessor
context.setSoldProduct(goodsInfo);
logger.info("in buildSellerBo not entry Seller Order Context , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
logger.info("in sellerBo not entry Seller Order Context , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
context.setSellerOrderComputeResult(computeResult);
... ...
... ... @@ -90,7 +90,7 @@ public class ImperfectPublishProcessor implements PublishProcessor<ImperfectOrde
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, salePrice, skupType);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
logger.warn("in buildSellerBo Seller imperfect OrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
logger.warn("in sellerBo Seller imperfect OrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
goodsInfo.setImageUrl(imperfectGoodsInfo.getGoodImg());
... ... @@ -99,7 +99,7 @@ public class ImperfectPublishProcessor implements PublishProcessor<ImperfectOrde
// compute every fee from price
SellerOrderComputeResult computeResult = icpNode.getComputeResult();
logger.info("in buildSellerBo Seller imperfect OrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
logger.info("in sellerBo Seller imperfect OrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
SellerBo sellerBo = icpNode.getSellerBo();
... ...
package com.yohoufo.order.service.seller.setting;
import com.yohobuy.ufo.model.order.bo.SellerLevelFuncBo;
import com.yohobuy.ufo.model.order.common.CommonEnterStageLevel;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.dal.order.SellerLevelFuncMapper;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.StoredSellerMapper;
import com.yohoufo.dal.order.model.SellerLevelFunc;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.dal.order.model.StoredSeller;
import com.yohoufo.order.constants.SellerConfig;
import com.yohoufo.order.service.impl.MetaConfigService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.SellerHelper;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Map;
@Component
public class AuthLevelChgeSupport {
@Autowired
private MetaConfigService metaConfigService;
@Autowired
private StoredSellerMapper storedSellerMapper;
@Autowired
private SellerWalletMapper sellerWalletMapper;
@Autowired
private SellerFuncService sellerFuncService;
@Autowired
private ProductProxyService productProxyService;
@Autowired
private SellerLevelFuncMapper sellerLevelFuncMapper;
private final Logger logger = LoggerUtils.getSellerOrderLogger();
public void processWithLevel(Integer currentLevel, Integer targetLevel, Integer uid){
logger.info("processWithLevel currentLevel {} targetLevel {} uid {}",currentLevel, targetLevel, uid);
if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == currentLevel ||
currentLevel== SuperEnterStageLevel.DISABLE.getCode()){
if(targetLevel == SuperEnterStageLevel.FULL.getCode()
||targetLevel == SuperEnterStageLevel.PARTITION.getCode()){
productProxyService.cancelHiddenGoods(uid);
}
}
if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == targetLevel
|| targetLevel == SuperEnterStageLevel.DISABLE.getCode()) {
if (currentLevel == SuperEnterStageLevel.FULL.getCode()
|| currentLevel == SuperEnterStageLevel.PARTITION.getCode()) {
productProxyService.hiddenGoods(uid);
}
}
}
/**
* 获取等级对应的界限值
* @param currentType
* @return
*/
public EntryThreshold getEntryThreshold(EntrySellerType currentType){
Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
return estMap.get(currentType);
}
/**
* 获取卖家(包括余额,当前功能等级)
* @param uid
* @return
*/
public SellerWrapper getSellerWrapper(int uid){
SellerWrapper sellerWrapper = new SellerWrapper(uid, logger)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.buildSellerWrapper()
.attachWallet(x->getLeftMoney(uid))
.buildSuperEnterStageLevel(sellerLevelFuncMapper::selectByPrimaryKey);
return sellerWrapper;
}
/**
* 获取余额
* @param uid
* @return
*/
public BigDecimal getLeftMoney(int uid){
SellerWallet sellerWallet = sellerWalletMapper.selectByUidAndType(uid, 1);
if (sellerWallet == null){
return new BigDecimal(0);
}
return sellerWallet.getAmount().add(sellerWallet.getLockAmount());
}
/**
* 获取某个用户目标等级能获取的功能
* key=变更前卖家的level, value=变更后卖家的level以及相关数据
* @param uid
* @param targetType
* @return
*/
public SellerLevelFuncBo getShouldLevel(int uid, EntrySellerType targetType){
//身份等级配置
Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
EntryThreshold threshold = estMap.get(targetType);
if (threshold == null){
return null;
}
// 根据余额判定 能达到当前等级的level
Pair<Integer, BigDecimal> levelAndTheshold = SellerHelper.getTypeLevelAndTheshold(threshold, getLeftMoney(uid));
Integer immediateLevel = levelAndTheshold.getKey();
// 入驻类型 + 余额计算出的level ==> 具体的功能-SellerLevelFunc
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetType.getCode(), immediateLevel);
// 获取level对应的界限值
slfb.setWalletThreshold(levelAndTheshold.getValue());
slfb.setLevel(immediateLevel);
return slfb;
}
}
... ...
package com.yohoufo.order.service.seller.setting;
import com.google.common.collect.Lists;
import com.yoho.core.config.ConfigReader;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.bo.SellerLevelFuncBo;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.UfoInfluxdbEvent;
import com.yohoufo.common.alarm.UfoInfluxdbVo;
import com.yohoufo.common.constant.InfluxdbFieldEnum;
import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
import com.yohoufo.order.common.EnterQuitEnum;
import com.yohoufo.order.event.SellerEnterTypeChangeEvent;
import com.yohoufo.order.service.IStoredSellerService;
import com.yohoufo.order.service.cache.StoredSellerCacheService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.MailSender;
import com.yohoufo.order.utils.MathUtils;
import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 以下场景导致的卖家的level发生变化
* 场景:
* 1.卖家钱包中的钱被划掉
* 2.充值成功
*/
@Component
public class EntrySellerWalletChangers implements ApplicationContextAware {
private static final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private AuthLevelChgeSupport levelChangeSupport;
private List<EntrySellerWalletChanger> changerList = Lists.newArrayList();
/**
* 钱包扣减
* @param uid
*/
public void deduct(int uid){
SellerWrapper sellerWrapper = levelChangeSupport.getSellerWrapper(uid);
EntrySellerType sellerType = EntrySellerType.of(sellerWrapper.getStoredSeller().getEntryType());
changerList.stream().filter(x->x.matchedEntrySellerType(sellerType)).findFirst().ifPresent(x->x.deduct(sellerWrapper));
}
/**
* 钱包充值
* @param uid
*/
public void recharge(int uid){
SellerWrapper sellerWrapper = levelChangeSupport.getSellerWrapper(uid);
EntrySellerType sellerType = EntrySellerType.of(sellerWrapper.getStoredSeller().getEntryType());
changerList.stream().filter(x->x.matchedEntrySellerType(sellerType)).findFirst().ifPresent(x->x.recharge(sellerWrapper));
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, EntrySellerWalletChanger> changerMap = applicationContext.getBeansOfType(EntrySellerWalletChanger.class);
changerList.addAll(changerMap.values());
}
private abstract class EntrySellerWalletChanger{
@Autowired
AuthLevelChgeSupport levelChangeSupport;
@Autowired
IStoredSellerService storedSellerService;
abstract boolean matchedEntrySellerType(EntrySellerType sellerType);
/**
* 获取当前卖家的卖家等级
* @param sellerWrapper
* @return
*/
EntrySellerType getCurrentSellerType(SellerWrapper sellerWrapper){
return EntrySellerType.of(sellerWrapper.getStoredSeller().getEntryType());
}
abstract void deduct(SellerWrapper sellerWrapper);
/**
* 充值场景
* @param sellerWrapper
*/
void recharge(SellerWrapper sellerWrapper){
int uid = sellerWrapper.getUid();
EntrySellerType sellerType = getCurrentSellerType(sellerWrapper);
// stored_seller中的level相关更新
SellerLevelFuncBo shouldLevelBo = levelChangeSupport.getShouldLevel(uid, sellerType);
if (shouldLevelBo == null){
return;
}
// level未发生变化
SuperEnterStageLevel stageLevel = sellerWrapper.sellerBo().getSuperEnterStageLevel();
if (shouldLevelBo.getLevel().equals(stageLevel.getCode())){
return;
}
storedSellerService.updateEnterSeller(uid, sellerType, shouldLevelBo);
levelChangeSupport.processWithLevel(stageLevel.getCode(),shouldLevelBo.getLevel(), sellerWrapper.getUid());
//触发卖家订单统计数据变更(卖家阶梯扣点)
EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
}
}
@Component
class FastDeliveryEntrySellerWalletChanger extends EntrySellerWalletChanger{
@Autowired
AuthLevelChgeSupport levelChangeSupport;
@Autowired
private InBoxFacade inBoxFacade;
@Autowired
private ProductProxyService productProxyService;
@Override
public boolean matchedEntrySellerType(EntrySellerType sellerType) {
return sellerType == EntrySellerType.FAST_DELIVERY_SUPER;
}
@Override
public void deduct(SellerWrapper sellerWrapper) {
logger.info("FastDeliveryEntrySellerWalletChanger uid {}", sellerWrapper.getUid());
EntrySellerType sellerType = getCurrentSellerType(sellerWrapper);
int uid = sellerWrapper.getUid();
SellerLevelFuncBo shouldLevelBo = levelChangeSupport.getShouldLevel(sellerWrapper.getUid(), sellerType);
if (shouldLevelBo == null){
return;
}
// 入驻类型 对应的功能界限值
EntryThreshold entryThreshold = levelChangeSupport.getEntryThreshold(sellerType);
BigDecimal leftMoney = sellerWrapper.getLeftInWallet();
if(leftMoney.compareTo(entryThreshold.getHiddenGoodsAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, entryThreshold.getHiddenGoodsAmount());
// 隐藏商品
productProxyService.hiddenGoods(uid);
}else if(leftMoney.compareTo(entryThreshold.getGoodsOnOffShelveAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, entryThreshold.getGoodsOnOffShelveAmount());
}else if (leftMoney.compareTo(entryThreshold.getPrepaymentAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, entryThreshold.getPrepaymentAmount());
}
}
}
@Component
class EntryPlusEntrySellerWalletChanger extends EntrySellerWalletChanger{
@Autowired
AuthLevelChgeSupport levelChangeSupport;
@Autowired
private IStoredSellerService storedSellerService;
@Autowired
private InBoxFacade inBoxFacade;
@Override
public boolean matchedEntrySellerType(EntrySellerType sellerType) {
return sellerType == EntrySellerType.SUPER_ENTRY;
}
@Override
public void deduct(SellerWrapper sellerWrapper) {
logger.info("EntryPlusEntrySellerWalletChanger uid {}", sellerWrapper.getUid());
EntrySellerType sellerType = getCurrentSellerType(sellerWrapper);
SellerLevelFuncBo shouldLevelBo = levelChangeSupport.getShouldLevel(sellerWrapper.getUid(), sellerType);
if (shouldLevelBo == null){
return;
}
// level未发生变化
SuperEnterStageLevel stageLevel = sellerWrapper.sellerBo().getSuperEnterStageLevel();
if (shouldLevelBo.getLevel().equals(stageLevel.getCode())){
return;
}
storedSellerService.updateEnterSeller(sellerWrapper.getUid(), sellerType, shouldLevelBo);
levelChangeSupport.processWithLevel(stageLevel.getCode(), shouldLevelBo.getLevel(), sellerWrapper.getUid() );
SuperEnterStageLevel targetSESL = SuperEnterStageLevel.of(shouldLevelBo.getLevel());
inBoxFacade.noticeSuperSellerDegrade(sellerWrapper.getUid(), targetSESL, shouldLevelBo.getWalletThreshold());
}
}
@Component
class LargeSettlementEntrySellerWalletChanger extends EntrySellerWalletChanger{
@Autowired
private StoredSellerCacheService storedSellerCacheService;
@Autowired
private ConfigReader configReader;
@Autowired
private InBoxFacade inBoxFacade;
@Autowired
private IStoredSellerService storedSellerService;
@Override
public boolean matchedEntrySellerType(EntrySellerType sellerType) {
return sellerType == EntrySellerType.LARGE_SETTLEMENT;
}
@Override
public void deduct(SellerWrapper sellerWrapper) {
logger.info("LargeSettlementEntrySellerWalletChanger uid {}", sellerWrapper.getUid());
EntrySellerType sellerType = EntrySellerType.LARGE_SETTLEMENT;;
SellerLevelFuncBo shouldLevelBo = levelChangeSupport.getShouldLevel(sellerWrapper.getUid(), sellerType);
if (shouldLevelBo == null){
return;
}
BigDecimal left = sellerWrapper.getLeftInWallet();
noticeLargeSettlementSuper(shouldLevelBo, sellerWrapper.sellerBo(), left);
int uid = sellerWrapper.getUid();
//hidden sale product
boolean needHiddenPrds = shouldLevelBo.getLevel() == SuperEnterStageLevel.DISABLE.getCode()
&& shouldLevelBo.getWalletThreshold().compareTo(left) > 0;
boolean cancelHidden = shouldLevelBo.getLevel() != SuperEnterStageLevel.DISABLE.getCode()
&& BigDecimal.ZERO.compareTo(left) < 0;
if (needHiddenPrds || cancelHidden){
storedSellerService.updateEnterSeller(sellerWrapper.getUid(), sellerType, shouldLevelBo);
SuperEnterStageLevel stageLevel = sellerWrapper.sellerBo().getSuperEnterStageLevel();
levelChangeSupport.processWithLevel(stageLevel.getCode(),shouldLevelBo.getLevel(), sellerWrapper.getUid() );
if (needHiddenPrds) {
SuperEnterStageLevel targetSESL = SuperEnterStageLevel.of(shouldLevelBo.getLevel());
inBoxFacade.noticeSuperSellerDegrade(uid, targetSESL, shouldLevelBo.getWalletThreshold());
}
}
}
// move code from sellerEntryApplyService
private void noticeLargeSettlementSuper(SellerLevelFuncBo bslfb, SellerBo sellerBo, BigDecimal left){
int uid = sellerBo.getUid();
Integer noticeCnt = null ;
SuperEnterStageLevel sesl = SuperEnterStageLevel.of(bslfb.getLevel());
boolean walletNotEnough = (sesl != null && bslfb.getWalletThreshold().compareTo(left) > 0 );
boolean notNotice = (Objects.isNull(noticeCnt= storedSellerCacheService.getNoticeCntWhenWalletNotEnough(uid, bslfb.getLevel())) || noticeCnt<1);
if (notNotice && walletNotEnough){
String thresholdStr = MathUtils.formatCurrencyStr(bslfb.getWalletThreshold().doubleValue());
try {
String mailTo = configReader.getString("ufo.order.seller.noticeHKSellerEmailTo", "chao.chen@yoho.cn,xiuchun.luo@yoho.cn");
String content = String.format(getNoticeContent(sesl), thresholdStr);
logger.info("in processLargeSettlementSuperWhenWalletChange ready 2 send mail uid {} sellerBo {} noticeCnt {} mailTo {} content {}",
uid, sellerBo, noticeCnt, mailTo, content);
MailSender.newMailSender()
.subject("卖家服务提醒")
.to(mailTo)
.body(content, "text/html;charset=utf-8")
.send();
storedSellerCacheService.setNoticeCntWhenWalletNotEnough(uid, bslfb.getLevel(), 1);
}catch (Exception ex){
logger.warn("processLargeSettlementSuperWhenWalletChange send mail fail, uid {} left wallet {}", uid, left, ex);
}
inBoxFacade.noticeLargeSettlementSuperDegrade(uid, sesl, thresholdStr,left );
}
logger.info("in processLargeSettlementSuperWhenWalletChange uid {} sellerBo {} noticeCnt {}",
uid, sellerBo, noticeCnt);
}
// move code from sellerEntryApplyService
private String getNoticeContent(SuperEnterStageLevel sesl){
String content;
switch (sesl){
case FULL:
content = "【UFO飞碟好物】您的账户保证金余额不足%s,为了不影响您的超级商家权限,请及时充值。";
break;
case PARTITION:
content = "【UFO飞碟好物】您的账户保证金余额不足%s,商品将不能正常上架,为了不影响您的超级商家权限,请及时充值。";
break;
case DISABLE:
content = "【UFO飞碟好物】您的账户保证金余额不足%s,平台将隐藏您所有出售中的商品,为了不影响您的超级商家权限,请及时充值";
break;
default:
content= null;
}
return content;
}
}
}
... ...
... ... @@ -31,8 +31,6 @@ import com.yohoufo.order.service.impl.MetaConfigService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.MailSender;
import com.yohoufo.order.utils.MathUtils;
import com.yohoufo.order.utils.SellerHelper;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -43,7 +41,6 @@ import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
/**
* Created by chao.chen on 2019/1/14.
... ... @@ -56,38 +53,38 @@ public class SellerEnterApplyService {
@Autowired
private SellerEnterApplyMapper sellerEnterApplyMapper;
@Autowired
private MetaConfigService metaConfigService;
// @Autowired
// private MetaConfigService metaConfigService;
@Autowired
private IStoredSellerService storedSellerService;
// @Autowired
// private IStoredSellerService storedSellerService;
@Autowired
private SellerFuncService sellerFuncService;
// @Autowired
// private SellerFuncService sellerFuncService;
@Autowired
private StoredSellerMapper storedSellerMapper;
@Autowired
private SellerService sellerService;
// @Autowired
// private SellerService sellerService;
@Autowired
private SellerLevelFuncMapper sellerLevelFuncMapper;
// @Autowired
// private SellerLevelFuncMapper sellerLevelFuncMapper;
@Autowired
private ProductProxyService productProxyService;
// @Autowired
// private ProductProxyService productProxyService;
@Autowired
private InBoxFacade inBoxFacade;
// @Autowired
// private InBoxFacade inBoxFacade;
@Autowired
private MerchantOrderPaymentService merchantOrderPaymentService;
// @Autowired
// private MerchantOrderPaymentService merchantOrderPaymentService;
@Autowired
private ConfigReader configReader;
// @Autowired
// private ConfigReader configReader;
@Autowired
private StoredSellerCacheService storedSellerCacheService;
// @Autowired
// private StoredSellerCacheService storedSellerCacheService;
/**
* 申请成为超级卖家
... ... @@ -115,10 +112,9 @@ public class SellerEnterApplyService {
}
SellerWrapper sellerWrapper = new SellerWrapper(uid,logger)
.addSpecialSuperFunc(sellerService::isSpecialSuper)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.buildSellerWrapper();
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
EntrySellerType currentEST = sellerBo.getEntrySellerType();
//当前身份和目标身份一致
... ... @@ -183,442 +179,33 @@ public class SellerEnterApplyService {
}
}
/**
*
* @param uid
* @param orderCode
* @param left
*/
public void audit(int uid, Long orderCode, BigDecimal left){
logger.info("in auditPass uid {} orderCode {} left {}", uid, orderCode, left);
//
SellerEnterApply seac = new SellerEnterApply();
seac.setUid(uid);
seac.setOrderCode(orderCode);
List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(seac);
if (seaList.size() > 1) {
logger.warn("in audit one orderCode mapped multiple apply,uid {} orderCode {}", uid, orderCode);
}
SellerEnterApply msea = seaList.get(0);
doAudit(uid, orderCode, left, msea);
}
private void doAudit(int uid, Long orderCode, BigDecimal left, SellerEnterApply msea){
//卖家包装类
SellerWrapper sellerWrapper = new SellerWrapper(uid,logger)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.addSpecialSuperFunc(sellerService::isSpecialSuper)
.buildSellerWrapper();
upgradeLevel(sellerWrapper, orderCode, left, msea);
}
public void upgradeLevel(SellerWrapper sellerWrapper,
Long orderCode, BigDecimal left,
SellerEnterApply msea){
int uid = sellerWrapper.getUid();
//是否有申请记录
//有两种:
// 1. 充值有订单号,根据订单号查询,
// 1.1 升级时充值有申请记录
// 1.2 普通充值没有申请记录
// 2. client 直接升级,根据请求的目标身份
//existApply 为false 只会是普通充值订单
boolean existApply = Objects.nonNull(msea);
logger.info("in upgradeLevel uid {} orderCode {} left wallet {} existApply {}",
uid, orderCode, left, existApply );
if (existApply){
processApplyOrder(sellerWrapper, left, orderCode, msea);
}else {
processCommonChargeOrder(sellerWrapper, orderCode);
}
}
/**
* 当卖家钱包余额充足时,直接升级
* @param sellerWrapper
* @param orderCode
* @param targetEST
*/
public void upgradeLevelIfFatWallet(SellerWrapper sellerWrapper, Long orderCode,
EntrySellerType targetEST){
Integer uid = sellerWrapper.getUid();
BigDecimal leftInWallet = sellerWrapper.getLeftInWallet();
SellerEnterApply sea = this.applySuperEntry(uid, orderCode, targetEST);
this.upgradeLevel(sellerWrapper, orderCode, leftInWallet, sea);
}
/**
* 充值订单处理
* @param sellerWrapper
* @param left
* @param orderCode
* @param msea
*/
private void processApplyOrder(SellerWrapper sellerWrapper,BigDecimal left,
Long orderCode, SellerEnterApply msea){
int uid = sellerWrapper.getUid();
//持久化的入驻信息
StoredSeller pss = sellerWrapper.getStoredSeller();
boolean noStoredSeller = Objects.isNull(pss) || pss.getValidStatus().equals(StoredSellerStatusEnum.quit.getId());
SellerBo sellerBo = sellerWrapper.buildSellerBo();
//当前身份
EntrySellerType currentEST = sellerBo.getEntrySellerType();
Integer currentEnterType = currentEST.getCode();
//身份等级配置
Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
//目标身份
EntrySellerType targetEst = EntrySellerType.getEntrySellerType(msea.getEnterType());
//申请是否已经通过
boolean isPassedApply = Objects.equals(SellerEnterApplyStatus.PASS.getCode(), msea.getStatus());
//目标身份对应的等级
Integer level = SellerHelper.getType2Level(targetEst, estMap, left);
//当前身份和申请时身份是否一致
Integer preEnterType;
boolean isMatchedET = Objects.equals(preEnterType=msea.getPreEnterType(), currentEnterType);
logger.info("in upgradeLevel ready pass apply and add StoredSeller, uid {} orderCode {} currentEnterType {} PreEnterType {} noStoredSeller {} target Level {} isMatchedET {}",
uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
if(Objects.equals(currentEnterType, EntrySellerType.NOT_ENTRY.getCode())){
//普通卖家 -> 普通入驻 ,1. apply 状态 ,2. enter_seller 从无到有
//普通卖家 -> 超级 ,1. apply 状态 ,2. enter_seller 从无到有
if (!isPassedApply){
passApply(msea);
}
if (noStoredSeller && isMatchedET){
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
storedSellerService.addUserAsStoredSeller(uid, targetEst, slfb);
//触发卖家订单统计数据变更(卖家阶梯扣点)
EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder()
.setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addTag(InfluxdbTagEnum.TAG_TYPE, targetEst.getCode() == EntrySellerType.COMMON.getCode() ? 2 : 3)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录 2代表普通入驻 3 代表超级卖家入驻
}else{
logger.warn("in upgradeLevel add StoredSeller fail, uid {} orderCode {}",
uid, orderCode);
}
}else if (Objects.equals(currentEnterType, EntrySellerType.COMMON.getCode())) {
//普通入驻 -> 超级 ,1. apply 状态 ,2. enter_seller 修改type & func list
passApply(msea);
//
if (!noStoredSeller && isMatchedET){
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
storedSellerService.updateEnterSeller(uid, targetEst, slfb);
//触发卖家订单统计数据变更(卖家阶梯扣点)
EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
if (EntrySellerType.SUPER_ENTRY.equals(targetEst)){
logger.info("in upgradeLevel ready pass apply then changeWalletToSuperSeller, uid {} orderCode {} currentEnterType {} PreEnterType {} noStoredSeller {} target Level {} isMatchedET {}",
uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
merchantOrderPaymentService.changeWalletToSuperSeller(uid);
}
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder()
.setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addTag(InfluxdbTagEnum.TAG_TYPE, 1)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录 1 代表升级
}else{
logger.warn("in upgradeLevel update StoredSeller fail, uid {} orderCode {}",
uid, orderCode);
}
}else if (Objects.equals(currentEnterType, EntrySellerType.SPECIAL_SUPER.getCode())){
//白名单超级卖家
logger.warn("in upgradeLevel SPECIAL_SUPER by charge, uid {} orderCode {}",
uid, orderCode);
/*
if (!isPassedApply){
passApply(msea);
}
if (!noStoredSeller && isMatchedET){
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
storedSellerService.updateEnterSeller(uid, targetEst, slfb);
if (EntrySellerType.SUPER_ENTRY.equals(targetEst)){
logger.info("in upgradeLevel ready pass apply then changeWalletToSuperSeller, uid {} orderCode {} currentEnterType {} PreEnterType {} noStoredSeller {} target Level {} isMatchedET {}",
uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
merchantOrderPaymentService.changeWalletToSuperSeller(uid);
//移除 白名单
storedSellerService.disableSpecialSuper(uid);
}
}else{
logger.warn("in upgradeLevel update StoredSeller fail, uid {} orderCode {}",
uid, orderCode);
}*/
}else if (Objects.equals(currentEnterType, EntrySellerType.SUPER_ENTRY.getCode())){
//超级卖家
upgradeSuperLevel(sellerWrapper, level, orderCode, targetEst, isMatchedET);
}
}
/**
* 普通充值订单处理
* @param sellerWrapper
* @param orderCode
*/
private void processCommonChargeOrder(SellerWrapper sellerWrapper,
Long orderCode){
int uid = sellerWrapper.getUid();
SellerBo sellerBo = sellerWrapper.buildSellerBo();
//当前身份
EntrySellerType currentEST = sellerBo.getEntrySellerType();
Integer currentEnterType = currentEST.getCode();
logger.warn("in upgradeLevel no record so that it's only common charge order, uid {} orderCode {}",
uid, orderCode);
if(Objects.equals(currentEnterType, EntrySellerType.NOT_ENTRY.getCode())){
//普通卖家 no way
logger.warn("in upgradeLevel no need any action, uid {} orderCode {} currentEnterType {}",
uid, orderCode, currentEnterType);
}else if (Objects.equals(currentEnterType, EntrySellerType.COMMON.getCode())) {
//普通入驻 -> 超级 ,1. apply 状态 ,2. enter_seller 修改type & func list
logger.warn("in upgradeLevel no need any action, uid {} orderCode {} currentEnterType {}",
uid, orderCode, currentEnterType);
}else if (Objects.equals(currentEnterType, EntrySellerType.SPECIAL_SUPER.getCode())){
//白名单超级卖家
logger.warn("in upgradeLevel no need any action, uid {} orderCode {} currentEnterType {}",
uid, orderCode, currentEnterType);
}else if (Objects.equals(currentEnterType, EntrySellerType.SUPER_ENTRY.getCode())){
//持久化的入驻信息
StoredSeller pss = sellerWrapper.getStoredSeller();
boolean isValid = Objects.equals(pss.getValidStatus(), StoredSellerStatusEnum.entered.getId());
if (isValid) {//身份等级配置
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFuncWithWallet(sellerWrapper);
//超级卖家
upgradeSuperLevel(sellerWrapper, slfb.getLevel(), orderCode, currentEST, true);
}
}
}
private int upgradeSuperLevel(SellerWrapper sellerWrapper,Integer level, Long orderCode,
EntrySellerType targetEst, boolean isMatchedET){
Integer uid = sellerWrapper.getUid();
logger.info("in upgradeSuperLevel uid {} orderCode {}", uid, orderCode);
sellerWrapper.buildSuperEnterStageLevel(sellerLevelFuncMapper::selectByPrimaryKey);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SuperEnterStageLevel sesl = sellerBo.getSuperEnterStageLevel();
Integer currentLevel = null;
boolean levelNeedUpgrade = Objects.nonNull(sesl)
&& Objects.nonNull(currentLevel = sesl.getCode())
&& !currentLevel.equals(level);
StoredSeller pss = sellerWrapper.getStoredSeller();
boolean noStoredSeller = Objects.isNull(pss);
logger.warn("in upgradeSuperLevel update StoredSeller, uid {} orderCode {} currentLevel {} target level {}",
uid, orderCode, currentLevel, level);
int result = 0;
if (!noStoredSeller && isMatchedET && levelNeedUpgrade) {
doUpgradeSuper(targetEst, currentLevel, level, uid);
//触发卖家订单统计数据变更(卖家阶梯扣点)
EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
}
return result;
}
private int doUpgradeSuper(EntrySellerType targetEst,Integer currentLevel, Integer level, Integer uid){
logger.info("doUpgradeSuper uid {} targetEst {} currentLevel {} target level {}",
uid, targetEst, currentLevel, level);
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
int result = storedSellerService.updateEnterSeller(uid, targetEst, slfb);
processWithLevel(currentLevel, level, uid);
return result;
}
private void processWithLevel(Integer currentLevel, Integer targetLevel, Integer uid){
logger.info("processWithLevel currentLevel {} targetLevel {} uid {}",currentLevel, targetLevel, uid);
if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == currentLevel ||
currentLevel== SuperEnterStageLevel.DISABLE.getCode()){
if(targetLevel == SuperEnterStageLevel.FULL.getCode()
||targetLevel == SuperEnterStageLevel.PARTITION.getCode()){
productProxyService.cancelHiddenGoods(uid);
}
}
if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == targetLevel
|| targetLevel == SuperEnterStageLevel.DISABLE.getCode()) {
if (currentLevel == SuperEnterStageLevel.FULL.getCode()
|| currentLevel == SuperEnterStageLevel.PARTITION.getCode()) {
productProxyService.hiddenGoods(uid);
}
}
}
/**
* 超级卖家钱包金额变化时触发降级动作
*
* @param sellerWrapper
* @param left
* @return
*/
public int changeLevel4Super(SellerWrapper sellerWrapper, BigDecimal left){
int uid = sellerWrapper.getUid();
//持久化的入驻信息
SellerBo sellerBo = sellerWrapper.buildSellerBo();
//当前身份
EntrySellerType currentEST = sellerBo.getEntrySellerType();
Integer currentEnterType = currentEST.getCode();
//身份等级配置
Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
EntryThreshold set = estMap.get(currentEST);
Supplier<SellerLevelFuncBo> slfSupplier = () ->SellerHelper.getSellerLevelFunc(currentEST, set, left);
//目标身份对应的等级
logger.info("in changeLevel4Super ready change StoredSeller targetFuncLevel func, uid {} currentEnterType {}, {}",
uid, currentEnterType, left);
// 扣保证金 极速卖家场景-触发阀值场景
if (sellerBo.isFastDeliverySuper()){
if(left.compareTo(set.getHiddenGoodsAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, set.getHiddenGoodsAmount());
// 隐藏商品
productProxyService.hiddenGoods(uid);
}else if(left.compareTo(set.getGoodsOnOffShelveAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, set.getGoodsOnOffShelveAmount());
}else if (left.compareTo(set.getPrepaymentAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, set.getPrepaymentAmount());
}
return 0;
}
int result = 0;
if (sellerBo.isNormalSuper()) {
SellerLevelFuncBo bslfb = slfSupplier.get();
Integer targetFuncLevel = bslfb.getLevel();
//
EntryLevelNode eln = buildEntryLevelNode(sellerWrapper, bslfb);
Integer currentLevel = eln.currentLevel;
boolean levelNeedUpgrade = eln.needUpgrade;
StoredSeller pss = sellerWrapper.getStoredSeller();
boolean isValid = Objects.equals(pss.getValidStatus(), StoredSellerStatusEnum.entered.getId());
logger.info("in changeLevel4Super update StoredSeller, uid {} currentLevel {} target targetFuncLevel {} levelNeedUpgrade {} isValid {}",
uid, currentLevel, targetFuncLevel, levelNeedUpgrade, isValid);
doUpgradeSuper(currentEST, currentLevel, targetFuncLevel, uid);
SuperEnterStageLevel targetSESL = SuperEnterStageLevel.getSuperEnterStageLevel(targetFuncLevel);
inBoxFacade.noticeSuperSellerDegrade(uid, targetSESL, bslfb.getWalletThreshold());
}
if (sellerBo.isLargeSettlementSuper() ){
processLargeSettlementSuperWhenWalletChange(sellerWrapper, left, slfSupplier);
private SellerEnterApply update(SellerEnterApply msea){
Integer id = msea.getId();
SellerEnterApply wpOfSea = new SellerEnterApply();
wpOfSea.setId(id);
Integer cdt = DateUtil.getCurrentTimeSecond();
wpOfSea.setUpdateTime(cdt);
if(sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea) > 0){
msea.setUpdateTime(cdt);
}
return result;
}
static class EntryLevelNode{
Integer currentLevel;
Integer targetLevel;
boolean needUpgrade;
}
private EntryLevelNode buildEntryLevelNode(SellerWrapper sellerWrapper, SellerLevelFuncBo bslfb){
Integer targetFuncLevel = bslfb.getLevel();
//
sellerWrapper.buildSuperEnterStageLevel(sellerLevelFuncMapper::selectByPrimaryKey);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SuperEnterStageLevel sesl = sellerBo.getSuperEnterStageLevel();
Integer currentLevel = null;
boolean levelNeedUpgrade = Objects.nonNull(sesl)
&& Objects.nonNull(currentLevel = sesl.getCode())
&& !currentLevel.equals(targetFuncLevel);
EntryLevelNode eln = new EntryLevelNode();
eln.currentLevel = currentLevel;
eln.targetLevel = targetFuncLevel;
eln.needUpgrade = levelNeedUpgrade;
return eln;
}
private EntryLevelNode buildEntryLevelNode(SellerWrapper sellerWrapper, Supplier<SellerLevelFuncBo> slfbSupplier){
SellerLevelFuncBo bslfb = slfbSupplier.get();
return buildEntryLevelNode(sellerWrapper, bslfb);
return msea;
}
private String getNoticeContent(SuperEnterStageLevel sesl){
String content;
switch (sesl){
case FULL:
content = "【UFO飞碟好物】您的账户保证金余额不足%s,为了不影响您的超级商家权限,请及时充值。";
break;
case PARTITION:
content = "【UFO飞碟好物】您的账户保证金余额不足%s,商品将不能正常上架,为了不影响您的超级商家权限,请及时充值。";
break;
case DISABLE:
content = "【UFO飞碟好物】您的账户保证金余额不足%s,平台将隐藏您所有出售中的商品,为了不影响您的超级商家权限,请及时充值";
break;
default:
content= null;
}
return content;
}
private void noticeLargeSettlementSuper(SellerLevelFuncBo bslfb, SellerBo sellerBo, BigDecimal left){
int uid = sellerBo.getUid();
Integer noticeCnt = null ;
SuperEnterStageLevel sesl = SuperEnterStageLevel.getSuperEnterStageLevel(bslfb.getLevel());
boolean walletNotEnough = (sesl != null && bslfb.getWalletThreshold().compareTo(left) > 0 );
boolean notNotice = (Objects.isNull(noticeCnt= storedSellerCacheService.getNoticeCntWhenWalletNotEnough(uid, bslfb.getLevel())) || noticeCnt<1);
if (notNotice && walletNotEnough){
String thresholdStr = MathUtils.formatCurrencyStr(bslfb.getWalletThreshold().doubleValue());
try {
String mailTo = configReader.getString("ufo.order.seller.noticeHKSellerEmailTo", "chao.chen@yoho.cn,xiuchun.luo@yoho.cn");
String content = String.format(getNoticeContent(sesl), thresholdStr);
logger.info("in processLargeSettlementSuperWhenWalletChange ready 2 send mail uid {} sellerBo {} noticeCnt {} mailTo {} content {}",
uid, sellerBo, noticeCnt, mailTo, content);
MailSender.newMailSender()
.subject("卖家服务提醒")
.to(mailTo)
.body(content, "text/html;charset=utf-8")
.send();
storedSellerCacheService.setNoticeCntWhenWalletNotEnough(uid, bslfb.getLevel(), 1);
}catch (Exception ex){
logger.warn("processLargeSettlementSuperWhenWalletChange send mail fail, uid {} left wallet {}", uid, left, ex);
}
inBoxFacade.noticeLargeSettlementSuperDegrade(uid, sesl, thresholdStr,left );
}
logger.info("in processLargeSettlementSuperWhenWalletChange uid {} sellerBo {} noticeCnt {}",
uid, sellerBo, noticeCnt);
private SellerEnterApply add(int uid, Long orderCode, EntrySellerType currentEST, EntrySellerType targetEST){
SellerEnterApply wpOfSea = new SellerEnterApply();
wpOfSea.setUid(uid);
wpOfSea.setOrderCode(orderCode);
wpOfSea.setPreEnterType(currentEST.getCode());
wpOfSea.setEnterType(targetEST.getCode());
Integer cdt = DateUtil.getCurrentTimeSecond();
wpOfSea.setCreateTime(cdt);
wpOfSea.setUpdateTime(cdt);
wpOfSea.setStatus(SellerEnterApplyStatus.WAITING_AUDIT.getCode());
sellerEnterApplyMapper.insertSelective(wpOfSea);
return wpOfSea;
}
private void processLargeSettlementSuperWhenWalletChange(SellerWrapper sellerWrapper, BigDecimal left,Supplier<SellerLevelFuncBo> slfSupplier){
SellerBo sellerBo = sellerWrapper.buildSellerBo();
if (sellerBo.isLargeSettlementSuper() ){
SellerLevelFuncBo bslfb = slfSupplier.get();
int uid = sellerBo.getUid();
noticeLargeSettlementSuper(bslfb, sellerBo, left);
//hidden sale product
boolean needHiddenPrds = bslfb.getLevel() == SuperEnterStageLevel.DISABLE.getCode()
&& bslfb.getWalletThreshold().compareTo(left) > 0;
boolean cancelHidden = bslfb.getLevel() != SuperEnterStageLevel.DISABLE.getCode()
&& BigDecimal.ZERO.compareTo(left) < 0;
logger.info("in processLargeSettlementSuperWhenWalletChange uid {} sellerBo {} needHiddenPrds {} cancelHidden {}",
uid, sellerBo, needHiddenPrds, cancelHidden);
EntrySellerType currentEST = sellerBo.getEntrySellerType();
if (needHiddenPrds || cancelHidden){
EntryLevelNode eln = buildEntryLevelNode(sellerWrapper, bslfb);
doUpgradeSuper(currentEST, eln.currentLevel, eln.targetLevel, uid);
if (needHiddenPrds) {
SuperEnterStageLevel targetSESL = SuperEnterStageLevel.getSuperEnterStageLevel(eln.targetLevel);
inBoxFacade.noticeSuperSellerDegrade(uid, targetSESL, bslfb.getWalletThreshold());
}
}
}
}
/**
... ... @@ -655,47 +242,492 @@ public class SellerEnterApplyService {
}
/**
* 获取申请入驻的记录
* @param uid
* @param orderCode
* @return
*/
public SellerEnterApply getSellerEntryApply(int uid, long orderCode){
SellerEnterApply seac = new SellerEnterApply();
seac.setUid(uid);
seac.setOrderCode(orderCode);
List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(seac);
public int passApply(SellerEnterApply sea){
if (Objects.equals(SellerEnterApplyStatus.PASS.getCode(), sea.getStatus())){
logger.info("passApply apply was passed, sea {}", sea);
return 0;
if (CollectionUtils.isEmpty(seaList)){
return null;
}
SellerEnterApply wpOfSea = new SellerEnterApply();
wpOfSea.setId(sea.getId());
Integer cdt = DateUtil.getCurrentTimeSecond();
wpOfSea.setUpdateTime(cdt);
wpOfSea.setStatus(SellerEnterApplyStatus.PASS.getCode());
return sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea);
}
private SellerEnterApply update(SellerEnterApply msea){
Integer id = msea.getId();
SellerEnterApply wpOfSea = new SellerEnterApply();
wpOfSea.setId(id);
Integer cdt = DateUtil.getCurrentTimeSecond();
wpOfSea.setUpdateTime(cdt);
if(sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea) > 0){
msea.setUpdateTime(cdt);
}
return msea;
return seaList.get(0);
}
private SellerEnterApply add(int uid, Long orderCode, EntrySellerType currentEST, EntrySellerType targetEST){
SellerEnterApply wpOfSea = new SellerEnterApply();
wpOfSea.setUid(uid);
wpOfSea.setOrderCode(orderCode);
wpOfSea.setPreEnterType(currentEST.getCode());
wpOfSea.setEnterType(targetEST.getCode());
Integer cdt = DateUtil.getCurrentTimeSecond();
wpOfSea.setCreateTime(cdt);
wpOfSea.setUpdateTime(cdt);
wpOfSea.setStatus(SellerEnterApplyStatus.WAITING_AUDIT.getCode());
sellerEnterApplyMapper.insertSelective(wpOfSea);
return wpOfSea;
public int passApply(int uid, long orderCode){
SellerEnterApply sellerEnterApply = new SellerEnterApply();
sellerEnterApply.setUid(uid);
sellerEnterApply.setOrderCode(orderCode);
sellerEnterApply.setStatus(SellerEnterApplyStatus.PASS.getCode());
Integer now = DateUtil.getCurrentTimeSecond();
sellerEnterApply.setUpdateTime(now);
return sellerEnterApplyMapper.updateStatusByUidOrderCode(sellerEnterApply);
}
// public int passApply(SellerEnterApply sea){
// if (Objects.equals(SellerEnterApplyStatus.PASS.getCode(), sea.getStatus())){
// logger.info("passApply apply was passed, sea {}", sea);
// return 0;
// }
// SellerEnterApply wpOfSea = new SellerEnterApply();
// wpOfSea.setId(sea.getId());
// Integer cdt = DateUtil.getCurrentTimeSecond();
// wpOfSea.setUpdateTime(cdt);
// wpOfSea.setStatus(SellerEnterApplyStatus.PASS.getCode());
// return sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea);
// }
/**
*
* @param uid
* @param orderCode
* @param left
*/
// public void audit(int uid, Long orderCode, BigDecimal left){
// logger.info("in auditPass uid {} orderCode {} left {}", uid, orderCode, left);
// //
// SellerEnterApply seac = new SellerEnterApply();
// seac.setUid(uid);
// seac.setOrderCode(orderCode);
// List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(seac);
// if (seaList.size() > 1) {
// logger.warn("in audit one orderCode mapped multiple apply,uid {} orderCode {}", uid, orderCode);
// }
// SellerEnterApply msea = seaList.get(0);
// doAudit(uid, orderCode, left, msea);
// }
// private void doAudit(int uid, Long orderCode, BigDecimal left, SellerEnterApply msea){
//
// //卖家包装类
// SellerWrapper sellerWrapper = new SellerWrapper(uid,logger)
// .storedSellerDataSource(storedSellerMapper::selectByUid)
// .buildSellerWrapper();
// upgradeLevel(sellerWrapper, orderCode, left, msea);
// }
// public void upgradeLevel(SellerWrapper sellerWrapper,
// Long orderCode, BigDecimal left,
// SellerEnterApply msea){
// int uid = sellerWrapper.getUid();
// //是否有申请记录
// //有两种:
// // 1. 充值有订单号,根据订单号查询,
// // 1.1 升级时充值有申请记录
// // 1.2 普通充值没有申请记录
// // 2. client 直接升级,根据请求的目标身份
// //existApply 为false 只会是普通充值订单
// boolean existApply = Objects.nonNull(msea);
// logger.info("in upgradeLevel uid {} orderCode {} left wallet {} existApply {}",
// uid, orderCode, left, existApply );
// if (existApply){
// processApplyOrder(sellerWrapper, left, orderCode, msea);
// }else {
// processCommonChargeOrder(sellerWrapper, orderCode);
// }
// }
/**
* 当卖家钱包余额充足时,直接升级
* @param sellerWrapper
* @param orderCode
* @param targetEST
*/
// public void upgradeLevelIfFatWallet(SellerWrapper sellerWrapper, Long orderCode,
// EntrySellerType targetEST){
// Integer uid = sellerWrapper.getUid();
// BigDecimal leftInWallet = sellerWrapper.getLeftInWallet();
// SellerEnterApply sea = this.applySuperEntry(uid, orderCode, targetEST);
// this.upgradeLevel(sellerWrapper, orderCode, leftInWallet, sea);
// }
/**
* 充值订单处理
* @param sellerWrapper
* @param left
* @param orderCode
* @param msea
*/
// private void processApplyOrder(SellerWrapper sellerWrapper,BigDecimal left,
// Long orderCode, SellerEnterApply msea){
// int uid = sellerWrapper.getUid();
//
// //持久化的入驻信息
// StoredSeller pss = sellerWrapper.getStoredSeller();
// boolean noStoredSeller = Objects.isNull(pss) || pss.getValidStatus().equals(StoredSellerStatusEnum.quit.getId());
// SellerBo sellerBo = sellerWrapper.sellerBo();
// //当前身份
// EntrySellerType currentEST = sellerBo.getEntrySellerType();
// Integer currentEnterType = currentEST.getCode();
// //身份等级配置
// Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
//
// //目标身份
// EntrySellerType targetEst = EntrySellerType.of(msea.getEnterType());
// //申请是否已经通过
// boolean isPassedApply = Objects.equals(SellerEnterApplyStatus.PASS.getCode(), msea.getStatus());
// //目标身份对应的等级
// Integer level = SellerHelper.getType2Level(targetEst, estMap, left);
// //当前身份和申请时身份是否一致
// Integer preEnterType;
// boolean isMatchedET = Objects.equals(preEnterType=msea.getPreEnterType(), currentEnterType);
// logger.info("in upgradeLevel ready pass apply and add StoredSeller, uid {} orderCode {} currentEnterType {} PreEnterType {} noStoredSeller {} target Level {} isMatchedET {}",
// uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
// if(Objects.equals(currentEnterType, EntrySellerType.NOT_ENTRY.getCode())){
// //普通卖家 -> 普通入驻 ,1. apply 状态 ,2. enter_seller 从无到有
// //普通卖家 -> 超级 ,1. apply 状态 ,2. enter_seller 从无到有
// if (!isPassedApply){
// passApply(msea);
// }
// if (noStoredSeller && isMatchedET){
// SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
// storedSellerService.addUserAsStoredSeller(uid, targetEst, slfb);
// //触发卖家订单统计数据变更(卖家阶梯扣点)
// EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
// EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder()
// .setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
// .addTag(InfluxdbTagEnum.TAG_TYPE, targetEst.getCode() == EntrySellerType.COMMON.getCode() ? 2 : 3)
// .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录 2代表普通入驻 3 代表超级卖家入驻
//
// }else{
// logger.warn("in upgradeLevel add StoredSeller fail, uid {} orderCode {}",
// uid, orderCode);
// }
//
// }else if (Objects.equals(currentEnterType, EntrySellerType.COMMON.getCode())) {
// //普通入驻 -> 超级 ,1. apply 状态 ,2. enter_seller 修改type & func list
// passApply(msea);
// //
// if (!noStoredSeller && isMatchedET){
// SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
// storedSellerService.updateEnterSeller(uid, targetEst, slfb);
// //触发卖家订单统计数据变更(卖家阶梯扣点)
// EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
// if (EntrySellerType.SUPER_ENTRY.equals(targetEst)){
// logger.info("in upgradeLevel ready pass apply then changeWalletToSuperSeller, uid {} orderCode {} currentEnterType {} PreEnterType {} noStoredSeller {} target Level {} isMatchedET {}",
// uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
// merchantOrderPaymentService.changeWalletToSuperSeller(uid);
// }
// EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder()
// .setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
// .addTag(InfluxdbTagEnum.TAG_TYPE, 1)
// .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录 1 代表升级
// }else{
// logger.warn("in upgradeLevel update StoredSeller fail, uid {} orderCode {}",
// uid, orderCode);
// }
// }else if (Objects.equals(currentEnterType, EntrySellerType.SPECIAL_SUPER.getCode())){
// //白名单超级卖家
// logger.warn("in upgradeLevel SPECIAL_SUPER by charge, uid {} orderCode {}",
// uid, orderCode);
// /*
// if (!isPassedApply){
// passApply(msea);
// }
// if (!noStoredSeller && isMatchedET){
// SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
// storedSellerService.updateEnterSeller(uid, targetEst, slfb);
// if (EntrySellerType.SUPER_ENTRY.equals(targetEst)){
// logger.info("in upgradeLevel ready pass apply then changeWalletToSuperSeller, uid {} orderCode {} currentEnterType {} PreEnterType {} noStoredSeller {} target Level {} isMatchedET {}",
// uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
// merchantOrderPaymentService.changeWalletToSuperSeller(uid);
// //移除 白名单
// storedSellerService.disableSpecialSuper(uid);
// }
// }else{
// logger.warn("in upgradeLevel update StoredSeller fail, uid {} orderCode {}",
// uid, orderCode);
// }*/
//
// }else if (Objects.equals(currentEnterType, EntrySellerType.SUPER_ENTRY.getCode())){
// //超级卖家
// upgradeSuperLevel(sellerWrapper, level, orderCode, targetEst, isMatchedET);
// }
// }
// /**
// * 普通充值订单处理
// * @param sellerWrapper
// * @param orderCode
// */
// private void processCommonChargeOrder(SellerWrapper sellerWrapper,
// Long orderCode){
// int uid = sellerWrapper.getUid();
//
// SellerBo sellerBo = sellerWrapper.sellerBo();
// //当前身份
// EntrySellerType currentEST = sellerBo.getEntrySellerType();
// Integer currentEnterType = currentEST.getCode();
// logger.warn("in upgradeLevel no record so that it's only common charge order, uid {} orderCode {}",
// uid, orderCode);
//
// if(Objects.equals(currentEnterType, EntrySellerType.NOT_ENTRY.getCode())){
// //普通卖家 no way
// logger.warn("in upgradeLevel no need any action, uid {} orderCode {} currentEnterType {}",
// uid, orderCode, currentEnterType);
//
// }else if (Objects.equals(currentEnterType, EntrySellerType.COMMON.getCode())) {
// //普通入驻 -> 超级 ,1. apply 状态 ,2. enter_seller 修改type & func list
// logger.warn("in upgradeLevel no need any action, uid {} orderCode {} currentEnterType {}",
// uid, orderCode, currentEnterType);
//
// }else if (Objects.equals(currentEnterType, EntrySellerType.SPECIAL_SUPER.getCode())){
// //白名单超级卖家
// logger.warn("in upgradeLevel no need any action, uid {} orderCode {} currentEnterType {}",
// uid, orderCode, currentEnterType);
// }else if (Objects.equals(currentEnterType, EntrySellerType.SUPER_ENTRY.getCode())){
// //持久化的入驻信息
// StoredSeller pss = sellerWrapper.getStoredSeller();
// boolean isValid = Objects.equals(pss.getValidStatus(), StoredSellerStatusEnum.entered.getId());
// if (isValid) {//身份等级配置
// SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFuncWithWallet(sellerWrapper);
// //超级卖家
// upgradeSuperLevel(sellerWrapper, slfb.getLevel(), orderCode, currentEST, true);
// }
// }
// }
// private int upgradeSuperLevel(SellerWrapper sellerWrapper,Integer level, Long orderCode,
// EntrySellerType targetEst, boolean isMatchedET){
//
// Integer uid = sellerWrapper.getUid();
// logger.info("in upgradeSuperLevel uid {} orderCode {}", uid, orderCode);
// sellerWrapper.buildSuperEnterStageLevel(sellerLevelFuncMapper::selectByPrimaryKey);
// SellerBo sellerBo = sellerWrapper.sellerBo();
// SuperEnterStageLevel sesl = sellerBo.getSuperEnterStageLevel();
// Integer currentLevel = null;
// boolean levelNeedUpgrade = Objects.nonNull(sesl)
// && Objects.nonNull(currentLevel = sesl.getCode())
// && !currentLevel.equals(level);
// StoredSeller pss = sellerWrapper.getStoredSeller();
// boolean noStoredSeller = Objects.isNull(pss);
// logger.warn("in upgradeSuperLevel update StoredSeller, uid {} orderCode {} currentLevel {} target level {}",
// uid, orderCode, currentLevel, level);
// int result = 0;
// if (!noStoredSeller && isMatchedET && levelNeedUpgrade) {
// doUpgradeSuper(targetEst, currentLevel, level, uid);
// //触发卖家订单统计数据变更(卖家阶梯扣点)
// EventBusPublisher.publishEvent(SellerEnterTypeChangeEvent.builder().sellerUid(uid).eventType(EnterQuitEnum.ENTER).build());
// EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
// .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
// }
// return result;
// }
// private int doUpgradeSuper(EntrySellerType targetEst,Integer currentLevel, Integer level, Integer uid){
// logger.info("doUpgradeSuper uid {} targetEst {} currentLevel {} target level {}",
// uid, targetEst, currentLevel, level);
// SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
// int result = storedSellerService.updateEnterSeller(uid, targetEst, slfb);
// processWithLevel(currentLevel, level, uid);
// return result;
// }
// private void processWithLevel(Integer currentLevel, Integer targetLevel, Integer uid){
// logger.info("processWithLevel currentLevel {} targetLevel {} uid {}",currentLevel, targetLevel, uid);
// if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == currentLevel ||
// currentLevel== SuperEnterStageLevel.DISABLE.getCode()){
// if(targetLevel == SuperEnterStageLevel.FULL.getCode()
// ||targetLevel == SuperEnterStageLevel.PARTITION.getCode()){
// productProxyService.cancelHiddenGoods(uid);
// }
// }
//
// if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == targetLevel
// || targetLevel == SuperEnterStageLevel.DISABLE.getCode()) {
// if (currentLevel == SuperEnterStageLevel.FULL.getCode()
// || currentLevel == SuperEnterStageLevel.PARTITION.getCode()) {
// productProxyService.hiddenGoods(uid);
// }
// }
// }
/**
* 超级卖家钱包金额变化时触发降级动作
*
* @param sellerWrapper
* @param left
* @return
*/
// public int changeLevel4Super(SellerWrapper sellerWrapper, BigDecimal left){
// int uid = sellerWrapper.getUid();
// //持久化的入驻信息
// SellerBo sellerBo = sellerWrapper.sellerBo();
// //当前身份
// EntrySellerType currentEST = sellerBo.of();
// Integer currentEnterType = currentEST.getCode();
// //身份等级配置
// Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
// EntryThreshold set = estMap.get(currentEST);
// Supplier<SellerLevelFuncBo> slfSupplier = () ->SellerHelper.getSellerLevelFunc(currentEST, set, left);
// //目标身份对应的等级
// logger.info("in changeLevel4Super ready change StoredSeller targetFuncLevel func, uid {} currentEnterType {}, {}",
// uid, currentEnterType, left);
//
// // 扣保证金 极速卖家场景-触发阀值场景
// if (sellerBo.isFastDeliverySuper()){
//
// if(left.compareTo(set.getHiddenGoodsAmount())<0){
// inBoxFacade.noticeFastDeliverySeller(uid, set.getHiddenGoodsAmount());
//
// // 隐藏商品
// productProxyService.hiddenGoods(uid);
//
// }else if(left.compareTo(set.getGoodsOnOffShelveAmount())<0){
// inBoxFacade.noticeFastDeliverySeller(uid, set.getGoodsOnOffShelveAmount());
// }else if (left.compareTo(set.getPrepaymentAmount())<0){
// inBoxFacade.noticeFastDeliverySeller(uid, set.getPrepaymentAmount());
// }
//
// return 0;
// }
//
// int result = 0;
// if (sellerBo.isNormalSuper()) {
// SellerLevelFuncBo bslfb = slfSupplier.get();
// Integer targetFuncLevel = bslfb.getLevel();
// //
// EntryLevelNode eln = buildEntryLevelNode(sellerWrapper, bslfb);
// Integer currentLevel = eln.currentLevel;
// boolean levelNeedUpgrade = eln.needUpgrade;
// StoredSeller pss = sellerWrapper.getStoredSeller();
// boolean isValid = Objects.equals(pss.getValidStatus(), StoredSellerStatusEnum.entered.getId());
//
// logger.info("in changeLevel4Super update StoredSeller, uid {} currentLevel {} target targetFuncLevel {} levelNeedUpgrade {} isValid {}",
// uid, currentLevel, targetFuncLevel, levelNeedUpgrade, isValid);
// doUpgradeSuper(currentEST, currentLevel, targetFuncLevel, uid);
// SuperEnterStageLevel targetSESL = SuperEnterStageLevel.of(targetFuncLevel);
// inBoxFacade.noticeSuperSellerDegrade(uid, targetSESL, bslfb.getWalletThreshold());
// }
//
// if (sellerBo.isLargeSettlementSuper() ){
// processLargeSettlementSuperWhenWalletChange(sellerWrapper, left, slfSupplier);
// }
//
// return result;
// }
// static class EntryLevelNode{
// Integer currentLevel;
// Integer targetLevel;
// boolean needUpgrade;
// }
// private EntryLevelNode buildEntryLevelNode(SellerWrapper sellerWrapper, SellerLevelFuncBo bslfb){
// Integer targetFuncLevel = bslfb.getLevel();
// //
// sellerWrapper.buildSuperEnterStageLevel(sellerLevelFuncMapper::selectByPrimaryKey);
// SellerBo sellerBo = sellerWrapper.sellerBo();
// SuperEnterStageLevel sesl = sellerBo.getSuperEnterStageLevel();
// Integer currentLevel = null;
// boolean levelNeedUpgrade = Objects.nonNull(sesl)
// && Objects.nonNull(currentLevel = sesl.getCode())
// && !currentLevel.equals(targetFuncLevel);
//
// EntryLevelNode eln = new EntryLevelNode();
// eln.currentLevel = currentLevel;
// eln.targetLevel = targetFuncLevel;
// eln.needUpgrade = levelNeedUpgrade;
// return eln;
// }
// private EntryLevelNode buildEntryLevelNode(SellerWrapper sellerWrapper, Supplier<SellerLevelFuncBo> slfbSupplier){
// SellerLevelFuncBo bslfb = slfbSupplier.get();
// return buildEntryLevelNode(sellerWrapper, bslfb);
// }
// private String getNoticeContent(SuperEnterStageLevel sesl){
// String content;
// switch (sesl){
// case FULL:
// content = "【UFO飞碟好物】您的账户保证金余额不足%s,为了不影响您的超级商家权限,请及时充值。";
// break;
// case PARTITION:
// content = "【UFO飞碟好物】您的账户保证金余额不足%s,商品将不能正常上架,为了不影响您的超级商家权限,请及时充值。";
// break;
// case DISABLE:
// content = "【UFO飞碟好物】您的账户保证金余额不足%s,平台将隐藏您所有出售中的商品,为了不影响您的超级商家权限,请及时充值";
// break;
// default:
// content= null;
// }
//
// return content;
// }
// private void noticeLargeSettlementSuper(SellerLevelFuncBo bslfb, SellerBo sellerBo, BigDecimal left){
// int uid = sellerBo.getUid();
// Integer noticeCnt = null ;
// SuperEnterStageLevel sesl = SuperEnterStageLevel.of(bslfb.getLevel());
// boolean walletNotEnough = (sesl != null && bslfb.getWalletThreshold().compareTo(left) > 0 );
// boolean notNotice = (Objects.isNull(noticeCnt= storedSellerCacheService.getNoticeCntWhenWalletNotEnough(uid, bslfb.getLevel())) || noticeCnt<1);
// if (notNotice && walletNotEnough){
// String thresholdStr = MathUtils.formatCurrencyStr(bslfb.getWalletThreshold().doubleValue());
// try {
// String mailTo = configReader.getString("ufo.order.seller.noticeHKSellerEmailTo", "chao.chen@yoho.cn,xiuchun.luo@yoho.cn");
// String content = String.format(getNoticeContent(sesl), thresholdStr);
// logger.info("in processLargeSettlementSuperWhenWalletChange ready 2 send mail uid {} sellerBo {} noticeCnt {} mailTo {} content {}",
// uid, sellerBo, noticeCnt, mailTo, content);
// MailSender.newMailSender()
// .subject("卖家服务提醒")
// .to(mailTo)
// .body(content, "text/html;charset=utf-8")
// .send();
// storedSellerCacheService.setNoticeCntWhenWalletNotEnough(uid, bslfb.getLevel(), 1);
// }catch (Exception ex){
// logger.warn("processLargeSettlementSuperWhenWalletChange send mail fail, uid {} left wallet {}", uid, left, ex);
// }
// inBoxFacade.noticeLargeSettlementSuperDegrade(uid, sesl, thresholdStr,left );
// }
// logger.info("in processLargeSettlementSuperWhenWalletChange uid {} sellerBo {} noticeCnt {}",
// uid, sellerBo, noticeCnt);
// }
// private void processLargeSettlementSuperWhenWalletChange(SellerWrapper sellerWrapper, BigDecimal left,Supplier<SellerLevelFuncBo> slfSupplier){
// SellerBo sellerBo = sellerWrapper.sellerBo();
// if (sellerBo.isLargeSettlementSuper() ){
// SellerLevelFuncBo bslfb = slfSupplier.get();
// int uid = sellerBo.getUid();
// noticeLargeSettlementSuper(bslfb, sellerBo, left);
//
// //hidden sale product
// boolean needHiddenPrds = bslfb.getLevel() == SuperEnterStageLevel.DISABLE.getCode()
// && bslfb.getWalletThreshold().compareTo(left) > 0;
// boolean cancelHidden = bslfb.getLevel() != SuperEnterStageLevel.DISABLE.getCode()
// && BigDecimal.ZERO.compareTo(left) < 0;
// logger.info("in processLargeSettlementSuperWhenWalletChange uid {} sellerBo {} needHiddenPrds {} cancelHidden {}",
// uid, sellerBo, needHiddenPrds, cancelHidden);
// EntrySellerType currentEST = sellerBo.of();
// if (needHiddenPrds || cancelHidden){
// EntryLevelNode eln = buildEntryLevelNode(sellerWrapper, bslfb);
// doUpgradeSuper(currentEST, eln.currentLevel, eln.targetLevel, uid);
// if (needHiddenPrds) {
// SuperEnterStageLevel targetSESL = SuperEnterStageLevel.of(eln.targetLevel);
// inBoxFacade.noticeSuperSellerDegrade(uid, targetSESL, bslfb.getWalletThreshold());
// }
// }
// }
// }
}
... ...
... ... @@ -91,7 +91,7 @@ public class SellerFuncService {
if (estc == null){
level = SellerConfig.ENTER_TYPE_DEFAULT_LEVEL;
}else{
EntrySellerType est = EntrySellerType.getEntrySellerType(estc);
EntrySellerType est = EntrySellerType.of(estc);
switch(est){
case SUPER_ENTRY:
level = SuperEnterStageLevel.DISABLE.getCode();
... ... @@ -109,43 +109,12 @@ public class SellerFuncService {
}
/**
* 钱包余额判定
* @param sellerWrapper
* @return
*/
public SellerLevelFuncBo getSellerLevelFuncWithWallet(SellerWrapper sellerWrapper){
int uid = sellerWrapper.getUid();
//left enter type is 入驻超级
BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
//当前身份
EntrySellerType currentEST = sellerBo.getEntrySellerType();
//身份等级配置
Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
Integer currentLevel = SellerHelper.getType2Level(currentEST, estMap, leftInWallet);
//持久化的入驻信息
StoredSeller pss = sellerWrapper.getStoredSeller();
boolean isValid = Objects.equals(pss.getValidStatus(), StoredSellerStatusEnum.entered.getId());
boolean existLevel = Objects.nonNull(currentLevel);
SellerLevelFuncBo slfb;
if (existLevel && isValid){
slfb = getSellerLevelFunc(currentEST.getCode(), currentLevel);
logger.info("in getSellerLevelFuncWithWallet SellerLevelFuncBo {} uid {}", slfb, uid);
}else{
slfb = getDefaultSLFB(currentEST.getCode());
logger.warn("in getSellerLevelFuncWithWallet getDefault uid {} SLFB {}", uid, slfb);
}
return slfb;
}
public SellerLevelFuncBo getSellerLevelFunc(SellerWrapper sellerWrapper){
int uid = sellerWrapper.getUid();
//持久化的入驻信息
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
//当前身份
EntrySellerType currentEST = sellerBo.getEntrySellerType();
if (SellerHelper.isSuper(currentEST)){
... ... @@ -160,7 +129,7 @@ public class SellerFuncService {
sellerWrapper.buildSuperEnterStageLevel(sellerLevelFuncMapper::selectByPrimaryKey);
//持久化的入驻信息
StoredSeller pss = sellerWrapper.getStoredSeller();
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
//当前身份
EntrySellerType currentEST = sellerBo.getEntrySellerType();
SuperEnterStageLevel sesl = sellerBo.getSuperEnterStageLevel();
... ... @@ -179,6 +148,40 @@ public class SellerFuncService {
}
/**
* 钱包余额判定
* @param sellerWrapper
* @return
*/
public SellerLevelFuncBo getSellerLevelFuncWithWallet(SellerWrapper sellerWrapper){
int uid = sellerWrapper.getUid();
//left enter type is 入驻超级
BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
SellerBo sellerBo = sellerWrapper.sellerBo();
//当前身份
EntrySellerType currentEST = sellerBo.getEntrySellerType();
//身份等级配置
Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
Integer currentLevel = SellerHelper.getType2Level(currentEST, estMap, leftInWallet);
//持久化的入驻信息
StoredSeller pss = sellerWrapper.getStoredSeller();
boolean isValid = Objects.equals(pss.getValidStatus(), StoredSellerStatusEnum.entered.getId());
boolean existLevel = Objects.nonNull(currentLevel); // 恒为true
SellerLevelFuncBo slfb;
if (existLevel && isValid){
slfb = getSellerLevelFunc(currentEST.getCode(), currentLevel);
logger.info("in getSellerLevelFuncWithWallet SellerLevelFuncBo {} uid {}", slfb, uid);
}else{
slfb = getDefaultSLFB(currentEST.getCode());
logger.warn("in getSellerLevelFuncWithWallet getDefault uid {} SLFB {}", uid, slfb);
}
return slfb;
}
public SellerLevelFuncBo getSellerLevelFunc(Integer enterType,Integer level){
if (level==null || level == SellerConfig.ENTER_TYPE_DEFAULT_LEVEL){
return getDefaultSLFB(enterType);
... ...
... ... @@ -16,6 +16,7 @@ import com.yohoufo.dal.order.model.SuperEntrySeller;
import com.yohoufo.order.common.SuperEntrySellerStatus;
import com.yohoufo.order.model.bo.PlatformServiceFeeDefinition;
import com.yohoufo.order.model.bo.SellerPlatformServiceFee;
import com.yohoufo.order.service.IStoredSellerDepositService;
import com.yohoufo.order.service.IStoredSellerService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.cache.StoredSellerCacheService;
... ... @@ -71,6 +72,9 @@ public class SellerService {
@Autowired
private SellerPlatformServiceFeeSupport sellerPlatformServiceFeeSupport;
@Autowired
EntrySellerWalletChangers entrySellerWalletChangers;
/**更低出价提醒
* 1)当有新卖家出价成功或调价成功时,给所有正在出售该sku(尺码)的其他卖家推送一条消息(push+消息盒子)
... ... @@ -123,7 +127,7 @@ public class SellerService {
public SellerWrapper getBaseSellerWrapper(Integer uid){
SellerWrapper sellerWrapper = new SellerWrapper(uid,logger)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.addSpecialSuperFunc(this::isSpecialSuper)
// .addSpecialSuperFunc(this::isSpecialSuper)
.buildSellerWrapper();
return sellerWrapper;
}
... ... @@ -132,7 +136,7 @@ public class SellerService {
logger.info("getSellerWithAuth uid {}", uid);
SellerWrapper sellerWrapper = getBaseSellerWrapper(uid).attachAssetPolicy()
.attachSellerLevelFunc((sw)->sellerFuncService.getSellerLevelFunc(sw));
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
return sellerBo;
}
... ... @@ -147,15 +151,15 @@ public class SellerService {
return false;
}
public boolean isSpecialSuper(int uid){
List<Integer> uidList = getSuperEntrySellerUids();
logger.info("isSuperEntrySeller check uid {} uidList {}", uid, uidList);
if (CollectionUtils.isNotEmpty(uidList)){
//hit or not
return uidList.contains(uid);
}
return false;
}
// public boolean isSpecialSuper(int uid){
// List<Integer> uidList = getSuperEntrySellerUids();
// logger.info("isSuperEntrySeller check uid {} uidList {}", uid, uidList);
// if (CollectionUtils.isNotEmpty(uidList)){
// //hit or not
// return uidList.contains(uid);
// }
// return false;
// }
/**
* 平台技术服务费
... ... @@ -214,13 +218,13 @@ public class SellerService {
* @return
*/
public EntrySellerType getEntrySellerType(int uid){
logger.info("getEntrySellerType uid {}", uid);
logger.info("of uid {}", uid);
SellerBo sellerBo = new SellerWrapper(uid,logger)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.addSpecialSuperFunc(this::isSpecialSuper)
.buildSellerWrapper().buildSellerBo();
// .addSpecialSuperFunc(this::isSpecialSuper)
.buildSellerWrapper().sellerBo();
EntrySellerType est = sellerBo.getEntrySellerType();
logger.info("getEntrySellerType uid {} EntrySellerType {}", uid, est);
logger.info("of uid {} EntrySellerType {}", uid, est);
return est;
}
... ... @@ -241,9 +245,9 @@ public class SellerService {
* @param uid
* @param orderCode
*/
public void processApply(Integer uid, Long orderCode, BigDecimal total){
sellerEnterApplyService.audit(uid, orderCode, total);
}
// public void processApply(Integer uid, Long orderCode, BigDecimal total){
// sellerEnterApplyService.audit(uid, orderCode, total);
// }
@Autowired
private MetaConfigService metaConfigService;
... ... @@ -252,41 +256,41 @@ public class SellerService {
return metaConfigService.getEntryThreshold();
}
public Boolean applySuperEnter(Integer uid){
SellerWrapper sellerWrapper =
new SellerWrapper(uid,logger)
.addSpecialSuperFunc(this::isSpecialSuper)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.buildSellerWrapper();
SellerBo sellerBo = sellerWrapper.buildSellerBo();
EntrySellerType currentEST = sellerBo.getEntrySellerType();
EntrySellerType targetEST = EntrySellerType.SUPER_ENTRY;
if (Objects.equals(targetEST, currentEST)
|| Objects.equals(EntrySellerType.SPECIAL_SUPER, currentEST)){
logger.info("applySuperEnter user was {} , uid {}", currentEST , uid);
return true;
}
//普通个人
if (Objects.equals(targetEST, EntrySellerType.NOT_ENTRY)){
logger.info("applySuperEnter user was {} , uid {}", currentEST , uid);
return false;
}
//left enter type is 入驻非超级
BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
sellerWrapper.setLeftInWallet(leftInWallet);
//前提:1. 当前卖家是 普通个人 or 入驻非超级 2. 钱包余额大于等于超级的阈值
Map<EntrySellerType,EntryThreshold> entryThreshold = getEntryThreshold();
EntryThreshold set = entryThreshold.get(EntrySellerType.SUPER_ENTRY);
boolean isFatWallet = leftInWallet.compareTo(set.getPrepaymentAmount()) >= 0;
logger.info("applySuperEnter uid {} leftInWallet {} super EntryThreshold {} isFatWallet {}",
uid, leftInWallet, set, isFatWallet);
//申请记录(新增 or 修改) 入驻卖家(enter_type level_func 功能菜单)
if (isFatWallet){
//insert apply
sellerEnterApplyService.upgradeLevelIfFatWallet(sellerWrapper, null, targetEST);
}
return isFatWallet;
}
// public Boolean applySuperEnter(Integer uid){
// SellerWrapper sellerWrapper =
// new SellerWrapper(uid,logger)
// .storedSellerDataSource(storedSellerMapper::selectByUid)
// .buildSellerWrapper();
// SellerBo sellerBo = sellerWrapper.sellerBo();
// EntrySellerType currentEST = sellerBo.of();
// EntrySellerType targetEST = EntrySellerType.SUPER_ENTRY;
// if (Objects.equals(targetEST, currentEST)
// || Objects.equals(EntrySellerType.SPECIAL_SUPER, currentEST)){
// logger.info("applySuperEnter user was {} , uid {}", currentEST , uid);
// return true;
// }
// //普通个人
// if (Objects.equals(targetEST, EntrySellerType.NOT_ENTRY)){
// logger.info("applySuperEnter user was {} , uid {}", currentEST , uid);
// return false;
// }
// //left enter type is 入驻非超级
// BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
// sellerWrapper.setLeftInWallet(leftInWallet);
// //前提:1. 当前卖家是 普通个人 or 入驻非超级 2. 钱包余额大于等于超级的阈值
// Map<EntrySellerType,EntryThreshold> entryThreshold = getEntryThreshold();
// EntryThreshold set = entryThreshold.get(EntrySellerType.SUPER_ENTRY);
// boolean isFatWallet = leftInWallet.compareTo(set.getPrepaymentAmount()) >= 0;
// logger.info("applySuperEnter uid {} leftInWallet {} super EntryThreshold {} isFatWallet {}",
// uid, leftInWallet, set, isFatWallet);
// //申请记录(新增 or 修改) 入驻卖家(enter_type level_func 功能菜单)
// if (isFatWallet){
// //insert apply
// sellerEnterApplyService.upgradeLevelIfFatWallet(sellerWrapper, null, targetEST);
// }
// return isFatWallet;
// }
/**
* 卖家账户划钱时触发
... ... @@ -295,10 +299,9 @@ public class SellerService {
public void processAfterWalletChange(Integer uid){
SellerWrapper sellerWrapper =
new SellerWrapper(uid,logger)
.addSpecialSuperFunc(this::isSpecialSuper)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.buildSellerWrapper();
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
EntrySellerType currentEST = sellerBo.getEntrySellerType();
List<EntrySellerType> targetESTs = new ArrayList<>(2);
targetESTs.add(EntrySellerType.SUPER_ENTRY);
... ... @@ -309,10 +312,15 @@ public class SellerService {
return ;
}
//left enter type is 入驻超级
BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
//
sellerEnterApplyService.changeLevel4Super(sellerWrapper, leftInWallet);
// BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
// sellerEnterApplyService.changeLevel4Super(sellerWrapper, leftInWallet);
// level发生变化
entrySellerWalletChangers.deduct(uid);
}
@Autowired
AuthLevelChgeSupport authLevelChgeSupport;
/**
* 检查当前用户是否为正常的超级卖家,即身份 + 钱包余额大于某个阈值
... ... @@ -322,25 +330,27 @@ public class SellerService {
public Boolean checkIsNormalSuper(Integer uid){
SellerWrapper sellerWrapper =
new SellerWrapper(uid,logger)
.addSpecialSuperFunc(this::isSpecialSuper)
// .addSpecialSuperFunc(this::isSpecialSuper)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.buildSellerWrapper();
SellerBo sellerBo = sellerWrapper.buildSellerBo();
SellerBo sellerBo = sellerWrapper.sellerBo();
EntrySellerType currentEST = sellerBo.getEntrySellerType();
EntrySellerType targetEST = EntrySellerType.SUPER_ENTRY;
if (!Objects.equals(targetEST, currentEST)){
logger.info("check isNormalSuper currentEST {} , uid {}", currentEST , uid);
logger.info("check isEntryPlus currentEST {} , uid {}", currentEST , uid);
return false;
}
//left enter type is 入驻超级
BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
EntryThreshold set = estMap.get(currentEST);
//目标身份对应的等级
SellerLevelFuncBo bslfb = SellerHelper.getSellerLevelFunc(currentEST, set, leftInWallet);
Integer level = bslfb.getLevel();
if (level != SuperEnterStageLevel.FULL.getCode()){
logger.warn("in checkIsNormalSuper not valid, uid {} level {} leftInWallet {}", uid, level, leftInWallet);
SellerLevelFuncBo sellerLevelFuncBo = authLevelChgeSupport.getShouldLevel(uid, targetEST);
// //left enter type is 入驻超级
// BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
// Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
// EntryThreshold set = estMap.get(currentEST);
// //目标身份对应的等级
// SellerLevelFuncBo bslfb = SellerHelper.getSellerLevelFunc(currentEST, set, leftInWallet);
Integer level = sellerLevelFuncBo.getLevel();
if (sellerLevelFuncBo.getLevel() != SuperEnterStageLevel.FULL.getCode()){
logger.warn("in checkIsNormalSuper not valid, uid {} level {}", uid, level);
return false;
}
return true;
... ... @@ -349,7 +359,6 @@ public class SellerService {
public SellerWrapper getFullDimensionSeller(int uid){
SellerWrapper sellerWrapper =
new SellerWrapper(uid,logger)
.addSpecialSuperFunc(this::isSpecialSuper)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.buildSellerWrapper().attachAssetPolicy()
.attachWallet(merchantOrderPaymentService::getWalletLeftAmount);
... ...
... ... @@ -36,26 +36,26 @@ public class SellerWrapper {
Function<Integer,StoredSeller> storedSellerFunc;
Function<Integer,Boolean> isSpecialSuperFunc;
// Function<Integer,Boolean> isSpecialSuperFunc;
SellerBo sellerBo = new SellerBo();
SellerWrapper(int uid,Logger logger){
public SellerWrapper(int uid, Logger logger){
this.uid = uid;
this.sellerBo.setUid(uid);
this.logger = logger;
}
SellerWrapper storedSellerDataSource(Function<Integer,StoredSeller> storedSellerFunc){
public SellerWrapper storedSellerDataSource(Function<Integer, StoredSeller> storedSellerFunc){
this.storedSellerFunc = storedSellerFunc;
return this;
}
SellerWrapper addSpecialSuperFunc(Function<Integer,Boolean> isSpecialSuperFunc){
this.isSpecialSuperFunc = isSpecialSuperFunc;
return this;
}
// SellerWrapper addSpecialSuperFunc(Function<Integer,Boolean> isSpecialSuperFunc){
// this.isSpecialSuperFunc = isSpecialSuperFunc;
// return this;
// }
SellerWrapper buildSellerWrapper(){
public SellerWrapper buildSellerWrapper(){
logger.info("buildSellerWrapper uid {}", uid);
if (uid <= 0){
logger.warn("buildSellerWrapper illegal uid {}", uid);
... ... @@ -77,12 +77,14 @@ public class SellerWrapper {
uid, validStatus, entryType);
if (Objects.equals(StoredSellerStatusEnum.quit.getId(), validStatus)) {
est = EntrySellerType.NOT_ENTRY;
} else if (isSpecialSuperFunc.apply(uid)) {
//case 3:valid ok and in white list
est = EntrySellerType.SPECIAL_SUPER;
} else {
}
// else if (isSpecialSuperFunc.apply(uid)) {
// //case 3:valid ok and in white list
// est = EntrySellerType.SPECIAL_SUPER;
// }
else {
//case 4: left common or super
est = EntrySellerType.getEntrySellerType(entryType);
est = EntrySellerType.of(entryType);
}
Integer funcId;
if (Objects.nonNull(funcId = storedSeller.getLevelFuncId())){
... ... @@ -112,6 +114,7 @@ public class SellerWrapper {
if (Objects.nonNull(entrySellerType)){
switch (entrySellerType){
case SUPER_ENTRY:
case FAST_DELIVERY_SUPER:
case LARGE_SETTLEMENT:
Integer levelFuncId = sellerBo.getLevelFuncId();
if(Objects.nonNull(levelFuncId)){
... ... @@ -119,7 +122,7 @@ public class SellerWrapper {
logger.info("buildSuperEnterStageLevel SellerLevelFunc uid {} levelFuncId {} SellerLevelFunc {}",
uid, levelFuncId, slf);
Integer level = slf.getLevel();
SuperEnterStageLevel sesl = SuperEnterStageLevel.getSuperEnterStageLevel(level);
SuperEnterStageLevel sesl = SuperEnterStageLevel.of(level);
sellerBo.setSuperEnterStageLevel(sesl);
}
break;
... ... @@ -187,7 +190,7 @@ public class SellerWrapper {
}
public SellerBo buildSellerBo(){
public SellerBo sellerBo(){
return sellerBo;
}
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.order.constants.SellerConfig;
import com.yohobuy.ufo.model.order.bo.SellerTypeNode;
import javafx.util.Pair;
import java.math.BigDecimal;
import java.util.Map;
... ... @@ -18,11 +19,42 @@ import java.util.Objects;
*/
public class SellerHelper {
public static SellerLevelFuncBo getSellerLevelFunc(EntrySellerType est, EntryThreshold et, BigDecimal left){
// public static SellerLevelFuncBo getSellerLevelFunc(EntrySellerType est, EntryThreshold et, BigDecimal left){
// Integer level = SellerConfig.ENTER_TYPE_DEFAULT_LEVEL;
// SellerLevelFuncBo slfb = new SellerLevelFuncBo();
// BigDecimal theshold = null;
// switch (est){
// case COMMON:
// theshold = et.getPrepaymentAmount();
// if (theshold.compareTo(left) <= 0) {
// level = CommonEnterStageLevel.ALL.getCode();
// }
// break;
// case SUPER_ENTRY:
// case LARGE_SETTLEMENT:
// // 余额<1000 3; 余额在1000~3000之间,2;月大于3000 1
// level = getSuperLevel(et,left);
// if (level == SuperEnterStageLevel.FULL.getCode()) {
// theshold = et.getPrepaymentAmount();
// }else if (level == SuperEnterStageLevel.PARTITION.getCode()){
// theshold = et.getGoodsOnOffShelveAmount();
// }else if (level == SuperEnterStageLevel.DISABLE.getCode()){
// theshold = et.getHiddenGoodsAmount();
// }
// break;
// }
// slfb.setLevel(level);
// slfb.setWalletThreshold(theshold);
// return slfb;
// }
public static Pair<Integer, BigDecimal> getTypeLevelAndTheshold(EntryThreshold et,
BigDecimal left){
Integer level = SellerConfig.ENTER_TYPE_DEFAULT_LEVEL;
SellerLevelFuncBo slfb = new SellerLevelFuncBo();
BigDecimal theshold = null;
switch (est){
switch (et.getEntrySellerType()){
case COMMON:
theshold = et.getPrepaymentAmount();
if (theshold.compareTo(left) <= 0) {
... ... @@ -31,7 +63,8 @@ public class SellerHelper {
break;
case SUPER_ENTRY:
case LARGE_SETTLEMENT:
level = getSuperLevel(et,left);
case FAST_DELIVERY_SUPER:
level = getSuperLevel(et, left);
if (level == SuperEnterStageLevel.FULL.getCode()) {
theshold = et.getPrepaymentAmount();
}else if (level == SuperEnterStageLevel.PARTITION.getCode()){
... ... @@ -41,9 +74,7 @@ public class SellerHelper {
}
break;
}
slfb.setLevel(level);
slfb.setWalletThreshold(theshold);
return slfb;
return new Pair<>(level, theshold);
}
public static Integer getType2Level(EntrySellerType targetEst, Map<EntrySellerType,EntryThreshold> estMap,
... ... @@ -66,7 +97,6 @@ public class SellerHelper {
return level;
}
public static Integer getSuperLevel(EntryThreshold et, BigDecimal left){
BigDecimal prepaymentAmount = et.getPrepaymentAmount(),
goodsOnOffShelveAmount = et.getGoodsOnOffShelveAmount(),
... ... @@ -85,13 +115,13 @@ public class SellerHelper {
return level;
}
public static boolean isNormalSuper(EntrySellerType est){
public static boolean isEntryPlus(EntrySellerType est){
return Objects.equals(est, EntrySellerType.SUPER_ENTRY);
}
public static boolean isSuper(EntrySellerType est){
boolean result = Objects.equals(est, EntrySellerType.SPECIAL_SUPER)
|| isNormalSuper(est)
|| isEntryPlus(est)
|| isLargeSettlement(est)
|| isFastDeliverySuper(est) ;
return result;
... ... @@ -137,11 +167,9 @@ public class SellerHelper {
sellerTypeNode.setSuper(isSuper);
}
boolean isNormalSuper = isNormalSuper(est);
if (isNormalSuper){
if (isEntryPlus(est)){
//超级卖家是否被降级
sellerTypeNode.setNormalSuper(isNormalSuper);
sellerTypeNode.setNormalSuper(true);
}
if (isLargeSettlement(est)){
... ...
... ... @@ -31,7 +31,7 @@ public class SellerWrapperTest {
for(StoredSeller storedSeller : storedSellers){
SellerWrapper sellerWrapper = new SellerWrapper(storedSeller.getUid(),logger)
.storedSellerDataSource((uid) -> storedSeller )
.addSpecialSuperFunc((uid)->false)
// .addSpecialSuperFunc((uid)->false)
.buildSellerWrapper().attachAssetPolicy();
logger.info("sellerWrapper {}", sellerWrapper);
}
... ... @@ -63,21 +63,21 @@ public class SellerWrapperTest {
@Test
public void testApplySuperEnter(){
int uid = 500031424;
sellerService.applySuperEnter(uid);
// sellerService.applySuperEnter(uid);
}
@Test
public void testAudit(){
int uid = 500031424;
long order = 6666666666L;
sellerEnterApplyService.audit(uid, order, new BigDecimal(100));
// sellerEnterApplyService.audit(uid, order, new BigDecimal(100));
}
@Test
public void testAuditCommonOrder(){
int uid = 500031424;
long order = 12345333L;
sellerEnterApplyService.audit(uid, order, new BigDecimal(3));
// sellerEnterApplyService.audit(uid, order, new BigDecimal(3));
}
@Test
... ... @@ -85,7 +85,7 @@ public class SellerWrapperTest {
int uid = 500031424;
SellerWrapper sellerWrapper =sellerService.getBaseSellerWrapper(uid);
BigDecimal left = new BigDecimal(6);
sellerEnterApplyService.changeLevel4Super(sellerWrapper, left);
// sellerEnterApplyService.changeLevel4Super(sellerWrapper, left);
}
}
}
... ...
... ... @@ -37,7 +37,7 @@ hystrix.threadpool.default.maxQueueSize=50000
hystrix.threadpool.default.queueSizeRejectionThreshold=45000
#zookeeper address
zkAddress=192.168.104.201:2181
zkAddress=192.168.104.244:2181
#zkAddress=192.168.102.45:2181
# web context
web.context=ufo-gateway
... ...
... ... @@ -37,7 +37,7 @@ hystrix.threadpool.default.maxQueueSize=50000
hystrix.threadpool.default.queueSizeRejectionThreshold=45000
#zookeeper address
zkAddress=192.168.104.201:2181
zkAddress=192.168.104.244:2181
#zkAddress=192.168.102.45:2181
# web context
web.context=ufo-gateway
... ...
redis:
gwNoSyncRedis :
servers:
- 192.168.104.201:6379
- 192.168.104.244:6379
... ...