|
|
|
|
@@ -1,9 +1,12 @@
|
|
|
|
|
package com.czg.service.order.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.exceptions.ValidateException;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
import com.czg.account.entity.ShopMerchant;
|
|
|
|
|
import com.czg.account.entity.ShopUser;
|
|
|
|
|
import com.czg.account.service.ShopMerchantService;
|
|
|
|
|
import com.czg.account.service.ShopUserService;
|
|
|
|
|
import com.czg.entity.req.*;
|
|
|
|
|
import com.czg.entity.resp.*;
|
|
|
|
|
import com.czg.order.entity.OrderInfo;
|
|
|
|
|
@@ -13,6 +16,7 @@ import com.czg.order.service.OrderPaymentService;
|
|
|
|
|
import com.czg.resp.CzgResult;
|
|
|
|
|
import com.czg.service.CzgPayService;
|
|
|
|
|
import com.czg.service.order.dto.OrderPayParamDTO;
|
|
|
|
|
import com.czg.service.order.dto.VipPayParamDTO;
|
|
|
|
|
import com.czg.service.order.enums.PayEnums;
|
|
|
|
|
import com.czg.service.order.service.PayService;
|
|
|
|
|
import com.czg.system.enums.SysParamCodeEnum;
|
|
|
|
|
@@ -39,6 +43,8 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
private ShopMerchantService shopMerchantService;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private SysParamsService sysParamsService;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private ShopUserService shopUserService;
|
|
|
|
|
@Resource
|
|
|
|
|
private CzgPayService czgPayService;
|
|
|
|
|
@Resource
|
|
|
|
|
@@ -47,8 +53,6 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
private OrderPaymentService paymentService;
|
|
|
|
|
|
|
|
|
|
private final BigDecimal MONEY_RATE = new BigDecimal("100");
|
|
|
|
|
private final String payJsonExtParam = "{\"payType\":\"1\"}";
|
|
|
|
|
private final String refundJsonExtParam = "{\"payType\":\"1\"}";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
|
|
|
|
@@ -58,7 +62,7 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
|
|
|
|
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY.getValue(), payOrderNo);
|
|
|
|
|
return h5Pay(payParam.getShopId(), new CzgH5PayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
|
|
|
|
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -66,11 +70,13 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
public CzgResult<Map<String, Object>> jsPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
|
|
|
|
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
|
|
|
|
AssertUtil.isNull(orderInfo, "订单不存在");
|
|
|
|
|
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
|
|
|
|
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
|
|
|
|
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
|
|
|
|
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI.getValue() : PayEnums.WECHAT_MINI.getValue(), payOrderNo);
|
|
|
|
|
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
|
|
|
|
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -81,7 +87,7 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
|
|
|
|
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI.getValue() : PayEnums.WECHAT_MINI.getValue(), payOrderNo);
|
|
|
|
|
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
|
|
|
|
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -92,20 +98,71 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
|
|
|
|
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN.getValue(), payOrderNo);
|
|
|
|
|
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
|
|
|
|
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam) {
|
|
|
|
|
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
|
|
|
|
AssertUtil.isNull(orderInfo, "订单不存在");
|
|
|
|
|
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
|
|
|
|
|
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount()));
|
|
|
|
|
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN.getValue(), payOrderNo);
|
|
|
|
|
return microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"点餐支付", payParam.getAuthCode(), payParam.getBuyerRemark(), payJsonExtParam));
|
|
|
|
|
"点餐支付", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CzgResult<Map<String, Object>> jsPayVip(String clintIp, VipPayParamDTO payParam) {
|
|
|
|
|
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
|
|
|
|
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
|
|
|
|
|
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
|
|
|
|
|
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
|
|
|
|
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
|
|
|
|
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, "", payParam.getAmount()));
|
|
|
|
|
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"会员充值", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam) {
|
|
|
|
|
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
|
|
|
|
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
|
|
|
|
|
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
|
|
|
|
|
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
|
|
|
|
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
|
|
|
|
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, "", payParam.getAmount()));
|
|
|
|
|
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"会员充值", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CzgResult<Map<String, Object>> scanPayVip(String clintIp, VipPayParamDTO payParam) {
|
|
|
|
|
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
|
|
|
|
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
|
|
|
|
|
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
|
|
|
|
|
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, "", payParam.getAmount()));
|
|
|
|
|
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"会员充值", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam) {
|
|
|
|
|
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
|
|
|
|
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
|
|
|
|
|
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
|
|
|
|
|
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
|
|
|
|
|
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
|
|
|
|
|
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, payParam.getAuthCode(), payParam.getAmount()));
|
|
|
|
|
return microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
|
|
|
|
|
"会员充值", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CzgResult<CzgRefundResp> refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull String refundReason, @NonNull BigDecimal refundAmount) {
|
|
|
|
|
|
|
|
|
|
@@ -150,20 +207,20 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
|
|
|
|
|
private CzgResult<Map<String, Object>> jsPay(@NonNull Long shopId, @NonNull String payType, CzgJsPayReq bizData) {
|
|
|
|
|
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
|
|
|
|
|
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
|
|
|
|
|
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
|
|
|
|
|
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
|
|
|
|
|
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
|
|
|
|
|
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
|
|
|
|
|
CzgResult<CzgJsPayResp> jsPayRespCzgResult = czgPayService.jsPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
|
|
|
|
|
return execPayResult(jsPayRespCzgResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CzgResult<Map<String, Object>> ltPay(@NonNull Long shopId, String payType, CzgLtPayReq bizData) {
|
|
|
|
|
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
|
|
|
|
|
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
|
|
|
|
|
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
|
|
|
|
|
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
|
|
|
|
|
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
|
|
|
|
|
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
|
|
|
|
|
CzgResult<CzgLtPayResp> ltPayRespCzgResult = czgPayService.ltPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
|
|
|
|
|
return execPayResult(ltPayRespCzgResult);
|
|
|
|
|
}
|
|
|
|
|
@@ -177,10 +234,10 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData) {
|
|
|
|
|
AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试");
|
|
|
|
|
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
|
|
|
|
|
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
|
|
|
|
|
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
|
|
|
|
|
AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试");
|
|
|
|
|
String firstTwoDigitsStr = bizData.getAuthCode().substring(0, 2);
|
|
|
|
|
|
|
|
|
|
// 将截取的字符串转换为整数
|
|
|
|
|
@@ -193,6 +250,8 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
} else if (firstTwoDigits >= 25 && firstTwoDigits <= 30) {
|
|
|
|
|
//支付宝支付
|
|
|
|
|
bizData.setSubAppid(shopMerchant.getAlipaySmallAppid());
|
|
|
|
|
}else {
|
|
|
|
|
throw new ValidateException("扫描码非法或暂不支持");
|
|
|
|
|
}
|
|
|
|
|
CzgResult<CzgMicroPayResp> czgScanPayResult = czgPayService.microPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
|
|
|
|
|
|
|
|
|
|
@@ -224,13 +283,16 @@ public class PayServiceImpl implements PayService {
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
case CzgH5PayResp h5PayResp -> map = JSONObject.parseObject(JSONObject.toJSONString(h5PayResp.getPayInfo()));
|
|
|
|
|
case CzgJsPayResp jsPayResp -> map = JSONObject.parseObject(JSONObject.toJSONString(jsPayResp.getPayInfo()));
|
|
|
|
|
case CzgH5PayResp h5PayResp ->
|
|
|
|
|
map = JSONObject.parseObject(JSONObject.toJSONString(h5PayResp.getPayInfo()));
|
|
|
|
|
case CzgJsPayResp jsPayResp ->
|
|
|
|
|
map = JSONObject.parseObject(JSONObject.toJSONString(jsPayResp.getPayInfo()));
|
|
|
|
|
case CzgLtPayResp ltPayResp -> {
|
|
|
|
|
map.put("payInfo", JSONObject.toJSONString(ltPayResp.getPayInfo()));
|
|
|
|
|
map.put("liteInfo", JSONObject.toJSONString(ltPayResp.getLiteInfo()));
|
|
|
|
|
}
|
|
|
|
|
case CzgScanPayResp scanPayResp -> map = JSONObject.parseObject(JSONObject.toJSONString(scanPayResp.getPayInfo()));
|
|
|
|
|
case CzgScanPayResp scanPayResp ->
|
|
|
|
|
map = JSONObject.parseObject(JSONObject.toJSONString(scanPayResp.getPayInfo()));
|
|
|
|
|
default -> throw new IllegalStateException("Unexpected value: " + data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|