sec_task_logistics.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package service
  2. import (
  3. "context"
  4. "github.com/sirupsen/logrus"
  5. "time"
  6. "youngee_m_api/db"
  7. "youngee_m_api/model/gorm_model"
  8. "youngee_m_api/model/http_model"
  9. )
  10. var SecLogistics *secLogistics
  11. type secLogistics struct {
  12. }
  13. func (*secLogistics) 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. }
  45. _, err = db.UpdateSecTask(ctx, updatdSecTask)
  46. if err != nil {
  47. logrus.WithContext(ctx).Errorf("[sectask logistics service] call UpdateSecTask error,err:%+v", err)
  48. return nil, err
  49. }
  50. // 插入任务日志、达人消息
  51. err = db.CreateTaskLog(ctx, newLogistics.TaskID, "发货时间")
  52. if err != nil {
  53. logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateTaskLog error,err:%+v", err)
  54. return nil, err
  55. }
  56. err = db.CreateMessageBySecTaskId(ctx, 8, 2, newLogistics.TaskID)
  57. if err != nil {
  58. logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateMessageByTaskId error,err:%+v", err)
  59. return nil, err
  60. }
  61. data := http_model.CreateSecTaskLogisticsData{}
  62. return &data, nil
  63. }
  64. func (*secLogistics) Update(ctx context.Context, request http_model.UpdateSecTaskLogisticsRequest) (*http_model.UpdateSecTaskLogisticsData, error) {
  65. ThingsType := request.ThingsType
  66. // 根据任务查询物流id
  67. logisticsInfo, err := db.GetLogistics(ctx, request.TaskID)
  68. if err != nil {
  69. logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
  70. return nil, err
  71. }
  72. newLogistics := gorm_model.YoungeeTaskLogistics{
  73. LogisticsID: logisticsInfo.LogisticsID,
  74. TaskID: request.TaskID,
  75. ThingsType: int64(ThingsType),
  76. ExplorestoreStarttime: time.Now(),
  77. ExplorestoreEndtime: time.Now(),
  78. DeliveryTime: time.Now(),
  79. }
  80. //实物
  81. if ThingsType == 1 {
  82. newLogistics.CompanyName = request.CompanyName
  83. newLogistics.LogisticsNumber = request.LogisticsNumber
  84. newLogistics.DeliveryTime = time.Now()
  85. } else if ThingsType == 3 {
  86. ExplorestoreStarttime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreStarttime, time.Local)
  87. ExplorestoreEndtime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreEndtime, time.Local)
  88. newLogistics.ExplorestoreStarttime = ExplorestoreStarttime
  89. newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
  90. }
  91. _, err = db.UpdateSecTaskLogistics(ctx, newLogistics)
  92. if err != nil {
  93. logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
  94. return nil, err
  95. }
  96. data := http_model.UpdateSecTaskLogisticsData{}
  97. return &data, nil
  98. }