|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.zanxiang.game.module.base.pojo.enums.PayDeviceEnum;
|
|
import com.zanxiang.game.module.base.pojo.enums.PayDeviceEnum;
|
|
import com.zanxiang.game.module.mybatis.entity.Order;
|
|
import com.zanxiang.game.module.mybatis.entity.Order;
|
|
import com.zanxiang.game.module.mybatis.entity.OrderPayParam;
|
|
import com.zanxiang.game.module.mybatis.entity.OrderPayParam;
|
|
|
|
+import com.zanxiang.game.module.mybatis.entity.User;
|
|
import com.zanxiang.game.module.sdk.enums.DeviceTypeEnum;
|
|
import com.zanxiang.game.module.sdk.enums.DeviceTypeEnum;
|
|
import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
|
|
import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
|
|
import com.zanxiang.game.module.sdk.enums.PayTypeEnum;
|
|
import com.zanxiang.game.module.sdk.enums.PayTypeEnum;
|
|
@@ -17,6 +18,7 @@ import com.zanxiang.game.module.sdk.service.*;
|
|
import com.zanxiang.game.module.sdk.service.pay.PayBaseService;
|
|
import com.zanxiang.game.module.sdk.service.pay.PayBaseService;
|
|
import com.zanxiang.game.module.sdk.util.SpringUtils;
|
|
import com.zanxiang.game.module.sdk.util.SpringUtils;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
|
+import com.zanxiang.module.util.bean.BeanUtil;
|
|
import com.zanxiang.module.util.exception.BaseException;
|
|
import com.zanxiang.module.util.exception.BaseException;
|
|
import com.zanxiang.module.web.util.IpUtil;
|
|
import com.zanxiang.module.web.util.IpUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -53,6 +55,9 @@ public class OrderPayServiceImpl implements IOrderPayService {
|
|
@Autowired
|
|
@Autowired
|
|
private IPayApplicationService payApplicationService;
|
|
private IPayApplicationService payApplicationService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserService userService;
|
|
|
|
+
|
|
@Value("${payConfig.wxPay.customH5Url}")
|
|
@Value("${payConfig.wxPay.customH5Url}")
|
|
private String customH5Url;
|
|
private String customH5Url;
|
|
|
|
|
|
@@ -63,56 +68,59 @@ public class OrderPayServiceImpl implements IOrderPayService {
|
|
private String serverUrl;
|
|
private String serverUrl;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public PayParamVO getPayParam(String code, String orderId, HttpServletRequest request) {
|
|
|
|
- Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
|
|
|
|
- .eq(Order::getOrderId, orderId));
|
|
|
|
- log.error("获取订单支付参数, code : {}, orderId : {}", code, orderId);
|
|
|
|
- if (order == null) {
|
|
|
|
- throw new BaseException("参数错误, 订单信息不存在");
|
|
|
|
- }
|
|
|
|
- if (Objects.equals(order.getStatus(), OrderStateEnum.CANCEL_PAY.getCode())) {
|
|
|
|
- throw new BaseException("订单已关闭, 请回到游戏重新下单");
|
|
|
|
- }
|
|
|
|
- if (Objects.equals(order.getStatus(), OrderStateEnum.SUCCESS_PAY.getCode())) {
|
|
|
|
- throw new BaseException("订单已支付, 请勿重复支付");
|
|
|
|
- }
|
|
|
|
|
|
+ public PayParamVO getPayParam(String code, String openId, String orderId, HttpServletRequest request) {
|
|
|
|
+ log.error("获取订单支付参数, code : {}, openId : {}, orderId : {}", code, openId, orderId);
|
|
|
|
+ Order order = this.orderFindAndCheck(orderId);
|
|
OrderPayParam orderPayParam = orderPayParamService.getOne(new LambdaQueryWrapper<OrderPayParam>()
|
|
OrderPayParam orderPayParam = orderPayParamService.getOne(new LambdaQueryWrapper<OrderPayParam>()
|
|
.eq(OrderPayParam::getOrderId, order.getOrderId()));
|
|
.eq(OrderPayParam::getOrderId, order.getOrderId()));
|
|
if (orderPayParam != null) {
|
|
if (orderPayParam != null) {
|
|
- return PayParamVO.builder()
|
|
|
|
- .orderId(orderPayParam.getOrderId())
|
|
|
|
- .appId(orderPayParam.getAppId())
|
|
|
|
- .payParam(orderPayParam.getPayParam())
|
|
|
|
- .build();
|
|
|
|
|
|
+ return BeanUtil.copy(orderPayParam, PayParamVO.class);
|
|
}
|
|
}
|
|
//创建支付参数
|
|
//创建支付参数
|
|
- ProductPayParamDTO bo = ProductPayParamDTO.builder()
|
|
|
|
- .gameId(order.getGameId())
|
|
|
|
- .userId(order.getUserId())
|
|
|
|
- .payDevice(order.getPayDeviceId())
|
|
|
|
- .deviceSystem(order.getDeviceSystem())
|
|
|
|
- .spbillCreateIp(IpUtil.getRealIp(request))
|
|
|
|
- .outTradeNo(order.getOrderId())
|
|
|
|
- .payWay(order.getPayWayId())
|
|
|
|
- .code(code)
|
|
|
|
- .build();
|
|
|
|
|
|
+ ProductPayParamDTO productPayParamDTO = this.transform(order, code, openId, IpUtil.getRealIp(request));
|
|
//调起支付
|
|
//调起支付
|
|
- PayTypeEnum payTypeEnum = PayTypeEnum.getByPayType(bo.getPayWay().intValue());
|
|
|
|
|
|
+ PayTypeEnum payTypeEnum = PayTypeEnum.getByPayType(productPayParamDTO.getPayWay().intValue());
|
|
PayBaseService service = SpringUtils.getBean(payTypeEnum.getClazz());
|
|
PayBaseService service = SpringUtils.getBean(payTypeEnum.getClazz());
|
|
- service.payCreate(bo);
|
|
|
|
|
|
+ service.payCreate(productPayParamDTO);
|
|
//重新查询
|
|
//重新查询
|
|
orderPayParam = orderPayParamService.getOne(new LambdaQueryWrapper<OrderPayParam>()
|
|
orderPayParam = orderPayParamService.getOne(new LambdaQueryWrapper<OrderPayParam>()
|
|
.eq(OrderPayParam::getOrderId, order.getOrderId()));
|
|
.eq(OrderPayParam::getOrderId, order.getOrderId()));
|
|
if (orderPayParam == null) {
|
|
if (orderPayParam == null) {
|
|
|
|
+ log.error("支付参数获取失败, orderId : {}", orderId);
|
|
throw new BaseException("支付参数获取失败");
|
|
throw new BaseException("支付参数获取失败");
|
|
}
|
|
}
|
|
- return PayParamVO.builder()
|
|
|
|
- .orderId(orderPayParam.getOrderId())
|
|
|
|
- .appId(orderPayParam.getAppId())
|
|
|
|
- .payParam(orderPayParam.getPayParam())
|
|
|
|
|
|
+ //返回支付参数
|
|
|
|
+ return BeanUtil.copy(orderPayParam, PayParamVO.class);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ProductPayParamDTO transform(Order order, String code, String openId, String ip) {
|
|
|
|
+ return ProductPayParamDTO.builder()
|
|
|
|
+ .gameId(order.getGameId())
|
|
|
|
+ .userId(order.getUserId())
|
|
|
|
+ .payDevice(order.getPayDeviceId())
|
|
|
|
+ .deviceSystem(order.getDeviceSystem())
|
|
|
|
+ .spbillCreateIp(ip)
|
|
|
|
+ .outTradeNo(order.getOrderId())
|
|
|
|
+ .payWay(order.getPayWayId())
|
|
|
|
+ .code(code)
|
|
|
|
+ .openId(openId)
|
|
.build();
|
|
.build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Order orderFindAndCheck(String orderId) {
|
|
|
|
+ Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderId, orderId));
|
|
|
|
+ if (order == null) {
|
|
|
|
+ throw new BaseException("参数错误, 订单信息不存在");
|
|
|
|
+ }
|
|
|
|
+ if (Objects.equals(order.getStatus(), OrderStateEnum.CANCEL_PAY.getCode())) {
|
|
|
|
+ throw new BaseException("订单已关闭, 请回到游戏重新下单");
|
|
|
|
+ }
|
|
|
|
+ if (Objects.equals(order.getStatus(), OrderStateEnum.SUCCESS_PAY.getCode())) {
|
|
|
|
+ throw new BaseException("订单已支付, 请勿重复支付");
|
|
|
|
+ }
|
|
|
|
+ return order;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Long getAppletPayDevice(UserData userData) {
|
|
public Long getAppletPayDevice(UserData userData) {
|
|
log.error("获取支付类型参数, 请求信息 userData : {}", JsonUtil.toString(userData));
|
|
log.error("获取支付类型参数, 请求信息 userData : {}", JsonUtil.toString(userData));
|
|
@@ -150,11 +158,15 @@ public class OrderPayServiceImpl implements IOrderPayService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> payCreate(ProductPayParam product, UserData userData) {
|
|
public Map<String, Object> payCreate(ProductPayParam product, UserData userData) {
|
|
|
|
+ //用户信息
|
|
|
|
+ User user = userService.getById(userData.getUserId());
|
|
|
|
+ if (user == null) {
|
|
|
|
+ throw new BaseException("参数错误, 用户信息不存在");
|
|
|
|
+ }
|
|
//创建订单
|
|
//创建订单
|
|
- orderService.createOrder(product, userData);
|
|
|
|
|
|
+ orderService.createOrder(product, user, userData);
|
|
//判断游戏类型
|
|
//判断游戏类型
|
|
- if (Objects.equals(PayDeviceEnum.APPLET_PAY.getPayDeviceId(), product.getPayDevice())
|
|
|
|
- || Objects.equals(PayDeviceEnum.CUSTOM_PAY.getPayDeviceId(), product.getPayDevice())) {
|
|
|
|
|
|
+ if (PayDeviceEnum.getByPayWayIdList().contains(product.getPayDevice())) {
|
|
//查询支付配置
|
|
//查询支付配置
|
|
GamePayWayDTO gamePayWayDTO = gamePayWayService.getGamePayWay(userData.getGameId(), product.getPayWay(), product.getPayDevice());
|
|
GamePayWayDTO gamePayWayDTO = gamePayWayService.getGamePayWay(userData.getGameId(), product.getPayWay(), product.getPayDevice());
|
|
//查询支付应用信息
|
|
//查询支付应用信息
|
|
@@ -166,12 +178,9 @@ public class OrderPayServiceImpl implements IOrderPayService {
|
|
paramMap.put("orderId", product.getOrderId());
|
|
paramMap.put("orderId", product.getOrderId());
|
|
paramMap.put("amount", product.getAmount());
|
|
paramMap.put("amount", product.getAmount());
|
|
paramMap.put("payH5Url", this.customH5Url);
|
|
paramMap.put("payH5Url", this.customH5Url);
|
|
|
|
+ paramMap.put("openId", user.getOpenId());
|
|
paramMap.put("description", "购买" + product.getAmount() + "元档充值");
|
|
paramMap.put("description", "购买" + product.getAmount() + "元档充值");
|
|
- if (this.serverUrl.contains("84game")) {
|
|
|
|
- paramMap.put("serverUrl", this.serverUrl + "/sdk");
|
|
|
|
- } else {
|
|
|
|
- paramMap.put("serverUrl", this.serverUrl + "/api/sdk");
|
|
|
|
- }
|
|
|
|
|
|
+ paramMap.put("serverUrl", this.serverUrl.contains("84game") ? this.serverUrl + "/sdk" : this.serverUrl + "/api/sdk");
|
|
log.error("下单参数返回, paramMap : {}", JsonUtil.toString(paramMap));
|
|
log.error("下单参数返回, paramMap : {}", JsonUtil.toString(paramMap));
|
|
return paramMap;
|
|
return paramMap;
|
|
}
|
|
}
|