userRecharge.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. return
  17. }
  18. p := gin.H{
  19. "appid": appid,
  20. "money": money,
  21. }
  22. global.Logger.Info("api moneyRecharge:", zap.Any("param:", p))
  23. errs := service.MoneyRecharge(appid, money, c)
  24. if errs == nil {
  25. response.Ok(c)
  26. } else {
  27. global.Logger.Error("数据库操作失败", zap.Any("error:", errs))
  28. response.FailWithMessage("充值失败", c)
  29. }
  30. }
  31. //产品剩余量充值接口
  32. func productRecharge(c *gin.Context) {
  33. appid := c.PostForm("appid")
  34. productId, err := strconv.Atoi(c.PostForm("productId"))
  35. rechargeNum, errs := strconv.Atoi(c.PostForm("rechargeNum"))
  36. endTime := c.PostForm("endTime")
  37. if err != nil || errs != nil {
  38. response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
  39. return
  40. }
  41. p := gin.H{
  42. "appid": appid,
  43. "productId": productId,
  44. "rechargeNum": rechargeNum,
  45. "endTime": endTime,
  46. }
  47. global.Logger.Info("api productRecharge:", zap.Any("param:", p))
  48. errss := service.ProductRecharge(appid, productId, rechargeNum, endTime, c)
  49. if errs == nil {
  50. response.Ok(c)
  51. } else {
  52. global.Logger.Error("数据库操作失败", zap.Any("error:", errss))
  53. response.FailWithMessage("充值失败", c)
  54. }
  55. }