activity_special_signup.go 5.1 KB

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