credit.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package http
  2. import (
  3. model "go-common/app/interface/main/credit/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // requirement user status in apply jury.
  9. func requirement(c *bm.Context) {
  10. mid, _ := c.Get("mid")
  11. rq, err := creditSvc.Requirement(c, mid.(int64))
  12. if err != nil {
  13. log.Error("creditSvc.Requirement(%d) error(%v)", mid, err)
  14. c.JSON(nil, err)
  15. return
  16. }
  17. c.JSON(rq, nil)
  18. }
  19. // apply user apply jury.
  20. func apply(c *bm.Context) {
  21. mid, _ := c.Get("mid")
  22. err := creditSvc.Apply(c, mid.(int64))
  23. if err != nil {
  24. log.Error("creditSvc.Apply(%d) error(%v)", mid, err)
  25. c.JSON(nil, err)
  26. return
  27. }
  28. c.JSON(nil, nil)
  29. }
  30. // jury jury user info.
  31. func jury(c *bm.Context) {
  32. mid, _ := c.Get("mid")
  33. ui, err := creditSvc.Jury(c, mid.(int64))
  34. if err != nil {
  35. log.Error("creditSvc.Jury(%d) error(%v)", mid, err)
  36. c.JSON(nil, err)
  37. return
  38. }
  39. c.JSON(ui, nil)
  40. }
  41. // caseObtain jury user obtain case list.
  42. func caseObtain(c *bm.Context) {
  43. mid, _ := c.Get("mid")
  44. v := new(model.ArgCid)
  45. if err := c.Bind(v); err != nil {
  46. return
  47. }
  48. id, err := creditSvc.CaseObtain(c, mid.(int64), v.Cid)
  49. if err != nil {
  50. log.Error("creditSvc.CaseObtain(%d) error(%v)", mid, err)
  51. c.JSON(nil, err)
  52. return
  53. }
  54. type reid struct {
  55. CID int64 `json:"id"`
  56. }
  57. var data reid
  58. data.CID = id
  59. c.JSON(data, nil)
  60. }
  61. // caseObtainByID jury user obtain case list.
  62. func caseObtainByID(c *bm.Context) {
  63. mid, _ := c.Get("mid")
  64. v := new(model.ArgCid)
  65. if err := c.Bind(v); err != nil {
  66. return
  67. }
  68. if v.Cid == 0 {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. err := creditSvc.CaseObtainByID(c, mid.(int64), v.Cid)
  73. if err != nil {
  74. log.Error("creditSvc.CaseObtain(%d) error(%v)", mid, err)
  75. c.JSON(nil, err)
  76. return
  77. }
  78. type reid struct {
  79. CID int64 `json:"id"`
  80. }
  81. var data reid
  82. data.CID = v.Cid
  83. c.JSON(data, nil)
  84. }
  85. // vote jury user vote case.
  86. func vote(c *bm.Context) {
  87. mid, _ := c.Get("mid")
  88. v := new(model.ArgVote)
  89. if err := c.Bind(v); err != nil {
  90. return
  91. }
  92. if err := creditSvc.Vote(c, mid.(int64), v.Cid, v.Attr, v.Vote, v.AType, v.AReason, v.Content, v.Likes, v.Hates); err != nil {
  93. log.Error("creditSvc.Vote(%d,%+v) error(%v)", mid, v, err)
  94. c.JSON(nil, err)
  95. return
  96. }
  97. c.JSON(nil, nil)
  98. }
  99. // voteInfo jury user vote info.
  100. func voteInfo(c *bm.Context) {
  101. mid, _ := c.Get("mid")
  102. v := new(model.ArgCid)
  103. if err := c.Bind(v); err != nil {
  104. return
  105. }
  106. vi, err := creditSvc.VoteInfo(c, mid.(int64), v.Cid)
  107. if err != nil {
  108. log.Error("creditSvc.VoteInfo(%d %d) error(%v)", mid, v.Cid, err)
  109. c.JSON(nil, err)
  110. return
  111. }
  112. var data interface{}
  113. if vi == nil || vi.MID == 0 {
  114. data = &struct{}{}
  115. } else {
  116. data = vi
  117. }
  118. c.JSON(data, nil)
  119. }
  120. // caseInfo jury get case info.
  121. func caseInfo(c *bm.Context) {
  122. v := new(model.ArgCid)
  123. if err := c.Bind(v); err != nil {
  124. return
  125. }
  126. ci, err := creditSvc.CaseInfo(c, v.Cid)
  127. if err != nil {
  128. log.Error("creditSvc.CaseInfo(%d) error(%v)", v.Cid, err)
  129. c.JSON(nil, err)
  130. return
  131. }
  132. c.JSON(ci, nil)
  133. }
  134. // juryCase jury user case info contain vote.
  135. func juryCase(c *bm.Context) {
  136. mid, _ := c.Get("mid")
  137. v := new(model.ArgCid)
  138. if err := c.Bind(v); err != nil {
  139. return
  140. }
  141. jc, err := creditSvc.JuryCase(c, mid.(int64), v.Cid)
  142. if err != nil {
  143. log.Error("creditSvc.JuryCase(%d %d) error(%v)", mid, v.Cid, err)
  144. c.JSON(nil, err)
  145. return
  146. }
  147. c.JSON(jc, nil)
  148. }
  149. // spJuryCase get specific jury case info.
  150. func spJuryCase(c *bm.Context) {
  151. var mid int64
  152. iMid, ok := c.Get("mid")
  153. if ok {
  154. mid = iMid.(int64)
  155. }
  156. v := new(model.ArgCid)
  157. if err := c.Bind(v); err != nil {
  158. return
  159. }
  160. jc, err := creditSvc.SpJuryCase(c, mid, v.Cid)
  161. if err != nil {
  162. log.Error("creditSvc.JuryCase(%d %d) error(%v)", mid, v.Cid, err)
  163. c.JSON(nil, err)
  164. return
  165. }
  166. c.JSON(jc, nil)
  167. }
  168. // caseList user case list.
  169. func caseList(c *bm.Context) {
  170. mid, _ := c.Get("mid")
  171. v := new(model.ArgPage)
  172. if err := c.Bind(v); err != nil {
  173. return
  174. }
  175. cl, err := creditSvc.CaseList(c, mid.(int64), v.PN, v.PS)
  176. if err != nil {
  177. log.Error("creditSvc.CaseList(%d,%d,%d) error(%v)", mid, v.PN, v.PS, err)
  178. c.JSON(nil, err)
  179. return
  180. }
  181. c.JSON(cl, nil)
  182. }
  183. // notice get jury notice.
  184. func notice(c *bm.Context) {
  185. n, err := creditSvc.Notice(c)
  186. if err != nil {
  187. log.Error("creditSvc.notice error(%v)", err)
  188. c.JSON(nil, err)
  189. return
  190. }
  191. c.JSON(n, nil)
  192. }
  193. // reasonList get reason list.
  194. func reasonList(c *bm.Context) {
  195. n, err := creditSvc.ReasonList(c)
  196. if err != nil {
  197. log.Error("creditSvc.ReasonList error(%v)", err)
  198. c.JSON(nil, err)
  199. return
  200. }
  201. c.JSON(n, nil)
  202. }
  203. // kpiList get kpi list.
  204. func kpiList(c *bm.Context) {
  205. mid, _ := c.Get("mid")
  206. n, err := creditSvc.KPIList(c, mid.(int64))
  207. if err != nil {
  208. log.Error("creditSvc.KpiList error(%v)", err)
  209. c.JSON(nil, err)
  210. return
  211. }
  212. c.JSON(n, nil)
  213. }
  214. // voteOpinion get vote opinion.
  215. func voteOpinion(c *bm.Context) {
  216. v := new(model.ArgOpinion)
  217. if err := c.Bind(v); err != nil {
  218. return
  219. }
  220. ops, count, err := creditSvc.VoteOpinion(c, v.Cid, v.PN, v.PS, v.Otype)
  221. if err != nil {
  222. log.Error("creditSvc.VoteOpinion error(%v)", err)
  223. c.JSON(nil, err)
  224. return
  225. }
  226. c.JSON(&model.OpinionRes{
  227. Count: count,
  228. Opinion: ops,
  229. }, nil)
  230. }
  231. // caseOpinion get case opinion.
  232. func caseOpinion(c *bm.Context) {
  233. v := new(model.ArgOpinion)
  234. if err := c.Bind(v); err != nil {
  235. return
  236. }
  237. ops, count, err := creditSvc.CaseOpinion(c, v.Cid, v.PN, v.PS)
  238. if err != nil {
  239. log.Error("creditSvc.CaseOpinion error(%v)", err)
  240. c.JSON(nil, err)
  241. return
  242. }
  243. c.JSON(&model.OpinionRes{
  244. Count: count,
  245. Opinion: ops,
  246. }, nil)
  247. }
  248. // batchBLKCases get case info.
  249. func batchBLKCases(c *bm.Context) {
  250. v := new(model.ArgIDs)
  251. if err := c.Bind(v); err != nil {
  252. return
  253. }
  254. cases, err := creditSvc.BatchBLKCases(c, v.IDs)
  255. if err != nil {
  256. log.Error("creditSvc.BatchBLKCases(%+v) error(%+v)", v.IDs, err)
  257. c.JSON(nil, err)
  258. return
  259. }
  260. c.JSON(cases, nil)
  261. }