Parcourir la source

fix : SDK新增提现记录提交接口

bilingfeng il y a 1 an
Parent
commit
e3dd2f3390

+ 34 - 4
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/enums/PayWayEnum.java

@@ -52,15 +52,45 @@ public enum PayWayEnum {
      * @param payWayId : 支付类型
      * @return : 支付类型枚举
      */
-    public static String getByPayWayId(Long payWayId) {
+    public static String getNameByPayWayId(Long payWayId) {
         if (payWayId == null) {
             return Strings.EMPTY;
         }
+        PayWayEnum payWayEnum = PayWayEnum.getByPayWayId(payWayId.intValue());
+        //获取支付名称
+        return payWayEnum == null ? Strings.EMPTY : payWayEnum.getPayWayName();
+    }
+
+    /**
+     * 根据支付类型id获取名称
+     *
+     * @param payWayId : 支付类型
+     * @return : 支付类型枚举
+     */
+    public static String getKeyByPayWayId(Integer payWayId) {
+        if (payWayId == null) {
+            return Strings.EMPTY;
+        }
+        PayWayEnum payWayEnum = PayWayEnum.getByPayWayId(payWayId);
+        //获取支付名称
+        return payWayEnum == null ? Strings.EMPTY : payWayEnum.getPayWayKey();
+    }
+
+    /**
+     * 根据支付类型id获取名称
+     *
+     * @param payWayId : 支付类型
+     * @return : 支付类型枚举
+     */
+    public static PayWayEnum getByPayWayId(Integer payWayId) {
+        if (payWayId == null) {
+            return null;
+        }
         for (PayWayEnum payWayEnum : PayWayEnum.values()) {
-            if (Objects.equals(payWayId.intValue(), payWayEnum.getPayWayId())) {
-                return payWayEnum.getPayWayName();
+            if (Objects.equals(payWayId, payWayEnum.getPayWayId())) {
+                return payWayEnum;
             }
         }
-        return Strings.EMPTY;
+        return null;
     }
 }

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GamePayWayServiceImpl.java

@@ -70,7 +70,7 @@ public class GamePayWayServiceImpl extends ServiceImpl<GamePayWayMapper, GamePay
                 .gameId(param.getGameId())
                 .payWayId(param.getPayWayId())
                 .payDeviceId(param.getPayDeviceId())
-                .payName(PayWayEnum.getByPayWayId(param.getPayWayId()) + PayDeviceEnum.getByPayWayId(param.getPayDeviceId()))
+                .payName(PayWayEnum.getNameByPayWayId(param.getPayWayId()) + PayDeviceEnum.getByPayWayId(param.getPayDeviceId()))
                 .remark(param.getRemark())
                 .status(StatusEnum.YES.getCode())
                 .isDelete(DeleteEnum.NO.getCode())

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/OrderServiceImpl.java

@@ -188,7 +188,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
             orderVO.setGameCategoryName(gameCategoryEnum == null ? null : gameCategoryEnum.getName());
         }
         //支付渠道, 场景
-        orderVO.setPayWayName(PayWayEnum.getByPayWayId(orderVO.getPayWayId()));
+        orderVO.setPayWayName(PayWayEnum.getNameByPayWayId(orderVO.getPayWayId()));
         orderVO.setPayDeviceName(PayDeviceEnum.getByPayWayId(orderVO.getPayDeviceId()));
     }
 

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/PayMerchantServiceImpl.java

@@ -170,7 +170,7 @@ public class PayMerchantServiceImpl extends ServiceImpl<PayMerchantMapper, PayMe
             }
         }
         //支付渠道
-        payMerchantListVO.setPayWayName(PayWayEnum.getByPayWayId(payMerchantListVO.getPayWayId()));
+        payMerchantListVO.setPayWayName(PayWayEnum.getNameByPayWayId(payMerchantListVO.getPayWayId()));
         //支付方式
         String payDeviceIds = payMerchant.getPayDeviceIds();
         if (Strings.isBlank(payDeviceIds)) {

+ 76 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameRemitLog.java

@@ -0,0 +1,76 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-17
+ * @description : 游戏提现记录
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_game_remit_log")
+public class GameRemitLog implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 用户id
+     */
+    private Long userId;
+
+    /**
+     * 游戏id
+     */
+    private Long gameId;
+
+    /**
+     * 交易订单号
+     */
+    private String merchantOrderNo;
+
+    /**
+     * 金额(单位 : 分)
+     */
+    private Long amount;
+
+    /**
+     * 提现平台
+     */
+    private String payPlatform;
+
+    /**
+     * 提现账号
+     */
+    private String payAccount;
+
+    /**
+     * 提现时间
+     */
+    private LocalDateTime createdTime;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+}

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/GameRemitLogMapper.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.mybatis.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zanxiang.game.module.mybatis.entity.GameRemitLog;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-17
+ * @description : ${description}
+ */
+public interface GameRemitLogMapper extends BaseMapper<GameRemitLog> {
+}

+ 36 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/RemitController.java

@@ -0,0 +1,36 @@
+package com.zanxiang.game.module.sdk.controller;
+
+import com.zanxiang.game.module.sdk.pojo.param.GameRemitLogParam;
+import com.zanxiang.game.module.sdk.service.IGameRemitLogService;
+import com.zanxiang.module.util.pojo.ResultVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-17
+ * @description : 提现
+ */
+@Api(tags = "注册登录接口")
+@RestController
+@RequestMapping(value = "/api/remit")
+public class RemitController {
+
+    @Autowired
+    private IGameRemitLogService gameRemitLogService;
+
+    @ApiOperation(value = "游戏提现记录日志推送")
+    @PostMapping("/log/push")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameRemitLogParam param) {
+        return ResultVO.ok(gameRemitLogService.addOrUpdate(param));
+    }
+}

