activity_special_day.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // 活动详情
  8. type CygxActivitySpecialDay struct {
  9. Id int `orm:"column(id);pk";description:"Id"`
  10. ActivityId int `description:"活动ID"`
  11. CreateTime time.Time `description:"创建时间"`
  12. DayTime string `description:"活动行程时间"`
  13. }
  14. // 活动详情
  15. type CygxActivitySpecialDayResp struct {
  16. Id int `orm:"column(id);pk";description:"Id"`
  17. ActivityId int `description:"活动ID"`
  18. CreateTime time.Time `description:"创建时间"`
  19. DayTime time.Time `description:"活动行程时间"`
  20. }
  21. // 添加活动
  22. func AddCygxActivitySpecialDay(items []*CygxActivitySpecialDay, activityId int) (newId int64, err error) {
  23. o := orm.NewOrmUsingDB("hz_cygx")
  24. to, err := o.Begin()
  25. if err != nil {
  26. return
  27. }
  28. defer func() {
  29. if err != nil {
  30. fmt.Println(err)
  31. _ = to.Rollback()
  32. } else {
  33. _ = to.Commit()
  34. }
  35. }()
  36. sql := ` DELETE FROM cygx_activity_special_day WHERE activity_id = ?`
  37. _, err = to.Raw(sql, activityId).Exec()
  38. if err != nil {
  39. return
  40. }
  41. if len(items) > 0 {
  42. for _, v := range items {
  43. _, err = to.Insert(v)
  44. if err != nil {
  45. return
  46. }
  47. }
  48. }
  49. return
  50. }
  51. // 列表
  52. func GetCygxActivitySpecialDayByActivityId(activityId int) (items []*CygxActivitySpecialDayResp, err error) {
  53. o := orm.NewOrmUsingDB("hz_cygx")
  54. sql := `SELECT * FROM cygx_activity_special_day as art WHERE activity_id= ? `
  55. _, err = o.Raw(sql, activityId).QueryRows(&items)
  56. return
  57. }