logistics.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. // 修改task_info中任务阶段
  78. err = db.UpdateTaskStageByTaskId(ctx, Logistics.TaskID, 2, 5) //修改为待传初稿
  79. if err != nil {
  80. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsDate error,err:%+v", err)
  81. return nil, err
  82. }
  83. // 对应招募策略待发货--,已发货++
  84. res := &http_model.CreateLogisticsData{
  85. LogisticsID: *logisticsID,
  86. }
  87. return res, nil
  88. }
  89. // 修改物流信息表
  90. func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
  91. ThingsType := newLogistics.ThingsType
  92. Logistics := gorm_model.YoungeeTaskLogistics{
  93. LogisticsID: newLogistics.LogisticsID,
  94. TaskID: newLogistics.TaskID,
  95. ThingsType: int64(ThingsType),
  96. DeliveryTime: time.Now(),
  97. SignedTime: time.Now(),
  98. }
  99. //实物
  100. if ThingsType == 1 {
  101. Logistics.CompanyName = newLogistics.CompanyName
  102. Logistics.LogisticsNumber = newLogistics.LogisticsNumber
  103. } else if ThingsType == 3 {
  104. fmt.Println("开始时间:", newLogistics.ExplorestoreStarttime)
  105. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  106. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  107. // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  108. } else {
  109. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  110. }
  111. logisticsID, err := db.UpdateLogistics(ctx, Logistics)
  112. if err != nil {
  113. logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogistics error,err:%+v", err)
  114. return nil, err
  115. }
  116. res := &http_model.CreateLogisticsData{
  117. LogisticsID: *logisticsID,
  118. }
  119. return res, nil
  120. }
  121. // 签收
  122. func (*logistics) SignForReceipt(ctx *gin.Context, data http_model.SignForReceiptRequest) interface{} {
  123. projectId, err1 := db.GetProjectIdByTaskId(ctx, conv.MustInt64(data.TaskStrategyIds[0].TaskId))
  124. if err1 != nil {
  125. logrus.WithContext(ctx).Errorf("[project service] call GetProjectIdByTaskId error,err:%+v", err1)
  126. return err1
  127. }
  128. // 签收时更新任务阶段
  129. project, err3 := db.GetProjectDetail(ctx, conv.MustInt64(*projectId))
  130. if err3 != nil {
  131. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err3)
  132. return err3
  133. }
  134. if project.ContentType == 1 {
  135. err := db.UpdateTaskStageByProjectId(ctx, conv.MustInt64(*projectId), 2, 9)
  136. if err != nil {
  137. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
  138. return err
  139. }
  140. } else {
  141. err := db.UpdateTaskStageByProjectId(ctx, conv.MustInt64(*projectId), 2, 7)
  142. if err != nil {
  143. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
  144. return err
  145. }
  146. }
  147. for _, value := range data.TaskStrategyIds {
  148. taskId := conv.MustInt64(value.TaskId)
  149. strategyId := conv.MustInt64(value.StrategyId)
  150. err := db.UpdateLogisticsStatus(ctx, taskId, 3)
  151. if err != nil {
  152. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsStatus error,err:%+v", err)
  153. return err
  154. }
  155. // 签收时间
  156. err = db.SignForReceipt(ctx, taskId)
  157. if err != nil {
  158. logrus.WithContext(ctx).Errorf("[project service] call SignForReceipt error,err:%+v", err)
  159. return err
  160. }
  161. // 查询StrategyID 通过 StrategyID 和 projectId
  162. StrategyID, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, strategyId)
  163. if err2 != nil {
  164. logrus.WithContext(ctx).Errorf("[project service] call GetStrategyIDByTS error,err:%+v", err1)
  165. return err2
  166. }
  167. // 修改招募策略中已签收数量
  168. err = db.UpdateLogisticsNumber(ctx, *StrategyID, 0, 0, 1)
  169. if err != nil {
  170. logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsNumber error,err:%+v", err)
  171. return err
  172. }
  173. }
  174. return nil
  175. }