Authored by qinchao

保证金预付和充值

package com.yohoufo.dal.order.model;
import lombok.Data;
import lombok.ToString;
import java.math.BigDecimal;
@Data
@ToString
public class EntrySellerRechargeOrder {
private Integer id;
... ... @@ -21,75 +26,4 @@ public class EntrySellerRechargeOrder {
private Integer updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Long getOrderCode() {
return orderCode;
}
public void setOrderCode(Long orderCode) {
this.orderCode = orderCode;
}
public Integer getPayment() {
return payment;
}
public void setPayment(Integer payment) {
this.payment = payment;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
... ...
package com.yohoufo.order.controller;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.IStoredSellerDepositService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
/**
* 入驻商户保证金
* Created by craig.qin on 2018/9/13.
... ... @@ -22,16 +22,18 @@ public class StoredSellerDepositController {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private IStoredSellerDepositService storedSellerDepositService;
/**
* 预存保证金
*/
@RequestMapping(params = "method=ufo.storedSellerOrder.depositPreStore")
@ResponseBody
public ApiResponse depositPreStore(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "amount", required = true) BigDecimal amount
) throws GatewayException {
logger.info("in ufo.StoredSellerDepositController.depositPreStore, uid {},amount {}", uid,amount);
return new ApiResponse.ApiResponseBuilder().code(200).data(null).message("预存保证金成功").build();
public ApiResponse depositPreStore(ShoppingRequest shoppingRequest) {
logger.info("in ufo.StoredSellerDepositController.depositPreStore, shoppingRequest {}", shoppingRequest);
OrderSubmitResponse orderSubmitResponse=storedSellerDepositService.depositPreStore(shoppingRequest);
return new ApiResponse.ApiResponseBuilder().code(200).data(orderSubmitResponse).message("预存保证金订单生成,请支付").build();
}
... ... @@ -40,11 +42,10 @@ public class StoredSellerDepositController {
*/
@RequestMapping(params = "method=ufo.sellerOrder.depositRecharge")
@ResponseBody
public ApiResponse depositRecharge(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "amount", required = true) BigDecimal amount) throws GatewayException {
logger.info("in ufo.StoredSellerDepositController.depositRecharge, uid {},amount {}", uid,amount);
return new ApiResponse.ApiResponseBuilder().data(null).code(200).message("充值成功").build();
public ApiResponse depositRecharge(ShoppingRequest shoppingRequest) {
logger.info("in ufo.StoredSellerDepositController.depositRecharge, shoppingRequest {}",shoppingRequest);
OrderSubmitResponse orderSubmitResponse=storedSellerDepositService.depositRecharge(shoppingRequest);
return new ApiResponse.ApiResponseBuilder().data(null).code(200).message("保证金充值订单生成,请支付").build();
}
}
... ...
package com.yohoufo.order.service;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.OrderSubmitResponse;
public interface IStoredSellerDepositService {
OrderSubmitResponse depositPreStore(ShoppingRequest shoppingRequest);
OrderSubmitResponse depositRecharge(ShoppingRequest shoppingRequest);
}
... ...
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;
}
}
... ...
... ... @@ -35,7 +35,7 @@ public class RealNameAuthorizeController {
GraphVerifyService graphVerifyService;
/**
* 获取实名认证账号信息
* 获取绑定的支付宝账号信息
*/
@RequestMapping(params = "method=ufo.user.aliPayAccountQuery")
public ApiResponse queryAuthorizeInfo( @RequestParam("uid") Integer uid) throws GatewayException {
... ... @@ -75,7 +75,6 @@ public class RealNameAuthorizeController {
return apiResponse;
}
/**
* 实名认证
* 直接绑定支付宝账号,不再与第三方校验
*/
@RequestMapping(params = "method=ufo.user.aliPayAccountBind")
... ... @@ -112,14 +111,14 @@ public class RealNameAuthorizeController {
* 是否已经芝麻认证
*/
@RequestMapping(params = "method=ufo.user.isRealNameCert")
public ApiResponse isRealNameCert(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter realNameAuthorize.isRealNameCert param reqVO is {}", reqVO);
public ApiResponse isRealNameCert(@RequestParam("uid") Integer uid) throws GatewayException {
logger.info("enter realNameAuthorize.isRealNameCert param uid is {}", uid);
//(1) 优先校验请求的参数
if (reqVO == null || reqVO.getUid() <=0 ){
if (uid == null || uid <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
ZhiMaCert zhiMaCertInfo =realNameAuthorizeService.getValidZhiMaCert(reqVO.getUid());
ZhiMaCert zhiMaCertInfo =realNameAuthorizeService.getValidZhiMaCert(uid);
boolean isZhiMaCert=false;
if(zhiMaCertInfo!=null){
isZhiMaCert=true;
... ...
... ... @@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
... ... @@ -25,14 +26,14 @@ public class StoredSellerController {
* 是否入驻商户
*/
@RequestMapping(params = "method=ufo.user.isStoredSeller")
public ApiResponse isStoredSeller(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter StoredSellerController isStoredSeller param reqVO is {}", reqVO);
public ApiResponse isStoredSeller(@RequestParam("uid") Integer uid) throws GatewayException {
logger.info("enter StoredSellerController isStoredSeller param uid is {}", uid);
//(1) 优先校验请求的参数
if (reqVO == null || reqVO.getUid() <=0 ){
if (uid == null || uid <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
boolean isStoredSeller=storedSellerService.isStoredSeller(reqVO.getUid());
boolean isStoredSeller=storedSellerService.isStoredSeller(uid);
return new ApiResponse(isStoredSeller);
}
... ...