activity_special_trip.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package models
  2. import (
  3. //"hongze/hongze_admin/models"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CygxActivitySpecialTrip struct {
  8. Id int `orm:"column(id);pk"`
  9. UserId int `description:"用户id,多个用,隔开"`
  10. ActivityId int `description:"活动ID"`
  11. CreateTime time.Time `description:"创建时间"`
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱号"`
  14. CompanyId int `description:"公司ID"`
  15. CompanyName string `description:"公司名称"`
  16. RealName string `description:"用户实际名称"`
  17. SellerName string `description:"所属销售"`
  18. AdminId int `description:"销售/管理员ID"`
  19. Source int `description:"来源,1小程序,2后台添加"`
  20. OutboundMobile string `description:"外呼手机号"`
  21. CountryCode string `description:"手机国家区号"`
  22. IsCancel string `description:"是否取消,1是,0否"`
  23. IsValid int `description:"参会报名是否有效 1:是,0"`
  24. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  25. }
  26. type CygxActivitySpecialTripResp struct {
  27. Id int `description:"ID"`
  28. UserId int `description:"用户id"`
  29. ActivityId int `description:"活动ID"`
  30. CreateTime string `description:"创建时间"`
  31. Mobile string `description:"手机号"`
  32. Email string `description:"邮箱号"`
  33. CompanyId int `description:"公司ID"`
  34. CompanyName string `description:"公司名称"`
  35. RealName string `description:"用户实际名称"`
  36. SellerName string `description:"所属销售"`
  37. OutboundMobile string `description:"外呼手机号"`
  38. CountryCode string `description:"手机国家区号"`
  39. }
  40. func GetCygxActivitySpecialTripList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripResp, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT *
  43. FROM
  44. cygx_activity_special_trip
  45. WHERE 1 = 1 ` + condition
  46. _, err = o.Raw(sql, pars).QueryRows(&item)
  47. return
  48. }
  49. // 获取某一用户的报名的数量
  50. func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
  51. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE user_id=? AND activity_id =? `
  52. o := orm.NewOrm()
  53. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  54. return
  55. }
  56. // 获取某一用户有效报名数量
  57. func GetUserActivitySpecialTripIsValidCount(uid, activityId int) (count int, err error) {
  58. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE user_id=? AND activity_id =? AND is_valid = 1 `
  59. o := orm.NewOrm()
  60. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  61. return
  62. }
  63. // 获取某一活动的报名的数量
  64. func GetActivitySpecialTripCountByActivityId(condition string, pars []interface{}) (count int, err error) {
  65. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip as t WHERE 1 = 1 ` + condition
  66. o := orm.NewOrm()
  67. err = o.Raw(sqlCount, pars).QueryRow(&count)
  68. return
  69. }
  70. // 获取某一活动的报名的数量 (同时关联活动类型进行获取)
  71. func GetActivitySpecialTripCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
  72. sqlCount := ` SELECT COUNT(1) AS count
  73. FROM
  74. cygx_activity_special_trip AS t
  75. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  76. WHERE
  77. 1= 1 ` + condition
  78. o := orm.NewOrm()
  79. err = o.Raw(sqlCount, pars).QueryRow(&count)
  80. return
  81. }
  82. // 获取空降的公司报名的记录
  83. func GetActivitySpecialTripAirborneCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
  84. sqlCount := ` SELECT COUNT(1) AS count
  85. FROM
  86. cygx_activity_special_meeting_detail AS t
  87. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  88. WHERE
  89. 1= 1 ` + condition
  90. o := orm.NewOrm()
  91. err = o.Raw(sqlCount, pars).QueryRow(&count)
  92. return
  93. }
  94. // 添加
  95. func AddCygxActivitySpecialTrip(item *CygxActivitySpecialTrip) (err error) {
  96. o := orm.NewOrm()
  97. _, err = o.Insert(item)
  98. return
  99. }
  100. // 取消
  101. func CancelActivitySpecialTrip(uid int, item *CygxActivitySpecialDetail) (err error) {
  102. o := orm.NewOrm()
  103. sql := `DELETE FROM cygx_activity_special_trip WHERE user_id=? AND activity_id=? `
  104. _, err = o.Raw(sql, uid, item.ActivityId).Exec()
  105. return
  106. }
  107. // CancelActivitySpecialTripIsValid 处理活动报名是否有效
  108. func CancelActivitySpecialTripIsValid(isValid, activityId, userId int) (err error) {
  109. sql := ` UPDATE cygx_activity_special_trip SET is_valid= ?,is_cancel = 1 WHERE activity_id = ? AND user_id = ? `
  110. o := orm.NewOrm()
  111. _, err = o.Raw(sql, isValid, activityId, userId).Exec()
  112. return
  113. }