sec_task_logistics.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. 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. // Selection中SampleNum - 1
  63. updateSelection, err := db.GetSelectionById(ctx, request.SelectionId)
  64. if err != nil {
  65. logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateMessageByTaskId error,err:%+v", err)
  66. return nil, err
  67. }
  68. num := updateSelection.RemainNum - 1
  69. selectionInfo := gorm_model.YounggeeSelectionInfo{
  70. SelectionID: request.SelectionId,
  71. RemainNum: num,
  72. }
  73. err = db.UpdateSelection(ctx, selectionInfo)
  74. data := http_model.CreateSecTaskLogisticsData{}
  75. return &data, nil
  76. }
  77. func (*secLogistics) Update(ctx context.Context, request http_model.UpdateSecTaskLogisticsRequest) (*http_model.UpdateSecTaskLogisticsData, error) {
  78. ThingsType := request.ThingsType
  79. // 根据任务查询物流id
  80. logisticsInfo, err := db.GetLogistics(ctx, request.TaskID)
  81. if err != nil {
  82. logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
  83. return nil, err
  84. }
  85. newLogistics := gorm_model.YoungeeTaskLogistics{
  86. LogisticsID: logisticsInfo.LogisticsID,
  87. TaskID: request.TaskID,
  88. ThingsType: int64(ThingsType),
  89. ExplorestoreStarttime: time.Now(),
  90. ExplorestoreEndtime: time.Now(),
  91. DeliveryTime: time.Now(),
  92. }
  93. //实物
  94. if ThingsType == 1 {
  95. newLogistics.CompanyName = request.CompanyName
  96. newLogistics.LogisticsNumber = request.LogisticsNumber
  97. newLogistics.DeliveryTime = time.Now()
  98. } else if ThingsType == 3 {
  99. ExplorestoreStarttime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreStarttime, time.Local)
  100. ExplorestoreEndtime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreEndtime, time.Local)
  101. newLogistics.ExplorestoreStarttime = ExplorestoreStarttime
  102. newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
  103. }
  104. _, err = db.UpdateSecTaskLogistics(ctx, newLogistics)
  105. if err != nil {
  106. logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
  107. return nil, err
  108. }
  109. data := http_model.UpdateSecTaskLogisticsData{}
  110. return &data, nil
  111. }