local_change_supplier_status.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_b_api/consts"
  6. "youngee_b_api/model/http_model"
  7. "youngee_b_api/service"
  8. "youngee_b_api/util"
  9. )
  10. func WrapLocalChangeTaskStatusHandler(ctx *gin.Context) {
  11. handler := newLocalChangeTaskStatusHandler(ctx)
  12. baseRun(handler)
  13. }
  14. func newLocalChangeTaskStatusHandler(ctx *gin.Context) *LocalChangeTaskStatusHandler {
  15. return &LocalChangeTaskStatusHandler{
  16. req: http_model.NewLocalChangeSupplierStatusRequst(),
  17. resp: http_model.NewLocalChangeSupplierStatusResponse(),
  18. ctx: ctx,
  19. }
  20. }
  21. type LocalChangeTaskStatusHandler struct {
  22. req *http_model.LocalChangeSupplierStatusRequest
  23. resp *http_model.CommonResponse
  24. ctx *gin.Context
  25. }
  26. func (p *LocalChangeTaskStatusHandler) getContext() *gin.Context {
  27. return p.ctx
  28. }
  29. func (p *LocalChangeTaskStatusHandler) getResponse() interface{} {
  30. return p.resp
  31. }
  32. func (p *LocalChangeTaskStatusHandler) getRequest() interface{} {
  33. return p.req
  34. }
  35. func (p *LocalChangeTaskStatusHandler) run() {
  36. // 1. 同意或拒绝
  37. err := service.SLocalLife.ChangeTaskSupplierStatus(p.ctx, p.req)
  38. if err != nil {
  39. logrus.Errorf("[ChangeTaskStatusHandler] call Create err:%+v\n", err)
  40. util.HandlerPackErrorResp(p.resp, consts.ErrorInternal, "")
  41. logrus.Info("ChangeTaskStatus fail,req:%+v", p.req)
  42. p.resp.Message = "状态变更失败"
  43. p.resp.Status = 40000
  44. return
  45. }
  46. // 变更达人和服务商合作次数
  47. if p.req.SupplierStatus == 2 {
  48. cooperateErr := service.STCooperate.CreateSTCooperate(p.ctx, p.req.SupplierId, p.req.TaskIds)
  49. if cooperateErr != nil {
  50. logrus.Errorf("[ChangeTaskStatusHandler] call Create err:%+v", cooperateErr)
  51. util.HandlerPackErrorResp(p.resp, consts.ErrorInternal, "")
  52. logrus.Info("ChangeTaskStatus fail,req:%+v", p.req)
  53. p.resp.Message = "合作次数修改失败"
  54. p.resp.Status = 40000
  55. return
  56. }
  57. }
  58. p.resp.Message = "任务状态更换成功"
  59. }
  60. func (p *LocalChangeTaskStatusHandler) checkParam() error {
  61. return nil
  62. }