user_yanxuan_permission.go 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygx/utils"
  5. "time"
  6. )
  7. type CygxUserYanxuanPermission struct {
  8. UserYanxuanPermissionId int64 `orm:"column(user_yanxuan_permission_id);pk"`
  9. UserId int `description:"用户ID"`
  10. CompanyId int `description:"权限开始日期"`
  11. StartDate string `description:"权限开始日期"`
  12. EndDate string `description:"权限结束日期"`
  13. Status string `description:"'试用','未开通'"`
  14. Mobile string `description:"手机号"`
  15. Email string `description:"邮箱"`
  16. RealName string `description:"用户实际名称"`
  17. CompanyName string `description:"公司名称"`
  18. AdminId int `description:"后台添加人员ID"`
  19. AdminRealName string `description:"后台添加人员姓名"`
  20. CreatedTime time.Time `description:"创建时间"`
  21. LastUpdatedTime time.Time `description:"修改时间根据时间戳自动更新"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. }
  24. type CygxUserYanxuanPermissionLog struct {
  25. UserYanxuanPermissionId int64 `orm:"column(user_yanxuan_permission_log_id);pk"`
  26. UserId int `description:"用户ID"`
  27. CompanyId int `description:"权限开始日期"`
  28. StartDate string `description:"权限开始日期"`
  29. EndDate string `description:"权限结束日期"`
  30. Status string `description:"'试用','未开通'"`
  31. Mobile string `description:"手机号"`
  32. Email string `description:"邮箱"`
  33. RealName string `description:"用户实际名称"`
  34. CompanyName string `description:"公司名称"`
  35. AdminId int `description:"后台添加人员ID"`
  36. AdminRealName string `description:"后台添加人员姓名"`
  37. CreatedTime time.Time `description:"创建时间"`
  38. LastUpdatedTime time.Time `description:"修改时间根据时间戳自动更新"`
  39. ModifyTime time.Time `description:"修改时间"`
  40. }
  41. // 根据用户ID获取是否开通过研选权限
  42. func GetCygxUserYanxuanPermissionCountByUserId(userId int) (count int, err error) {
  43. o := orm.NewOrm()
  44. sql := ` SELECT COUNT(1) FROM cygx_user_yanxuan_permission WHERE status = '试用' AND user_id = ? `
  45. err = o.Raw(sql, userId).QueryRow(&count)
  46. return
  47. }
  48. // 列表
  49. func GetCygxUserYanxuanPermissionList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxUserYanxuanPermission, err error) {
  50. o := orm.NewOrm()
  51. sql := `SELECT * FROM cygx_user_yanxuan_permission WHERE 1= 1 `
  52. if condition != "" {
  53. sql += condition
  54. }
  55. sql += ` LIMIT ?,? `
  56. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  57. return
  58. }
  59. // 根据用户ID获取研选开通详情
  60. func GetCygxUserYanxuanPermissionDetailByUserId(userId int) (item *CygxUserYanxuanPermission, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT * FROM cygx_user_yanxuan_permission WHERE status = '试用' AND user_id = ? `
  63. err = o.Raw(sql, userId).QueryRow(&item)
  64. return
  65. }
  66. // UpdateCygxUserYanxuanPermissionToClose 把权限到期的状态进行更新
  67. func UpdateCygxUserYanxuanPermissionToClose() (err error) {
  68. o := orm.NewOrm()
  69. sql := `UPDATE cygx_user_yanxuan_permission SET status = '未开通' WHERE status = '试用' AND end_date < ? `
  70. _, err = o.Raw(sql, time.Now().Format(utils.FormatDate)).Exec()
  71. return
  72. }