activity_special_signup.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxActivitySpecialSignup struct {
  7. Id int `orm:"column(id);pk"`
  8. ActivityId int `description:"活动ID"`
  9. UserId int `description:"用户ID"`
  10. CreateTime time.Time `description:"创建时间"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. RealName string `description:"用户实际名称"`
  16. SellerName string `description:"所属销售"`
  17. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  18. }
  19. type SignupSpecialStatus struct {
  20. ActivityId int `description:"活动ID"`
  21. HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  22. PopupMsg string `description:"权限弹窗信息"`
  23. PopupMsg2 string `description:"权限弹窗信息"`
  24. Status int `description:"返回类型,1:添加,2:取消"`
  25. SellerMobile string `description:"销售电话"`
  26. SellerName string `description:"销售姓名"`
  27. SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  28. }
  29. // 添加
  30. func AddCygxActivitySpecialSignup(item *CygxActivitySpecialSignup) (err error) {
  31. o := orm.NewOrm()
  32. _, err = o.Insert(item)
  33. return
  34. }
  35. // 获取某一用户的报名的数量
  36. func GetUserCygxActivitySpecialSignup(uid, activityId int) (count int, err error) {
  37. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_signup WHERE user_id=? AND activity_id =? `
  38. o := orm.NewOrm()
  39. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  40. return
  41. }
  42. // 删除
  43. func DeleteCygxActivitySpecialSignup(uid, activityId int) (err error) {
  44. o := orm.NewOrm()
  45. sql := `DELETE FROM cygx_activity_special_signup WHERE user_id=? AND activity_id=? `
  46. _, err = o.Raw(sql, uid, activityId).Exec()
  47. return
  48. }
  49. // 列表
  50. func GetActivityListSpecialAll(activityId int) (items []*CygxActivitySpecialSignup, err error) {
  51. o := orm.NewOrm()
  52. sql := `SELECT art.* FROM cygx_activity_special_signup as art WHERE 1= 1 AND activity_id = ? GROUP BY company_id`
  53. _, err = o.Raw(sql, activityId).QueryRows(&items)
  54. return
  55. }
  56. // 列表
  57. func GetActivityListSpecialByActivityId(activityId int) (items []*CygxActivitySpecialSignup, err error) {
  58. o := orm.NewOrm()
  59. sql := `SELECT art.* FROM cygx_activity_special_signup as art WHERE 1= 1 AND activity_id = ? `
  60. _, err = o.Raw(sql, activityId).QueryRows(&items)
  61. return
  62. }
  63. type CygxActivitySpecialSignupResp struct {
  64. Id int `orm:"column(id);pk"`
  65. ActivityId int `description:"活动ID"`
  66. UserId int `description:"用户ID"`
  67. CreateTime time.Time `description:"创建时间"`
  68. Mobile string `description:"手机号"`
  69. Email string `description:"邮箱"`
  70. CompanyId int `description:"公司id"`
  71. CompanyName string `description:"公司名称"`
  72. RealName string `description:"用户实际名称"`
  73. SellerName string `description:"所属销售"`
  74. Count string `description:"所属销售"`
  75. }
  76. // 列表
  77. func GetActivityListSpecialGroupByMobile(condition string, pars []interface{}) (items []*CygxActivitySpecialSignupResp, err error) {
  78. o := orm.NewOrm()
  79. sql := `SELECT s.*, COUNT( 1 ) AS count FROM cygx_activity_special_signup as s INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id ` + condition + ` GROUP BY s.mobile`
  80. _, err = o.Raw(sql, pars).QueryRows(&items)
  81. return
  82. }
  83. // 列表
  84. func GetActivityListSpecialGroupByCompanyId(condition string, pars []interface{}) (items []*CygxActivitySpecialSignupResp, err error) {
  85. o := orm.NewOrm()
  86. sql := `SELECT *, COUNT( 1 ) AS count FROM cygx_activity_special_signup as s INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  87. ` + condition + ` GROUP BY s.company_id`
  88. _, err = o.Raw(sql, pars).QueryRows(&items)
  89. return
  90. }
  91. // UpdateActivitySpecialSignupNumMulti 批量修改专项调研感兴趣的人数排名
  92. func UpdateActivitySpecialSignupNumMulti(items []*CygxActivitySpecialSignupResp) (err error) {
  93. o := orm.NewOrm()
  94. p, err := o.Raw("UPDATE cygx_activity_special_signup SET user_num = ? WHERE mobile = ?").Prepare()
  95. if err != nil {
  96. return
  97. }
  98. defer func() {
  99. _ = p.Close() // 别忘记关闭 statement
  100. }()
  101. for _, v := range items {
  102. _, err = p.Exec(v.Count, v.Mobile)
  103. if err != nil {
  104. return
  105. }
  106. }
  107. return
  108. }
  109. // UpdateActivitySpecialSignupCompanyIdMulti 批量修改专项调研感兴趣的用户的对应公司ID
  110. func UpdateActivitySpecialSignupCompanyIdMulti(items []*WxUser) (err error) {
  111. o := orm.NewOrm()
  112. p, err := o.Raw("UPDATE cygx_activity_special_signup SET company_id = ? WHERE mobile = ?").Prepare()
  113. if err != nil {
  114. return
  115. }
  116. defer func() {
  117. _ = p.Close() // 别忘记关闭 statement
  118. }()
  119. for _, v := range items {
  120. _, err = p.Exec(v.CompanyId, v.Mobile)
  121. if err != nil {
  122. return
  123. }
  124. }
  125. return
  126. }
  127. // UpdateActivitySpecialSignupCompanyNumMulti 批量修改专项调研感兴趣的公司对应的数量
  128. func UpdateActivitySpecialSignupCompanyNumMulti(items []*CygxActivitySpecialSignupResp) (err error) {
  129. o := orm.NewOrm()
  130. p, err := o.Raw("UPDATE cygx_activity_special_signup SET company_num = ? WHERE company_id = ?").Prepare()
  131. if err != nil {
  132. return
  133. }
  134. defer func() {
  135. _ = p.Close() // 别忘记关闭 statement
  136. }()
  137. for _, v := range items {
  138. _, err = p.Exec(v.Count, v.CompanyId)
  139. if err != nil {
  140. return
  141. }
  142. }
  143. return
  144. }