jointly.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/admin/main/vip/model"
  6. "go-common/library/ecode"
  7. )
  8. // JointlysByState jointlys by state.
  9. func (s *Service) JointlysByState(c context.Context, state int8) (res []*model.Jointly, err error) {
  10. now := time.Now().Unix()
  11. res, err = s.dao.JointlysByState(c, state, time.Now().Unix())
  12. for _, v := range res {
  13. switch {
  14. case v.StartTime > now:
  15. v.State = model.WillEffect
  16. case v.StartTime < now && v.EndTime > now:
  17. v.State = model.Effect
  18. case v.EndTime < now:
  19. v.State = model.LoseEffect
  20. }
  21. }
  22. return
  23. }
  24. // AddJointly add jointly.
  25. func (s *Service) AddJointly(c context.Context, j *model.ArgAddJointly) (err error) {
  26. if j.StartTime >= j.EndTime {
  27. err = ecode.VipStartTimeErr
  28. return
  29. }
  30. if len(j.Title) > _maxTitleLen {
  31. err = ecode.VipTitleTooLongErr
  32. return
  33. }
  34. if len(j.Content) > _maxContentLen {
  35. err = ecode.VipContentTooLongErr
  36. return
  37. }
  38. _, err = s.dao.AddJointly(c, &model.Jointly{
  39. Title: j.Title,
  40. Content: j.Content,
  41. Operator: j.Operator,
  42. StartTime: j.StartTime,
  43. EndTime: j.EndTime,
  44. Link: j.Link,
  45. IsHot: j.IsHot,
  46. })
  47. return
  48. }
  49. // ModifyJointly modify jointly.
  50. func (s *Service) ModifyJointly(c context.Context, j *model.ArgModifyJointly) (err error) {
  51. if j.StartTime >= j.EndTime {
  52. err = ecode.VipStartTimeErr
  53. return
  54. }
  55. if len(j.Title) > _maxTitleLen {
  56. err = ecode.VipTitleTooLongErr
  57. return
  58. }
  59. if len(j.Content) > _maxContentLen {
  60. err = ecode.VipContentTooLongErr
  61. return
  62. }
  63. _, err = s.dao.UpdateJointly(c, &model.Jointly{
  64. Title: j.Title,
  65. Content: j.Content,
  66. Operator: j.Operator,
  67. Link: j.Link,
  68. IsHot: j.IsHot,
  69. ID: j.ID,
  70. StartTime: j.StartTime,
  71. EndTime: j.EndTime,
  72. })
  73. return
  74. }
  75. // DeleteJointly delete jointly .
  76. func (s *Service) DeleteJointly(c context.Context, id int64) (err error) {
  77. _, err = s.dao.DeleteJointly(c, id)
  78. return
  79. }