package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type CompanyProduct struct { CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"` CompanyId int `description:"客户id"` ProductId int `description:"产品id"` ProductName string `description:"产品名称"` CompanyName string `description:"客户名称"` Source string `description:"来源"` Reasons string `description:"新增理由"` Status string `description:"客户状态"` IndustryId int `description:"行业id"` IndustryName string `description:"行业名称"` SellerId int `description:"销售id"` SellerName string `description:"销售名称"` GroupId int `description:"销售分组id"` DepartmentId int `description:"销售部门id"` IsSuspend int `description:"1:暂停,0:启用"` SuspendTime time.Time `description:"暂停启用时间"` ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"` FreezeTime time.Time `description:"冻结时间"` Remark string `description:"备注信息"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` LoseReason string `description:"流失原因"` LossTime time.Time `description:"流失时间"` CompanyType string `description:"客户类型"` ViewTotal int `description:"总阅读次数"` LastViewTime time.Time `description:"最后一次阅读时间"` } //判断客户权限总数 func GetCompanyProductPermissionCount(companyId, productId int) (count int, err error) { sql := ` SELECT COUNT(DISTINCT c.chart_permission_id) AS COUNT FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id INNER JOIN company_report_permission AS c ON a.company_id=c.company_id WHERE b.company_id=? AND b.product_id=? AND b.status IN('正式','试用','永续') AND c.product_id=? ` o := orm.NewOrm() err = o.Raw(sql, companyId, productId, productId).QueryRow(&count) return } type CompanyProductDetail struct { CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"` CompanyId int `description:"客户id"` ProductId int `description:"产品id"` ProductName string `description:"产品名称"` CompanyName string `description:"客户名称"` Source string `description:"来源"` Reasons string `description:"新增理由"` Status string `description:"客户状态"` IndustryId int `description:"行业id"` IndustryName string `description:"行业名称"` SellerId int `description:"销售id"` SellerName string `description:"销售名称"` GroupId int `description:"销售分组id"` DepartmentId int `description:"销售部门id"` IsSuspend int `description:"1:暂停,0:启用"` SuspendTime time.Time `description:"暂停启用时间"` ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"` FreezeTime time.Time `description:"冻结时间"` Remark string `description:"备注信息"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` LoseReason string `description:"流失原因"` LossTime time.Time `description:"流失时间"` } func GetCompanyProductsByUserId(userId int) (items []*CompanyProductDetail, err error) { sql := ` SELECT a.* FROM company_product AS a INNER JOIN wx_user AS b ON a.company_id=b.company_id WHERE b.user_id=? ` o := orm.NewOrm() _, err = o.Raw(sql, userId).QueryRows(&items) return } // GetTacticsPermissionIdByCompanyId 获取客户的策略权限 func GetTacticsPermissionIdByCompanyId(companyId, productId int) (count int, err error) { sql := `SELECT COUNT(DISTINCT crp.chart_permission_id) AS COUNT from chart_permission cp INNER JOIN company_report_permission AS crp ON cp.chart_permission_id = crp.chart_permission_id WHERE crp.company_id=? AND crp.product_id=? AND cp.permission_name="策略"` o := orm.NewOrm() err = o.Raw(sql, companyId, productId).QueryRow(&count) return } // UpdateCompanyProductViewData 更新客户产品的阅读记录(阅读时间、总阅读次数) func UpdateCompanyProductViewData(companyId, productId int, lastViewTime string) (err error) { sql := ` update company_product set view_total=view_total+1,last_view_time=? WHERE company_id=? and product_id =? ` o := orm.NewOrm() _, err = o.Raw(sql, lastViewTime, companyId, productId).Exec() return }