logistics.go 3.8 KB

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