income.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 upIncomeList(c *bm.Context) {
  11. v := new(struct {
  12. MIDs []int64 `form:"mids,split"`
  13. Type int `form:"type"`
  14. GroupType int `form:"group_type" default:"1"`
  15. FromTime int64 `form:"from_time" validate:"required,min=1"`
  16. ToTime int64 `form:"to_time" validate:"required,min=1"`
  17. MinIncome int64 `form:"min_income"`
  18. MaxIncome int64 `form:"max_income"`
  19. From int `form:"from" validate:"min=0" default:"0"`
  20. Limit int `form:"limit" validate:"min=1" default:"20"`
  21. })
  22. if err := c.Bind(v); err != nil {
  23. return
  24. }
  25. data, total, err := incomeSvr.UpIncomeList(c, v.MIDs, v.Type, v.GroupType, v.FromTime, v.ToTime, v.MinIncome, v.MaxIncome, v.From, v.Limit)
  26. if err != nil {
  27. log.Error("growup incomeSvr.UpIncomeList error(%v)", err)
  28. c.JSON(nil, err)
  29. return
  30. }
  31. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  32. "code": 0,
  33. "message": "0",
  34. "result": data,
  35. "paging": map[string]int{
  36. "page_size": v.Limit,
  37. "total": total,
  38. },
  39. }))
  40. }
  41. func upIncomeListExport(c *bm.Context) {
  42. v := new(struct {
  43. MIDs []int64 `form:"mids,split"`
  44. Type int `form:"type"`
  45. GroupType int `form:"group_type" default:"1"`
  46. FromTime int64 `form:"from_time" validate:"min=1,required"`
  47. ToTime int64 `form:"to_time" validate:"min=1,required"`
  48. MinIncome int64 `form:"min_income"`
  49. MaxIncome int64 `form:"max_income"`
  50. From int `form:"from" validate:"min=0" default:"0"`
  51. Limit int `form:"limit" validate:"min=1" default:"20"`
  52. })
  53. if err := c.Bind(v); err != nil {
  54. return
  55. }
  56. content, err := incomeSvr.UpIncomeListExport(c, v.MIDs, v.Type, v.GroupType, v.FromTime, v.ToTime, v.MinIncome, v.MaxIncome, v.From, v.Limit)
  57. if err != nil {
  58. log.Error("growup incomeSvr.UpIncomeListExport error(%v)", err)
  59. c.JSON(nil, err)
  60. return
  61. }
  62. c.Render(http.StatusOK, CSV{
  63. Content: content,
  64. Title: fmt.Sprintf("%s-%s", time.Now().Format("2006-01-02"), "up_income"),
  65. })
  66. }
  67. func upIncomeStatis(c *bm.Context) {
  68. v := new(struct {
  69. MIDs []int64 `form:"mids,split"`
  70. Type int `form:"type"`
  71. GroupType int `form:"group_type" default:"1"`
  72. FromTime int64 `form:"from_time" validate:"required,min=1"`
  73. ToTime int64 `form:"to_time" validate:"required,min=1"`
  74. })
  75. if err := c.Bind(v); err != nil {
  76. return
  77. }
  78. data, err := incomeSvr.UpIncomeStatis(c, v.MIDs, v.Type, v.GroupType, v.FromTime, v.ToTime)
  79. if err != nil {
  80. log.Error("growup incomeSvr.UpIncomeStatis error(%v)", err)
  81. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  82. "code": err,
  83. "status": "fail",
  84. }))
  85. return
  86. }
  87. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  88. "code": 0,
  89. "message": "0",
  90. "result": data,
  91. "status": "success",
  92. }))
  93. }
  94. func archiveStatis(c *bm.Context) {
  95. v := new(struct {
  96. CategoryID []int64 `form:"category_id,split"`
  97. Type int `form:"type"`
  98. GroupType int `form:"group_type" default:"1"`
  99. FromTime int64 `form:"from_time" validate:"required,min=1"`
  100. ToTime int64 `form:"to_time" validate:"required,min=1"`
  101. })
  102. if err := c.Bind(v); err != nil {
  103. return
  104. }
  105. data, err := incomeSvr.ArchiveStatis(c, v.CategoryID, v.Type, v.GroupType, v.FromTime, v.ToTime)
  106. if err != nil {
  107. log.Error("growup incomeSvr.ArchiveStatis error(%v)", err)
  108. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  109. "code": err,
  110. "status": "fail",
  111. }))
  112. return
  113. }
  114. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  115. "code": 0,
  116. "message": "0",
  117. "result": data,
  118. "status": "success",
  119. }))
  120. }
  121. func archiveSection(c *bm.Context) {
  122. v := new(struct {
  123. CategoryID []int64 `form:"category_id,split"`
  124. Type int `form:"type"`
  125. GroupType int `form:"group_type" default:"1"`
  126. FromTime int64 `form:"from_time" validate:"required,min=1"`
  127. ToTime int64 `form:"to_time" validate:"required,min=1"`
  128. })
  129. if err := c.Bind(v); err != nil {
  130. return
  131. }
  132. data, err := incomeSvr.ArchiveSection(c, v.CategoryID, v.Type, v.GroupType, v.FromTime, v.ToTime)
  133. if err != nil {
  134. log.Error("growup incomeSvr.ArchiveSection error(%v)", err)
  135. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  136. "code": err,
  137. "status": "fail",
  138. }))
  139. return
  140. }
  141. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  142. "code": 0,
  143. "message": "0",
  144. "result": data,
  145. "status": "success",
  146. }))
  147. }
  148. func archiveDetail(c *bm.Context) {
  149. v := new(struct {
  150. MID int64 `form:"mid" validate:"required"`
  151. Type int `form:"type"`
  152. GroupType int `form:"group_type" default:"1"`
  153. FromTime int64 `form:"from_time" validate:"required,min=1"`
  154. ToTime int64 `form:"to_time" validate:"required,min=1"`
  155. })
  156. if err := c.Bind(v); err != nil {
  157. return
  158. }
  159. data, err := incomeSvr.ArchiveDetail(c, v.MID, v.Type, v.GroupType, v.FromTime, v.ToTime)
  160. if err != nil {
  161. log.Error("growup incomeSvr.ArchiveDetail error(%v)", err)
  162. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  163. "code": err,
  164. "status": "fail",
  165. }))
  166. return
  167. }
  168. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  169. "code": 0,
  170. "message": "0",
  171. "result": data,
  172. "status": "success",
  173. }))
  174. }
  175. func archiveTop(c *bm.Context) {
  176. v := new(struct {
  177. AIDs []int64 `form:"aids,split"`
  178. Type int `form:"type"`
  179. GroupType int `form:"group_type" default:"1"`
  180. FromTime int64 `form:"from_time" validate:"required,min=1"`
  181. ToTime int64 `form:"to_time" validate:"required,min=1"`
  182. From int `form:"from" validate:"min=0" default:"0"`
  183. Limit int `form:"limit" validate:"min=1" default:"20"`
  184. })
  185. if err := c.Bind(v); err != nil {
  186. return
  187. }
  188. data, total, err := incomeSvr.ArchiveTop(c, v.AIDs, v.Type, v.GroupType, v.FromTime, v.ToTime, v.From, v.Limit)
  189. if err != nil {
  190. log.Error("growup incomeSvr.ArchiveTop error(%v)", err)
  191. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  192. "code": err,
  193. "status": "fail",
  194. }))
  195. return
  196. }
  197. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  198. "code": 0,
  199. "message": "0",
  200. "result": data,
  201. "status": "success",
  202. "paging": map[string]int{
  203. "page_size": v.Limit,
  204. "total": total,
  205. },
  206. }))
  207. }
  208. func bgmDetail(c *bm.Context) {
  209. v := new(struct {
  210. SID int64 `form:"sid"`
  211. FromTime int64 `form:"from_time" validate:"required,min=1"`
  212. ToTime int64 `form:"to_time" validate:"required,min=1"`
  213. From int `form:"from" validate:"min=0" default:"0"`
  214. Limit int `form:"limit" validate:"min=1" default:"20"`
  215. })
  216. if err := c.Bind(v); err != nil {
  217. return
  218. }
  219. data, total, err := incomeSvr.BgmDetail(c, v.SID, v.FromTime, v.ToTime, v.From, v.Limit)
  220. if err != nil {
  221. log.Error("growup incomeSvr.BgmDetail error(%v)", err)
  222. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  223. "code": err,
  224. "status": "fail",
  225. }))
  226. return
  227. }
  228. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  229. "code": 0,
  230. "message": "0",
  231. "result": data,
  232. "status": "success",
  233. "paging": map[string]int{
  234. "page_size": v.Limit,
  235. "total": total,
  236. },
  237. }))
  238. }
  239. func archiveBreach(c *bm.Context) {
  240. username, _, err := checkCookie(c)
  241. if err != nil {
  242. c.JSON(nil, err)
  243. return
  244. }
  245. v := new(struct {
  246. Type int `form:"type"`
  247. AIDs []int64 `form:"aids,split" validate:"required"`
  248. MID int64 `form:"mid" validate:"required"`
  249. Reason string `form:"reason" validate:"required"`
  250. })
  251. if err = c.Bind(v); err != nil {
  252. return
  253. }
  254. err = incomeSvr.ArchiveBreach(c, v.Type, v.AIDs, v.MID, v.Reason, username)
  255. if err != nil {
  256. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  257. "code": 500,
  258. "message": err.Error(),
  259. }))
  260. } else {
  261. c.JSON(nil, nil)
  262. }
  263. }
  264. func archiveBlack(c *bm.Context) {
  265. v := new(struct {
  266. Type int `form:"type"`
  267. AIDs []int64 `form:"aids,split" validate:"required"`
  268. MID int64 `form:"mid" validate:"required"`
  269. })
  270. if err := c.Bind(v); err != nil {
  271. return
  272. }
  273. err := incomeSvr.ArchiveBlack(c, v.Type, v.AIDs, v.MID)
  274. if err != nil {
  275. log.Error("growup incomeSvr.ArchiveBlack error(%v)", err)
  276. }
  277. c.JSON(nil, err)
  278. }
  279. func breachList(c *bm.Context) {
  280. v := new(struct {
  281. MIDs []int64 `form:"mids,split"`
  282. AIDs []int64 `form:"aids,split"`
  283. Type int `form:"type"`
  284. FromTime int64 `form:"from_time" validate:"required,min=1"`
  285. ToTime int64 `form:"to_time" validate:"required,min=1"`
  286. Reason string `form:"reason"`
  287. From int `form:"from" validate:"min=0" default:"0"`
  288. Limit int `form:"limit" validate:"min=1" default:"20"`
  289. })
  290. if err := c.Bind(v); err != nil {
  291. return
  292. }
  293. data, total, err := incomeSvr.BreachList(c, v.MIDs, v.AIDs, v.Type, v.FromTime, v.ToTime, v.Reason, v.From, v.Limit)
  294. if err != nil {
  295. log.Error("growup incomeSvr.BreachList error(%v)", err)
  296. c.JSON(nil, err)
  297. return
  298. }
  299. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  300. "code": 0,
  301. "message": "0",
  302. "result": data,
  303. "paging": map[string]int{
  304. "page_size": v.Limit,
  305. "total": total,
  306. },
  307. }))
  308. }
  309. func breachStatis(c *bm.Context) {
  310. v := new(struct {
  311. MIDs []int64 `form:"mids,split"`
  312. AIDs []int64 `form:"aids,split"`
  313. Type int `form:"type"`
  314. GroupType int `form:"group_type"`
  315. FromTime int64 `form:"from_time" validate:"required,min=1"`
  316. ToTime int64 `form:"to_time" validate:"required,min=1"`
  317. Reason string `form:"reason"`
  318. })
  319. if err := c.Bind(v); err != nil {
  320. return
  321. }
  322. data, err := incomeSvr.BreachStatis(c, v.MIDs, v.AIDs, v.Type, v.GroupType, v.FromTime, v.ToTime, v.Reason)
  323. if err != nil {
  324. log.Error("growup incomeSvr.BreachStatis error(%v)", err)
  325. c.JSON(nil, err)
  326. return
  327. }
  328. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  329. "code": 0,
  330. "message": "0",
  331. "result": data,
  332. "status": "success",
  333. }))
  334. }
  335. func exportBreach(c *bm.Context) {
  336. v := new(struct {
  337. MIDs []int64 `form:"mids,split"`
  338. AIDs []int64 `form:"aids,split"`
  339. Type int `form:"type"`
  340. FromTime int64 `form:"from_time" validate:"required,min=1"`
  341. ToTime int64 `form:"to_time" validate:"required,min=1"`
  342. Reason string `form:"reason"`
  343. From int `form:"from" validate:"min=0" default:"0"`
  344. Limit int `form:"limit" validate:"min=1" default:"20"`
  345. })
  346. if err := c.Bind(v); err != nil {
  347. return
  348. }
  349. content, err := incomeSvr.ExportBreach(c, v.MIDs, v.AIDs, v.Type, v.FromTime, v.ToTime, v.Reason, v.From, v.Limit)
  350. if err != nil {
  351. log.Error("growup svr.ExportBreach error(%v)", err)
  352. c.JSON(nil, err)
  353. return
  354. }
  355. c.Render(http.StatusOK, CSV{
  356. Content: content,
  357. Title: fmt.Sprintf("%s-%s", time.Now().Format("2006-01-02"), "breach_record"),
  358. })
  359. }