logistics.go 4.5 KB

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