stat.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/spy/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func updateStatState(c *bm.Context) {
  10. var (
  11. params = c.Request.Form
  12. state int64
  13. id int64
  14. operater string
  15. err error
  16. )
  17. state, err = strconv.ParseInt(params.Get("state"), 10, 8)
  18. if err != nil {
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. id, err = strconv.ParseInt(params.Get("id"), 10, 64)
  23. if err != nil {
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. operater = params.Get("operater")
  28. if operater == "" {
  29. c.JSON(nil, ecode.RequestErr)
  30. return
  31. }
  32. err = spySrv.UpdateState(c, int8(state), id, operater)
  33. if err != nil {
  34. log.Error("spySrv.UpdateState error(%v)", err)
  35. c.JSON(nil, err)
  36. return
  37. }
  38. c.JSON(nil, nil)
  39. }
  40. func updateStatQuantity(c *bm.Context) {
  41. var (
  42. params = c.Request.Form
  43. count int64
  44. id int64
  45. operater string
  46. err error
  47. )
  48. count, err = strconv.ParseInt(params.Get("count"), 10, 64)
  49. if err != nil {
  50. c.JSON(nil, ecode.RequestErr)
  51. return
  52. }
  53. id, err = strconv.ParseInt(params.Get("id"), 10, 64)
  54. if err != nil {
  55. c.JSON(nil, ecode.RequestErr)
  56. return
  57. }
  58. operater = params.Get("operater")
  59. if operater == "" {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. err = spySrv.UpdateStatQuantity(c, count, id, operater)
  64. if err != nil {
  65. log.Error("spySrv.UpdateStatQuantity error(%v)", err)
  66. c.JSON(nil, err)
  67. return
  68. }
  69. c.JSON(nil, err)
  70. }
  71. func deleteStat(c *bm.Context) {
  72. var (
  73. params = c.Request.Form
  74. id int64
  75. operater string
  76. err error
  77. )
  78. id, err = strconv.ParseInt(params.Get("id"), 10, 64)
  79. if err != nil {
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. operater = params.Get("operater")
  84. if operater == "" {
  85. c.JSON(nil, ecode.RequestErr)
  86. return
  87. }
  88. err = spySrv.DeleteStat(c, 1, id, operater)
  89. if err != nil {
  90. log.Error("spySrv.DeleteStat error(%v)", err)
  91. c.JSON(nil, err)
  92. return
  93. }
  94. c.JSON(nil, err)
  95. }
  96. func addRemark(c *bm.Context) {
  97. var (
  98. params = c.Request.Form
  99. remark string
  100. id int64
  101. operater string
  102. err error
  103. )
  104. remark = params.Get("remark")
  105. if err != nil || len(remark) > model.MaxRemarkLen {
  106. c.JSON(nil, ecode.RequestErr)
  107. return
  108. }
  109. id, err = strconv.ParseInt(params.Get("id"), 10, 64)
  110. if err != nil {
  111. c.JSON(nil, ecode.RequestErr)
  112. return
  113. }
  114. operater = params.Get("operater")
  115. if operater == "" {
  116. c.JSON(nil, ecode.RequestErr)
  117. return
  118. }
  119. err = spySrv.AddLog2(c, &model.Log{
  120. RefID: id,
  121. Name: operater,
  122. Module: model.UpdateStat,
  123. Context: remark,
  124. })
  125. if err != nil {
  126. log.Error("spySrv.AddLog2 error(%v)", err)
  127. c.JSON(nil, err)
  128. return
  129. }
  130. c.JSON(nil, err)
  131. }
  132. func remarkList(c *bm.Context) {
  133. var (
  134. params = c.Request.Form
  135. id int64
  136. err error
  137. data []*model.Log
  138. )
  139. id, err = strconv.ParseInt(params.Get("id"), 10, 64)
  140. if err != nil {
  141. c.JSON(nil, ecode.RequestErr)
  142. return
  143. }
  144. data, err = spySrv.LogList(c, id, model.UpdateStat)
  145. if err != nil {
  146. log.Error("spySrv.logList error(%v)", err)
  147. c.JSON(nil, err)
  148. return
  149. }
  150. c.JSON(data, err)
  151. }
  152. func statPage(c *bm.Context) {
  153. var (
  154. params = c.Request.Form
  155. id int64
  156. mid int64
  157. t int64
  158. ps, pn int
  159. err error
  160. data *model.StatPage
  161. )
  162. id, err = strconv.ParseInt(params.Get("id"), 10, 64)
  163. if err != nil {
  164. c.JSON(nil, ecode.RequestErr)
  165. return
  166. }
  167. t, err = strconv.ParseInt(params.Get("type"), 10, 8)
  168. if err != nil {
  169. c.JSON(nil, ecode.RequestErr)
  170. return
  171. }
  172. if int8(t) == model.AccountType {
  173. mid = id
  174. id = 0
  175. }
  176. if ps, err = strconv.Atoi(params.Get("ps")); err != nil {
  177. ps = model.DefPs
  178. }
  179. if pn, err = strconv.Atoi(params.Get("pn")); err != nil {
  180. pn = model.DefPn
  181. }
  182. data, err = spySrv.StatPage(c, mid, id, int8(t), pn, ps)
  183. if err != nil {
  184. log.Error("spySrv.StatPage error(%v)", err)
  185. c.JSON(nil, err)
  186. return
  187. }
  188. c.JSON(data, err)
  189. }