logistics.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. RecruitStrategyID := newLogistics.RecruitStrategyID
  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, RecruitStrategyID)
  44. if err != nil {
  45. logrus.WithContext(ctx).Errorf("[logistics service] call CreateLogistics error,err:%+v", err)
  46. return nil, err
  47. }
  48. // 修改招募策略中已发货待发货数量
  49. err = db.UpdateLogisticsNumber(ctx, RecruitStrategyID, 1, -1, 0)
  50. if err != nil {
  51. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsNumber error,err:%+v", err)
  52. return nil, err
  53. }
  54. // 修改task_info中发货状态
  55. err = db.UpdateLogisticsStatus(ctx, Logistics.TaskID, 2)
  56. if err != nil {
  57. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsStatus error,err:%+v", err)
  58. return nil, err
  59. }
  60. // 对应招募策略待发货--,已发货++
  61. res := &http_model.CreateLogisticsData{
  62. LogisticsID: *logisticsID,
  63. }
  64. return res, nil
  65. }
  66. // 修改物流信息表
  67. func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
  68. ThingsType := newLogistics.ThingsType
  69. Logistics := gorm_model.YoungeeTaskLogistics{
  70. LogisticsID: newLogistics.LogisticsID,
  71. TaskID: newLogistics.TaskID,
  72. ThingsType: int64(ThingsType),
  73. DeliveryTime: time.Now(),
  74. SignedTime: time.Now(),
  75. }
  76. //实物
  77. if ThingsType == 1 {
  78. Logistics.CompanyName = newLogistics.CompanyName
  79. Logistics.LogisticsNumber = newLogistics.LogisticsNumber
  80. } else if ThingsType == 3 {
  81. fmt.Println("开始时间:", newLogistics.ExplorestoreStarttime)
  82. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  83. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  84. // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  85. } else {
  86. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  87. }
  88. logisticsID, err := db.UpdateLogistics(ctx, Logistics)
  89. if err != nil {
  90. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogistics error,err:%+v", err)
  91. return nil, err
  92. }
  93. res := &http_model.CreateLogisticsData{
  94. LogisticsID: *logisticsID,
  95. }
  96. return res, nil
  97. }
  98. // 签收
  99. func (*logistics) SignForReceipt(ctx *gin.Context, data http_model.SignForReceiptRequest) interface{} {
  100. for _, value := range data.TaskStrategyIds {
  101. taskId := conv.MustInt64(value.TaskId)
  102. strategyId := conv.MustInt64(value.StrategyId)
  103. err := db.UpdateLogisticsStatus(ctx, taskId, 3)
  104. if err != nil {
  105. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsStatus error,err:%+v", err)
  106. return err
  107. }
  108. // 签收时间
  109. err = db.SignForReceipt(ctx, taskId)
  110. if err != nil {
  111. logrus.WithContext(ctx).Errorf("[project service] call SignForReceipt error,err:%+v", err)
  112. return err
  113. }
  114. projectId, err1 := db.GetProjectIdByTaskId(ctx, taskId)
  115. if err1 != nil {
  116. logrus.WithContext(ctx).Errorf("[project service] call GetProjectIdByTaskId error,err:%+v", err1)
  117. return err1
  118. }
  119. // 查询recruitStrategyID 通过 StrategyID 和 projectId
  120. recruitStrategyId, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, strategyId)
  121. if err2 != nil {
  122. logrus.WithContext(ctx).Errorf("[project service] call GetRecruitStrategyIdByTS error,err:%+v", err1)
  123. return err2
  124. }
  125. // 修改招募策略中已签收数量
  126. err = db.UpdateLogisticsNumber(ctx, *recruitStrategyId, 0, 0, 1)
  127. if err != nil {
  128. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsNumber error,err:%+v", err)
  129. return err
  130. }
  131. }
  132. return nil
  133. }