sec_task_logistics.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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: 7,
  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.CreateMessageByTaskId(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. newLogistics := gorm_model.YoungeeTaskLogistics{
  67. LogisticsID: request.LogisticsId,
  68. TaskID: request.TaskID,
  69. ThingsType: int64(ThingsType),
  70. ExplorestoreStarttime: time.Now(),
  71. ExplorestoreEndtime: time.Now(),
  72. DeliveryTime: time.Now(),
  73. }
  74. //实物
  75. if ThingsType == 1 {
  76. newLogistics.CompanyName = request.CompanyName
  77. newLogistics.LogisticsNumber = request.LogisticsNumber
  78. newLogistics.DeliveryTime = time.Now()
  79. } else if ThingsType == 3 {
  80. ExplorestoreStarttime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreStarttime, time.Local)
  81. ExplorestoreEndtime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreEndtime, time.Local)
  82. newLogistics.ExplorestoreStarttime = ExplorestoreStarttime
  83. newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
  84. }
  85. _, err := db.UpdateSecTaskLogistics(ctx, newLogistics)
  86. if err != nil {
  87. logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
  88. return nil, err
  89. }
  90. data := http_model.UpdateSecTaskLogisticsData{}
  91. return &data, nil
  92. }