task_controller.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/vo"
  7. )
  8. type TaskController struct{}
  9. type GetAllProductParam struct {
  10. EnterpriseId string `json:"enterprise_id"`
  11. }
  12. type SelectionDetailParam struct {
  13. EnterpriseId string `json:"enterprise_id"`
  14. SelectionId string `json:"selection_id"`
  15. }
  16. // 关联商品-已有商品展示
  17. func (t TaskController) GetAllProduct(c *gin.Context) {
  18. search := &GetAllProductParam{}
  19. err := c.BindJSON(&search)
  20. if err != nil {
  21. logrus.Errorf("Request bind err:%+v\n", err)
  22. returnError(c, 40000, "error")
  23. return
  24. }
  25. result, err := service.ProductService{}.GetTaskProducts(search.EnterpriseId)
  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, "error")
  40. return
  41. }
  42. productId, err := service.ProductService{}.CreateProduct(data)
  43. returnSuccess(c, 20000, productId)
  44. }
  45. // 关联商品-完成关联创建带货任务
  46. func (t TaskController) CreateSelection(c *gin.Context) {
  47. data := &vo.SelectionInfoCreateParam{}
  48. err := c.BindJSON(data)
  49. if err != nil {
  50. logrus.Errorf("Request bind err:%+v\n", err)
  51. returnError(c, 40000, "error")
  52. return
  53. }
  54. selectionId, err := service.SelectionInfoService{}.CreateSelectionInfo(data)
  55. if err != nil {
  56. logrus.Errorf("[CreateSelection] call CreateSelection err:%+v\n", err)
  57. returnError(c, 40000, "error")
  58. return
  59. }
  60. returnSuccess(c, 20000, *selectionId)
  61. }
  62. // 更新带货任务(样品奖励、补充信息)
  63. func (t TaskController) UpdateSelection(c *gin.Context) {
  64. data := &vo.SelectionInfoUpdateParam{}
  65. err := c.BindJSON(data)
  66. if err != nil {
  67. logrus.Errorf("Request bind err:%+v\n", err)
  68. returnError(c, 40000, "error")
  69. return
  70. }
  71. selectionId, err := service.SelectionInfoService{}.UpdateSelectionInfo(data)
  72. if err != nil {
  73. logrus.Errorf("[UpdateSelection] call UpdateSelection err:%+v\n", err)
  74. returnError(c, 40000, "error")
  75. return
  76. }
  77. returnSuccess(c, 20000, *selectionId)
  78. }
  79. // 电商带货任务预览
  80. func (t TaskController) GetSelectionDetail(c *gin.Context) {
  81. data := &SelectionDetailParam{}
  82. err := c.BindJSON(data)
  83. if err != nil {
  84. logrus.Errorf("Request bind err:%+v\n", err)
  85. returnError(c, 40000, "error")
  86. return
  87. }
  88. res, err := service.SelectionInfoService{}.GetSelectionDetail(data.SelectionId, data.EnterpriseId)
  89. if err != nil {
  90. logrus.Errorf("[GetSelectionDetail] call Show err:%+v\n", err)
  91. returnError(c, 40000, "error")
  92. return
  93. }
  94. returnSuccess(c, 20000, res)
  95. }