web_elec.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. package http
  2. import (
  3. "go-common/app/interface/main/creative/model/elec"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/metadata"
  8. "strconv"
  9. )
  10. func webUserElec(c *bm.Context) {
  11. ip := metadata.String(c, metadata.RemoteIP)
  12. // check user
  13. midI, ok := c.Get("mid")
  14. if !ok {
  15. c.JSON(nil, ecode.NoLogin)
  16. return
  17. }
  18. mid, _ := midI.(int64)
  19. elecUser, err := elecSvc.UserInfo(c, mid, ip)
  20. if err != nil {
  21. c.JSON(nil, err)
  22. return
  23. }
  24. c.JSON(elecUser, nil)
  25. }
  26. func webUserElecUpdate(c *bm.Context) {
  27. params := c.Request.Form
  28. stateStr := params.Get("state")
  29. ip := metadata.String(c, metadata.RemoteIP)
  30. // check user
  31. midI, ok := c.Get("mid")
  32. if !ok {
  33. c.JSON(nil, ecode.NoLogin)
  34. return
  35. }
  36. mid, _ := midI.(int64)
  37. state, err := strconv.ParseInt(stateStr, 10, 8)
  38. if err != nil {
  39. log.Error("strconv.ParseInt(%s) error(%v)", stateStr, err)
  40. c.JSON(nil, ecode.RequestErr)
  41. return
  42. }
  43. elecUser, err := elecSvc.UserUpdate(c, mid, int8(state), ip)
  44. if err != nil {
  45. c.JSON(nil, err)
  46. return
  47. }
  48. c.JSON(elecUser, nil)
  49. }
  50. func webArcElecUpdate(c *bm.Context) {
  51. params := c.Request.Form
  52. aidStr := params.Get("aid")
  53. stateStr := params.Get("state")
  54. ip := metadata.String(c, metadata.RemoteIP)
  55. // check user
  56. midI, ok := c.Get("mid")
  57. if !ok {
  58. c.JSON(nil, ecode.NoLogin)
  59. return
  60. }
  61. mid, _ := midI.(int64)
  62. aid, err := strconv.ParseInt(aidStr, 10, 64)
  63. if err != nil {
  64. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. state, err := strconv.ParseInt(stateStr, 10, 8)
  69. if err != nil {
  70. log.Error("strconv.ParseInt(%s) error(%v)", stateStr, err)
  71. c.JSON(nil, ecode.RequestErr)
  72. return
  73. }
  74. c.JSON(nil, elecSvc.ArcUpdate(c, mid, aid, int8(state), ip))
  75. }
  76. func webElecNotify(c *bm.Context) {
  77. ip := metadata.String(c, metadata.RemoteIP)
  78. // check user
  79. _, ok := c.Get("mid")
  80. if !ok {
  81. c.JSON(nil, ecode.NoLogin)
  82. return
  83. }
  84. notify, err := elecSvc.Notify(c, ip)
  85. if err != nil {
  86. c.JSON(nil, err)
  87. return
  88. }
  89. c.JSON(notify, nil)
  90. }
  91. func webElecStatus(c *bm.Context) {
  92. ip := metadata.String(c, metadata.RemoteIP)
  93. // check user
  94. midI, ok := c.Get("mid")
  95. if !ok {
  96. c.JSON(nil, ecode.NoLogin)
  97. return
  98. }
  99. mid, _ := midI.(int64)
  100. st, err := elecSvc.Status(c, mid, ip)
  101. if err != nil {
  102. c.JSON(nil, err)
  103. return
  104. }
  105. c.JSON(st, nil)
  106. }
  107. func webElecUpStatus(c *bm.Context) {
  108. params := c.Request.Form
  109. spdayStr := params.Get("display_specialday")
  110. ip := metadata.String(c, metadata.RemoteIP)
  111. // check user
  112. midI, ok := c.Get("mid")
  113. if !ok {
  114. c.JSON(nil, ecode.NoLogin)
  115. return
  116. }
  117. mid, _ := midI.(int64)
  118. spday, err := strconv.ParseInt(spdayStr, 10, 8)
  119. if err != nil {
  120. log.Error("strconv.ParseInt(%s) error(%v)", spdayStr, err)
  121. c.JSON(nil, ecode.RequestErr)
  122. return
  123. }
  124. c.JSON(nil, elecSvc.UpStatus(c, mid, int(spday), ip))
  125. }
  126. func webElecRecentRank(c *bm.Context) {
  127. ip := metadata.String(c, metadata.RemoteIP)
  128. params := c.Request.Form
  129. sizeStr := params.Get("size")
  130. // check user
  131. midI, ok := c.Get("mid")
  132. if !ok {
  133. c.JSON(nil, ecode.NoLogin)
  134. return
  135. }
  136. mid, _ := midI.(int64)
  137. size, err := strconv.ParseInt(sizeStr, 10, 8)
  138. if err != nil || size == 0 || size > 100 { //返回条数 (最大100,不传默认50)
  139. size = 50
  140. }
  141. recRank, err := elecSvc.RecentRank(c, mid, size, ip)
  142. if err != nil {
  143. c.JSON(nil, err)
  144. return
  145. }
  146. c.JSON(map[string][]*elec.Rank{
  147. "list": recRank,
  148. }, nil)
  149. }
  150. func webElecCurrentRank(c *bm.Context) {
  151. ip := metadata.String(c, metadata.RemoteIP)
  152. // check user
  153. midI, ok := c.Get("mid")
  154. if !ok {
  155. c.JSON(nil, ecode.NoLogin)
  156. return
  157. }
  158. mid, _ := midI.(int64)
  159. curRank, err := elecSvc.CurrentRank(c, mid, ip)
  160. if err != nil {
  161. c.JSON(nil, err)
  162. return
  163. }
  164. c.JSON(map[string][]*elec.Rank{
  165. "list": curRank,
  166. }, nil)
  167. }
  168. func webElecTotalRank(c *bm.Context) {
  169. ip := metadata.String(c, metadata.RemoteIP)
  170. // check user
  171. midI, ok := c.Get("mid")
  172. if !ok {
  173. c.JSON(nil, ecode.NoLogin)
  174. return
  175. }
  176. mid, _ := midI.(int64)
  177. tolRank, err := elecSvc.TotalRank(c, mid, ip)
  178. if err != nil {
  179. c.JSON(nil, err)
  180. return
  181. }
  182. c.JSON(map[string][]*elec.Rank{
  183. "list": tolRank,
  184. }, nil)
  185. }
  186. func webElecDailyBill(c *bm.Context) {
  187. ip := metadata.String(c, metadata.RemoteIP)
  188. params := c.Request.Form
  189. pageStr := params.Get("pn")
  190. psStr := params.Get("ps")
  191. bg := params.Get("begin")
  192. end := params.Get("end")
  193. // check user
  194. midI, ok := c.Get("mid")
  195. if !ok {
  196. c.JSON(nil, ecode.NoLogin)
  197. return
  198. }
  199. mid, _ := midI.(int64)
  200. pn, _ := strconv.Atoi(pageStr)
  201. if pn <= 0 {
  202. pn = 1
  203. }
  204. ps, _ := strconv.Atoi(psStr)
  205. if ps <= 0 || ps > 100 {
  206. ps = 100
  207. }
  208. bill, err := elecSvc.DailyBill(c, mid, pn, ps, bg, end, ip)
  209. if err != nil {
  210. c.JSON(nil, err)
  211. return
  212. }
  213. c.JSON(bill, nil)
  214. }
  215. func webElecBalance(c *bm.Context) {
  216. ip := metadata.String(c, metadata.RemoteIP)
  217. // check user
  218. midI, ok := c.Get("mid")
  219. if !ok {
  220. c.JSON(nil, ecode.NoLogin)
  221. return
  222. }
  223. mid, _ := midI.(int64)
  224. bal, err := elecSvc.Balance(c, mid, ip)
  225. if err != nil {
  226. c.JSON(nil, err)
  227. return
  228. }
  229. c.JSON(bal, nil)
  230. }
  231. func webRemarkList(c *bm.Context) {
  232. ip := metadata.String(c, metadata.RemoteIP)
  233. params := c.Request.Form
  234. pageStr := params.Get("pn")
  235. psStr := params.Get("ps")
  236. bg := params.Get("begin")
  237. end := params.Get("end")
  238. // check user
  239. midI, ok := c.Get("mid")
  240. if !ok {
  241. c.JSON(nil, ecode.NoLogin)
  242. return
  243. }
  244. mid, _ := midI.(int64)
  245. pn, _ := strconv.Atoi(pageStr)
  246. if pn <= 0 {
  247. pn = 1
  248. }
  249. ps, _ := strconv.Atoi(psStr)
  250. if ps <= 0 || ps > 12 {
  251. ps = 12
  252. }
  253. bill, err := elecSvc.RemarkList(c, mid, pn, ps, bg, end, ip)
  254. if err != nil {
  255. c.JSON(nil, err)
  256. return
  257. }
  258. c.JSON(bill, nil)
  259. }
  260. func webRemarkDetail(c *bm.Context) {
  261. ip := metadata.String(c, metadata.RemoteIP)
  262. params := c.Request.Form
  263. idStr := params.Get("id")
  264. // check user
  265. midI, ok := c.Get("mid")
  266. if !ok {
  267. c.JSON(nil, ecode.NoLogin)
  268. return
  269. }
  270. mid, _ := midI.(int64)
  271. id, err := strconv.ParseInt(idStr, 10, 64)
  272. if err != nil {
  273. log.Error("strconv.ParseInt(%s) error(%v)", idStr, err)
  274. c.JSON(nil, ecode.RequestErr)
  275. return
  276. }
  277. rm, err := elecSvc.RemarkDetail(c, mid, id, ip)
  278. if err != nil {
  279. c.JSON(nil, err)
  280. return
  281. }
  282. c.JSON(rm, nil)
  283. }
  284. func webRemark(c *bm.Context) {
  285. params := c.Request.Form
  286. idStr := params.Get("id")
  287. msg := params.Get("msg")
  288. ck := c.Request.Header.Get("cookie")
  289. ak := params.Get("access_key")
  290. ip := metadata.String(c, metadata.RemoteIP)
  291. // check user
  292. midI, ok := c.Get("mid")
  293. if !ok {
  294. c.JSON(nil, ecode.NoLogin)
  295. return
  296. }
  297. mid, _ := midI.(int64)
  298. id, err := strconv.ParseInt(idStr, 10, 64)
  299. if err != nil {
  300. log.Error("strconv.ParseInt(%s) error(%v)", idStr, err)
  301. c.JSON(nil, ecode.RequestErr)
  302. return
  303. }
  304. st, err := elecSvc.Remark(c, mid, id, msg, ak, ck, ip)
  305. if err != nil {
  306. c.JSON(nil, err)
  307. return
  308. }
  309. c.JSON(st, nil)
  310. }
  311. func webRecentElec(c *bm.Context) {
  312. req := c.Request
  313. params := req.Form
  314. ip := metadata.String(c, metadata.RemoteIP)
  315. ck := c.Request.Header.Get("cookie")
  316. ak := params.Get("access_key")
  317. pageStr := params.Get("pn")
  318. psStr := params.Get("ps")
  319. // check user
  320. midI, ok := c.Get("mid")
  321. if !ok {
  322. c.JSON(nil, ecode.NoLogin)
  323. return
  324. }
  325. mid, _ := midI.(int64)
  326. if mid == 0 {
  327. c.JSON(nil, ecode.NoLogin)
  328. return
  329. }
  330. pn, _ := strconv.Atoi(pageStr)
  331. if pn <= 0 {
  332. pn = 1
  333. }
  334. ps, _ := strconv.Atoi(psStr)
  335. if ps <= 0 || ps > 20 {
  336. ps = 20
  337. }
  338. var rec *elec.RecentElecList
  339. elecStat, _ := elecSvc.UserState(c, mid, ip, ak, ck)
  340. if elecStat != nil && elecStat.State == "2" {
  341. rec, _ = elecSvc.RecentElec(c, mid, pn, ps, ip)
  342. }
  343. if rec == nil {
  344. rec = recl
  345. }
  346. c.JSON(rec, nil)
  347. }