+ 64 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/param/GameRemitLogParam.java

@@ -0,0 +1,64 @@
+package com.zanxiang.game.module.sdk.pojo.param;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-17
+ * @description : 游戏提现参数
+ */
+@Data
+public class GameRemitLogParam {
+
+    /**
+     * 用户id
+     */
+    @NotNull(message = "用户id不可为空")
+    private Long userId;
+
+    /**
+     * 游戏id
+     */
+    @NotBlank(message = "游戏应用id不可为空")
+    private String appId;
+
+    /**
+     * 交易订单号
+     */
+    @NotBlank(message = "交易订单号不可为空")
+    private String merchantOrderNo;
+
+    /**
+     * 金额(单位 : 分)
+     */
+    @NotNull(message = "金额不可为空")
+    private Long amount;
+
+    /**
+     * 提现平台,  1 : 支付宝, 2 : 微信
+     */
+    @NotNull(message = "提现平台不可为空")
+    private Integer payPlatform;
+
+    /**
+     * 提现账号
+     */
+    @NotBlank(message = "提现账号不可为空")
+    private String payAccount;
+
+    /**
+     * 提现时间
+     */
+    @NotBlank(message = "提现时间不可为空")
+    private LocalDateTime createdTime;
+
+    /**
+     * 加密标识
+     */
+    @NotBlank(message = "加密标识不可为空")
+    private String sign;
+}

+ 21 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameRemitLogService.java

@@ -0,0 +1,21 @@
+package com.zanxiang.game.module.sdk.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.GameRemitLog;
+import com.zanxiang.game.module.sdk.pojo.param.GameRemitLogParam;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-17
+ * @description : 游戏提现记录
+ */
+public interface IGameRemitLogService extends IService<GameRemitLog> {
+
+    /**
+     * 添加或更新
+     *
+     * @param param 参数
+     * @return boolean
+     */
+    boolean addOrUpdate(GameRemitLogParam param);
+}

+ 87 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameRemitLogServiceImpl.java

@@ -0,0 +1,87 @@
+package com.zanxiang.game.module.sdk.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.base.pojo.enums.PayWayEnum;
+import com.zanxiang.game.module.mybatis.entity.GameExt;
+import com.zanxiang.game.module.mybatis.entity.GameRemitLog;
+import com.zanxiang.game.module.mybatis.mapper.GameRemitLogMapper;
+import com.zanxiang.game.module.sdk.pojo.param.GameRemitLogParam;
+import com.zanxiang.game.module.sdk.service.IGameExtService;
+import com.zanxiang.game.module.sdk.service.IGameRemitLogService;
+import com.zanxiang.game.module.sdk.util.SignUtil;
+import com.zanxiang.module.util.exception.BaseException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.Objects;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-17
+ * @description : 游戏提现记录
+ */
+@Slf4j
+@Service
+public class GameRemitLogServiceImpl extends ServiceImpl<GameRemitLogMapper, GameRemitLog> implements IGameRemitLogService {
+
+    @Autowired
+    private IGameExtService gameExtService;
+
+    @Override
+    public boolean addOrUpdate(GameRemitLogParam param) {
+        GameExt gameExt = gameExtService.getByGameAppId(param.getAppId());
+        StringBuilder sb = new StringBuilder();
+        sb.append("payKey=").append(gameExt.getPayKey());
+        sb.append("&appId=").append(param.getAppId());
+        sb.append("&userId=").append(param.getUserId());
+        sb.append("&merchantOrderNo=").append(param.getMerchantOrderNo());
+        sb.append("&createdTime=").append(param.getCreatedTime());
+
+        log.error("加密签名字符串, str : {}", sb.toString());
+
+        String mySign;
+        try {
+            mySign = SignUtil.MD5(sb.toString());
+        } catch (Exception e) {
+            log.error("md5工具类加密异常, str : {}, e : {}", sb.toString(), e.getMessage());
+            throw new BaseException("MD5加密异常");
+        }
+        //签名错误
+        if (!Objects.equals(mySign, param.getSign())) {
+            log.error("游戏提现签名验证失败, mySign : {}, sign : {}", mySign, param.getSign());
+            throw new BaseException("签名验证失败");
+        }
+        GameRemitLog gameRemitLog = super.getOne(new LambdaQueryWrapper<GameRemitLog>()
+                .eq(GameRemitLog::getMerchantOrderNo, param.getMerchantOrderNo()));
+        if (gameRemitLog == null) {
+            gameRemitLog = this.transform(param, gameExt.getGameId());
+        } else {
+            gameRemitLog.setUserId(param.getUserId());
+            gameRemitLog.setGameId(gameExt.getGameId());
+            gameRemitLog.setAmount(param.getAmount());
+            gameRemitLog.setPayPlatform(PayWayEnum.getKeyByPayWayId(param.getPayPlatform()));
+            gameRemitLog.setPayAccount(param.getPayAccount());
+            gameRemitLog.setCreatedTime(param.getCreatedTime());
+            gameRemitLog.setUpdateTime(LocalDateTime.now());
+        }
+        return super.saveOrUpdate(gameRemitLog);
+    }
+
+    private GameRemitLog transform(GameRemitLogParam param, Long gameId) {
+        return GameRemitLog.builder()
+                .userId(param.getUserId())
+                .gameId(gameId)
+                .merchantOrderNo(param.getMerchantOrderNo())
+                .amount(param.getAmount())
+                .payPlatform(PayWayEnum.getKeyByPayWayId(param.getPayPlatform()))
+                .payAccount(param.getPayAccount())
+                .createdTime(param.getCreatedTime())
+                .createTime(LocalDateTime.now())
+                .updateTime(LocalDateTime.now())
+                .build();
+    }
+
+}