userRecharge.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package v1
  2. import (
  3. "encoding/json"
  4. "sfbase/global"
  5. "sfis/model/response"
  6. "sfis/service"
  7. "strconv"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. )
  11. //充值相关接口服务
  12. func RechargeApiRegister(router *gin.Engine) {
  13. routerGroup := router.Group("/sfis/api/v1/user/")
  14. routerGroup.Use()
  15. {
  16. routerGroup.POST("/moneyRecharge", moneyRecharge)
  17. routerGroup.POST("/productRecharge", productRecharge)
  18. }
  19. }
  20. //余额充值接口
  21. func moneyRecharge(c *gin.Context) {
  22. appid := c.PostForm("appid")
  23. money, err := strconv.Atoi(c.PostForm("money"))
  24. if err != nil {
  25. response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
  26. }
  27. p := gin.H{
  28. "appid": appid,
  29. "money": money,
  30. }
  31. bs, _ := json.Marshal(p)
  32. param := string(bs)
  33. global.Logger.Info("api moneyRecharge:", zap.Any("param:", param))
  34. service.MoneyRecharge(appid, money, c)
  35. }
  36. //产品剩余量充值接口
  37. func productRecharge(c *gin.Context) {
  38. appid := c.PostForm("appid")
  39. productId, err := strconv.Atoi(c.PostForm("productId"))
  40. rechargeNum, errs := strconv.Atoi(c.PostForm("rechargeNum"))
  41. endTime := c.PostForm("endTime")
  42. if err != nil || errs != nil {
  43. response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
  44. }
  45. p := gin.H{
  46. "appid": appid,
  47. "productId": productId,
  48. "rechargeNum": rechargeNum,
  49. "endTime": endTime,
  50. }
  51. bs, _ := json.Marshal(p)
  52. param := string(bs)
  53. global.Logger.Info("api productRecharge:", zap.Any("param:", param))
  54. service.ProductRecharge(appid, productId, rechargeNum, endTime, c)
  55. }