userRecharge.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package user
  2. import (
  3. "sfbase/global"
  4. "sfis/model/response"
  5. "sfis/service"
  6. "strconv"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. )
  10. //余额充值接口
  11. func moneyRecharge(c *gin.Context) {
  12. appid := c.PostForm("appid")
  13. money, err := strconv.Atoi(c.PostForm("money"))
  14. if err != nil {
  15. response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
  16. }
  17. p := gin.H{
  18. "appid": appid,
  19. "money": money,
  20. }
  21. global.Logger.Info("api moneyRecharge:", zap.Any("param:", p))
  22. errs := service.MoneyRecharge(appid, money, c)
  23. if errs == nil {
  24. response.Ok(c)
  25. } else {
  26. global.Logger.Error("数据库操作失败", zap.Any("error:", errs))
  27. response.FailWithMessage("充值失败", c)
  28. }
  29. }
  30. //产品剩余量充值接口
  31. func productRecharge(c *gin.Context) {
  32. appid := c.PostForm("appid")
  33. productId, err := strconv.Atoi(c.PostForm("productId"))
  34. rechargeNum, errs := strconv.Atoi(c.PostForm("rechargeNum"))
  35. endTime := c.PostForm("endTime")
  36. if err != nil || errs != nil {
  37. response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
  38. }
  39. p := gin.H{
  40. "appid": appid,
  41. "productId": productId,
  42. "rechargeNum": rechargeNum,
  43. "endTime": endTime,
  44. }
  45. global.Logger.Info("api productRecharge:", zap.Any("param:", p))
  46. errss := service.ProductRecharge(appid, productId, rechargeNum, endTime, c)
  47. if errs == nil {
  48. response.Ok(c)
  49. } else {
  50. global.Logger.Error("数据库操作失败", zap.Any("error:", errss))
  51. response.FailWithMessage("充值失败", c)
  52. }
  53. }