logistics.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "youngee_b_api/db"
  7. "youngee_b_api/model/gorm_model"
  8. "youngee_b_api/model/http_model"
  9. "github.com/gin-gonic/gin"
  10. "github.com/issue9/conv"
  11. "github.com/sirupsen/logrus"
  12. )
  13. var Logistics *logistics
  14. type logistics struct {
  15. }
  16. // 在物流信息表插入记录
  17. func (*logistics) Create(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
  18. ThingsType := newLogistics.ThingsType
  19. StrategyID := newLogistics.StrategyID
  20. Logistics := gorm_model.YoungeeTaskLogistics{
  21. LogisticsID: newLogistics.LogisticsID,
  22. TaskID: newLogistics.TaskID,
  23. ThingsType: int64(ThingsType),
  24. ExplorestoreStarttime: time.Now(),
  25. ExplorestoreEndtime: time.Now(),
  26. DeliveryTime: time.Now(),
  27. SignedTime: time.Now(),
  28. }
  29. fmt.Println("ThingsType:", ThingsType)
  30. //实物
  31. if ThingsType == 1 {
  32. Logistics.CompanyName = newLogistics.CompanyName
  33. Logistics.LogisticsNumber = newLogistics.LogisticsNumber
  34. Logistics.DeliveryTime = time.Now()
  35. } else if ThingsType == 3 {
  36. fmt.Println("开始时间:", newLogistics.ExplorestoreStarttime)
  37. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  38. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  39. // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  40. } else {
  41. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  42. }
  43. logisticsID, err := db.CreateLogistics(ctx, Logistics, StrategyID)
  44. if err != nil {
  45. logrus.WithContext(ctx).Errorf("[logistics service] call CreateLogistics error,err:%+v", err)
  46. return nil, err
  47. }
  48. projectId, err1 := db.GetProjectIdByTaskId(ctx, newLogistics.TaskID)
  49. if err1 != nil {
  50. logrus.WithContext(ctx).Errorf("[project service] call GetProjectIdByTaskId error,err:%+v", err1)
  51. return nil, err1
  52. }
  53. // 查询StrategyID 通过 StrategyID 和 projectId
  54. RecruitStrategyId, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, StrategyID)
  55. if err2 != nil {
  56. logrus.WithContext(ctx).Errorf("[project service] call GetStrategyIDByTS error,err:%+v", err1)
  57. return nil, err2
  58. }
  59. fmt.Println("RecruitStrategyId: ", *RecruitStrategyId)
  60. // 修改招募策略中已签收数量
  61. err = db.UpdateLogisticsNumber(ctx, *RecruitStrategyId, 1, -1, 0)
  62. if err != nil {
  63. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsNumber error,err:%+v", err)
  64. return nil, err
  65. }
  66. // 修改task_info中发货状态
  67. err = db.UpdateLogisticsStatus(ctx, Logistics.TaskID, 2)
  68. if err != nil {
  69. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsStatus error,err:%+v", err)
  70. return nil, err
  71. }
  72. // 对应招募策略待发货--,已发货++
  73. res := &http_model.CreateLogisticsData{
  74. LogisticsID: *logisticsID,
  75. }
  76. return res, nil
  77. }
  78. // 修改物流信息表
  79. func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
  80. ThingsType := newLogistics.ThingsType
  81. Logistics := gorm_model.YoungeeTaskLogistics{
  82. LogisticsID: newLogistics.LogisticsID,
  83. TaskID: newLogistics.TaskID,
  84. ThingsType: int64(ThingsType),
  85. DeliveryTime: time.Now(),
  86. SignedTime: time.Now(),
  87. }
  88. //实物
  89. if ThingsType == 1 {
  90. Logistics.CompanyName = newLogistics.CompanyName
  91. Logistics.LogisticsNumber = newLogistics.LogisticsNumber
  92. } else if ThingsType == 3 {
  93. fmt.Println("开始时间:", newLogistics.ExplorestoreStarttime)
  94. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  95. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  96. // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  97. } else {
  98. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  99. }
  100. logisticsID, err := db.UpdateLogistics(ctx, Logistics)
  101. if err != nil {
  102. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogistics error,err:%+v", err)
  103. return nil, err
  104. }
  105. res := &http_model.CreateLogisticsData{
  106. LogisticsID: *logisticsID,
  107. }
  108. return res, nil
  109. }
  110. // 签收
  111. func (*logistics) SignForReceipt(ctx *gin.Context, data http_model.SignForReceiptRequest) interface{} {
  112. for _, value := range data.TaskStrategyIds {
  113. taskId := conv.MustInt64(value.TaskId)
  114. strategyId := conv.MustInt64(value.StrategyId)
  115. err := db.UpdateLogisticsStatus(ctx, taskId, 3)
  116. if err != nil {
  117. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsStatus error,err:%+v", err)
  118. return err
  119. }
  120. // 签收时间
  121. err = db.SignForReceipt(ctx, taskId)
  122. if err != nil {
  123. logrus.WithContext(ctx).Errorf("[project service] call SignForReceipt error,err:%+v", err)
  124. return err
  125. }
  126. projectId, err1 := db.GetProjectIdByTaskId(ctx, taskId)
  127. if err1 != nil {
  128. logrus.WithContext(ctx).Errorf("[project service] call GetProjectIdByTaskId error,err:%+v", err1)
  129. return err1
  130. }
  131. // 查询StrategyID 通过 StrategyID 和 projectId
  132. StrategyID, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, strategyId)
  133. if err2 != nil {
  134. logrus.WithContext(ctx).Errorf("[project service] call GetStrategyIDByTS error,err:%+v", err1)
  135. return err2
  136. }
  137. // 修改招募策略中已签收数量
  138. err = db.UpdateLogisticsNumber(ctx, *StrategyID, 0, 0, 1)
  139. if err != nil {
  140. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsNumber error,err:%+v", err)
  141. return err
  142. }
  143. }
  144. return nil
  145. }