...
|
...
|
@@ -4,16 +4,21 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.tools.common.beans.ApiResponse;
|
|
|
import com.yohobuy.ufo.model.enums.StoredSellerStatusEnum;
|
|
|
import com.yohobuy.ufo.model.order.common.EntrySellerDepositType;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.constants.OrderConstant;
|
|
|
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
|
|
|
import com.yohoufo.common.caller.UfoServiceCaller;
|
|
|
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
|
|
|
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
|
|
|
import com.yohoufo.order.common.Payment;
|
|
|
import com.yohoufo.order.model.request.ShoppingRequest;
|
|
|
import com.yohoufo.order.model.response.OrderSubmitResponse;
|
|
|
import com.yohoufo.order.service.IStoredSellerDepositService;
|
|
|
import com.yohoufo.order.service.MerchantOrderPaymentService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -40,6 +45,12 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi |
|
|
@Autowired
|
|
|
EntrySellerRechargeOrderMapper entrySellerRechargeOrderMapper;
|
|
|
|
|
|
@Autowired
|
|
|
SellerOrderService sellerOrderService;
|
|
|
|
|
|
@Autowired
|
|
|
MerchantOrderPaymentService merchantOrderPaymentService;
|
|
|
|
|
|
/**
|
|
|
* 充值保证金
|
|
|
*/
|
...
|
...
|
@@ -140,6 +151,114 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi |
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退出入驻
|
|
|
* @param uid
|
|
|
*/
|
|
|
@Override
|
|
|
public void quitStoredSellerAndReturnDeposit(Integer uid){
|
|
|
logger.info("StoredSellerServiceImpl quitStoredSeller enter uid is {} ",uid);
|
|
|
|
|
|
if(!isEntrySeller(uid)){
|
|
|
logger.error("StoredSellerServiceImpl quitStoredSeller store seller isEntrySeller false,uid is {} ",uid);
|
|
|
throw new ServiceException(400,"商户入驻状态为非入驻,不允许退驻!");
|
|
|
}
|
|
|
|
|
|
Integer expectStatus= StoredSellerStatusEnum.entered.getId();
|
|
|
|
|
|
// 检查商户是否有出售中的商品,或者有订单未完成的 ,都不可以提交
|
|
|
Integer total=sellerOrderService.getUnfinishedOrderBySellerUid(uid);
|
|
|
|
|
|
if(total!=null && total>0){
|
|
|
logger.error("quitStoredSeller not allowed cause of unfinished order ,uid {} ,total {}" ,uid,total);
|
|
|
throw new ServiceException(400,"商户存在未完成订单,不允许退驻!");
|
|
|
}
|
|
|
|
|
|
total=sellerOrderService.getCanSellSkupBySellerUid(uid);
|
|
|
if(total!=null && total>0){
|
|
|
logger.error("quitStoredSeller not allowed cause of can seller product ,uid {} ,total {}" ,uid,total);
|
|
|
throw new ServiceException(400,"商户存在出售中商品,不允许退驻!");
|
|
|
}
|
|
|
|
|
|
String aliPayAccount = getAlipayAccount(uid);
|
|
|
if(StringUtils.isBlank(aliPayAccount)){
|
|
|
logger.error("quitStoredSeller not allowed cause of aliPayAccount is blank ,uid {}" ,uid);
|
|
|
throw new ServiceException(400,"商户存在出售中商品,不允许退驻!");
|
|
|
}
|
|
|
|
|
|
|
|
|
ApiResponse<Integer> resp = ufoServiceCaller.call("ufo.user.updateStoredSellerQuitStatus", ApiResponse.class, uid);
|
|
|
|
|
|
logger.info("StoredSellerServiceImpl quitStoredSeller call updateStoredSellerQuitStatus ,uid is {} ,resp is {} ",uid,resp);
|
|
|
|
|
|
if(resp!=null&&resp.getCode()==200&&resp.getData()!=null&&(Integer)resp.getData()>0){
|
|
|
//创建一个退款订单
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE);
|
|
|
BigDecimal amount=BigDecimal.ZERO;
|
|
|
//保证金订单类型
|
|
|
Integer type = EntrySellerDepositType.GO_BACK.getType();
|
|
|
|
|
|
// 生成订单数据,insert db
|
|
|
EntrySellerRechargeOrder entrySellerRechargeOrder=new EntrySellerRechargeOrder();
|
|
|
entrySellerRechargeOrder.setUid(uid);
|
|
|
entrySellerRechargeOrder.setOrderCode(orderCode);
|
|
|
entrySellerRechargeOrder.setPayment(Payment.ALIPAY.getCode());
|
|
|
entrySellerRechargeOrder.setStatus(0);//0 未支付,1已支付
|
|
|
entrySellerRechargeOrder.setAmount(amount);
|
|
|
entrySellerRechargeOrder.setType(type);
|
|
|
|
|
|
int now = (int) (System.currentTimeMillis()/1000);
|
|
|
entrySellerRechargeOrder.setCreateTime(now);
|
|
|
entrySellerRechargeOrder.setUpdateTime(now);
|
|
|
|
|
|
logger.info("enter StoredSellerDepositServiceImpl quitStoredSellerAndReturnDeposit begin save entrySellerRechargeOrder {} ",entrySellerRechargeOrder);
|
|
|
int num = entrySellerRechargeOrderMapper.insert(entrySellerRechargeOrder);
|
|
|
logger.info("enter StoredSellerDepositServiceImpl quitStoredSellerAndReturnDeposit end save entrySellerRechargeOrder {} ,num {}",entrySellerRechargeOrder,num);
|
|
|
|
|
|
//获取退款金额
|
|
|
BigDecimal returnAmount = merchantOrderPaymentService.getReturnMoney(uid,orderCode);
|
|
|
// 执行退保证金的操作
|
|
|
logger.info("StoredSellerServiceImpl merchantOrderPaymentService begin ,uid {},returnAmount {} ",uid,returnAmount);
|
|
|
|
|
|
boolean returnResult=false;
|
|
|
if(returnAmount!=null){
|
|
|
returnResult=merchantOrderPaymentService.returnAllEarnest(uid,orderCode,returnAmount,aliPayAccount);
|
|
|
logger.info("StoredSellerServiceImpl merchantOrderPaymentService end ,uid {}",uid);
|
|
|
}
|
|
|
|
|
|
//退保证金成功,更新记录
|
|
|
int orderStatus=0;//未支付
|
|
|
if(returnResult){
|
|
|
orderStatus=1;//已支付
|
|
|
}
|
|
|
|
|
|
logger.info("StoredSellerServiceImpl updateReturnDepositByOrderCode ,orderCode {} ,returnAmount {} ,orderStatus {} ,ts {}",
|
|
|
orderCode,returnAmount,orderStatus,now);
|
|
|
int updateNum=entrySellerRechargeOrderMapper.updateReturnDepositByOrderCode(orderCode,
|
|
|
returnAmount==null?BigDecimal.ZERO:returnAmount,orderStatus,now);
|
|
|
logger.info("StoredSellerServiceImpl updateReturnDepositByOrderCode update num {} ,orderCode {} ,returnAmount {} ,orderStatus {} ,ts {}",updateNum,
|
|
|
orderCode,returnAmount,orderStatus,now);
|
|
|
|
|
|
}else{
|
|
|
logger.error("StoredSellerServiceImpl quitStoredSellerAndReturnDeposit update row is 0,uid {}",uid);
|
|
|
throw new ServiceException(400,"商户退驻失败,请重新检查状态!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private String getAlipayAccount(int targetUid) {
|
|
|
ApiResponse<AuthorizeResultRespVO> resp = ufoServiceCaller.call("ufo.user.aliPayAccountQuery", ApiResponse.class, targetUid);
|
|
|
if (resp != null) {
|
|
|
AuthorizeResultRespVO data = (AuthorizeResultRespVO) resp.getData();
|
|
|
if (data != null && data.getAlipayAccount() != null) {
|
|
|
return data.getAlipayAccount();
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private BigDecimal getValidMoney(String money) {
|
|
|
try {
|
|
|
BigDecimal bd = new BigDecimal(money);
|
...
|
...
|
|