labour.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package http
  2. import (
  3. "strconv"
  4. model "go-common/app/interface/main/credit/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. )
  10. func getQs(c *bm.Context) {
  11. mid, _ := c.Get("mid")
  12. qs, err := creditSvc.GetQs(c, mid.(int64))
  13. if err != nil {
  14. log.Error("creditSvc.getQs(%d) error(%v)", mid, err)
  15. c.JSON(nil, err)
  16. return
  17. }
  18. c.JSON(qs, nil)
  19. }
  20. func commitQs(c *bm.Context) {
  21. var (
  22. mid, _ = c.Get("mid")
  23. params = c.Request.Form
  24. idStr = params.Get("id")
  25. buvidStr = params.Get("buvid")
  26. anStr = params.Get("ans")
  27. labourAns = &model.LabourAns{}
  28. refer = c.Request.Referer()
  29. ua = c.Request.UserAgent()
  30. )
  31. ids, err := xstr.SplitInts(idStr)
  32. if err != nil {
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. answer, err := xstr.SplitInts(anStr)
  37. if err != nil {
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. labourAns.ID = ids
  42. labourAns.Answer = answer
  43. commitRes, err := creditSvc.CommitQs(c, mid.(int64), refer, ua, buvidStr, labourAns)
  44. if err != nil {
  45. log.Error("creditSvc.commitQs(%d) error(%v)", mid, err)
  46. c.JSON(nil, err)
  47. return
  48. }
  49. c.JSON(commitRes, nil)
  50. }
  51. func addQs(c *bm.Context) {
  52. var (
  53. params = c.Request.Form
  54. question = params.Get("question")
  55. ansStr = params.Get("ans")
  56. avIDStr = params.Get("av_id")
  57. statusStr = params.Get("status")
  58. sourceStr = params.Get("source")
  59. )
  60. ans, err := strconv.ParseInt(ansStr, 10, 64)
  61. if err != nil || ans < 0 {
  62. c.JSON(nil, ecode.RequestErr)
  63. return
  64. }
  65. avID, err := strconv.ParseInt(avIDStr, 10, 64)
  66. if err != nil || avID <= 0 {
  67. c.JSON(nil, ecode.RequestErr)
  68. return
  69. }
  70. status, err := strconv.ParseInt(statusStr, 10, 64)
  71. if err != nil || status <= 0 {
  72. c.JSON(nil, ecode.RequestErr)
  73. return
  74. }
  75. source, err := strconv.ParseInt(sourceStr, 10, 64)
  76. if err != nil || source < 0 {
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. var qs = &model.LabourQs{Question: question, Ans: ans, AvID: avID, Status: status, Source: source}
  81. if err = creditSvc.AddQs(c, qs); err != nil {
  82. log.Error("creditSvc.AddQs(%+v) error(%v)", qs, err)
  83. c.JSON(nil, err)
  84. return
  85. }
  86. c.JSON(nil, nil)
  87. }
  88. func setQs(c *bm.Context) {
  89. var (
  90. params = c.Request.Form
  91. id, _ = strconv.ParseInt(params.Get("id"), 10, 64)
  92. ans, _ = strconv.ParseInt(params.Get("ans"), 10, 64)
  93. status, _ = strconv.ParseInt(params.Get("status"), 10, 64)
  94. )
  95. if err := creditSvc.SetQs(c, id, ans, status); err != nil {
  96. log.Error("creditSvc.SetQs(id:%d ans:%d status:%d) error(%v)", id, ans, status, err)
  97. c.JSON(nil, err)
  98. return
  99. }
  100. c.JSON(nil, nil)
  101. }
  102. func delQs(c *bm.Context) {
  103. var err error
  104. v := new(model.ArgDElQS)
  105. if err = c.Bind(v); err != nil {
  106. return
  107. }
  108. if err = creditSvc.DelQs(c, v.ID, v.IsDel); err != nil {
  109. log.Error("creditSvc.delQs(id:%d isDel:%d error(%v)", v.ID, v.IsDel, err)
  110. c.JSON(nil, err)
  111. return
  112. }
  113. c.JSON(nil, nil)
  114. }
  115. func isAnswered(c *bm.Context) {
  116. v := new(model.ArgHistory)
  117. if err := c.Bind(v); err != nil {
  118. return
  119. }
  120. anState, err := creditSvc.IsAnswered(c, v.MID, v.STime)
  121. if err != nil {
  122. log.Error("creditSvc.isanswered(mid:%d mtime:%d error(%v)", v.MID, v.STime, err)
  123. c.JSON(nil, err)
  124. return
  125. }
  126. type data struct {
  127. Status int8 `json:"status"`
  128. }
  129. var rs data
  130. rs.Status = anState
  131. c.JSON(rs, nil)
  132. }