123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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"`
- }
- // 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
- }
|