activity_special_signup.go 5.3 KB

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