article_department_follow.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxArticleDepartmentFollow struct {
  7. Id int `orm:"column(id);pk"`
  8. DepartmentId int `description:"作者ID"`
  9. UserId int `description:"用户ID"`
  10. Mobile string `description:"手机号"`
  11. Email string `description:"邮箱"`
  12. CompanyId int `description:"公司id"`
  13. CompanyName string `description:"公司名称"`
  14. Type int `description:"操作方式,1报名,2取消报名"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. RealName string `description:"用户实际名称"`
  18. }
  19. type ArticleDepartmentIdRep struct {
  20. DepartmentId int `description:"作者ID"`
  21. }
  22. // 添加
  23. func AddArticleDepartmentFollow(item *CygxArticleDepartmentFollow) (lastId int64, err error) {
  24. o := orm.NewOrm()
  25. lastId, err = o.Insert(item)
  26. return
  27. }
  28. type CygxArticleDepartmentFollowResp struct {
  29. Status int `description:"1:关注,2:取消关注"`
  30. GoFollow bool `description:"是否去关注"`
  31. }
  32. func RemoveArticleDepartmentFollow(userId, industrialManagementId, doType int) (err error) {
  33. o := orm.NewOrm()
  34. sql := `DELETE FROM cygx_article_department_follow WHERE user_id=? AND department_id=? `
  35. _, err = o.Raw(sql, userId, industrialManagementId).Exec()
  36. return
  37. }
  38. // 获取数量
  39. func GetArticleDepartmentFollow(userId, departmentId int, condition string) (count int, err error) {
  40. sql := `SELECT COUNT(1) AS count FROM cygx_article_department_follow WHERE user_id=? AND department_id=? ` + condition
  41. err = orm.NewOrm().Raw(sql, userId, departmentId).QueryRow(&count)
  42. return
  43. }
  44. // 获取数量
  45. func GetArticleDepartmentFollowByUid(userId int) (count int, err error) {
  46. sql := `SELECT COUNT(1) AS count FROM cygx_article_department_follow WHERE user_id=? `
  47. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  48. return
  49. }
  50. // 获取列表信息根据手机号分组
  51. func GetArticleDepartmentFollowByMobileList(condition string) (items []*CygxArticleDepartmentFollow, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT * FROM cygx_article_department_follow WHERE 1 =1 ` + condition + ` GROUP BY user_id `
  54. _, err = o.Raw(sql).QueryRows(&items)
  55. return
  56. }
  57. // 修改用户关注作者的相关信息
  58. func UpdateCygxArticleDepartmentFollow(wxUser *WxUserItem) (err error) {
  59. o := orm.NewOrm()
  60. var sql string
  61. if wxUser.Mobile != "" {
  62. sql = `UPDATE cygx_article_department_follow SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  63. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  64. } else if wxUser.Email != "" {
  65. sql = `UPDATE cygx_article_department_follow SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
  66. _, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
  67. }
  68. return
  69. }