comein_event.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ComeinEvent 全时会议表
  7. type ComeinEvent struct {
  8. ComeinEventId int `orm:"column(comein_event_id);pk" description:"自增id"`
  9. RoadshowId int `description:"路演ID"`
  10. ConferenceId string `description:"电话会议ID"`
  11. Title string `description:"活动标题"`
  12. StartTime time.Time `description:"路演开始时间"`
  13. EndTime time.Time `description:"路演结束时间"`
  14. People int `description:"实际入会人数"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ShareSellerId int `description:"分享销售ID"`
  17. }
  18. // TableName 表名变更
  19. func (comeinEventInfo *ComeinEvent) TableName() string {
  20. return "comein_event"
  21. }
  22. // GetComeinEventByRoadshowId 根据进门会议的路演id获取进门会议(已同步)
  23. func GetComeinEventByRoadshowId(comeinId int) (item *ComeinEvent, err error) {
  24. o := orm.NewOrm()
  25. sql := "select * from comein_event where roadshow_id=? "
  26. err = o.Raw(sql, comeinId).QueryRow(&item)
  27. return
  28. }
  29. // GetComeInEventById 主键获取进门到会
  30. func GetComeInEventById(comeInEventId int) (item *ComeinEvent, err error) {
  31. o := orm.NewOrm()
  32. sql := "select * from comein_event where comein_event_id = ? "
  33. err = o.Raw(sql, comeInEventId).QueryRow(&item)
  34. return
  35. }
  36. // Update 更新进门会议
  37. func (comeinEventInfo *ComeinEvent) Update(cols []string) (err error) {
  38. o := orm.NewOrm()
  39. _, err = o.Update(comeinEventInfo, cols...)
  40. return
  41. }
  42. // AddComeinEvent 新增进门会议
  43. func AddComeinEvent(comeinEvent *ComeinEvent) (err error) {
  44. o := orm.NewOrm()
  45. id, err := o.Insert(comeinEvent)
  46. if err != nil {
  47. return
  48. }
  49. comeinEvent.ComeinEventId = int(id)
  50. return
  51. }
  52. type ComeinEventItem struct {
  53. ComeinEventId int `orm:"column(comein_event_id);pk" description:"自增id"`
  54. RoadshowId int `description:"路演ID"`
  55. ConferenceId string `description:"电话会议ID"`
  56. Title string `description:"活动标题"`
  57. StartTime time.Time `description:"路演开始时间"`
  58. EndTime time.Time `description:"路演结束时间"`
  59. People int `description:"实际入会人数"`
  60. CreateTime time.Time `description:"创建时间"`
  61. ShareSellerId int `description:"分享销售ID"`
  62. ShareSellerName string `description:"分享销售姓名"`
  63. }
  64. // GetComeinList 获取进门列表数据
  65. func GetComeinList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*ComeinEventItem, err error) {
  66. o := orm.NewOrm()
  67. sql := "select a.*,c.real_name as share_seller_name from comein_event a left join admin c on a.share_seller_id = c.admin_id " +
  68. " where 1=1 "
  69. sql += condition
  70. sql += ` order by a.start_time DESC,comein_event_id desc `
  71. totalSql := `select count(1) total from (` + sql + `) z `
  72. err = o.Raw(totalSql, pars).QueryRow(&total)
  73. if err != nil {
  74. return
  75. }
  76. sql += ` LIMIT ?,? `
  77. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  78. return
  79. }
  80. // AddComeinEventAndUser 添加进门活动和用户
  81. func AddComeinEventAndUser(comeinEventInfo *ComeinEvent, userList []*ComeinEventUser) {
  82. o := orm.NewOrm()
  83. to, err := o.Begin()
  84. if err != nil {
  85. return
  86. }
  87. defer func() {
  88. if err != nil {
  89. _ = to.Rollback()
  90. } else {
  91. _ = to.Commit()
  92. }
  93. }()
  94. id, err := to.Insert(comeinEventInfo)
  95. if err != nil {
  96. return
  97. }
  98. comeinEventInfo.ComeinEventId = int(id)
  99. // 联系人入库
  100. if len(userList) > 0 {
  101. for _, v := range userList {
  102. v.ComeinEventId = comeinEventInfo.ComeinEventId
  103. }
  104. _, tmpErr := to.InsertMulti(len(userList), userList)
  105. if tmpErr != nil {
  106. err = tmpErr
  107. return
  108. }
  109. }
  110. }