|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
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.order.common.EntrySellerDepositType;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.constants.OrderConstant;
|
|
|
import com.yohoufo.common.caller.UfoServiceCaller;
|
|
|
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
|
|
|
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
|
|
|
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.support.codegenerator.OrderCodeGenerator;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
@Service
|
|
|
public class StoredSellerDepositServiceImpl implements IStoredSellerDepositService {
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(StoredSellerDepositServiceImpl.class);
|
|
|
|
|
|
|
|
|
@Value("${deposit.prestore}")
|
|
|
private Integer depositPreStore;
|
|
|
|
|
|
@Autowired
|
|
|
UfoServiceCaller ufoServiceCaller;
|
|
|
|
|
|
@Autowired
|
|
|
OrderCodeGenerator orderCodeGenerator;
|
|
|
|
|
|
@Autowired
|
|
|
EntrySellerRechargeOrderMapper entrySellerRechargeOrderMapper;
|
|
|
|
|
|
/**
|
|
|
* 充值保证金
|
|
|
*/
|
|
|
@Override
|
|
|
public OrderSubmitResponse depositRecharge(ShoppingRequest shoppingRequest){
|
|
|
logger.info("enter StoredSellerDepositServiceImpl depositRecharge {} ", JSON.toJSONString(shoppingRequest));
|
|
|
Integer uid = shoppingRequest.getUid();
|
|
|
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 ServiceException(400, "金额不合法,预存金额必须大于0");
|
|
|
}
|
|
|
|
|
|
//是否是入驻商户
|
|
|
if(!isEntrySeller(uid)){
|
|
|
throw new ServiceException(400, "不是入驻商户,无法充值!");
|
|
|
}
|
|
|
|
|
|
// 生成订单号
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE);
|
|
|
|
|
|
//保证金订单类型
|
|
|
Integer type = EntrySellerDepositType.RECHARGE.getType();
|
|
|
|
|
|
// 生成订单数据,insert db
|
|
|
EntrySellerRechargeOrder entrySellerRechargeOrder=new EntrySellerRechargeOrder();
|
|
|
entrySellerRechargeOrder.setUid(uid);
|
|
|
entrySellerRechargeOrder.setOrderCode(orderCode);
|
|
|
//entrySellerRechargeOrder.setPayment();
|
|
|
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 depositRecharge begin save entrySellerRechargeOrder {} ",entrySellerRechargeOrder);
|
|
|
int num = entrySellerRechargeOrderMapper.insert(entrySellerRechargeOrder);
|
|
|
logger.info("enter StoredSellerDepositServiceImpl depositRecharge end save entrySellerRechargeOrder {} ,num {}",entrySellerRechargeOrder,num);
|
|
|
|
|
|
// 返回结果
|
|
|
return OrderSubmitResponse.builder().orderCode(orderCode).paymentStatus(OrderConstant.N_STR).build();
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 预存保证金
|
|
|
*/
|
|
|
@Override
|
|
|
public OrderSubmitResponse depositPreStore(ShoppingRequest shoppingRequest){
|
|
|
logger.info("enter StoredSellerDepositServiceImpl depositPreStore {} ", JSON.toJSONString(shoppingRequest));
|
|
|
Integer uid = shoppingRequest.getUid();
|
|
|
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 ServiceException(400, "金额不合法,预存金额必须大于0");
|
|
|
}
|
|
|
|
|
|
if(amount.compareTo(new BigDecimal(depositPreStore))<0){
|
|
|
throw new ServiceException(400, "金额不合法,预存金额小于系统预设值");
|
|
|
}
|
|
|
|
|
|
if(!isZhiMaCertPass(uid)){
|
|
|
throw new ServiceException(400, "请先实名认证");
|
|
|
}
|
|
|
// 生成订单号
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE);
|
|
|
|
|
|
//保证金订单类型
|
|
|
Integer type = EntrySellerDepositType.PRE_STORE.getType();
|
|
|
|
|
|
// 生成订单数据,insert db
|
|
|
EntrySellerRechargeOrder entrySellerRechargeOrder=new EntrySellerRechargeOrder();
|
|
|
entrySellerRechargeOrder.setUid(uid);
|
|
|
entrySellerRechargeOrder.setOrderCode(orderCode);
|
|
|
//entrySellerRechargeOrder.setPayment();
|
|
|
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 depositPreStore begin save entrySellerRechargeOrder {} ",entrySellerRechargeOrder);
|
|
|
int num = entrySellerRechargeOrderMapper.insert(entrySellerRechargeOrder);
|
|
|
logger.info("enter StoredSellerDepositServiceImpl depositPreStore end save entrySellerRechargeOrder {} ,num {}",entrySellerRechargeOrder,num);
|
|
|
|
|
|
// 返回结果
|
|
|
return OrderSubmitResponse.builder().orderCode(orderCode).paymentStatus(OrderConstant.N_STR).build();
|
|
|
|
|
|
}
|
|
|
|
|
|
private BigDecimal getValidMoney(String money) {
|
|
|
try {
|
|
|
BigDecimal bd = new BigDecimal(money);
|
|
|
return bd;
|
|
|
} catch (Exception e) {
|
|
|
throw new ServiceException(400, "金额不合法");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否入驻商户
|
|
|
* @param targetUid
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean isEntrySeller(int targetUid) {
|
|
|
ApiResponse<Boolean> resp = ufoServiceCaller.call("ufo.user.isStoredSeller", ApiResponse.class, targetUid);
|
|
|
if (resp != null) {
|
|
|
Boolean data = (Boolean) resp.getData();
|
|
|
if (data != null) {
|
|
|
return data;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否芝麻认证通过
|
|
|
* @param targetUid
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean isZhiMaCertPass(int targetUid) {
|
|
|
ApiResponse<Boolean> resp = ufoServiceCaller.call("ufo.user.isRealNameCert", ApiResponse.class, targetUid);
|
|
|
if (resp != null) {
|
|
|
Boolean data = (Boolean) resp.getData();
|
|
|
if (data != null) {
|
|
|
return data;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
} |
...
|
...
|
|