user_yanxuan_permission.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type UpdateUserYanxuanPermissionReq struct {
  7. UserId int `description:"用户ID"`
  8. Type int `description:"类型 0关闭 、1开通"`
  9. }
  10. type CygxUserYanxuanPermission struct {
  11. UserYanxuanPermissionId int64 `orm:"column(user_yanxuan_permission_id);pk"`
  12. UserId int `description:"用户ID"`
  13. CompanyId int `description:"权限开始日期"`
  14. StartDate string `description:"权限开始日期"`
  15. EndDate string `description:"权限结束日期"`
  16. Status string `description:"'试用','未开通'"`
  17. Mobile string `description:"手机号"`
  18. Email string `description:"邮箱"`
  19. RealName string `description:"用户实际名称"`
  20. CompanyName string `description:"公司名称"`
  21. AdminId int `description:"后台添加人员ID"`
  22. AdminRealName string `description:"后台添加人员姓名"`
  23. CreatedTime time.Time `description:"创建时间"`
  24. LastUpdatedTime time.Time `description:"修改时间根据时间戳自动更新"`
  25. ModifyTime time.Time `description:"修改时间"`
  26. }
  27. type CygxUserYanxuanPermissionLog struct {
  28. UserYanxuanPermissionId int64 `orm:"column(user_yanxuan_permission_log_id);pk"`
  29. UserId int `description:"用户ID"`
  30. CompanyId int `description:"权限开始日期"`
  31. StartDate string `description:"权限开始日期"`
  32. EndDate string `description:"权限结束日期"`
  33. Status string `description:"'试用','未开通'"`
  34. Mobile string `description:"手机号"`
  35. Email string `description:"邮箱"`
  36. RealName string `description:"用户实际名称"`
  37. CompanyName string `description:"公司名称"`
  38. AdminId int `description:"后台添加人员ID"`
  39. AdminRealName string `description:"后台添加人员姓名"`
  40. CreatedTime time.Time `description:"创建时间"`
  41. LastUpdatedTime time.Time `description:"修改时间根据时间戳自动更新"`
  42. ModifyTime time.Time `description:"修改时间"`
  43. }
  44. // 添加
  45. func AddCygxUserYanxuanPermission(item *CygxUserYanxuanPermission) (lastId int64, err error) {
  46. o := orm.NewOrmUsingDB("hz_cygx")
  47. lastId, err = o.Insert(item)
  48. return
  49. }
  50. // 添加日志记录
  51. func AddCygxUserYanxuanPermissionLog(item *CygxUserYanxuanPermissionLog) (lastId int64, err error) {
  52. o := orm.NewOrmUsingDB("hz_cygx")
  53. lastId, err = o.Insert(item)
  54. return
  55. }
  56. // 根据用户ID获取是否开通过研选权限
  57. func GetCygxUserYanxuanPermissionCountByUserId(userId int) (count int, err error) {
  58. o := orm.NewOrmUsingDB("hz_cygx")
  59. sql := ` SELECT COUNT(1) FROM cygx_user_yanxuan_permission WHERE user_id = ? `
  60. err = o.Raw(sql, userId).QueryRow(&count)
  61. return
  62. }
  63. // 将研选权限状态改为未开通
  64. func UpdateCygxUserYanxuanPermissionClose(userId int) (err error) {
  65. o := orm.NewOrmUsingDB("hz_cygx")
  66. sql := ` UPDATE cygx_user_yanxuan_permission
  67. SET
  68. status ='未开通',
  69. modify_time = ?
  70. WHERE user_id = ? `
  71. _, err = o.Raw(sql, time.Now(), userId).Exec()
  72. return
  73. }
  74. // 将研选权限状态改为未开通
  75. func UpdateCygxUserYanxuanPermissionOpen(item *CygxUserYanxuanPermission) (err error) {
  76. o := orm.NewOrmUsingDB("hz_cygx")
  77. updateParams := make(map[string]interface{})
  78. updateParams["CompanyId"] = item.CompanyId
  79. updateParams["StartDate"] = item.StartDate
  80. updateParams["EndDate"] = item.EndDate
  81. updateParams["Status"] = item.Status
  82. updateParams["Mobile"] = item.Mobile
  83. updateParams["Email"] = item.Email
  84. updateParams["RealName"] = item.RealName
  85. updateParams["CompanyName"] = item.CompanyName
  86. updateParams["AdminId"] = item.AdminId
  87. updateParams["AdminRealName"] = item.AdminRealName
  88. ptrStructOrTableName := "cygx_user_yanxuan_permission"
  89. whereParam := map[string]interface{}{"user_id": item.UserId}
  90. qs := o.QueryTable(ptrStructOrTableName)
  91. for expr, exprV := range whereParam {
  92. qs = qs.Filter(expr, exprV)
  93. }
  94. _, err = qs.Update(updateParams)
  95. return
  96. }
  97. // 列表
  98. func GetCygxUserYanxuanPermissionList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxUserYanxuanPermission, err error) {
  99. o := orm.NewOrmUsingDB("hz_cygx")
  100. sql := `SELECT * FROM cygx_user_yanxuan_permission WHERE 1= 1 `
  101. if condition != "" {
  102. sql += condition
  103. }
  104. sql += ` LIMIT ?,? `
  105. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  106. return
  107. }