|
|
@@ -47,48 +47,92 @@ public class ThirdPayBusiness {
|
|
|
|
|
|
/**
|
|
|
* 创建二维码支付的收款码
|
|
|
- * @param mapParams 三维码参数
|
|
|
+ * @param mapParams 二维码参数
|
|
|
* @return 二维信息
|
|
|
*/
|
|
|
public R<Map<String, String>> createCollectQrCode(Map<String, String> mapParams) {
|
|
|
- Long userId = Long.valueOf(mapParams.get("userId"));
|
|
|
- BigDecimal dealValue = new BigDecimal(mapParams.get("dealValue"));
|
|
|
- R<PayOrderBo> resultBo = createPayOrderBo(userId, dealValue);
|
|
|
- if (R.isError(resultBo)) {
|
|
|
- return R.fail(resultBo.getMsg());
|
|
|
- }
|
|
|
- PayOrderBo bo = resultBo.getData();
|
|
|
- R<PayOrderVo> result = createThirdPayOrder(bo);
|
|
|
+ R<PayOrderVo> result = createThirdPayOrder(mapParams);
|
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getMsg());
|
|
|
}
|
|
|
- String orderSn = result.getData().getOrderId().toString();
|
|
|
- String callBackUrl = result.getData().getBackUrl() + orderSn;
|
|
|
- bo.setBackUrl(callBackUrl);
|
|
|
+ PayOrderVo vo = result.getData();
|
|
|
|
|
|
- return createWechatQrCode(result.getData());
|
|
|
+ //请求生成二维码
|
|
|
+ return createWechatQrCode(vo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建直接支付
|
|
|
+ * @param mapParams 直接支付订单参数
|
|
|
+ * @return 支付结果
|
|
|
+ */
|
|
|
public R<String> createDirectPayment(Map<String, String> mapParams){
|
|
|
- Long userId = Long.valueOf(mapParams.get("userId"));
|
|
|
- BigDecimal dealValue = new BigDecimal(mapParams.get("dealValue"));
|
|
|
- R<PayOrderBo> resultBo = createPayOrderBo(userId, dealValue);
|
|
|
- if (R.isError(resultBo)) {
|
|
|
- return R.fail(resultBo.getMsg());
|
|
|
- }
|
|
|
- PayOrderBo bo = resultBo.getData();
|
|
|
- R<PayOrderVo> result = createThirdPayOrder(bo);
|
|
|
+ R<PayOrderVo> result = createThirdPayOrder(mapParams);
|
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getMsg());
|
|
|
}
|
|
|
PayOrderVo vo = result.getData();
|
|
|
- String orderSn = result.getData().getOrderId().toString();
|
|
|
- String callBackUrl = result.getData().getBackUrl() + orderSn;
|
|
|
- bo.setBackUrl(callBackUrl);
|
|
|
|
|
|
//请求支付
|
|
|
- return requestForPpayment(vo, mapParams);
|
|
|
+ return requestForPayment(vo, mapParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建第三方充值支付订单
|
|
|
+ * @param mapParams 订单参数
|
|
|
+ * @return 订单信息
|
|
|
+ */
|
|
|
+ public R<PayOrderVo> createThirdPayOrder(Map<String, String> mapParams) {
|
|
|
+ Long userId = Long.valueOf(mapParams.get("userId"));
|
|
|
+ BigDecimal dealValue = new BigDecimal(mapParams.get("dealValue"));
|
|
|
+ R<PayOrderBo> result = createPayOrderBo(userId, dealValue);
|
|
|
+
|
|
|
+ if (R.isError(result)) {
|
|
|
+ return R.fail(result.getMsg());
|
|
|
+ }
|
|
|
+ PayOrderBo bo = result.getData();
|
|
|
+ if (payOrderService.insertByBo(bo)) {
|
|
|
+ PayOrderVo vo = payOrderService.queryById(bo.getOrderId());
|
|
|
+ vo.setBackUrl(vo.getBackUrl() + vo.getOrderId());
|
|
|
+
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
+ log.error("[{}]-[订单创建失败]-[{}]", CreditTypeEnum.getMessage(bo.getCreditType()), JSONUtil.toJsonStr(bo));
|
|
|
+ return R.fail(MessageFormat.format("[{0}]-[订单创建失败]", CreditTypeEnum.getMessage(bo.getCreditType())));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装第三方充值支付订单业务对象
|
|
|
+ * @param userId 人员Id
|
|
|
+ * @param dealValue 充值金额
|
|
|
+ * @return 订单业务对象
|
|
|
+ */
|
|
|
+ public R<PayOrderBo> createPayOrderBo(Long userId, BigDecimal dealValue) {
|
|
|
+ PtUserAccountVo userAccountVo = userAccountService.queryById(userId);
|
|
|
+ if (ObjectUtil.isEmpty(userAccountVo)) {
|
|
|
+ return R.fail(String.format("[无此充值账户信息]-[userId:%s]", userId));
|
|
|
+ }
|
|
|
+ String callBackUrl = thirdPayConfig.getRechargeBackUrl() + "result/";
|
|
|
+ PayOrderBo payOrderBo = new PayOrderBo();
|
|
|
+ payOrderBo.setCreditTime(DateUtil.date());
|
|
|
+ payOrderBo.setCreditType(CreditTypeEnum.WECHAT_RECHARGE.code().toString());
|
|
|
+ payOrderBo.setPayStyle(PayStyleEnum.WECHAT.code().toString());
|
|
|
+ payOrderBo.setPayStatus(PayStatusEnum.UNPAID.code().toString());
|
|
|
+ payOrderBo.setReceiptMoney(dealValue);
|
|
|
+ payOrderBo.setCreditStatus(CreditStatusEnum.CREATE.code().toString());
|
|
|
+ payOrderBo.setTitle(CreditTypeEnum.WECHAT_RECHARGE.message());
|
|
|
+ payOrderBo.setBackUrl(callBackUrl);
|
|
|
+ payOrderBo.setRealName(userAccountVo.getRealName());
|
|
|
+ payOrderBo.setUserId(userAccountVo.getUserId());
|
|
|
+ payOrderBo.setPhone(userAccountVo.getPhone());
|
|
|
+ payOrderBo.setDeptName(userAccountVo.getDeptName());
|
|
|
+ payOrderBo.setDeptId(userAccountVo.getDeptId());
|
|
|
+ payOrderBo.setCreateBy(userAccountVo.getUserId());
|
|
|
+ payOrderBo.setCreateTime(DateUtil.date());
|
|
|
+
|
|
|
+ return R.ok(payOrderBo);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 第三方支付回调处理
|
|
|
* 1.更新订单的支付状态
|
|
|
@@ -131,54 +175,29 @@ public class ThirdPayBusiness {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 生成第三方支付订单
|
|
|
+ * 更新订单的支付状态
|
|
|
*
|
|
|
* @param bo 订单信息
|
|
|
- * @return 订单信息
|
|
|
+ * @return 更新结果
|
|
|
*/
|
|
|
- public R<PayOrderVo> createThirdPayOrder(PayOrderBo bo) {
|
|
|
- if (payOrderService.insertByBo(bo)) {
|
|
|
- return R.ok(payOrderService.queryById(bo.getOrderId()));
|
|
|
+ public R<PayOrderVo> setOrderPayResult(PayOrderBo bo) {
|
|
|
+ PayOrderVo vo = payOrderService.queryById(bo.getOrderId());
|
|
|
+ if (ObjectUtil.isEmpty(vo)) {
|
|
|
+ log.error("[更新订单状状态失败]-[无此支付订单]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
+ return R.fail("[更新订单状状态失败]-[无此支付订单]");
|
|
|
}
|
|
|
- log.error("[{}]-[订单创建失败]-[{}]", CreditTypeEnum.getMessage(bo.getCreditType()), JSONUtil.toJsonStr(bo));
|
|
|
- return R.fail(MessageFormat.format("[{0}]-[订单创建失败]", CreditTypeEnum.getMessage(bo.getCreditType())));
|
|
|
- }
|
|
|
-
|
|
|
- public R<PayOrderVo> createThirdPayOrder(Map<String, String> mapParams) {
|
|
|
- Long userId = Long.valueOf(mapParams.get("userId"));
|
|
|
- BigDecimal dealValue = new BigDecimal(mapParams.get("dealValue"));
|
|
|
- R<PayOrderBo> result = createPayOrderBo(userId, dealValue);
|
|
|
-
|
|
|
- if (R.isError(result)) {
|
|
|
- return R.fail(result.getMsg());
|
|
|
+ String paySn = vo.getPaySn();
|
|
|
+ if (ObjectUtil.isNotEmpty(paySn) && ObjectUtil.notEqual(paySn, bo.getPaySn())) {
|
|
|
+ log.error("[更新订单状状态失败]-[收款方流水号和系统不一致]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
+ return R.fail("[更新订单状状态失败]-[收款方流水号和系统不一致]");
|
|
|
}
|
|
|
- PayOrderBo bo = result.getData();
|
|
|
- return createThirdPayOrder(bo);
|
|
|
- }
|
|
|
-
|
|
|
- public R<PayOrderBo> createPayOrderBo(Long userId, BigDecimal dealValue) {
|
|
|
- PtUserAccountVo userAccountVo = userAccountService.queryById(userId);
|
|
|
- if (ObjectUtil.isEmpty(userAccountVo)) {
|
|
|
- return R.fail(String.format("[无此充值账户信息]-[userId:%s]", userId));
|
|
|
+ bo.setBackUrl(vo.getBackUrl() + bo.getOrderId() + "/" + bo.getPaySn());
|
|
|
+ vo = payOrderService.updateOrderStatus(bo);
|
|
|
+ if (ObjectUtil.isEmpty(vo)) {
|
|
|
+ log.error("[更新订单支付状态失败]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
+ return R.fail("[更新订单支付状态失败]");
|
|
|
}
|
|
|
- String callBackUrl = thirdPayConfig.getRechargeBackUrl() + "/result/";
|
|
|
- PayOrderBo payOrderBo = new PayOrderBo();
|
|
|
- payOrderBo.setCreditTime(DateUtil.date());
|
|
|
- payOrderBo.setCreditType(CreditTypeEnum.WECHAT_RECHARGE.code().toString());
|
|
|
- payOrderBo.setPayStyle(PayStyleEnum.WECHAT.code().toString());
|
|
|
- payOrderBo.setPayStatus(PayStatusEnum.UNPAID.code().toString());
|
|
|
- payOrderBo.setReceiptMoney(dealValue);
|
|
|
- payOrderBo.setCreditStatus(CreditStatusEnum.CREATE.code().toString());
|
|
|
- payOrderBo.setTitle(CreditTypeEnum.WECHAT_RECHARGE.message());
|
|
|
- payOrderBo.setBackUrl(callBackUrl);
|
|
|
- payOrderBo.setUserId(userAccountVo.getUserId());
|
|
|
- payOrderBo.setPhone(userAccountVo.getPhone());
|
|
|
- payOrderBo.setDeptName(userAccountVo.getDeptName());
|
|
|
- payOrderBo.setDeptId(userAccountVo.getDeptId());
|
|
|
- payOrderBo.setCreateBy(userAccountVo.getUserId());
|
|
|
- payOrderBo.setCreateTime(DateUtil.date());
|
|
|
-
|
|
|
- return R.ok(payOrderBo);
|
|
|
+ return R.ok(vo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -208,43 +227,34 @@ public class ThirdPayBusiness {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新订单的支付状态
|
|
|
+ * 更新订单的入账状态
|
|
|
*
|
|
|
* @param bo 订单信息
|
|
|
* @return 更新结果
|
|
|
*/
|
|
|
- public R<PayOrderVo> setOrderPayResult(PayOrderBo bo) {
|
|
|
- PayOrderVo vo = payOrderService.queryById(bo.getOrderId());
|
|
|
- if (ObjectUtil.isEmpty(vo)) {
|
|
|
- log.error("[更新订单状状态失败]-[无此支付订单]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
- return R.fail("[更新订单状状态失败]-[无此支付订单]");
|
|
|
- }
|
|
|
- String paySn = vo.getPaySn();
|
|
|
- if (ObjectUtil.isNotEmpty(paySn) && ObjectUtil.notEqual(paySn, bo.getPaySn())) {
|
|
|
- log.error("[更新订单状状态失败]-[收款方流水号和系统不一致]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
- return R.fail("[更新订单状状态失败]-[收款方流水号和系统不一致]");
|
|
|
- }
|
|
|
- vo = payOrderService.updateOrderStatus(bo);
|
|
|
+ public R<PayOrderVo> setOrderPostResult(PayOrderBo bo) {
|
|
|
+ PayOrderVo vo = payOrderService.updateOrderStatus(bo);
|
|
|
if (ObjectUtil.isEmpty(vo)) {
|
|
|
- log.error("[更新订单支付状态失败]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
- return R.fail("[更新订单支付状态失败]");
|
|
|
+ log.error("[更新订单入账状态失败]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
+ return R.fail("[更新订单入账状态失败]");
|
|
|
}
|
|
|
return R.ok(vo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新订单的入账状态
|
|
|
- *
|
|
|
- * @param bo 订单信息
|
|
|
- * @return 更新结果
|
|
|
+ * 根据一卡通订单号查询充值订单支付结果
|
|
|
+ * @param orderSn 订单号
|
|
|
+ * @return 查询结果
|
|
|
*/
|
|
|
- public R<PayOrderVo> setOrderPostResult(PayOrderBo bo) {
|
|
|
- PayOrderVo vo = payOrderService.updateOrderStatus(bo);
|
|
|
+ public R<Void> queryOrderPayResult(String orderSn) {
|
|
|
+ PayOrderVo vo = payOrderService.queryById(Long.valueOf(orderSn));
|
|
|
if (ObjectUtil.isEmpty(vo)) {
|
|
|
- log.error("[更新订单入账状态失败]-[{}]", JSONUtil.toJsonStr(bo));
|
|
|
- return R.fail("[更新订单入账状态失败]");
|
|
|
+ return R.fail(String.format("[无此订单]-[订单号:%s]", orderSn));
|
|
|
}
|
|
|
- return R.ok(vo);
|
|
|
+ if (ObjectUtil.equals(vo.getPayStatus(), PayStatusEnum.SUCCESS.code().toString())) {
|
|
|
+ return R.ok(String.format("[订单已支付]-[订单号:%s]", orderSn));
|
|
|
+ }
|
|
|
+ return R.fail(String.format("[订单待支付]-[订单号:%s]", orderSn));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -252,7 +262,7 @@ public class ThirdPayBusiness {
|
|
|
* @param vo 订单信息
|
|
|
* @return 二维码
|
|
|
*/
|
|
|
- public R<Map<String, String>> createWechatQrCode(PayOrderVo vo) {
|
|
|
+ private R<Map<String, String>> createWechatQrCode(PayOrderVo vo) {
|
|
|
String qrCodeUrl = thirdPayConfig.getPayApi() + "qrCode";
|
|
|
vo.setBackUrl(thirdPayConfig.getRechargeBackUrl() + vo.getOrderId());
|
|
|
HttpRequest req = HttpUtil.createPost(qrCodeUrl);
|
|
|
@@ -275,7 +285,7 @@ public class ThirdPayBusiness {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public R<String> requestForPpayment(PayOrderVo vo,Map<String, String> mapParams){
|
|
|
+ private R<String> requestForPayment(PayOrderVo vo, Map<String, String> mapParams){
|
|
|
String sendUrl = thirdPayConfig.getPayApi() + "toPay";
|
|
|
vo.setBackUrl(thirdPayConfig.getRechargeBackUrl() + vo.getOrderId());
|
|
|
HttpRequest req = HttpUtil.createPost(sendUrl);
|
|
|
@@ -306,14 +316,5 @@ public class ThirdPayBusiness {
|
|
|
return R.fail("[微信支付错误]");
|
|
|
}
|
|
|
}
|
|
|
- public R<Void> queryOrderPayResult(String orderSn) {
|
|
|
- PayOrderVo vo = payOrderService.queryById(Long.valueOf(orderSn));
|
|
|
- if (ObjectUtil.isEmpty(vo)) {
|
|
|
- return R.fail(String.format("[无此订单]-[订单号:%s]", orderSn));
|
|
|
- }
|
|
|
- if (ObjectUtil.equals(vo.getPayStatus(), PayStatusEnum.SUCCESS.code().toString())) {
|
|
|
- return R.ok(String.format("[订单已支付]-[订单号:%s]", orderSn));
|
|
|
- }
|
|
|
- return R.fail(String.format("[订单待支付]-[订单号:%s]", orderSn));
|
|
|
- }
|
|
|
+
|
|
|
}
|