@@ -5,9 +5,12 @@ import com.github.binarywang.wxpay.v3.util.AesUtils; | |||
import com.iformall.annotation.AuthIgnore; | |||
import com.iformall.common.ErrorCode; | |||
import com.iformall.domain.po.ProductOrder; | |||
import com.iformall.domain.po.ProductOrderPay; | |||
import com.iformall.domain.po.WxAppinfo; | |||
import com.iformall.domain.po.WxPayAccount; | |||
import com.iformall.enums.EnumAppPlat; | |||
import com.iformall.enums.EnumProductOrderPayVendor; | |||
import com.iformall.service.ProductOrderPayService; | |||
import com.iformall.service.ProductOrderService; | |||
import com.iformall.service.WxAppinfoService; | |||
import com.iformall.service.WxPayAccountService; | |||
@@ -41,7 +44,7 @@ public class CallbackPayController extends BaseController { | |||
private WxPayAccountService wxPayAccountService; | |||
@Autowired | |||
private ProductOrderService productOrderService; | |||
private ProductOrderPayService productOrderPayService; | |||
@Autowired | |||
private PayServiceFactory payServiceFactory; | |||
@@ -69,14 +72,34 @@ public class CallbackPayController extends BaseController { | |||
logger.info("微信支付回调解密数据{}"+decryptString); | |||
JSONObject jsonObject = JSONObject.parseObject(decryptString); | |||
String out_order_no = jsonObject.getString("out_trade_no"); | |||
/** | |||
* 交易类型,枚举值: | |||
* JSAPI:公众号支付 | |||
* NATIVE:扫码支付 | |||
* App:App支付 | |||
* MICROPAY:付款码支付 | |||
* MWEB:H5支付 | |||
* FACEPAY:刷脸支付 | |||
*/ | |||
String trade_type = jsonObject.getString("trade_type"); | |||
EnumProductOrderPayVendor payVendorEnum = null; | |||
if("JSAPI".equals(trade_type)){ | |||
payVendorEnum = EnumProductOrderPayVendor.PAY_WAY_WECHAT; | |||
}else if("NATIVE".equals(trade_type)){ | |||
payVendorEnum = EnumProductOrderPayVendor.PAY_WAY_WECHAT_NATIVE; | |||
} | |||
if(payVendorEnum == null){ | |||
logger.error("微信支付回调处理支付方式异常{}"+trade_type); | |||
response.setStatus(ErrorCode.SYS_SERVER_ERROR.getCode()); | |||
} | |||
ProductOrder productOrder = productOrderService.getById(Long.parseLong(out_order_no)); | |||
ProductOrderPay orderPay = productOrderPayService.getByOrder(Long.parseLong(out_order_no), payVendorEnum); | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(productOrder.getPayVendor()); | |||
productOrderService.handleProductOrderByQuery(appInfo,payAccount,productOrder,payAdapterService); | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payVendorEnum.getCode()); | |||
productOrderPayService.handleProductOrderByQuery(appInfo,payAccount,orderPay,payAdapterService); | |||
response.setStatus(200); | |||
}catch(Exception e){ | |||
logger.error("微信支付回调处理异常"+e); | |||
logger.error("微信支付回调处理异常{}"+e); | |||
response.setStatus(ErrorCode.SYS_SERVER_ERROR.getCode()); | |||
} | |||
@@ -103,10 +126,11 @@ public class CallbackPayController extends BaseController { | |||
if("payment".equals(type)){ | |||
String out_order_no = (String)pMap.get("cp_orderno"); | |||
ProductOrder productOrder = productOrderService.getById(Long.parseLong(out_order_no)); | |||
EnumProductOrderPayVendor payVendorEnum = EnumProductOrderPayVendor.PAY_WAY_TT; | |||
ProductOrderPay orderPay = productOrderPayService.getByOrder(Long.parseLong(out_order_no), payVendorEnum); | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(productOrder.getPayVendor()); | |||
productOrderService.handleProductOrderByQuery(appInfo,payAccount,productOrder,payAdapterService); | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payVendorEnum.getCode()); | |||
productOrderPayService.handleProductOrderByQuery(appInfo,payAccount,orderPay,payAdapterService); | |||
resultMap.put("err_no",0); | |||
resultMap.put("err_tips","success"); | |||
@@ -49,6 +49,9 @@ public class ProductOrderController extends BaseController { | |||
@Autowired | |||
private ProductOrderService productOrderService; | |||
@Autowired | |||
private ProductOrderPayService productOrderPayService; | |||
@Autowired | |||
private ProductService productService; | |||
@@ -132,7 +135,7 @@ public class ProductOrderController extends BaseController { | |||
@AuthIgnore | |||
@ApiOperation(value = "创建支付", notes = "") | |||
@PostMapping("createPay") | |||
public ResultData createPay(@RequestBody ProductOrder record){ | |||
public ResultData createPay(@RequestBody ProductOrderPay record){ | |||
logger.debug("[" + getIpAddr() + "] ProductOrderController::createPay"); | |||
String orderNumber = record.getOrderNumber(); | |||
String openId = record.getOpenId(); | |||
@@ -154,58 +157,59 @@ public class ProductOrderController extends BaseController { | |||
} | |||
} | |||
Long id = null; | |||
Long orderId = null; | |||
try{ | |||
id = Long.parseLong(orderNumber); | |||
orderId = Long.parseLong(orderNumber); | |||
}catch (Exception e){ } | |||
if(id == null){ | |||
if(orderId == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"订单号异常"); | |||
} | |||
ProductOrder productOrder = productOrderService.getById(id); | |||
if(productOrder == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未查询到订单"); | |||
} | |||
productOrder.setOpenId(openId); | |||
productOrder.setPayVendor(payVendor); | |||
ResultData resultData = productOrderService.createPay(productOrder); | |||
ResultData resultData = productOrderPayService.createPay(orderId, payVendorEnum, openId); | |||
return resultData; | |||
} | |||
@AuthIgnore | |||
@ApiOperation("根据id查询接口") | |||
@GetMapping("/findStatus") | |||
@ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true) | |||
public ResultData findStatus(String orderNumber) { | |||
public ResultData findStatus(String orderNumber,Integer payVendor) { | |||
logger.debug("[" + getIpAddr() + "] ProductOrderController::findStatus"); | |||
if(StringUtils.isBlank(orderNumber)){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"订单号为空"); | |||
} | |||
Long id = null; | |||
Long orderId = null; | |||
try{ | |||
id = Long.parseLong(orderNumber); | |||
orderId = Long.parseLong(orderNumber); | |||
}catch (Exception e){ } | |||
if(id == null){ | |||
if(orderId == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"订单号异常"); | |||
} | |||
ProductOrder productOrder = productOrderService.getById(id); | |||
if(productOrder == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未查询到订单"); | |||
//todo 临时兼容处理 该字段不能为空 | |||
if(payVendor == null){ | |||
payVendor = EnumProductOrderPayVendor.PAY_WAY_WECHAT.getCode(); | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"支付方式为空"); | |||
} | |||
if(productOrder.getPayVendor() == null){ | |||
return new ResultData(productOrder); | |||
EnumProductOrderPayVendor payVendoEnum = EnumProductOrderPayVendor.getEnum(payVendor); | |||
if(payVendoEnum == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"支付方式异常"); | |||
} | |||
ProductOrderPay orderPay = productOrderPayService.getByOrder(orderId, payVendoEnum); | |||
if(orderPay == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未查询到支付订单"); | |||
} | |||
if(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrder.getOrderStatus())){ | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(productOrder.getPayVendor()); | |||
if(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(orderPay.getPayOrderStatus()) | |||
|| EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENTING.getCode().equals(orderPay.getPayOrderStatus())){ | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payVendor); | |||
if(payAdapterService == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"该订单不支持当前支付"); | |||
} | |||
EnumProductOrderPayVendor payVendoEnum = EnumProductOrderPayVendor.getEnum(productOrder.getPayVendor()); | |||
WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(productOrder.getProjectType(), payVendoEnum.getPlat()); | |||
WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(orderPay.getProjectType(), payVendoEnum.getPlat()); | |||
if(appinfo == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"未找到支付应用"); | |||
} | |||
@@ -214,108 +218,108 @@ public class ProductOrderController extends BaseController { | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"未找到支付密钥"); | |||
} | |||
ResultData resultData = productOrderService.handleProductOrderByQuery(appinfo,payAccount,productOrder,payAdapterService); | |||
ResultData resultData = productOrderPayService.handleProductOrderByQuery(appinfo,payAccount,orderPay,payAdapterService); | |||
} | |||
return new ResultData(productOrder); | |||
return new ResultData(orderPay); | |||
} | |||
@AuthIgnore | |||
@ApiOperation(value = "获取详情链接", notes = "") | |||
@PostMapping("getPayUrl") | |||
public ResultData getPayUrl(@RequestBody ProductOrder record) { | |||
logger.debug("[" + getIpAddr() + "] ProductOrderController::getPayUrl"); | |||
if(StringUtils.isBlank(record.getAppId())){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "appId 不能为空"); | |||
} | |||
WxAppinfo wxAppinfo = wxAppinfoService.getOnlyByAppIdFromRedis(record.getAppId()); | |||
if(wxAppinfo == null){ | |||
return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
} | |||
if(record.getUserId() == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"用户编号为空"); | |||
} | |||
WxCUserBasicInfo basicUser = wxCUserBasicInfoService.getById(record.getUserId()); | |||
if(basicUser == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到用户"); | |||
} | |||
if(record.getProductId() == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商品编号为空"); | |||
} | |||
Product product = productService.getById(record.getProductId()); | |||
if(product == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到商品"); | |||
} | |||
if(!wxAppinfo.getProjectType().equals(product.getProjectType())){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据异常"); | |||
} | |||
try { | |||
EnumProject project = EnumProject.getEnum(wxAppinfo.getProjectType()); | |||
EnumAppPlat plat = EnumAppPlat.getByCode(wxAppinfo.getPlat()); | |||
String productScheme = Constant.mainPageUrl; | |||
String sceneParam = "t:dt_p:"+record.getProductId()+"_u:"+record.getUserId(); | |||
Date timeAfterDays = DateUtils.getTimeAfterDays(1, new Date()); | |||
Long expireTime = timeAfterDays.getTime()/1000; | |||
return schemeService.generateScheme(project,plat,productScheme,sceneParam,expireTime); | |||
} catch (MallinkException e) { | |||
return new ResultData(e.getErrorCode(), e.getMessage()); | |||
}catch (Exception e) { | |||
this.logger.error(e.getMessage(), e); | |||
return new ResultData(ErrorCode.SYS_SERVER_ERROR); | |||
} | |||
} | |||
@AuthIgnore | |||
@ApiOperation(value = "创建支付(不验证用户)", notes = "") | |||
@PostMapping("pay") | |||
public ResultData pay(@RequestBody ProductOrder record) { | |||
logger.debug("[" + getIpAddr() + "] ProductOrderController::pay"); | |||
if(record.getPayVendor() == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"支付方式为空"); | |||
} | |||
EnumProductOrderPayVendor payVendorEnum = EnumProductOrderPayVendor.getEnum(record.getPayVendor()); | |||
if(payVendorEnum == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"支付方式参数错误"); | |||
} | |||
if(EnumProductOrderPayVendor.PAY_WAY_WECHAT.getCode().equals(record.getPayVendor())){ | |||
if(StringUtils.isBlank(record.getOpenId())){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"openId为空"); | |||
} | |||
} | |||
record.setProfitSharing(payVendorEnum.getProfitSharing()); | |||
if(record.getUserId() == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"用户编号为空"); | |||
} | |||
WxCUserBasicInfo basicUser = wxCUserBasicInfoService.getById(record.getUserId()); | |||
if(basicUser == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到用户"); | |||
} | |||
if(record.getProductId() == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商品编号为空"); | |||
} | |||
Product product = productService.getById(record.getProductId()); | |||
if(product == null){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到商品"); | |||
} | |||
// @AuthIgnore | |||
// @ApiOperation(value = "获取详情链接", notes = "") | |||
// @PostMapping("getPayUrl") | |||
// public ResultData getPayUrl(@RequestBody ProductOrder record) { | |||
// logger.debug("[" + getIpAddr() + "] ProductOrderController::getPayUrl"); | |||
// if(StringUtils.isBlank(record.getAppId())){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "appId 不能为空"); | |||
// } | |||
// WxAppinfo wxAppinfo = wxAppinfoService.getOnlyByAppIdFromRedis(record.getAppId()); | |||
// if(wxAppinfo == null){ | |||
// return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
// } | |||
// | |||
// if(record.getUserId() == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"用户编号为空"); | |||
// } | |||
// WxCUserBasicInfo basicUser = wxCUserBasicInfoService.getById(record.getUserId()); | |||
// if(basicUser == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到用户"); | |||
// } | |||
// | |||
// if(record.getProductId() == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商品编号为空"); | |||
// } | |||
// Product product = productService.getById(record.getProductId()); | |||
// if(product == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到商品"); | |||
// } | |||
// | |||
// if(!wxAppinfo.getProjectType().equals(product.getProjectType())){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据异常"); | |||
// } | |||
// | |||
// try { | |||
// EnumProject project = EnumProject.getEnum(wxAppinfo.getProjectType()); | |||
// EnumAppPlat plat = EnumAppPlat.getByCode(wxAppinfo.getPlat()); | |||
// String productScheme = Constant.mainPageUrl; | |||
// String sceneParam = "t:dt_p:"+record.getProductId()+"_u:"+record.getUserId(); | |||
// Date timeAfterDays = DateUtils.getTimeAfterDays(1, new Date()); | |||
// Long expireTime = timeAfterDays.getTime()/1000; | |||
// return schemeService.generateScheme(project,plat,productScheme,sceneParam,expireTime); | |||
// } catch (MallinkException e) { | |||
// return new ResultData(e.getErrorCode(), e.getMessage()); | |||
// }catch (Exception e) { | |||
// this.logger.error(e.getMessage(), e); | |||
// return new ResultData(ErrorCode.SYS_SERVER_ERROR); | |||
// } | |||
// } | |||
record.setProductTitle(product.getTitle()); | |||
record.setProductEnTitle(product.getEnTitle()); | |||
record.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
record.setProjectType(product.getProjectType()); | |||
record.setOrderPrice(product.getSellPriceRmb()); | |||
productOrderService.saveOrUpdate(record); | |||
return productOrderService.createPay(record); | |||
} | |||
// @AuthIgnore | |||
// @ApiOperation(value = "创建支付(不验证用户)", notes = "") | |||
// @PostMapping("pay") | |||
// public ResultData pay(@RequestBody ProductOrder record) { | |||
// logger.debug("[" + getIpAddr() + "] ProductOrderController::pay"); | |||
// if(record.getPayVendor() == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"支付方式为空"); | |||
// } | |||
// EnumProductOrderPayVendor payVendorEnum = EnumProductOrderPayVendor.getEnum(record.getPayVendor()); | |||
// if(payVendorEnum == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"支付方式参数错误"); | |||
// } | |||
// | |||
// if(EnumProductOrderPayVendor.PAY_WAY_WECHAT.getCode().equals(record.getPayVendor())){ | |||
// if(StringUtils.isBlank(record.getOpenId())){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"openId为空"); | |||
// } | |||
// } | |||
//// record.setProfitSharing(payVendorEnum.getProfitSharing()); | |||
// | |||
// if(record.getUserId() == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"用户编号为空"); | |||
// } | |||
// WxCUserBasicInfo basicUser = wxCUserBasicInfoService.getById(record.getUserId()); | |||
// if(basicUser == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到用户"); | |||
// } | |||
// | |||
// if(record.getProductId() == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商品编号为空"); | |||
// } | |||
// Product product = productService.getById(record.getProductId()); | |||
// if(product == null){ | |||
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到商品"); | |||
// } | |||
// | |||
// record.setProductTitle(product.getTitle()); | |||
// record.setProductEnTitle(product.getEnTitle()); | |||
// record.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
// record.setProjectType(product.getProjectType()); | |||
// record.setOrderPrice(product.getSellPriceRmb()); | |||
// productOrderService.saveOrUpdate(record); | |||
// | |||
// return productOrderService.createPay(record); | |||
// } | |||
} |
@@ -47,9 +47,6 @@ public class ProductOrder extends TenantEntity { | |||
@io.swagger.annotations.ApiModelProperty(value="",name="remark") | |||
private String remark; | |||
@io.swagger.annotations.ApiModelProperty(value="支付侧的订单号",name="orderId") | |||
private String orderId; | |||
@io.swagger.annotations.ApiModelProperty(value="支付者",name="openId") | |||
private String openId; | |||
@@ -0,0 +1,90 @@ | |||
package com.iformall.domain.po; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.iformall.domain.po.base.TenantEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.ToString; | |||
import java.math.BigDecimal; | |||
import java.util.Date; | |||
@TableName(value = "product_order_pay") | |||
@Data | |||
@ToString(callSuper = true) | |||
@EqualsAndHashCode(callSuper = true) | |||
public class ProductOrderPay extends TenantEntity { | |||
protected Long id; | |||
@io.swagger.annotations.ApiModelProperty(value="系统订单号",name="orderId") | |||
private Long orderId; | |||
@io.swagger.annotations.ApiModelProperty(value="系统订单号",name="orderNumber") | |||
private String orderNumber; | |||
@io.swagger.annotations.ApiModelProperty(value="订单金额(分)",name="payAmount") | |||
private Integer payAmount; | |||
@io.swagger.annotations.ApiModelProperty(value="用户id",name="userId") | |||
private Long userId; | |||
@io.swagger.annotations.ApiModelProperty(value="",name="orderDetail") | |||
private String orderDetail; | |||
@io.swagger.annotations.ApiModelProperty(value="支付者",name="openId") | |||
private String openId; | |||
@io.swagger.annotations.ApiModelProperty(value="EnumProject",name="projectType") | |||
private Integer projectType; | |||
@io.swagger.annotations.ApiModelProperty(value = "EnumProductOrderPayVendor", name = "payVendor") | |||
private Integer payVendor; | |||
@io.swagger.annotations.ApiModelProperty(value="",name="ip") | |||
private String ip; | |||
@io.swagger.annotations.ApiModelProperty(value="第三方订单号",name="transactionId") | |||
private String transactionId; | |||
@io.swagger.annotations.ApiModelProperty(value="EnumPayOrderStatus",name="payOrderStatus") | |||
private Integer payOrderStatus; | |||
@io.swagger.annotations.ApiModelProperty(value="支付时间",name="payTime") | |||
private Date payTime; | |||
@io.swagger.annotations.ApiModelProperty(value="支付失败原因",name="failReason") | |||
private String failReason; | |||
@io.swagger.annotations.ApiModelProperty(value="支付渠道",name="payWay") | |||
private Integer payWay; | |||
@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
private Date createDate; | |||
@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||
private Date updateDate; | |||
@io.swagger.annotations.ApiModelProperty(value="EnumProfitSharing",name="profitSharing") | |||
private Integer profitSharing; | |||
@TableField(exist = false) | |||
private String payAmountStr; | |||
public String getPayAmountStr() { | |||
return payAmount != null ? new BigDecimal(payAmount).divide(new BigDecimal(100)).toPlainString() : payAmountStr; | |||
} | |||
@TableField(exist = false) | |||
private Date startDate; | |||
@TableField(exist = false) | |||
private Date endDate; | |||
@TableField(exist = false) | |||
private Date payStartDate; | |||
@TableField(exist = false) | |||
private Date payEndDate; | |||
@TableField(exist = false) | |||
private Integer isOrderStatus; | |||
} |
@@ -10,6 +10,7 @@ import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; | |||
import com.iformall.douyin.pay.orderQuery.QueryRefundResult; | |||
import com.iformall.douyin.pay.orderQuery.QuerySettleResult; | |||
import com.iformall.douyin.pay.preOrder.*; | |||
import com.iformall.enums.EnumPayOrderStatus; | |||
import com.iformall.enums.EnumPayStatus; | |||
import com.iformall.enums.EnumProductOrderStatus; | |||
import com.iformall.exception.MallinkException; | |||
@@ -195,15 +196,15 @@ public class DouYinPayHelper { | |||
} | |||
String orderStatus = result.getOrderStatus(); | |||
if(StringUtils.isBlank(orderStatus)){ | |||
return EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode(); | |||
return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode(); | |||
}else if("PROCESSING".equals(orderStatus)){//以观后效 | |||
return EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENTING.getCode(); | |||
return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENTING.getCode(); | |||
}else if("SUCCESS".equals(orderStatus)){ | |||
return EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode(); | |||
return EnumPayOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode(); | |||
}else if("FAIL".equals(orderStatus)){ | |||
return EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode(); | |||
return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode(); | |||
}else if("TIMEOUT".equals(orderStatus)){ | |||
return EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode(); | |||
return EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode(); | |||
} | |||
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询抖音支付状态失败"+payOrderNo); | |||
} | |||
@@ -0,0 +1,44 @@ | |||
package com.iformall.enums; | |||
/** | |||
* Created by Stormeye on 2018/08/09. | |||
*/ | |||
public enum EnumPayOrderStatus { | |||
// | |||
// ORDER_STATUS_PENDING_CREATE(0, "创建"), | |||
ORDER_STATUS_PENDING_PAYMENT(1, "待支付"), | |||
ORDER_STATUS_PENDING_PAYMENTING(2, "支付中"), | |||
ORDER_STATUS_PAYMENT_SUCCESS(3, "已支付"), | |||
ORDER_STATUS_OVERTIME_CANCEL(4, "已取消"), | |||
ORDER_STATUS_PENDING_REFUND(5,"待退款"), | |||
ORDER_STATUS_REFUND_SUCCESS(6, "已退款"), | |||
ORDER_STATUS_REFUND_FAILD(7, "退款失败"), | |||
ORDER_STATUS_REFUND_WAIT(10, "重复支付需要退款"), | |||
; | |||
public static EnumPayOrderStatus getEnum(Integer code) { | |||
for (EnumPayOrderStatus value : values()) { | |||
if (value.getCode().equals(code)) { | |||
return value; | |||
} | |||
} | |||
return null; | |||
} | |||
private Integer code; | |||
private String message; | |||
EnumPayOrderStatus(Integer code, String message) { | |||
this.code = code; | |||
this.message = message; | |||
} | |||
public Integer getCode() { | |||
return code; | |||
} | |||
public String getMessage() { | |||
return message; | |||
} | |||
} |
@@ -6,7 +6,7 @@ package com.iformall.enums; | |||
public enum EnumProductOrderPayVendor { | |||
PAY_WAY_WECHAT(1, "微信小程序",EnumAppPlat.WX.getCode(),EnumProfitSharing.PROFIT_SHARING_NO.getCode()), | |||
PAY_WAY_WECHAT_NATIVE(2, "微信Native",null,null), | |||
PAY_WAY_WECHAT_NATIVE(2, "微信Native",EnumAppPlat.WX.getCode(),EnumProfitSharing.PROFIT_SHARING_NO.getCode()), | |||
PAY_WAY_ALIPAY(3, "支付宝小程序",null,null), | |||
PAY_WAY_ALIPAY_WAP(4, "支付宝H5",null,null), | |||
PAY_WAY_TT(5, "抖音小程序",EnumAppPlat.TOUTIAO.getCode(),EnumProfitSharing.PROFIT_SHARING_NO.getCode()), | |||
@@ -13,6 +13,7 @@ public enum EnumProductType { | |||
product_1(1, "充值金币"), | |||
product_2(2, "充值套餐"), | |||
; | |||
public static EnumProductType getEnum(Integer code) { | |||
@@ -0,0 +1,19 @@ | |||
package com.iformall.mapper; | |||
import com.iformall.common.CommonMapper; | |||
import com.iformall.domain.po.ProductOrder; | |||
import com.iformall.domain.po.ProductOrderPay; | |||
import org.apache.ibatis.annotations.Param; | |||
import java.util.List; | |||
public interface ProductOrderPayMapper extends CommonMapper<ProductOrderPay, Long> { | |||
List<ProductOrderPay> findList(ProductOrderPay record); | |||
int orderPayUpdStatus(ProductOrderPay productOrderPay); | |||
ProductOrderPay selectByOrder(@Param("orderId")Long orderId, @Param("payVendor")Integer payVendor); | |||
void updStatusByOrder(@Param("orderId")Long orderId, @Param("payOrderStatus")Integer payOrderStatus); | |||
} |
@@ -0,0 +1,39 @@ | |||
package com.iformall.service; | |||
import com.github.pagehelper.PageInfo; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.domain.po.ProductOrder; | |||
import com.iformall.domain.po.ProductOrderPay; | |||
import com.iformall.domain.po.WxAppinfo; | |||
import com.iformall.domain.po.WxPayAccount; | |||
import com.iformall.enums.EnumProductOrderPayVendor; | |||
import com.iformall.service.pay.service.pay.PayAdapterService; | |||
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
import java.util.List; | |||
public interface ProductOrderPayService { | |||
/** | |||
* 根据实体查询分页列表 | |||
* | |||
* @param record | |||
* @param pageIndex | |||
* @param pageSize | |||
* @return | |||
*/ | |||
PageInfo<ProductOrderPay> listAsPage(ProductOrderPay record, Integer pageIndex, Integer pageSize); | |||
void saveOrUpdate(ProductOrderPay record); | |||
ProductOrderPay getById(Long id); | |||
ProductOrderPay getByOrder(Long orderId,EnumProductOrderPayVendor payVendorEnum); | |||
ResultData createPay(Long orderId, EnumProductOrderPayVendor payVendorEnum, String openId); | |||
ResultData handleProductOrderByQuery(WxAppinfo appinfo,WxPayAccount payAccount,ProductOrderPay productOrderPay,PayAdapterService payAdapterService); | |||
void handleProductOrderSuccess(ProductOrderPay productOrderPay, PayQueryAdapterResult result); | |||
} |
@@ -24,15 +24,10 @@ public interface ProductOrderService { | |||
ProductOrder getById(Long id); | |||
ResultData createPay(ProductOrder productOrder); | |||
ResultData handleProductOrderByQuery(WxAppinfo appinfo,WxPayAccount payAccount,ProductOrder productOrder,PayAdapterService payAdapterService); | |||
void handleProductOrderSuccess(ProductOrder productOrder, PayQueryAdapterResult result); | |||
List<ProductOrder> findList(ProductOrder record); | |||
void handldSharing(ProductOrder order); | |||
void handldTimeOut(Long id); | |||
} |
@@ -73,21 +73,21 @@ public class WxPayOrderServiceHelper { | |||
return null; | |||
} | |||
public static EnumProductOrderStatus getProductOrderStatus(String trade_state) { | |||
public static EnumPayOrderStatus getProductOrderStatus(String trade_state) { | |||
if ("SUCCESS".equals(trade_state)) { | |||
return EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS; | |||
return EnumPayOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS; | |||
}else if ("REFUND".equals(trade_state)) { | |||
return EnumProductOrderStatus.ORDER_STATUS_REFUND_SUCCESS; | |||
return EnumPayOrderStatus.ORDER_STATUS_REFUND_SUCCESS; | |||
}else if ("NOTPAY".equals(trade_state)) { | |||
return EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT; | |||
return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT; | |||
}else if ("CLOSED".equals(trade_state)) { | |||
return EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL; | |||
return EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL; | |||
}else if ("REVOKED".equals(trade_state)) { | |||
return EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT; | |||
return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT; | |||
}else if ("USERPAYING".equals(trade_state)) { | |||
return EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENTING; | |||
return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENTING; | |||
}else if ("PAYERROR".equals(trade_state)) { | |||
return EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT; | |||
return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT; | |||
} | |||
return null; | |||
} | |||
@@ -0,0 +1,283 @@ | |||
package com.iformall.service.impl; | |||
import com.github.pagehelper.PageHelper; | |||
import com.github.pagehelper.PageInfo; | |||
import com.iformall.common.ErrorCode; | |||
import com.iformall.common.IdWorker; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.domain.po.*; | |||
import com.iformall.enums.*; | |||
import com.iformall.exception.MallinkException; | |||
import com.iformall.mapper.ProductMapper; | |||
import com.iformall.mapper.ProductOrderMapper; | |||
import com.iformall.mapper.ProductOrderPayMapper; | |||
import com.iformall.mapper.ProductOrderSharingMapper; | |||
import com.iformall.service.*; | |||
import com.iformall.service.pay.PayServiceFactory; | |||
import com.iformall.service.pay.service.pay.PayAdapterService; | |||
import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
import com.iformall.utils.DateUtils; | |||
import com.iformall.utils.RedisLock; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.aop.framework.AopContext; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Propagation; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import java.util.Date; | |||
import java.util.List; | |||
@Service | |||
@Slf4j | |||
public class ProductOrderPayServiceImpl implements ProductOrderPayService { | |||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
@Autowired | |||
ProductOrderMapper productOrderMapper; | |||
@Autowired | |||
ProductOrderPayMapper productOrderPayMapper; | |||
@Autowired | |||
ProductOrderSharingMapper productOrderSharingMapper; | |||
@Autowired | |||
ProductMapper productMapper; | |||
@Autowired | |||
UserBasicPropertyService userBasicPropertyService; | |||
@Autowired | |||
WxAppinfoService wxAppinfoService; | |||
@Autowired | |||
WxPayAccountService wxPayAccountService; | |||
@Autowired | |||
PayServiceFactory payServiceFactory; | |||
@Autowired | |||
RedisLock redisLock; | |||
@Override | |||
public PageInfo<ProductOrderPay> listAsPage(ProductOrderPay record, Integer pageIndex, Integer pageSize) { | |||
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> productOrderPayMapper.findList(record)); | |||
} | |||
@Override | |||
public void saveOrUpdate(ProductOrderPay record) { | |||
Date now = new Date(); | |||
if (record.getId() == null) { | |||
final IdWorker idWorker = IdWorker.get(); | |||
record.setId(idWorker.nextId()); | |||
record.setCreateDate(now); | |||
record.setUpdateDate(now); | |||
productOrderPayMapper.insert(record); | |||
} else { | |||
record.setUpdateDate(now); | |||
productOrderPayMapper.updateById(record); | |||
} | |||
} | |||
@Override | |||
public ProductOrderPay getById(Long id) { | |||
return productOrderPayMapper.selectById(id); | |||
} | |||
@Override | |||
public ProductOrderPay getByOrder(Long orderId, EnumProductOrderPayVendor payVendorEnum) { | |||
return productOrderPayMapper.selectByOrder(orderId,payVendorEnum.getCode()); | |||
} | |||
@Override | |||
public ResultData createPay(Long orderId, EnumProductOrderPayVendor payVendorEnum, String openId) { | |||
ProductOrder productOrder = productOrderMapper.selectById(orderId); | |||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrder.getOrderStatus())){ | |||
return new ResultData(ErrorCode.ORDER_IS_FAIL.getCode(),"订单已取消或已支付"); | |||
} | |||
WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(productOrder.getProjectType(), payVendorEnum.getPlat()); | |||
if(appinfo == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"未找到支付应用"); | |||
} | |||
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appinfo.getPayId()); | |||
if(payAccount == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"未找到支付配置"); | |||
} | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payVendorEnum.getCode()); | |||
if(payAdapterService == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"不支持当前支付"); | |||
} | |||
ProductOrderPay productOrderPay = productOrderPayMapper.selectByOrder(orderId,payVendorEnum.getCode()); | |||
Date now = new Date(); | |||
if(productOrderPay != null){ | |||
ResultData resultData = handleProductOrderByQuery(appinfo,payAccount,productOrderPay,payAdapterService); | |||
if(ResultData.SUCCESS != resultData.code){ | |||
return resultData; | |||
} | |||
if(EnumPayOrderStatus.ORDER_STATUS_PENDING_REFUND.getCode().equals(productOrderPay.getPayOrderStatus()) | |||
|| EnumPayOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode().equals(productOrderPay.getPayOrderStatus()) | |||
|| EnumPayOrderStatus.ORDER_STATUS_REFUND_FAILD.getCode().equals(productOrderPay.getPayOrderStatus()) | |||
|| EnumPayOrderStatus.ORDER_STATUS_REFUND_WAIT.getCode().equals(productOrderPay.getPayOrderStatus())){ | |||
return new ResultData(ErrorCode.ORDER_IS_FAIL.getCode(),"当前订单存在异常,请查看支付记录"); | |||
} | |||
if(!EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrderPay.getPayOrderStatus())){ | |||
return new ResultData(ErrorCode.ORDER_IS_FAIL.getCode(),"订单已取消或已支付"); | |||
} | |||
}else{ | |||
productOrderPay = new ProductOrderPay(); | |||
final IdWorker idWorker = IdWorker.get(); | |||
productOrderPay.setId(idWorker.nextId()); | |||
productOrderPay.setOrderId(productOrder.getId()); | |||
productOrderPay.setOrderNumber(productOrder.getId().toString()); | |||
productOrderPay.setPayAmount(productOrder.getOrderPrice()); | |||
productOrderPay.setUserId(productOrder.getUserId()); | |||
productOrderPay.setOrderDetail(productOrder.getProductTitle()); | |||
productOrderPay.setOpenId(openId); | |||
productOrderPay.setProjectType(productOrder.getProjectType()); | |||
productOrderPay.setPayVendor(payVendorEnum.getCode()); | |||
productOrderPay.setPayOrderStatus(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
productOrderPay.setProfitSharing(payVendorEnum.getProfitSharing()); | |||
productOrderPay.setCreateDate(now); | |||
productOrderPay.setUpdateDate(now); | |||
productOrderPayMapper.insert(productOrderPay); | |||
} | |||
try { | |||
PayAdapterResult payResult = payAdapterService.createPay(productOrderPay, appinfo, payAccount); | |||
if(payResult.isSuccess()){ | |||
ProductOrderPay updPay = new ProductOrderPay(); | |||
updPay.setId(productOrder.getId()); | |||
updPay.setTransactionId(payResult.getTransactionId()); | |||
updPay.setUpdateDate(new Date()); | |||
productOrderPayMapper.updateById(updPay); | |||
return new ResultData(payResult.getData()); | |||
}else{ | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), payResult.getMsg(), payResult.getData()); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(),"支付订单异常"); | |||
} | |||
} | |||
@Override | |||
public ResultData handleProductOrderByQuery(WxAppinfo appinfo,WxPayAccount payAccount,ProductOrderPay productOrderPay,PayAdapterService payAdapterService) { | |||
try { | |||
PayQueryAdapterResult result = payAdapterService.queryPayStatus(productOrderPay, appinfo, payAccount); | |||
Integer productOrderStatus = result.getCode(); | |||
if(productOrderStatus == null){ | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(),"查询支付单异常"); | |||
} | |||
if(EnumPayOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode().equals(productOrderStatus)){ | |||
ProductOrderPayServiceImpl proxy = (ProductOrderPayServiceImpl) AopContext.currentProxy(); | |||
proxy.handleProductOrderSuccess(productOrderPay,result); | |||
}else if(EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode().equals(productOrderStatus) | |||
|| EnumPayOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode().equals(productOrderStatus)){ | |||
productOrderPay.setOpenId(result.getOpenId()); | |||
productOrderPay.setTransactionId(result.getTransactionId()); | |||
productOrderPay.setPayTime(result.getPayTime()); | |||
productOrderPay.setPayWay(result.getWay()); | |||
productOrderPay.setPayOrderStatus(productOrderStatus); | |||
// productOrder.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
productOrderPay.setUpdateDate(new Date()); | |||
int num = productOrderPayMapper.orderPayUpdStatus(productOrderPay); | |||
}else if(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrderStatus)){ | |||
}else{ | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(),"支付单状态异常"); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
} | |||
return new ResultData(); | |||
} | |||
@Override | |||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
public void handleProductOrderSuccess(ProductOrderPay productOrderPay, PayQueryAdapterResult result) { | |||
String lockKey = "productOrderPay:success:"+productOrderPay.getOrderId(); | |||
long time = System.currentTimeMillis() + 5000; | |||
String timeStr = String.valueOf(time); | |||
try{ | |||
// while (!redisLock.lock2(lockKey, timeStr)){ | |||
// Thread.sleep(1000); | |||
// } | |||
if(!redisLock.lock2(lockKey, timeStr)){ | |||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"当前订单处理中,请稍后重试"); | |||
} | |||
ProductOrderPay orderPay = productOrderPayMapper.selectById(productOrderPay.getId()); | |||
if(EnumPayOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode().equals(orderPay.getPayOrderStatus())){ | |||
return; | |||
} | |||
if(EnumPayOrderStatus.ORDER_STATUS_PENDING_REFUND.getCode().equals(productOrderPay.getPayOrderStatus()) | |||
|| EnumPayOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode().equals(productOrderPay.getPayOrderStatus()) | |||
|| EnumPayOrderStatus.ORDER_STATUS_REFUND_FAILD.getCode().equals(productOrderPay.getPayOrderStatus()) | |||
|| EnumPayOrderStatus.ORDER_STATUS_REFUND_WAIT.getCode().equals(productOrderPay.getPayOrderStatus())){ | |||
logger.info("当前支付订单已处理:"+productOrderPay.getId()); | |||
return ; | |||
} | |||
Date now = new Date(); | |||
productOrderPay.setOpenId(result.getOpenId()); | |||
productOrderPay.setTransactionId(result.getTransactionId()); | |||
productOrderPay.setPayTime(result.getPayTime()); | |||
productOrderPay.setPayOrderStatus(EnumPayOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
ProductOrder order = productOrderMapper.selectById(productOrderPay.getOrderId()); | |||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(order.getOrderStatus())){ | |||
productOrderPay.setPayOrderStatus(EnumPayOrderStatus.ORDER_STATUS_REFUND_WAIT.getCode()); | |||
} | |||
productOrderPay.setUpdateDate(now); | |||
productOrderPayMapper.orderPayUpdStatus(productOrderPay); | |||
if(EnumPayOrderStatus.ORDER_STATUS_REFUND_WAIT.getCode().equals(productOrderPay.getPayOrderStatus())){ | |||
logger.info("当前订单异常支付,退款处理"); | |||
//todo 退款 | |||
return; | |||
} | |||
order.setOpenId(productOrderPay.getOpenId()); | |||
order.setPayVendor(productOrderPay.getPayVendor()); | |||
order.setTransactionId(productOrderPay.getTransactionId()); | |||
order.setPayment(productOrderPay.getPayAmount()); | |||
order.setPaymentTime(productOrderPay.getPayTime()); | |||
order.setPayWay(productOrderPay.getPayWay()); | |||
order.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
order.setUpdateDate(now); | |||
productOrderMapper.orderPayUpdStatus(order); | |||
Product product = productMapper.selectById(order.getProductId()); | |||
if(EnumProductType.product_1.getCode().equals(product.getType())){ | |||
userBasicPropertyService.updUserGlod(order.getUserId(),product.getProjectType(),EnumPropertyLogType.RECHARGE.getCode(), | |||
order.getId(),product.getGlod(),now); | |||
}else if(EnumProductType.product_2.getCode().equals(product.getType())){ | |||
//todo 处理套餐 | |||
} | |||
}catch(MallinkException e){ | |||
throw e; | |||
}catch(Exception e){ | |||
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
}finally { | |||
redisLock.unlock(lockKey, timeStr); | |||
} | |||
} | |||
} |
@@ -10,11 +10,9 @@ import com.iformall.enums.*; | |||
import com.iformall.exception.MallinkException; | |||
import com.iformall.mapper.ProductMapper; | |||
import com.iformall.mapper.ProductOrderMapper; | |||
import com.iformall.mapper.ProductOrderPayMapper; | |||
import com.iformall.mapper.ProductOrderSharingMapper; | |||
import com.iformall.service.ProductOrderService; | |||
import com.iformall.service.UserBasicPropertyService; | |||
import com.iformall.service.WxAppinfoService; | |||
import com.iformall.service.WxPayAccountService; | |||
import com.iformall.service.*; | |||
import com.iformall.service.pay.PayServiceFactory; | |||
import com.iformall.service.pay.service.pay.PayAdapterService; | |||
import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
@@ -43,6 +41,9 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||
@Autowired | |||
ProductOrderMapper productOrderMapper; | |||
@Autowired | |||
ProductOrderPayMapper productOrderPayMapper; | |||
@Autowired | |||
ProductOrderSharingMapper productOrderSharingMapper; | |||
@@ -61,6 +62,9 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||
@Autowired | |||
PayServiceFactory payServiceFactory; | |||
@Autowired | |||
ProductOrderPayService productOrderPayService; | |||
@Autowired | |||
RedisLock redisLock; | |||
@@ -90,137 +94,6 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||
return productOrderMapper.selectById(id); | |||
} | |||
@Override | |||
public ResultData createPay(ProductOrder productOrder) { | |||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrder.getOrderStatus())){ | |||
return new ResultData(ErrorCode.ORDER_IS_FAIL.getCode(),"订单已取消或已支付"); | |||
} | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(productOrder.getPayVendor()); | |||
if(payAdapterService == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"该订单不支持当前支付"); | |||
} | |||
EnumProductOrderPayVendor payVendoEnum = EnumProductOrderPayVendor.getEnum(productOrder.getPayVendor()); | |||
WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(productOrder.getProjectType(), payVendoEnum.getPlat()); | |||
if(appinfo == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"未找到支付应用"); | |||
} | |||
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appinfo.getPayId()); | |||
if(payAccount == null){ | |||
return new ResultData(ErrorCode.ORDER_IS_NOT_PAY.getCode(),"未找到支付密钥"); | |||
} | |||
ResultData resultData = handleProductOrderByQuery(appinfo,payAccount,productOrder,payAdapterService); | |||
if(ResultData.SUCCESS != resultData.code){ | |||
return resultData; | |||
} | |||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrder.getOrderStatus())){ | |||
return new ResultData(ErrorCode.ORDER_IS_FAIL.getCode(),"订单已取消或已支付"); | |||
} | |||
try { | |||
PayAdapterResult payResult = payAdapterService.createPay(productOrder, appinfo, payAccount); | |||
if(payResult.isSuccess()){ | |||
ProductOrder updOrder = new ProductOrder(); | |||
updOrder.setId(productOrder.getId()); | |||
updOrder.setPayVendor(productOrder.getPayVendor()); | |||
updOrder.setOrderId(payResult.getTransactionId()); | |||
updOrder.setUpdateDate(new Date()); | |||
productOrderMapper.updateById(updOrder); | |||
return new ResultData(payResult.getData()); | |||
}else{ | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), payResult.getMsg(), payResult.getData()); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(),"支付订单异常"); | |||
} | |||
} | |||
@Override | |||
public ResultData handleProductOrderByQuery(WxAppinfo appinfo,WxPayAccount payAccount,ProductOrder productOrder,PayAdapterService payAdapterService) { | |||
try { | |||
PayQueryAdapterResult result = payAdapterService.queryPayStatus(productOrder, appinfo, payAccount); | |||
Integer productOrderStatus = result.getCode(); | |||
if(productOrderStatus == null){ | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(),"查询支付单异常"); | |||
} | |||
if(EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode().equals(productOrderStatus)){ | |||
ProductOrderServiceImpl proxy = (ProductOrderServiceImpl) AopContext.currentProxy(); | |||
proxy.handleProductOrderSuccess(productOrder,result); | |||
}else if(EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode().equals(productOrderStatus) | |||
|| EnumProductOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode().equals(productOrderStatus)){ | |||
productOrder.setOpenId(result.getOpenId()); | |||
productOrder.setTransactionId(result.getTransactionId()); | |||
productOrder.setPaymentTime(result.getPayTime()); | |||
productOrder.setPayWay(result.getWay()); | |||
productOrder.setOrderStatus(productOrderStatus); | |||
// productOrder.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
productOrder.setUpdateDate(new Date()); | |||
int num = productOrderMapper.orderPayUpdStatus(productOrder); | |||
}else if(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrderStatus)){ | |||
}else{ | |||
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(),"支付单状态异常"); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
} | |||
return new ResultData(); | |||
} | |||
@Override | |||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
public void handleProductOrderSuccess(ProductOrder productOrder, PayQueryAdapterResult result) { | |||
String lockKey = "productOrder:success:"+productOrder.getId(); | |||
long time = System.currentTimeMillis() + 5000; | |||
String timeStr = String.valueOf(time); | |||
try{ | |||
// while (!redisLock.lock2(lockKey, timeStr)){ | |||
// Thread.sleep(1000); | |||
// } | |||
if(!redisLock.lock2(lockKey, timeStr)){ | |||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请稍后重试"); | |||
} | |||
ProductOrder order = this.getById(productOrder.getId()); | |||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(order.getOrderStatus())){ | |||
return; | |||
} | |||
Date now = new Date(); | |||
productOrder.setOpenId(result.getOpenId()); | |||
productOrder.setTransactionId(result.getTransactionId()); | |||
productOrder.setPaymentTime(result.getPayTime()); | |||
productOrder.setPayWay(result.getWay()); | |||
productOrder.setOrderStatus(result.getCode()); | |||
productOrder.setUpdateDate(now); | |||
productOrder.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
int num = productOrderMapper.orderPayUpdStatus(productOrder); | |||
if(num == 0){ | |||
return; | |||
}else if(num > 1){ | |||
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
} | |||
Product product = productMapper.selectById(order.getProductId()); | |||
if(EnumProductType.product_1.getCode().equals(product.getType())){ | |||
userBasicPropertyService.updUserGlod(order.getUserId(),product.getProjectType(),EnumPropertyLogType.RECHARGE.getCode(), | |||
order.getId(),product.getGlod(),now); | |||
} | |||
}catch(Exception e){ | |||
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
}finally { | |||
redisLock.unlock(lockKey, timeStr); | |||
} | |||
} | |||
@Override | |||
public List<ProductOrder> findList(ProductOrder record) { | |||
return productOrderMapper.findList(record); | |||
@@ -262,6 +135,7 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||
} | |||
@Override | |||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
public void handldTimeOut(Long id) { | |||
ProductOrder productOrder = productOrderMapper.selectById(id); | |||
if(productOrder == null){ | |||
@@ -270,27 +144,39 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrder.getOrderStatus())){ | |||
return; | |||
} | |||
if(productOrder.getPayVendor() != null){ | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(productOrder.getPayVendor()); | |||
EnumProductOrderPayVendor payVendoEnum = EnumProductOrderPayVendor.getEnum(productOrder.getPayVendor()); | |||
WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(productOrder.getProjectType(), payVendoEnum.getPlat()); | |||
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appinfo.getPayId()); | |||
ResultData resultData = handleProductOrderByQuery(appinfo,payAccount,productOrder,payAdapterService); | |||
if(ResultData.SUCCESS != resultData.code){ | |||
return; | |||
ProductOrderPay orderPayQ = new ProductOrderPay(); | |||
orderPayQ.setOrderId(productOrder.getId()); | |||
List<ProductOrderPay> payList = productOrderPayMapper.findList(orderPayQ); | |||
if(payList != null && !payList.isEmpty()){ | |||
for (ProductOrderPay orderPay:payList) { | |||
PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(orderPay.getPayVendor()); | |||
EnumProductOrderPayVendor payVendoEnum = EnumProductOrderPayVendor.getEnum(orderPay.getPayVendor()); | |||
WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(orderPay.getProjectType(), payVendoEnum.getPlat()); | |||
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appinfo.getPayId()); | |||
ResultData resultData = productOrderPayService.handleProductOrderByQuery(appinfo,payAccount,orderPay,payAdapterService); | |||
if(ResultData.SUCCESS != resultData.code){ | |||
return; | |||
} | |||
} | |||
} | |||
productOrder = productOrderMapper.selectById(id); | |||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(productOrder.getOrderStatus())){ | |||
return; | |||
} | |||
Date hourDateBefore = DateUtils.getHourDateBefore(1, new Date()); | |||
if(productOrder.getCreateDate().before(hourDateBefore)){ | |||
productOrder.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
productOrder.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
productOrder.setUpdateDate(new Date()); | |||
int num = productOrderMapper.orderPayUpdStatus(productOrder); | |||
ProductOrder orderUpd = new ProductOrder(); | |||
orderUpd.setId(id); | |||
orderUpd.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
orderUpd.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
orderUpd.setUpdateDate(new Date()); | |||
int num = productOrderMapper.orderPayUpdStatus(orderUpd); | |||
if(num == 1){ | |||
productOrderPayMapper.updStatusByOrder(id,EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
} | |||
} | |||
} | |||
@@ -32,11 +32,11 @@ public interface PayAdapterService { | |||
/** | |||
* 真正支付过程,调用对应端的API调用支付 | |||
* @param payAccount WxPayAccount | |||
* @param order ProductOrder | |||
* @param orderPay ProductOrderPay | |||
* @param appInfo C端app | |||
* @throws Exception | |||
*/ | |||
public PayAdapterResult createPay(ProductOrder order,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
public PayAdapterResult createPay(ProductOrderPay orderPay,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
/** | |||
* 查询支付结果,调用对应端的API查询支付结果 | |||
@@ -49,7 +49,7 @@ public interface PayAdapterService { | |||
*/ | |||
public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
/** | |||
* 根据返回结果对象解析出支付状态 | |||
@@ -227,16 +227,16 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
DouYinCreatePreOrder preOrder = new DouYinCreatePreOrder(); | |||
preOrder.setAppId(appInfo.getAppId()); | |||
preOrder.setSercrect(appInfo.getSecret()); | |||
preOrder.setSalt(payAccount.getMerchantApiKey()); | |||
preOrder.setOutOrderNo(order.getOrderNumber()); | |||
preOrder.setTotalAmount(order.getOrderPrice()); | |||
preOrder.setSubject(appInfo.getName()+"-"+order.getProductTitle()); | |||
preOrder.setBody(appInfo.getName()+"-"+order.getProductTitle()); | |||
preOrder.setOutOrderNo(orderPay.getOrderNumber()); | |||
preOrder.setTotalAmount(orderPay.getPayAmount()); | |||
preOrder.setSubject(appInfo.getName()+"-"+orderPay.getOrderDetail()); | |||
preOrder.setBody(appInfo.getName()+"-"+orderPay.getOrderDetail()); | |||
preOrder.setValidTime(60*60); | |||
// preOrder.setNotifyUrl();//回调地址 | |||
// preOrder.setThirdpartyId();//第三方服务商ID | |||
@@ -258,12 +258,12 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
} | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getMerchantApiKey(), order.getOrderNumber(), null); | |||
int code = DouYinPayHelper.getPayStatusFromOrderQueryResult(orderQueryResult,order.getOrderNumber()); | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getMerchantApiKey(), orderPay.getOrderNumber(), null); | |||
int code = DouYinPayHelper.getPayStatusFromOrderQueryResult(orderQueryResult,orderPay.getOrderNumber()); | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(code); | |||
result.setMsg(EnumProductOrderStatus.getEnum(code).getMessage()); | |||
result.setMsg(EnumPayOrderStatus.getEnum(code).getMessage()); | |||
result.setTransactionId(orderQueryResult.getChannelNo()); | |||
result.setWay(orderQueryResult.getWay()); | |||
if(StringUtils.isNotBlank(orderQueryResult.getPayTime())){ | |||
@@ -30,7 +30,7 @@ public class WxH5PaySFTService extends BaseWxPaySFTAdapterService implements CDr | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -42,7 +42,7 @@ public class WxH5PaySFTService extends BaseWxPaySFTAdapterService implements CDr | |||
} | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -195,7 +195,7 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -267,7 +267,7 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i | |||
} | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -29,7 +29,7 @@ public class WxH5PayService extends BaseWxPayV2AdapterService implements CDrivi | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -40,7 +40,7 @@ public class WxH5PayService extends BaseWxPayV2AdapterService implements CDrivi | |||
} | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -249,7 +249,7 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -260,7 +260,7 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem | |||
} | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -217,7 +217,7 @@ public class WxMiniMaPayAdapterService extends BaseWxPayV2AdapterService impleme | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -256,7 +256,7 @@ public class WxMiniMaPayAdapterService extends BaseWxPayV2AdapterService impleme | |||
} | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
return null; | |||
} | |||
@@ -96,25 +96,25 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl | |||
return req; | |||
} | |||
private V3CreatePayReq generateCreatePayRequest(ProductOrder productOrder,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception { | |||
private V3CreatePayReq generateCreatePayRequest(ProductOrderPay productOrderPay,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception { | |||
V3CreatePayReq req = new V3CreatePayReq(); | |||
req.setAppid(appInfo.getAppId()); | |||
req.setMchid(payAccount.getSubMchId()); | |||
try { | |||
//中文必须要这样,否则会双方签名失败 | |||
req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"-"+productOrder.getProductTitle())); | |||
req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"-"+productOrderPay.getOrderDetail())); | |||
} catch (UnsupportedEncodingException e) { | |||
req.setDescription("weixin miniApp product"); | |||
} | |||
req.setOut_trade_no(productOrder.getOrderNumber()); | |||
req.setOut_trade_no(productOrderPay.getOrderNumber()); | |||
req.setNotify_url(payAccount.getPayNotifyV3Url(appInfo.getProjectType())); | |||
V3PayAmountReq amout = new V3PayAmountReq(); | |||
amout.setTotal(productOrder.getOrderPrice()); | |||
amout.setTotal(productOrderPay.getPayAmount()); | |||
req.setAmount(amout); | |||
V3Payer payer = new V3Payer(); | |||
payer.setOpenid(productOrder.getOpenId()); | |||
payer.setOpenid(productOrderPay.getOpenId()); | |||
req.setPayer(payer); | |||
return req; | |||
@@ -234,14 +234,14 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
WxPayService payService = maUtil.getWxPayServiceBySelfModel(appInfo, payAccount); | |||
V3CreatePayReq payReq = generateCreatePayRequest(order,appInfo,payAccount); | |||
V3CreatePayReq payReq = generateCreatePayRequest(orderPay,appInfo,payAccount); | |||
try { | |||
String response = WxPayV3.payCommonWithMiniApp(payService, payReq); | |||
return getOrderPResult(response,payService,appInfo,payAccount,order.getOrderNumber()); | |||
return getOrderPResult(response,payService,appInfo,payAccount,orderPay.getOrderNumber()); | |||
}catch(WxPayException e) { | |||
log.error("wexin pay v3 error",e); | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); | |||
@@ -277,7 +277,7 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl | |||
openid = payer.getString("openid"); | |||
} | |||
EnumProductOrderStatus payStatus = WxPayOrderServiceHelper.getProductOrderStatus(tradeState); | |||
EnumPayOrderStatus payStatus = WxPayOrderServiceHelper.getProductOrderStatus(tradeState); | |||
if (null == payStatus) { | |||
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态非法["+tradeState+"]"); | |||
} | |||
@@ -354,18 +354,18 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl | |||
/** | |||
* 单商户模式 | |||
* @param order | |||
* @param orderPay | |||
* @param appInfo | |||
* @param payAccount | |||
* @return | |||
* @throws Exception | |||
*/ | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
WxPayService payService = maUtil.getWxPayServiceBySelfModel(appInfo, payAccount); | |||
V3PayQuery req = new V3PayQuery(); | |||
req.setMchid(payAccount.getSubMchId()); | |||
req.setOut_trade_no(order.getOrderNumber()); | |||
req.setOut_trade_no(orderPay.getOrderNumber()); | |||
try { | |||
String response = WxPayV3.payQuery(payService, req); | |||
if (StringUtils.isBlank(response)){ | |||
@@ -377,13 +377,13 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl | |||
log.error("pay common v3 query response error",e); | |||
if("ORDER_CLOSED".equals(e.getErrCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
result.setMsg(EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getMessage()); | |||
result.setCode(EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
result.setMsg(EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getMessage()); | |||
return result; | |||
}else if("ORDER_NOT_EXIST".equals(e.getErrCode()) || "ORDERNOTEXIST".equals(e.getErrCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
result.setMsg(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getMessage()); | |||
result.setCode(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
result.setMsg(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getMessage()); | |||
return result; | |||
} | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); | |||
@@ -38,25 +38,25 @@ public class WxNativePayV3AdapterService extends BaseWxPayV3AdapterService imple | |||
@Autowired | |||
MaUtil maUtil; | |||
private V3CreatePayReq generateCreatePayRequest(ProductOrder productOrder,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception { | |||
private V3CreatePayReq generateCreatePayRequest(ProductOrderPay productOrderPay,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception { | |||
V3CreatePayReq req = new V3CreatePayReq(); | |||
req.setAppid(appInfo.getAppId()); | |||
req.setMchid(payAccount.getSubMchId()); | |||
try { | |||
//中文必须要这样,否则会双方签名失败 | |||
req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"-"+productOrder.getProductTitle())); | |||
req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"-"+productOrderPay.getOrderDetail())); | |||
} catch (UnsupportedEncodingException e) { | |||
req.setDescription("weixin miniApp product"); | |||
} | |||
req.setOut_trade_no(productOrder.getOrderNumber()); | |||
req.setOut_trade_no(productOrderPay.getOrderNumber()); | |||
req.setNotify_url(payAccount.getPayNotifyV3Url(appInfo.getProjectType())); | |||
V3PayAmountReq amout = new V3PayAmountReq(); | |||
amout.setTotal(productOrder.getOrderPrice()); | |||
amout.setTotal(productOrderPay.getPayAmount()); | |||
req.setAmount(amout); | |||
V3Payer payer = new V3Payer(); | |||
payer.setOpenid(productOrder.getOpenId()); | |||
payer.setOpenid(productOrderPay.getOpenId()); | |||
req.setPayer(payer); | |||
return req; | |||
@@ -97,14 +97,14 @@ public class WxNativePayV3AdapterService extends BaseWxPayV3AdapterService imple | |||
} | |||
@Override | |||
public PayAdapterResult createPay(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
WxPayService payService = maUtil.getWxPayServiceBySelfModel(appInfo, payAccount); | |||
V3CreatePayReq payReq = generateCreatePayRequest(order,appInfo,payAccount); | |||
V3CreatePayReq payReq = generateCreatePayRequest(orderPay,appInfo,payAccount); | |||
try { | |||
String response = WxPayV3.payCommonNative(payService, payReq); | |||
return getOrderPResult(response,payService,appInfo,payAccount,order.getOrderNumber()); | |||
return getOrderPResult(response,payService,appInfo,payAccount,orderPay.getOrderNumber()); | |||
}catch(WxPayException e) { | |||
log.error("wexin pay v3 error",e); | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); | |||
@@ -140,7 +140,7 @@ public class WxNativePayV3AdapterService extends BaseWxPayV3AdapterService imple | |||
openid = payer.getString("openid"); | |||
} | |||
EnumProductOrderStatus payStatus = WxPayOrderServiceHelper.getProductOrderStatus(tradeState); | |||
EnumPayOrderStatus payStatus = WxPayOrderServiceHelper.getProductOrderStatus(tradeState); | |||
if (null == payStatus) { | |||
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态非法["+tradeState+"]"); | |||
} | |||
@@ -200,11 +200,11 @@ public class WxNativePayV3AdapterService extends BaseWxPayV3AdapterService imple | |||
* @throws Exception | |||
*/ | |||
@Override | |||
public PayQueryAdapterResult queryPayStatus(ProductOrder order, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||
WxPayService payService = maUtil.getWxPayServiceBySelfModel(appInfo, payAccount); | |||
V3PayQuery req = new V3PayQuery(); | |||
req.setMchid(payAccount.getSubMchId()); | |||
req.setOut_trade_no(order.getOrderNumber()); | |||
req.setOut_trade_no(orderPay.getOrderNumber()); | |||
try { | |||
String response = WxPayV3.payQuery(payService, req); | |||
if (StringUtils.isBlank(response)){ | |||
@@ -216,13 +216,13 @@ public class WxNativePayV3AdapterService extends BaseWxPayV3AdapterService imple | |||
log.error("pay common v3 query response error",e); | |||
if("ORDER_CLOSED".equals(e.getErrCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
result.setMsg(EnumProductOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getMessage()); | |||
result.setCode(EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
result.setMsg(EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getMessage()); | |||
return result; | |||
}else if("ORDER_NOT_EXIST".equals(e.getErrCode()) || "ORDERNOTEXIST".equals(e.getErrCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
result.setMsg(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getMessage()); | |||
result.setCode(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
result.setMsg(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getMessage()); | |||
return result; | |||
} | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); | |||
@@ -17,7 +17,6 @@ | |||
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
<result column="remark" jdbcType="VARCHAR" property="remark"/> | |||
<result column="order_id" jdbcType="VARCHAR" property="orderId"/> | |||
<result column="open_id" jdbcType="VARCHAR" property="openId"/> | |||
<result column="profit_sharing" jdbcType="INTEGER" property="profitSharing"/> | |||
<result column="transaction_id" jdbcType="VARCHAR" property="transactionId"/> | |||
@@ -30,7 +29,7 @@ | |||
<sql id="allColumns"> | |||
`id`,`order_number`,`tenant_id`,`parent_tenant_id`,`user_id`,`product_id`,`product_title`,`product_en_title`,`order_status`, | |||
`project_type`,`pay_vendor`,`order_price`,`create_date`,`update_date`, | |||
`remark`,`order_id`,`open_id`,`profit_sharing`,`transaction_id`,`payment`,`payment_time`,`pay_way` | |||
`remark`,`open_id`,`profit_sharing`,`transaction_id`,`payment`,`payment_time`,`pay_way` | |||
</sql> | |||
<sql id="dynamicWhereConditions"> | |||
@@ -67,10 +66,6 @@ | |||
<if test=" null != projectType "> and `project_type` = #{projectType} </if> | |||
<if test=" null != payVendor "> and `pay_vendor` = #{payVendor} </if> | |||
<if test=" null != orderId "> | |||
and `order_id` = #{orderId} | |||
</if> | |||
<if test=" null != profitSharing "> | |||
and `profit_sharing` = #{profitSharing} | |||
</if> | |||
@@ -126,9 +121,15 @@ | |||
<if test=" null != openId"> | |||
,`open_id` = #{openId} | |||
</if> | |||
<if test=" null != payVendor"> | |||
,`pay_vendor` = #{payVendor} | |||
</if> | |||
<if test=" null != transactionId"> | |||
,`transaction_id` = #{transactionId} | |||
</if> | |||
<if test=" null != payment"> | |||
,`payment` = #{payment} | |||
</if> | |||
<if test=" null != paymentTime"> | |||
,`payment_time` = #{paymentTime} | |||
</if> | |||
@@ -0,0 +1,155 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.iformall.mapper.ProductOrderPayMapper"> | |||
<resultMap id="BaseResultMap" type="com.iformall.domain.po.ProductOrderPay"> | |||
<id column="id" jdbcType="BIGINT" property="id"/> | |||
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
<result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
<result column="order_id" jdbcType="BIGINT" property="orderId"/> | |||
<result column="order_number" jdbcType="VARCHAR" property="orderNumber"/> | |||
<result column="pay_amount" jdbcType="INTEGER" property="payAmount"/> | |||
<result column="user_id" jdbcType="BIGINT" property="userId"/> | |||
<result column="order_detail" jdbcType="VARCHAR" property="orderDetail"/> | |||
<result column="open_id" jdbcType="VARCHAR" property="openId"/> | |||
<result column="project_type" jdbcType="TINYINT" property="projectType"/> | |||
<result column="pay_vendor" jdbcType="TINYINT" property="payVendor" /> | |||
<result column="ip" jdbcType="VARCHAR" property="ip"/> | |||
<result column="transaction_id" jdbcType="VARCHAR" property="transactionId"/> | |||
<result column="pay_order_status" jdbcType="INTEGER" property="payOrderStatus"/> | |||
<result column="pay_time" jdbcType="TIMESTAMP" property="payTime"/> | |||
<result column="fail_reason" jdbcType="VARCHAR" property="failReason"/> | |||
<result column="pay_way" jdbcType="INTEGER" property="payWay"/> | |||
<result column="profit_sharing" jdbcType="INTEGER" property="profitSharing"/> | |||
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
</resultMap> | |||
<sql id="allColumns"> | |||
`id`,`tenant_id`,`parent_tenant_id`,`order_id`,`order_number`,`pay_amount`,`user_id`,`order_detail`,`open_id`, | |||
`project_type`,`pay_vendor`,`ip`,`transaction_id`,`pay_order_status`,`pay_time`,`fail_reason` | |||
`pay_way`,`profit_sharing`,`create_date`,`update_date` | |||
</sql> | |||
<sql id="dynamicWhereConditions"> | |||
where 1 = 1 | |||
<if test=" null != id "> | |||
and `id` = #{id} | |||
</if> | |||
<if test=" null != tenantId and '' != tenantId"> | |||
and `tenant_id` = #{tenantId} | |||
</if> | |||
<if test=" null != parentTenantId and '' != parentTenantId"> | |||
and `parent_tenant_id` = #{parentTenantId} | |||
</if> | |||
<if test=" null != orderId "> | |||
and `order_id` = #{orderId} | |||
</if> | |||
<if test=" null != orderNumber "> | |||
and `order_number` = #{orderNumber} | |||
</if> | |||
<if test=" null != userId "> | |||
and `user_id` = #{userId} | |||
</if> | |||
<if test=" null != projectType "> and `project_type` = #{projectType} </if> | |||
<if test=" null != payVendor "> and `pay_vendor` = #{payVendor} </if> | |||
<if test=" null != transactionId "> | |||
and `transaction_id` = #{transactionId} | |||
</if> | |||
<if test=" null != profitSharing "> | |||
and `profit_sharing` = #{profitSharing} | |||
</if> | |||
<if test=" null != payOrderStatus "> | |||
and `pay_order_status` = #{payOrderStatus} | |||
</if> | |||
<if test=" null != startDate "> | |||
and `create_date` >= #{startDate} | |||
</if> | |||
<if test=" null != endDate"> | |||
and `create_date` <= #{endDate} | |||
</if> | |||
<if test=" null != payStartDate "> | |||
and `pay_time` >= #{payStartDate} | |||
</if> | |||
<if test=" null != payEndDate"> | |||
and `pay_time` <= #{payEndDate} | |||
</if> | |||
<if test=" null != statusS "> | |||
and `order_status` in | |||
<foreach collection="statusS" index="index" item="sItem" open="(" separator="," close=")"> | |||
#{sItem} | |||
</foreach> | |||
</if> | |||
<if test=" null != ids "> | |||
and id in | |||
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
#{idItem} | |||
</foreach> | |||
</if> | |||
<if test=" null != sortColumns">order by ${sortColumns}</if> | |||
</sql> | |||
<select id="findList" parameterType="com.iformall.domain.po.ProductOrderPay" resultMap="BaseResultMap"> | |||
select | |||
<include refid="allColumns"/> | |||
from product_order_pay | |||
<include refid="dynamicWhereConditions"/> | |||
</select> | |||
<update id="orderPayUpdStatus" parameterType="com.iformall.domain.po.ProductOrderPay"> | |||
update product_order_pay | |||
set `pay_order_status` = #{payOrderStatus} | |||
,`update_date` = #{updateDate} | |||
<if test=" null != openId"> | |||
,`open_id` = #{openId} | |||
</if> | |||
<if test=" null != transactionId"> | |||
,`transaction_id` = #{transactionId} | |||
</if> | |||
<if test=" null != payTime"> | |||
,`pay_time` = #{payTime} | |||
</if> | |||
<if test=" null != payWay"> | |||
,`pay_way` = #{payWay} | |||
</if> | |||
where id = #{id} | |||
and `pay_order_status` != #{payOrderStatus} | |||
<if test=" null != isOrderStatus"> | |||
and `pay_order_status` = #{isOrderStatus} | |||
</if> | |||
</update> | |||
<select id="selectByOrder" parameterType="java.util.HashMap" resultMap="BaseResultMap"> | |||
select | |||
<include refid="allColumns"/> | |||
from product_order_pay | |||
where `order_id` = #{orderId} | |||
and `pay_vendor` = #{payVendor} | |||
</select> | |||
<update id="orderPayUpdStatus" parameterType="java.util.HashMap"> | |||
update product_order_pay | |||
set `pay_order_status` = #{payOrderStatus} | |||
,`update_date` = now() | |||
where `order_id` = #{orderId} | |||
</update> | |||
</mapper> |