app_elec.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package http
  2. import (
  3. "go-common/app/interface/main/creative/model/elec"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/net/metadata"
  7. "strconv"
  8. )
  9. var (
  10. cb = &elec.ChargeBill{}
  11. recl = &elec.RecentElecList{}
  12. )
  13. func appElecBill(c *bm.Context) {
  14. ip := metadata.String(c, metadata.RemoteIP)
  15. req := c.Request
  16. params := req.Form
  17. ck := c.Request.Header.Get("cookie")
  18. ak := params.Get("access_key")
  19. pageStr := params.Get("pn")
  20. psStr := params.Get("ps")
  21. midStr, _ := c.Get("mid")
  22. mid := midStr.(int64)
  23. if mid <= 0 {
  24. c.JSON(nil, ecode.CreativeNotLogin)
  25. return
  26. }
  27. pn, _ := strconv.Atoi(pageStr)
  28. if pn <= 0 {
  29. pn = 1
  30. }
  31. ps, _ := strconv.Atoi(psStr)
  32. if ps <= 0 || ps > 20 {
  33. ps = 20
  34. }
  35. bal, err := elecSvc.Balance(c, mid, ip)
  36. if err != nil {
  37. c.JSON(nil, err)
  38. return
  39. }
  40. var bil *elec.ChargeBill
  41. elecStat, _ := elecSvc.UserState(c, mid, ip, ak, ck)
  42. if elecStat != nil && elecStat.State == "2" {
  43. bil, _ = elecSvc.AppDailyBill(c, mid, pn, ps, ip)
  44. }
  45. if bil == nil {
  46. bil = cb
  47. }
  48. c.JSON(map[string]interface{}{
  49. "balance": bal,
  50. "bill": bil,
  51. }, nil)
  52. }
  53. func appElecRecentRank(c *bm.Context) {
  54. req := c.Request
  55. params := req.Form
  56. ip := metadata.String(c, metadata.RemoteIP)
  57. ck := c.Request.Header.Get("cookie")
  58. ak := params.Get("access_key")
  59. pageStr := params.Get("pn")
  60. psStr := params.Get("ps")
  61. midStr, _ := c.Get("mid")
  62. mid := midStr.(int64)
  63. if mid <= 0 {
  64. c.JSON(nil, ecode.CreativeNotLogin)
  65. return
  66. }
  67. pn, _ := strconv.Atoi(pageStr)
  68. if pn <= 0 {
  69. pn = 1
  70. }
  71. ps, _ := strconv.Atoi(psStr)
  72. if ps <= 0 || ps > 20 {
  73. ps = 20
  74. }
  75. var rec *elec.RecentElecList
  76. elecStat, _ := elecSvc.UserState(c, mid, ip, ak, ck)
  77. if elecStat != nil && elecStat.State == "2" {
  78. rec, _ = elecSvc.RecentElec(c, mid, pn, ps, ip)
  79. }
  80. if rec == nil {
  81. rec = recl
  82. }
  83. c.JSON(rec, nil)
  84. }