logistics.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package sectask_service
  2. import (
  3. "context"
  4. "github.com/sirupsen/logrus"
  5. "time"
  6. "youngee_b_api/db"
  7. "youngee_b_api/model/gorm_model"
  8. "youngee_b_api/model/http_model"
  9. )
  10. var Logistics *logistics
  11. type logistics struct {
  12. }
  13. func (*logistics) Create(ctx context.Context, request http_model.CreateSecTaskLogisticsRequest) (*http_model.CreateSecTaskLogisticsData, error) {
  14. ThingsType := request.ThingsType
  15. newLogistics := gorm_model.YoungeeTaskLogistics{
  16. TaskID: request.TaskID,
  17. ThingsType: int64(ThingsType),
  18. ExplorestoreStarttime: time.Now(),
  19. ExplorestoreEndtime: time.Now(),
  20. DeliveryTime: time.Now(),
  21. }
  22. //实物
  23. if ThingsType == 1 {
  24. newLogistics.CompanyName = request.CompanyName
  25. newLogistics.LogisticsNumber = request.LogisticsNumber
  26. newLogistics.DeliveryTime = time.Now()
  27. } else if ThingsType == 3 {
  28. ExplorestoreStarttime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreStarttime, time.Local)
  29. ExplorestoreEndtime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreEndtime, time.Local)
  30. newLogistics.ExplorestoreStarttime = ExplorestoreStarttime
  31. newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
  32. }
  33. _, err := db.CreateSecTaskLogistics(ctx, newLogistics)
  34. if err != nil {
  35. logrus.WithContext(ctx).Errorf("[newLogistics service] call CreatenewLogistics error,err:%+v", err)
  36. return nil, err
  37. }
  38. // 修改task_info中发货时间、任务阶段
  39. updatdSecTask := gorm_model.YounggeeSecTaskInfo{
  40. TaskID: request.TaskID,
  41. LogisticsStatus: 2,
  42. TaskStage: 8,
  43. DeliveryDate: time.Now(),
  44. FreeStage: 4,
  45. }
  46. _, err = db.UpdateSecTask(ctx, updatdSecTask)
  47. if err != nil {
  48. logrus.WithContext(ctx).Errorf("[sectask logistics service] call UpdateSecTask error,err:%+v", err)
  49. return nil, err
  50. }
  51. taskInfo, taskErr := db.GetSecTaskById(ctx, request.TaskID)
  52. if taskErr != nil {
  53. return nil, taskErr
  54. }
  55. // 更新带货任务已发货人数
  56. err = db.UpdateSelectionNum(ctx, taskInfo.SelectionID)
  57. if err != nil {
  58. return nil, err
  59. }
  60. // 插入任务日志、达人消息
  61. err = db.CreateTaskLog(ctx, newLogistics.TaskID, "发货时间")
  62. if err != nil {
  63. logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateTaskLog error,err:%+v", err)
  64. return nil, err
  65. }
  66. err = db.CreateMessageBySecTaskId(ctx, 8, 2, newLogistics.TaskID)
  67. if err != nil {
  68. logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateMessageByTaskId error,err:%+v", err)
  69. return nil, err
  70. }
  71. data := http_model.CreateSecTaskLogisticsData{}
  72. return &data, nil
  73. }
  74. func (*logistics) Update(ctx context.Context, request http_model.UpdateSecTaskLogisticsRequest) (*http_model.UpdateSecTaskLogisticsData, error) {
  75. ThingsType := request.ThingsType
  76. // 根据任务查询物流id
  77. logisticsInfo, err := db.GetLogistics(ctx, request.TaskID)
  78. if err != nil {
  79. logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
  80. return nil, err
  81. }
  82. newLogistics := gorm_model.YoungeeTaskLogistics{
  83. LogisticsID: logisticsInfo.LogisticsID,
  84. TaskID: request.TaskID,
  85. ThingsType: int64(ThingsType),
  86. ExplorestoreStarttime: time.Now(),
  87. ExplorestoreEndtime: time.Now(),
  88. DeliveryTime: time.Now(),
  89. }
  90. //实物
  91. if ThingsType == 1 {
  92. newLogistics.CompanyName = request.CompanyName
  93. newLogistics.LogisticsNumber = request.LogisticsNumber
  94. newLogistics.DeliveryTime = time.Now()
  95. } else if ThingsType == 3 {
  96. ExplorestoreStarttime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreStarttime, time.Local)
  97. ExplorestoreEndtime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreEndtime, time.Local)
  98. newLogistics.ExplorestoreStarttime = ExplorestoreStarttime
  99. newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
  100. }
  101. _, err = db.UpdateSecTaskLogistics(ctx, newLogistics)
  102. if err != nil {
  103. logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
  104. return nil, err
  105. }
  106. data := http_model.UpdateSecTaskLogisticsData{}
  107. return &data, nil
  108. }