123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_task/utils"
- "time"
- )
- type CompanyReportPermission struct {
- CompanyReportPermissionId int64 `orm:"column(company_report_permission_id);pk"`
- CompanyId int `description:"公司id"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- ReportPermissionId int `description:"权限id(作废)"`
- Status string `description:"状态"`
- CreatedTime time.Time `description:"创建时间"`
- LastUpdatedTime time.Time `description:"更新时间"`
- ChartPermissionId int `description:"大分类ID"`
- StartDate string `description:"合同开始日期"`
- EndDate string `description:"合同结束日期"`
- ModifyTime string `description:"更新时间"`
- IsUpgrade int `description:"是否升级,1是,0否"`
- ExpensiveYx int `description:"权益研选: 0-3w; 1-5w"`
- }
- // 客户授权产品结构体(包含产品名称)
- type CompanyReportPermissionAndName struct {
- CompanyReportPermissionId int `description:"客户授权产品id"`
- CompanyId int
- ReportPermissionId int
- CreatedTime time.Time
- LastUpdatedTime time.Time
- ChartPermissionId int
- StartDate string `description:"权限开始日期"`
- EndDate string `description:"权限结束日期"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- CompanyContractId int `description:"合同id"`
- PermissionName string `description:"客户授权产品的名称"`
- ClassifyName string `description:"客户授权产品的分类名称"`
- Status string `description:"'正式','试用','关闭'"`
- ModifyTime time.Time `description:"修改时间"`
- }
- // Update 更新客户产品权限
- func (item *CompanyReportPermission) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(item, cols...)
- return
- }
- func GetCompanyReportPermission(companyId int) (items []*CompanyReportPermission, err error) {
- sql := `SELECT * FROM company_report_permission WHERE company_id=? `
- _, err = orm.NewOrm().Raw(sql, companyId).QueryRows(&items)
- return
- }
- func AddCompanyReportPermission(item *CompanyReportPermission) (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(item)
- return
- }
- func ModifyCompanyOldPermission(startDate, endDate, productName string, companyId, productId int) (err error) {
- o := orm.NewOrm()
- 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 `
- _, err = o.Raw(sql, startDate, endDate, productId, productName, companyId).Exec()
- return
- }
- // GetCompanyReportPermissionNeedTryOut 获取需要正式转关闭的产品权益
- func GetCompanyReportPermissionNeedTryOut(endDate string) (items []*CompanyReportPermission, err error) {
- o := orm.NewOrm()
- sql := `SELECT *
- FROM company_report_permission
- WHERE status='正式' AND end_date<=?`
- _, err = o.Raw(sql, endDate).QueryRows(&items)
- return
- }
- // GetCompanyReportPermissionNeedClose 获取需要关闭的产品权限
- func GetCompanyReportPermissionNeedClose(endDate string) (items []*CompanyReportPermission, err error) {
- o := orm.NewOrm()
- sql := `SELECT *
- FROM company_report_permission
- WHERE status='试用' AND end_date<=?`
- _, err = o.Raw(sql, endDate).QueryRows(&items)
- return
- }
- // CompanyReportPermissionTryOut 正式转试用用户权限
- func CompanyReportPermissionTryOut(companyReportPermissionId int64, companyId, productId int) (err error) {
- startDate := time.Now().Format(utils.FormatDate)
- endDate := time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
- o := orm.NewOrm()
- //修改产品权限状态为关闭
- //sql := `UPDATE company_report_permission SET status='试用',modify_time=NOW() WHERE company_report_permission_id = ? AND company_id= ? AND product_id = ? `
- 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 = ? `
- _, err = o.Raw(sql, startDate, endDate, companyReportPermissionId, companyId, productId).Exec()
- //_, err = o.Raw(sql, companyReportPermissionId, companyId, productId).Exec()
- if err != nil {
- return err
- }
- return
- }
- // CompanyReportPermissionClose 关闭用户权限
- func CompanyReportPermissionClose(companyReportPermissionId int64, companyId, productId int) (err error) {
- o := orm.NewOrm()
- //修改产品权限状态为关闭
- sql := `UPDATE company_report_permission SET status='关闭',modify_time=NOW() WHERE company_report_permission_id = ? AND company_id= ? AND product_id = ? `
- _, err = o.Raw(sql, companyReportPermissionId, companyId, productId).Exec()
- if err != nil {
- return err
- }
- return
- }
- // 查询是否存在还未过期的产品权限
- func GetCompanyReportPermissionCount(companyId, productId int) (count int, err error) {
- o := orm.NewOrm()
- startDate := time.Now().Format(utils.FormatDate)
- countSql := `SELECT
- COUNT(company_report_permission_id ) AS COUNT
- FROM company_report_permission WHERE status in ('试用','正式') AND end_date >= ? AND company_id= ? AND product_id = ? `
- err = o.Raw(countSql, startDate, companyId, productId).QueryRow(&count)
- return
- }
- func GetCompanyReportPermissionByStatus(companyId, productId int, status string) (items []*CompanyReportPermission, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? AND status = ? `
- _, err = o.Raw(sql, companyId, productId, status).QueryRows(&items)
- return
- }
- // 根据企业用户id和产品id获取所有正式的权限
- func GetCompanyProductReportPermissionList(companyId []int, productId int) (items []*CompanyReportPermissionAndName, err error) {
- o := orm.NewOrm()
- sql := `SELECT a.*,b.permission_name,b.classify_name FROM company_report_permission a left join chart_permission b on a.chart_permission_id=b.chart_permission_id WHERE a.company_id IN (` + utils.GetOrmInReplace(len(companyId)) + `) and a.product_id=? AND a.status IN ('正式','试用','永续') `
- _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
- return
- }
|