web.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. package http
  2. import (
  3. "fmt"
  4. "net/http"
  5. "time"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/render"
  9. )
  10. func add(c *bm.Context) {
  11. v := new(struct {
  12. MID int64 `form:"mid"`
  13. AccountType int `form:"account_type"`
  14. })
  15. if err := c.Bind(v); err != nil {
  16. return
  17. }
  18. err := svr.AddUp(c, v.MID, v.AccountType)
  19. if err != nil {
  20. log.Error("growup svr.AddUp error(%v)", err)
  21. }
  22. c.JSON(nil, err)
  23. }
  24. func recovery(c *bm.Context) {
  25. v := new(struct {
  26. MID int64 `form:"mid"`
  27. })
  28. if err := c.Bind(v); err != nil {
  29. return
  30. }
  31. err := svr.Recovery(c, v.MID)
  32. if err != nil {
  33. log.Error("growup svr.Recovery error(%v)", err)
  34. }
  35. c.JSON(nil, err)
  36. }
  37. // pgc移除不区分业务
  38. func deleteUp(c *bm.Context) {
  39. v := new(struct {
  40. MID int64 `form:"mid"`
  41. })
  42. if err := c.Bind(v); err != nil {
  43. return
  44. }
  45. err := svr.DeleteUp(c, v.MID)
  46. if err != nil {
  47. log.Error("growup svr.DeleteUp error(%v)", err)
  48. }
  49. c.JSON(nil, err)
  50. }
  51. func queryForUps(c *bm.Context) {
  52. v := new(struct {
  53. BusinessType int `form:"business_type"`
  54. AccountType int `form:"account_type"`
  55. States []int64 `form:"account_states,split"`
  56. MID int64 `form:"mid"`
  57. Category int `form:"category"`
  58. SignType int `form:"sign_type"`
  59. Nickname string `form:"nickname"`
  60. Lower int `form:"lower"`
  61. Upper int `form:"upper"`
  62. From int `form:"from" default:"0" validate:"min=0"`
  63. Limit int `form:"limit" default:"20" validate:"min=1"`
  64. Sort string `form:"sort"`
  65. })
  66. if err := c.Bind(v); err != nil {
  67. return
  68. }
  69. ups, total, err := svr.QueryFromUpInfo(c, v.BusinessType, v.AccountType, v.States, v.MID, v.Category, v.SignType, v.Nickname, v.Lower, v.Upper, v.From, v.Limit, v.Sort)
  70. if err != nil {
  71. log.Error("growup svr.QueryFromUpInfo error(%v)", err)
  72. c.JSON(nil, err)
  73. return
  74. }
  75. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  76. "code": 0,
  77. "message": "0",
  78. "data": ups,
  79. "paging": map[string]int{
  80. "page_size": v.Limit,
  81. "total": total,
  82. },
  83. }))
  84. }
  85. func reject(c *bm.Context) {
  86. v := new(struct {
  87. Type int `form:"type"`
  88. MIDs []int64 `form:"mids,split"`
  89. Reason string `form:"reason" validate:"required"`
  90. Days int `form:"days"`
  91. })
  92. if err := c.Bind(v); err != nil {
  93. return
  94. }
  95. err := svr.Reject(c, v.Type, v.MIDs, v.Reason, v.Days)
  96. if err != nil {
  97. log.Error("growup svr.Reject error(%v)", err)
  98. }
  99. c.JSON(nil, err)
  100. }
  101. func pass(c *bm.Context) {
  102. v := new(struct {
  103. Type int `form:"type"`
  104. MIDs []int64 `form:"mids,split"`
  105. })
  106. if err := c.Bind(v); err != nil {
  107. return
  108. }
  109. err := svr.Pass(c, v.MIDs, v.Type)
  110. if err != nil {
  111. log.Error("growup svr.Pass error(%v)", err)
  112. }
  113. c.JSON(nil, err)
  114. }
  115. func dismiss(c *bm.Context) {
  116. v := new(struct {
  117. Type int `form:"type"`
  118. MID int64 `form:"mid" validate:"required"`
  119. Reason string `form:"reason" validate:"required"`
  120. })
  121. if err := c.Bind(v); err != nil {
  122. return
  123. }
  124. u, err := c.Request.Cookie("username")
  125. if err != nil {
  126. c.JSON(nil, err)
  127. return
  128. }
  129. username := u.Value
  130. err = svr.Dismiss(c, username, v.Type, 3, v.MID, v.Reason)
  131. if err != nil {
  132. log.Error("growup svr.Dismiss error(%v)", err)
  133. }
  134. c.JSON(nil, err)
  135. }
  136. func forbid(c *bm.Context) {
  137. v := new(struct {
  138. Type int `form:"type"`
  139. MID int64 `form:"mid" validate:"required"`
  140. Reason string `form:"reason" validate:"required"`
  141. Days int `form:"days"`
  142. })
  143. if err := c.Bind(v); err != nil {
  144. return
  145. }
  146. u, err := c.Request.Cookie("username")
  147. if err != nil {
  148. c.JSON(nil, err)
  149. return
  150. }
  151. username := u.Value
  152. err = svr.Forbid(c, username, v.Type, 3, v.MID, v.Reason, v.Days, v.Days*86400)
  153. if err != nil {
  154. log.Error("growup svr.Forbid error(%v)", err)
  155. }
  156. c.JSON(nil, err)
  157. }
  158. func addToBlocked(c *bm.Context) {
  159. v := new(struct {
  160. MID int64 `form:"mid"`
  161. })
  162. if err := c.Bind(v); err != nil {
  163. return
  164. }
  165. err := svr.Block(c, v.MID)
  166. if err != nil {
  167. log.Error("growup svr.Block error(%v)", err)
  168. }
  169. c.JSON(nil, err)
  170. }
  171. func queryFromBlocked(c *bm.Context) {
  172. v := new(struct {
  173. MID int64 `form:"mid"`
  174. Category int `form:"category"`
  175. Nickname string `form:"nickname"`
  176. Lower int `form:"lower"`
  177. Upper int `form:"upper"`
  178. From int `form:"from" default:"0" validate:"min=0"`
  179. Limit int `form:"limit" default:"20" validate:"min=1"`
  180. Sort string `form:"sort"`
  181. })
  182. if err := c.Bind(v); err != nil {
  183. return
  184. }
  185. ups, total, err := svr.QueryFromBlocked(c, v.MID, v.Category, v.Nickname, v.Lower, v.Upper, v.From, v.Limit, v.Sort)
  186. if err != nil {
  187. log.Error("growup svr.QueryFromBlocked error(%v)", err)
  188. c.JSON(nil, err)
  189. return
  190. }
  191. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  192. "code": 0,
  193. "message": "0",
  194. "data": ups,
  195. "paging": map[string]int{
  196. "page_size": v.Limit,
  197. "total": total,
  198. },
  199. }))
  200. }
  201. func deleteFromBlocked(c *bm.Context) {
  202. v := new(struct {
  203. MID int64 `form:"mid"`
  204. })
  205. if err := c.Bind(v); err != nil {
  206. return
  207. }
  208. err := svr.DeleteFromBlocked(c, v.MID)
  209. if err != nil {
  210. log.Error("growup svr.DeleteFromBlocked error(%v)", err)
  211. }
  212. c.JSON(nil, err)
  213. }
  214. func updateAccountState(c *bm.Context) {
  215. v := new(struct {
  216. MID int64 `form:"mid"`
  217. State int `form:"state"`
  218. })
  219. if err := c.Bind(v); err != nil {
  220. return
  221. }
  222. err := svr.UpdateUpAccountState(c, "up_info_video", v.MID, v.State)
  223. if err != nil {
  224. log.Error("growup svr.UpdateUpAccountState error(%v)", err)
  225. }
  226. c.JSON(nil, err)
  227. }
  228. func delUpAccount(c *bm.Context) {
  229. v := new(struct {
  230. MID int64 `form:"mid" validate:"required"`
  231. })
  232. if err := c.Bind(v); err != nil {
  233. return
  234. }
  235. err := svr.DelUpAccount(c, v.MID)
  236. if err != nil {
  237. log.Error("growup svr.DelUpAccount error(%v)", err)
  238. }
  239. c.JSON(nil, err)
  240. }
  241. func updateUpAccount(c *bm.Context) {
  242. v := new(struct {
  243. MID int64 `form:"mid" validate:"required"`
  244. IsDeleted int `form:"is_deleted"`
  245. WithdrawDate string `form:"withdraw_date" validate:"required"`
  246. })
  247. if err := c.Bind(v); err != nil {
  248. return
  249. }
  250. err := svr.UpdateUpAccount(c, v.MID, v.IsDeleted, v.WithdrawDate)
  251. if err != nil {
  252. log.Error("growup svr.UpdateUpAccount error(%v)", err)
  253. }
  254. c.JSON(nil, err)
  255. }
  256. func recoverCredit(c *bm.Context) {
  257. v := new(struct {
  258. Type int `form:"type"`
  259. ID int64 `form:"id" validate:"required"`
  260. MID int64 `form:"mid" validate:"required"`
  261. })
  262. if err := c.Bind(v); err != nil {
  263. return
  264. }
  265. err := svr.RecoverCreditScore(c, v.Type, v.ID, v.MID)
  266. if err != nil {
  267. log.Error("growup svr.RecoverCreditScore error(%v)", err)
  268. }
  269. c.JSON(nil, err)
  270. }
  271. func creditRecords(c *bm.Context) {
  272. v := new(struct {
  273. MID int64 `form:"mid" validate:"required"`
  274. })
  275. if err := c.Bind(v); err != nil {
  276. return
  277. }
  278. crs, err := svr.CreditRecords(c, v.MID)
  279. if err != nil {
  280. log.Error("growup svr.CreditRecords error(%v)", err)
  281. c.JSON(nil, err)
  282. return
  283. }
  284. c.JSON(crs, nil)
  285. }
  286. func exportUps(c *bm.Context) {
  287. v := new(struct {
  288. BusinessType int `form:"business_type"`
  289. AccountType int `form:"account_type"`
  290. States []int64 `form:"account_states,split"`
  291. MID int64 `form:"mid"`
  292. Category int `form:"category"`
  293. SignType int `form:"sign_type"`
  294. Nickname string `form:"nickname"`
  295. Lower int `form:"lower"`
  296. Upper int `form:"upper"`
  297. From int `form:"from" default:"0" validate:"min=0"`
  298. Limit int `form:"limit" default:"20" validate:"min=1"`
  299. Sort string `form:"sort"`
  300. })
  301. if err := c.Bind(v); err != nil {
  302. return
  303. }
  304. content, err := svr.ExportUps(c, v.BusinessType, v.AccountType, v.States, v.MID, v.Category, v.SignType, v.Nickname, v.Lower, v.Upper, v.From, v.Limit, v.Sort)
  305. if err != nil {
  306. c.JSON(nil, err)
  307. log.Error("growup svr.ExportUps error(%v)", err)
  308. return
  309. }
  310. c.Render(http.StatusOK, CSV{
  311. Content: content,
  312. Title: fmt.Sprintf("%s-%s", time.Now().Format("2006-01-02"), "ups"),
  313. })
  314. }
  315. func upState(c *bm.Context) {
  316. v := new(struct {
  317. Type int `form:"type"`
  318. MID int64 `form:"mid" validate:"required"`
  319. })
  320. if err := c.Bind(v); err != nil {
  321. return
  322. }
  323. data, err := svr.UpState(c, v.MID, v.Type)
  324. if err != nil {
  325. log.Error("growup svr.UpState error(%v)", err)
  326. c.JSON(nil, err)
  327. return
  328. }
  329. c.JSON(data, nil)
  330. }