logistics.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // Create 在物流信息表插入记录
  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. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  37. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  38. // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  39. } else {
  40. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  41. }
  42. logisticsID, err := db.CreateLogistics(ctx, Logistics, StrategyID)
  43. if err != nil {
  44. logrus.WithContext(ctx).Errorf("[logistics service] call CreateLogistics error,err:%+v", err)
  45. return nil, err
  46. }
  47. projectId, err1 := db.GetProjectIdByTaskId(ctx, newLogistics.TaskID)
  48. if err1 != nil {
  49. logrus.WithContext(ctx).Errorf("[project service] call GetProjectIdByTaskId error,err:%+v", err1)
  50. return nil, err1
  51. }
  52. // 查询StrategyID 通过 StrategyID 和 projectId
  53. RecruitStrategyId, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, StrategyID)
  54. if err2 != nil {
  55. logrus.WithContext(ctx).Errorf("[project service] call GetStrategyIDByTS error,err:%+v", err1)
  56. return nil, err2
  57. }
  58. fmt.Println("RecruitStrategyId: ", *RecruitStrategyId)
  59. // 修改招募策略中已签收数量
  60. err = db.UpdateLogisticsNumber(ctx, *RecruitStrategyId, 1, -1, 0)
  61. if err != nil {
  62. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsNumber error,err:%+v", err)
  63. return nil, err
  64. }
  65. // 修改task_info中发货状态
  66. err = db.UpdateLogisticsStatus(ctx, Logistics.TaskID, 2)
  67. if err != nil {
  68. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsStatus error,err:%+v", err)
  69. return nil, err
  70. }
  71. // 修改task_info中发货状态
  72. err = db.UpdateLogisticsDate(ctx, Logistics.TaskID)
  73. if err != nil {
  74. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsDate error,err:%+v", err)
  75. return nil, err
  76. }
  77. // 对应招募策略待发货--,已发货++
  78. res := &http_model.CreateLogisticsData{
  79. LogisticsID: *logisticsID,
  80. }
  81. return res, nil
  82. }
  83. // 修改物流信息表
  84. func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
  85. ThingsType := newLogistics.ThingsType
  86. Logistics := gorm_model.YoungeeTaskLogistics{
  87. LogisticsID: newLogistics.LogisticsID,
  88. TaskID: newLogistics.TaskID,
  89. ThingsType: int64(ThingsType),
  90. DeliveryTime: time.Now(),
  91. SignedTime: time.Now(),
  92. }
  93. //实物
  94. if ThingsType == 1 {
  95. Logistics.CompanyName = newLogistics.CompanyName
  96. Logistics.LogisticsNumber = newLogistics.LogisticsNumber
  97. } else if ThingsType == 3 {
  98. fmt.Println("开始时间:", newLogistics.ExplorestoreStarttime)
  99. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  100. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  101. // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  102. } else {
  103. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  104. }
  105. logisticsID, err := db.UpdateLogistics(ctx, Logistics)
  106. if err != nil {
  107. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogistics error,err:%+v", err)
  108. return nil, err
  109. }
  110. res := &http_model.CreateLogisticsData{
  111. LogisticsID: *logisticsID,
  112. }
  113. return res, nil
  114. }
  115. // 签收
  116. func (*logistics) SignForReceipt(ctx *gin.Context, data http_model.SignForReceiptRequest) interface{} {
  117. projectId, err1 := db.GetProjectIdByTaskId(ctx, conv.MustInt64(data.TaskStrategyIds[0].TaskId))
  118. if err1 != nil {
  119. logrus.WithContext(ctx).Errorf("[project service] call GetProjectIdByTaskId error,err:%+v", err1)
  120. return err1
  121. }
  122. // 签收时更新任务阶段
  123. project, err3 := db.GetProjectDetail(ctx, conv.MustInt64(*projectId))
  124. if err3 != nil {
  125. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err3)
  126. return err3
  127. }
  128. if project.ContentType == 1 {
  129. err := db.UpdateTaskStage(ctx, conv.MustInt64(*projectId), 2, 11)
  130. if err != nil {
  131. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
  132. return err
  133. }
  134. } else {
  135. err := db.UpdateTaskStage(ctx, conv.MustInt64(*projectId), 2, 8)
  136. if err != nil {
  137. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
  138. return err
  139. }
  140. }
  141. for _, value := range data.TaskStrategyIds {
  142. taskId := conv.MustInt64(value.TaskId)
  143. strategyId := conv.MustInt64(value.StrategyId)
  144. err := db.UpdateLogisticsStatus(ctx, taskId, 3)
  145. if err != nil {
  146. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsStatus error,err:%+v", err)
  147. return err
  148. }
  149. // 签收时间
  150. err = db.SignForReceipt(ctx, taskId)
  151. if err != nil {
  152. logrus.WithContext(ctx).Errorf("[project service] call SignForReceipt error,err:%+v", err)
  153. return err
  154. }
  155. // 查询StrategyID 通过 StrategyID 和 projectId
  156. StrategyID, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, strategyId)
  157. if err2 != nil {
  158. logrus.WithContext(ctx).Errorf("[project service] call GetStrategyIDByTS error,err:%+v", err1)
  159. return err2
  160. }
  161. // 修改招募策略中已签收数量
  162. err = db.UpdateLogisticsNumber(ctx, *StrategyID, 0, 0, 1)
  163. if err != nil {
  164. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsNumber error,err:%+v", err)
  165. return err
  166. }
  167. }
  168. return nil
  169. }