activity_special_signup.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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
  80. INNER JOIN wx_user AS u ON u.user_id = s.user_id ` + condition + ` GROUP BY s.mobile`
  81. _, err = o.Raw(sql, pars).QueryRows(&items)
  82. return
  83. }
  84. //列表
  85. func GetActivityListSpecialGroupByCompanyId(condition string, pars []interface{}) (items []*CygxActivitySpecialSignupResp, err error) {
  86. o := orm.NewOrm()
  87. 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
  88. INNER JOIN wx_user AS u ON u.user_id = s.user_id ` + condition + ` GROUP BY s.company_id`
  89. _, err = o.Raw(sql, pars).QueryRows(&items)
  90. return
  91. }
  92. // UpdateActivitySpecialSignupNumMulti 批量修改专项调研感兴趣的人数排名
  93. func UpdateActivitySpecialSignupNumMulti(items []*CygxActivitySpecialSignupResp) (err error) {
  94. o := orm.NewOrm()
  95. p, err := o.Raw("UPDATE cygx_activity_special_signup SET user_num = ? WHERE mobile = ?").Prepare()
  96. if err != nil {
  97. return
  98. }
  99. defer func() {
  100. _ = p.Close() // 别忘记关闭 statement
  101. }()
  102. for _, v := range items {
  103. _, err = p.Exec(v.Count, v.Mobile)
  104. if err != nil {
  105. return
  106. }
  107. }
  108. return
  109. }
  110. // UpdateActivitySpecialSignupCompanyIdMulti 批量修改专项调研感兴趣的用户的对应公司ID
  111. func UpdateActivitySpecialSignupCompanyIdMulti(items []*WxUser) (err error) {
  112. o := orm.NewOrm()
  113. p, err := o.Raw("UPDATE cygx_activity_special_signup SET company_id = ? WHERE mobile = ?").Prepare()
  114. if err != nil {
  115. return
  116. }
  117. defer func() {
  118. _ = p.Close() // 别忘记关闭 statement
  119. }()
  120. for _, v := range items {
  121. _, err = p.Exec(v.CompanyId, v.Mobile)
  122. if err != nil {
  123. return
  124. }
  125. }
  126. return
  127. }
  128. // UpdateActivitySpecialSignupCompanyNumMulti 批量修改专项调研感兴趣的公司对应的数量
  129. func UpdateActivitySpecialSignupCompanyNumMulti(items []*CygxActivitySpecialSignupResp) (err error) {
  130. o := orm.NewOrm()
  131. p, err := o.Raw("UPDATE cygx_activity_special_signup SET company_num = ? WHERE company_id = ?").Prepare()
  132. if err != nil {
  133. return
  134. }
  135. defer func() {
  136. _ = p.Close() // 别忘记关闭 statement
  137. }()
  138. for _, v := range items {
  139. _, err = p.Exec(v.Count, v.CompanyId)
  140. if err != nil {
  141. return
  142. }
  143. }
  144. return
  145. }