logistics.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package service
  2. import (
  3. "context"
  4. "youngee_b_api/db"
  5. "youngee_b_api/model/gorm_model"
  6. "youngee_b_api/model/http_model"
  7. )
  8. var Logistics *logistics
  9. type logistics struct {
  10. }
  11. func (*logistics) Create(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
  12. ThingsType := newLogistics.ThingsType
  13. RecruitStrategyID := newLogistics.RecruitStrategyID
  14. Logistics := gorm_model.YoungeeTaskLogistics{
  15. LogisticsID: newLogistics.LogisticsID,
  16. TaskID: newLogistics.TaskID,
  17. ThingsType: ThingsType,
  18. }
  19. //实物
  20. if ThingsType == 1 {
  21. Logistics.CompanyName = newLogistics.CompanyName
  22. Logistics.DeliveryTime = newLogistics.DeliveryTime
  23. } else if ThingsType == 2 {
  24. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  25. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  26. Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  27. } else {
  28. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  29. }
  30. logisticsID, err := db.CreateLogistics(ctx, Logistics, RecruitStrategyID)
  31. if err != nil {
  32. return nil, err
  33. }
  34. res := &http_model.CreateLogisticsData{
  35. LogisticsID: *logisticsID,
  36. }
  37. return res, nil
  38. }
  39. func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
  40. ThingsType := newLogistics.ThingsType
  41. Logistics := gorm_model.YoungeeTaskLogistics{
  42. LogisticsID: newLogistics.LogisticsID,
  43. TaskID: newLogistics.TaskID,
  44. ThingsType: ThingsType,
  45. }
  46. //实物
  47. if ThingsType == 1 {
  48. Logistics.CompanyName = newLogistics.CompanyName
  49. Logistics.DeliveryTime = newLogistics.DeliveryTime
  50. } else if ThingsType == 2 {
  51. Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
  52. Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
  53. Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
  54. } else {
  55. Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
  56. }
  57. logisticsID, err := db.UpdateLogistics(ctx, Logistics)
  58. if err != nil {
  59. return nil, err
  60. }
  61. res := &http_model.CreateLogisticsData{
  62. LogisticsID: *logisticsID,
  63. }
  64. return res, nil
  65. }