company_report_permission.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_task/utils"
  5. "time"
  6. )
  7. type CompanyReportPermission struct {
  8. CompanyReportPermissionId int64 `orm:"column(company_report_permission_id);pk"`
  9. CompanyId int `description:"公司id"`
  10. ProductId int `description:"产品id"`
  11. ProductName string `description:"产品名称"`
  12. ReportPermissionId int `description:"权限id(作废)"`
  13. Status string `description:"状态"`
  14. CreatedTime time.Time `description:"创建时间"`
  15. LastUpdatedTime time.Time `description:"更新时间"`
  16. ChartPermissionId int `description:"大分类ID"`
  17. StartDate string `description:"合同开始日期"`
  18. EndDate string `description:"合同结束日期"`
  19. ModifyTime string `description:"更新时间"`
  20. IsUpgrade int `description:"是否升级,1是,0否"`
  21. ExpensiveYx int `description:"权益研选: 0-3w; 1-5w"`
  22. }
  23. // Update 更新客户产品权限
  24. func (item *CompanyReportPermission) Update(cols []string) (err error) {
  25. o := orm.NewOrm()
  26. _, err = o.Update(item, cols...)
  27. return
  28. }
  29. func GetCompanyReportPermission(companyId int) (items []*CompanyReportPermission, err error) {
  30. sql := `SELECT * FROM company_report_permission WHERE company_id=? `
  31. _, err = orm.NewOrm().Raw(sql, companyId).QueryRows(&items)
  32. return
  33. }
  34. func AddCompanyReportPermission(item *CompanyReportPermission) (err error) {
  35. o := orm.NewOrm()
  36. _, err = o.Insert(item)
  37. return
  38. }
  39. func ModifyCompanyOldPermission(startDate, endDate, productName string, companyId, productId int) (err error) {
  40. o := orm.NewOrm()
  41. sql := `UPDATE company_report_permission SET start_date=?,end_date=?,product_id=?,product_name=?,modify_time=NOW() WHERE company_id=? AND start_date IS NULL `
  42. _, err = o.Raw(sql, startDate, endDate, productId, productName, companyId).Exec()
  43. return
  44. }
  45. // GetCompanyReportPermissionNeedTryOut 获取需要正式转关闭的产品权益
  46. func GetCompanyReportPermissionNeedTryOut(endDate string) (items []*CompanyReportPermission, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT *
  49. FROM company_report_permission
  50. WHERE status='正式' AND end_date<=?`
  51. _, err = o.Raw(sql, endDate).QueryRows(&items)
  52. return
  53. }
  54. // GetCompanyReportPermissionNeedClose 获取需要关闭的产品权限
  55. func GetCompanyReportPermissionNeedClose(endDate string) (items []*CompanyReportPermission, err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT *
  58. FROM company_report_permission
  59. WHERE status='试用' AND end_date<=?`
  60. _, err = o.Raw(sql, endDate).QueryRows(&items)
  61. return
  62. }
  63. // CompanyReportPermissionTryOut 正式转试用用户权限
  64. func CompanyReportPermissionTryOut(companyReportPermissionId int64, companyId, productId int) (err error) {
  65. startDate := time.Now().Format(utils.FormatDate)
  66. endDate := time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  67. o := orm.NewOrm()
  68. //修改产品权限状态为关闭
  69. //sql := `UPDATE company_report_permission SET status='试用',modify_time=NOW() WHERE company_report_permission_id = ? AND company_id= ? AND product_id = ? `
  70. sql := `UPDATE company_report_permission SET status='试用',start_date=?,end_date=?,modify_time=NOW() WHERE company_report_permission_id = ? AND company_id= ? AND product_id = ? `
  71. _, err = o.Raw(sql, startDate, endDate, companyReportPermissionId, companyId, productId).Exec()
  72. //_, err = o.Raw(sql, companyReportPermissionId, companyId, productId).Exec()
  73. if err != nil {
  74. return err
  75. }
  76. return
  77. }
  78. // CompanyReportPermissionClose 关闭用户权限
  79. func CompanyReportPermissionClose(companyReportPermissionId int64, companyId, productId int) (err error) {
  80. o := orm.NewOrm()
  81. //修改产品权限状态为关闭
  82. sql := `UPDATE company_report_permission SET status='关闭',modify_time=NOW() WHERE company_report_permission_id = ? AND company_id= ? AND product_id = ? `
  83. _, err = o.Raw(sql, companyReportPermissionId, companyId, productId).Exec()
  84. if err != nil {
  85. return err
  86. }
  87. return
  88. }
  89. // 查询是否存在还未过期的产品权限
  90. func GetCompanyReportPermissionCount(companyId, productId int) (count int, err error) {
  91. o := orm.NewOrm()
  92. startDate := time.Now().Format(utils.FormatDate)
  93. countSql := `SELECT
  94. COUNT(company_report_permission_id ) AS COUNT
  95. FROM company_report_permission WHERE status in ('试用','正式') AND end_date >= ? AND company_id= ? AND product_id = ? `
  96. err = o.Raw(countSql, startDate, companyId, productId).QueryRow(&count)
  97. return
  98. }
  99. func GetCompanyReportPermissionByStatus(companyId, productId int, status string) (items []*CompanyReportPermission, err error) {
  100. o := orm.NewOrm()
  101. sql := `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? AND status = ? `
  102. _, err = o.Raw(sql, companyId, productId, status).QueryRows(&items)
  103. return
  104. }