task_controller.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_b_api/app/service"
  6. "youngee_b_api/app/service/review_service"
  7. "youngee_b_api/app/vo"
  8. )
  9. type TaskController struct{}
  10. type SelectionDetailParam struct {
  11. SelectionId string `json:"selection_id"`
  12. EnterpriseId string `json:"enterprise_id"`
  13. SubAccountId int `json:"sub_account_id"`
  14. }
  15. // 关联商品-已有商品展示
  16. func (t TaskController) GetAllProduct(c *gin.Context) {
  17. search := vo.GetAllProductParam{}
  18. err := c.BindJSON(&search)
  19. if err != nil {
  20. logrus.Errorf("Request bind err:%+v\n", err)
  21. returnError(c, 40000, "参数错误")
  22. return
  23. }
  24. var result vo.ResultVO
  25. result, err = service.ProductService{}.GetTaskProductsByUserId(search)
  26. if err != nil {
  27. returnError(c, 40000, "error")
  28. return
  29. }
  30. returnSuccess(c, 20000, result)
  31. return
  32. }
  33. // 关联商品-新建商品
  34. func (t TaskController) CreateProduct(c *gin.Context) {
  35. data := &vo.ProductCreateParam{}
  36. err := c.BindJSON(data)
  37. if err != nil {
  38. logrus.Errorf("Request bind err:%+v\n", err)
  39. returnError(c, 40000, "参数错误")
  40. return
  41. }
  42. productId, err := service.ProductService{}.CreateProduct(data)
  43. resultMap := make(map[string]int64)
  44. resultMap["product_id"] = productId
  45. returnSuccess(c, 20000, resultMap)
  46. }
  47. // 关联商品-完成关联创建带货任务
  48. func (t TaskController) CreateSelection(c *gin.Context) {
  49. data := &vo.SelectionInfoCreateParam{}
  50. err := c.BindJSON(data)
  51. if err != nil {
  52. logrus.Errorf("Request bind err:%+v\n", err)
  53. returnError(c, 40000, "参数错误")
  54. return
  55. }
  56. selectionId, err := service.SelectionInfoService{}.CreateSelectionInfo(data)
  57. if err != nil {
  58. logrus.Errorf("[CreateSelection] call CreateSelection err:%+v\n", err)
  59. returnError(c, 40000, "error")
  60. return
  61. }
  62. resultMap := make(map[string]string)
  63. resultMap["selection_id"] = *selectionId
  64. returnSuccess(c, 20000, resultMap)
  65. }
  66. // 更新带货任务(样品奖励、补充信息)
  67. func (t TaskController) UpdateSelection(c *gin.Context) {
  68. data := &vo.SelectionInfoUpdateParam{}
  69. err := c.BindJSON(data)
  70. if err != nil {
  71. logrus.Errorf("Request bind err:%+v\n", err)
  72. returnError(c, 40000, "参数错误")
  73. return
  74. }
  75. selectionId, err := service.SelectionInfoService{}.UpdateSelectionInfo(data)
  76. if err != nil {
  77. logrus.Errorf("[UpdateSelection] call UpdateSelection err:%+v\n", err)
  78. returnError(c, 40000, "error")
  79. return
  80. }
  81. resultMap := make(map[string]string)
  82. resultMap["selection_id"] = *selectionId
  83. returnSuccess(c, 20000, resultMap)
  84. }
  85. // 电商带货任务预览
  86. func (t TaskController) GetSelectionDetail(c *gin.Context) {
  87. data := &SelectionDetailParam{}
  88. err := c.BindJSON(data)
  89. if err != nil {
  90. logrus.Errorf("Request bind err:%+v\n", err)
  91. returnError(c, 40000, "参数错误")
  92. return
  93. }
  94. res, err := service.SelectionInfoService{}.GetSelectionDetail(data.SelectionId, data.EnterpriseId)
  95. if err != nil {
  96. logrus.Errorf("[GetSelectionDetail] call Show err:%+v\n", err)
  97. returnError(c, 40000, "error")
  98. return
  99. }
  100. returnSuccess(c, 20000, res)
  101. }
  102. // 电商带货任务审核
  103. func (t TaskController) CheckSelectionInfo(c *gin.Context) {
  104. //data := &vo.ContentCheckParam{}
  105. //err := c.BindJSON(data)
  106. //if err != nil {
  107. // logrus.Errorf("Request bind err:%+v\n", err)
  108. // returnError(c, 40000, "error")
  109. // return
  110. //}
  111. //res, err := service.ContentService{}.CheckContent(data)
  112. //if err != nil {
  113. // logrus.Errorf("[CheckSelectionInfo] call Show err:%+v\n", err)
  114. // returnError(c, 40000, "error")
  115. // return
  116. //}
  117. //
  118. //returnSuccess(c, 20000, *res)
  119. data := &vo.ContentCheckParam{}
  120. err := c.BindJSON(data)
  121. if err != nil {
  122. logrus.Errorf("Request bind err:%+v\n", err)
  123. returnError(c, 40000, "参数错误")
  124. return
  125. }
  126. sdk := review_service.Config(data.AK, data.SK, data.ProjectId)
  127. res1, err1 := sdk.CheckContent(data.Text)
  128. res2, err2 := sdk.CheckImage(data.Image)
  129. res3, err3 := sdk.CheckDocument(data.Document, data.Format)
  130. res4, err4 := sdk.CheckVideo(data.Video)
  131. res5, err5 := sdk.CheckCredentials(data.Credentials)
  132. if err1 != nil {
  133. logrus.Errorf("[CheckSelectionInfo] call Show err:%+v\n", err)
  134. returnError(c, 40000, res1)
  135. return
  136. }
  137. if err2 != nil {
  138. logrus.Errorf("[CheckSelectionInfo] call Show err:%+v\n", err)
  139. returnError(c, 40000, res2)
  140. return
  141. }
  142. if err3 != nil {
  143. logrus.Errorf("[CheckSelectionInfo] call Show err:%+v\n", err)
  144. returnError(c, 40000, res3)
  145. return
  146. }
  147. if err4 != nil {
  148. logrus.Errorf("[CheckSelectionInfo] call Show err:%+v\n", err)
  149. returnError(c, 40000, res4)
  150. return
  151. }
  152. if err5 != nil {
  153. logrus.Errorf("[CheckSelectionInfo] call Show err:%+v\n", err)
  154. returnError(c, 40000, res5)
  155. return
  156. }
  157. returnSuccess(c, 20000, res3)
  158. }