xuzhiheng 4 жил өмнө
parent
commit
ecab48ce40

+ 0 - 60
api/v1/userRecharge.go

@@ -1,60 +0,0 @@
-package v1
-
-import (
-	"encoding/json"
-	"sfbase/global"
-	"sfis/model/response"
-	"sfis/service"
-	"strconv"
-
-	"github.com/gin-gonic/gin"
-	"go.uber.org/zap"
-)
-
-//充值相关接口服务
-func RechargeApiRegister(router *gin.Engine) {
-	routerGroup := router.Group("/sfis/api/v1/user/")
-	routerGroup.Use()
-	{
-		routerGroup.POST("/moneyRecharge", moneyRecharge)
-		routerGroup.POST("/productRecharge", productRecharge)
-	}
-}
-
-//余额充值接口
-func moneyRecharge(c *gin.Context) {
-	appid := c.PostForm("appid")
-	money, err := strconv.Atoi(c.PostForm("money"))
-	if err != nil {
-		response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
-	}
-	p := gin.H{
-		"appid": appid,
-		"money": money,
-	}
-	bs, _ := json.Marshal(p)
-	param := string(bs)
-	global.Logger.Info("api moneyRecharge:", zap.Any("param:", param))
-	service.MoneyRecharge(appid, money, c)
-}
-
-//产品剩余量充值接口
-func productRecharge(c *gin.Context) {
-	appid := c.PostForm("appid")
-	productId, err := strconv.Atoi(c.PostForm("productId"))
-	rechargeNum, errs := strconv.Atoi(c.PostForm("rechargeNum"))
-	endTime := c.PostForm("endTime")
-	if err != nil || errs != nil {
-		response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
-	}
-	p := gin.H{
-		"appid":       appid,
-		"productId":   productId,
-		"rechargeNum": rechargeNum,
-		"endTime":     endTime,
-	}
-	bs, _ := json.Marshal(p)
-	param := string(bs)
-	global.Logger.Info("api productRecharge:", zap.Any("param:", param))
-	service.ProductRecharge(appid, productId, rechargeNum, endTime, c)
-}

+ 7 - 4
manage/user/user.go

@@ -2,11 +2,12 @@ package user
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
-	"github.com/gin-gonic/gin"
-	"go.uber.org/zap"
 	"log"
 	"log"
 	"sfbase/global"
 	"sfbase/global"
 
 
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
+
 	sutils "sfbase/utils"
 	sutils "sfbase/utils"
 	"sfis/model"
 	"sfis/model"
 	"sfis/model/response"
 	"sfis/model/response"
@@ -23,6 +24,8 @@ func DevUserManageRegister(router *gin.Engine) {
 		userGroup.POST("/create", userCreate)
 		userGroup.POST("/create", userCreate)
 		userGroup.POST("/userProductChoose", userProductChoose)
 		userGroup.POST("/userProductChoose", userProductChoose)
 		userGroup.POST("/userProductList", userProductList)
 		userGroup.POST("/userProductList", userProductList)
+		userGroup.POST("/moneyRecharge", moneyRecharge)
+		userGroup.POST("/productRecharge", productRecharge)
 	}
 	}
 }
 }
 
 
@@ -30,7 +33,7 @@ func DevUserManageRegister(router *gin.Engine) {
 func userCreate(c *gin.Context) {
 func userCreate(c *gin.Context) {
 	var user model.User
 	var user model.User
 	if err := c.ShouldBind(&user); err != nil {
 	if err := c.ShouldBind(&user); err != nil {
-		response.FailWithMessage("参数错误",c)
+		response.FailWithMessage("参数错误", c)
 		return
 		return
 	}
 	}
 	global.Logger.Info("manage userCreate接口参数:", zap.Any("param", user))
 	global.Logger.Info("manage userCreate接口参数:", zap.Any("param", user))
@@ -39,7 +42,7 @@ func userCreate(c *gin.Context) {
 	key := sutils.GetComplexRandom(8, 3, 5)
 	key := sutils.GetComplexRandom(8, 3, 5)
 	user.SecretKey = key
 	user.SecretKey = key
 	user.AppID = appId
 	user.AppID = appId
-	service.CreateUser(user,c)
+	service.CreateUser(user, c)
 
 
 }
 }
 
 

+ 0 - 1
router/route.go

@@ -17,7 +17,6 @@ func InitRouter(middleware ...gin.HandlerFunc) *gin.Engine {
 		})
 		})
 	})
 	})
 	v1.ProjectApiRegister(router)
 	v1.ProjectApiRegister(router)
-	v1.RechargeApiRegister(router)
 	user.DevUserManageRegister(router)
 	user.DevUserManageRegister(router)
 	product.ProductManageRegister(router)
 	product.ProductManageRegister(router)
 	return router
 	return router

+ 4 - 17
service/userRecharge.go

@@ -1,11 +1,9 @@
 package service
 package service
 
 
 import (
 import (
-	"sfbase/global"
 	"sfis/db"
 	"sfis/db"
 	"sfis/lock"
 	"sfis/lock"
 	"sfis/model"
 	"sfis/model"
-	"sfis/model/response"
 
 
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin"
 
 
@@ -13,11 +11,10 @@ import (
 	"sfis/utils"
 	"sfis/utils"
 	"time"
 	"time"
 
 
-	"go.uber.org/zap"
 	"gorm.io/gorm"
 	"gorm.io/gorm"
 )
 )
 
 
-func MoneyRecharge(appid string, money int, context *gin.Context) {
+func MoneyRecharge(appid string, money int, context *gin.Context) error {
 	//取出用户锁
 	//取出用户锁
 	lock.MainLock.Lock()
 	lock.MainLock.Lock()
 	userLock := lock.UserLockMap[appid]
 	userLock := lock.UserLockMap[appid]
@@ -46,15 +43,10 @@ func MoneyRecharge(appid string, money int, context *gin.Context) {
 		}
 		}
 		return nil
 		return nil
 	})
 	})
-	if errs == nil {
-		response.Ok(context)
-	} else {
-		global.Logger.Error("数据库操作失败", zap.Any("error:", errs))
-		response.FailWithMessage("充值失败", context)
-	}
+	return errs
 }
 }
 
 
-func ProductRecharge(appid string, productId, rechargeNum int, endTime string, context *gin.Context) {
+func ProductRecharge(appid string, productId, rechargeNum int, endTime string, context *gin.Context) error {
 	//取出用户锁
 	//取出用户锁
 	lock.MainLock.Lock()
 	lock.MainLock.Lock()
 	userLock := lock.UserLockMap[appid]
 	userLock := lock.UserLockMap[appid]
@@ -105,10 +97,5 @@ func ProductRecharge(appid string, productId, rechargeNum int, endTime string, c
 		}
 		}
 		return nil
 		return nil
 	})
 	})
-	if errs == nil {
-		response.Ok(context)
-	} else {
-		global.Logger.Error("数据库操作失败", zap.Any("error:", errs))
-		response.FailWithMessage("充值失败", context)
-	}
+	return errs
 }
 }