123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package company
- import (
- "hongze/hongze_yb/models/tables/admin"
- "hongze/hongze_yb/models/tables/chart_permission"
- "hongze/hongze_yb/models/tables/company_product"
- "hongze/hongze_yb/models/tables/company_report_permission"
- "hongze/hongze_yb/utils"
- )
- // GetClassNameListByProductId 根据权限id获取权限分类
- func GetClassNameListByProductId(productId int64) (list []*chart_permission.ChartPermission, err error) {
- list, err = chart_permission.GetClassNameListByProductId(productId)
- return
- }
- // GetPermissionListByProductId 根据product_id获取所有的权限列表
- func GetPermissionListByProductId(productId int64) (list []*chart_permission.ChartPermission, err error) {
- list, err = chart_permission.GetListByProductId(productId)
- return
- }
- // GetValidPermissionByCompany2ProductId 根据客户id和产品id获取有效的权限列表
- func GetValidPermissionByCompany2ProductId(companyId, productId int64) (list []*company_report_permission.CompanyReportPermission, err error) {
- where := make(map[string]interface{})
- where["company_id ="] = companyId
- where["product_id ="] = productId
- where["status in"] = []string{"正式", "试用", "永续"}
- list, err = company_report_permission.GetByWhereMap(where)
- return
- }
- // GetValidPermissionIdListByCompany2ProductId 根据客户id和产品id获取有效的权限id列表
- func GetValidPermissionIdListByCompany2ProductId(companyId, productId int64) (list []int, err error) {
- companyReportPermissionList, err := GetValidPermissionByCompany2ProductId(companyId, productId)
- if err != nil {
- return
- }
- for _, v := range companyReportPermissionList {
- list = append(list, v.ChartPermissionID)
- }
- return
- }
- // PermissionCheckInfo 权限校验完成后的结果
- type PermissionCheckInfo struct {
- Name string `json:"name" description:"销售名称"`
- Mobile string `json:"mobile" description:"手机号"`
- Type string `json:"type" description:"校验失败,没有权限,需要让前端处理的类型,枚举值:apply,contact"`
- }
- // CheckPermissionByFicc 权限校验
- func CheckPermissionByFicc(companyId int64, permissionId int) (ok bool, permissionCheckInfo PermissionCheckInfo, err error) {
- //非潜在客户
- var productId int64
- productId = 1
- if companyId > 1 {
- //查询是否 开通ficc的客户
- companyProductInfo, tmpErr := company_product.GetByCompany2ProductId(companyId, productId)
- if tmpErr != nil {
- // 没有开通ficc的客户
- if tmpErr == utils.ErrNoRow {
- permissionCheckInfo.Type = "apply"
- return
- }
- err = tmpErr
- return
- }
- // 如果客户ficc产品的状态是流失,那么也是让去申请
- if companyProductInfo.Status == "流失" {
- permissionCheckInfo.Type = "apply"
- return
- }
- // 获取有效的权限id列表
- validPermissionIdList, tmpErr := GetValidPermissionIdListByCompany2ProductId(companyId, productId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 校验在有效的权限id列表中是否存在该权限
- for _, validPermissionId := range validPermissionIdList {
- //如果有该权限id,那么直接返回校验通过
- if validPermissionId == permissionId {
- ok = true
- return
- }
- }
- //查找对应客户的销售信息
- adminInfo, tmpErr := admin.GetByAdminId(companyProductInfo.SellerID)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- permissionCheckInfo = PermissionCheckInfo{
- Name: adminInfo.RealName,
- Mobile: adminInfo.Mobile,
- Type: "contact",
- }
- } else {
- permissionCheckInfo.Type = "apply"
- }
- return
- }
|