Authored by tanling

支付虚实分离

... ... @@ -173,6 +173,10 @@ public class WeixinPayConfig {
//用户标识,trade_type=JSAPI,此参数必传
public static final String OPEN_ID = "openid";
public static final String LIMIT_PAY = "limit_pay";
public static final String NO_CREDIT = "no_credit";
//-------统一下单接口返回字段----------------------------------------
public static final String RETURN_CODE = "return_code";
... ...
package com.yohoufo.order.service;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class PaymentSupportService {
@Autowired
OrderCodeGenerator orderCodeGenerator;
@Autowired
BuyerOrderMapper buyerOrderMapper;
@Autowired
BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
AppraiseOrderMapper appraiseOrderMapper;
/**
* 虚拟支付
* @param orderCode
* @return
*/
public boolean isVirtualPay(long orderCode){
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
// 商家入驻保证金 ==> 用户入驻缴纳的保证金以及充值的保证金
if (codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()){
return true;
}
// 个人卖家上架保证金 ==> 用户没有入驻,上架商品缴纳的保证金
else if (codeMeta.getType() == OrderCodeType.SELLER_TYPE.getType()){
return true;
}
else if (codeMeta.getType() == OrderCodeType.BUYER_TYPE.getType()){
// 闪购寄存
return isQuickDeliverDeposite(orderCode);
}
// 寄售保证金 and 实物鉴定
else if (codeMeta.getType() == OrderCodeType.GOODS_SERVICE.getType()){
AppraiseOrder appraiseOrder = appraiseOrderMapper.selectByOrderCode(orderCode);
if (appraiseOrder != null){
if (appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()){
return true;
}else if(appraiseOrder.getAttributes() == OrderAttributes.APPRAISE.getCode()){
return false;
}
}
}
// 寄存续约费 寄存滞纳金 寄存召回运费
else if(codeMeta.getType() == OrderCodeType.STORAGE_MANAGEMENT.getType()){
return true;
}
return false;
}
private boolean isQuickDeliverDeposite(long orderCode){
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
if (buyerOrder == null){
return false;
}
// 买家订单属性 ==>寄存
if (buyerOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()){
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
if (buyerOrderGoods == null){
return false;
}
// 卖家订单属性==> 闪购
SellerOrderGoods sellerOrder = sellerOrderGoodsMapper.selectByPrimaryKey(buyerOrderGoods.getSkup());
if (sellerOrder!=null && sellerOrder.getAttributes() == OrderAttributes.QUICK_DELIVER.getCode()){
return true;
}
}
return false;
}
}
... ...
... ... @@ -19,6 +19,7 @@ import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.model.TransferData;
import com.yohoufo.order.service.PaymentSupportService;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
... ... @@ -69,6 +70,9 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
return "";
}
@Autowired
PaymentSupportService paymentSupportService;
@Autowired
OrderCodeGenerator orderCodeGenerator;
... ... @@ -651,9 +655,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
tradeNo = outTradeNo;
}
// 入驻or充值 不允许用支付信用卡入口
CodeMeta codeMeta = orderCodeGenerator.expId(Long.parseLong(tradeNo));
if (codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()){
if (paymentSupportService.isVirtualPay(Long.parseLong(tradeNo))){
params.put("disable_pay_channels", "credit_group"); // 禁用信用卡
}
... ...
... ... @@ -15,6 +15,7 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.service.PaymentSupportService;
import com.yohoufo.order.service.pay.AbstractPayService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -39,6 +40,9 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
@Autowired
private HttpClient httpClient;
@Autowired
PaymentSupportService paymentSupportService;
protected abstract String getMchId();
protected abstract String getMchKey();
... ... @@ -506,6 +510,12 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
parameters.put(WeixinPayConfig.ApiConstants.OPEN_ID, orderInfo.getOpenid());
}
parameters.put(WeixinPayConfig.ApiConstants.TIME_EXPIRE, getPayExpireTimeStr(orderInfo));
// 虚拟支付
if (paymentSupportService.isVirtualPay(orderInfo.getOrderCode())) {
parameters.put(WeixinPayConfig.ApiConstants.LIMIT_PAY, WeixinPayConfig.ApiConstants.NO_CREDIT);
}
//md5签名
String sign = WXUtils.signMd5(parameters, getMchKey());
parameters.put(WeixinPayConfig.ApiConstants.SIGN, sign);
... ...