package services import ( "errors" "hongze/hongze_clpt/models" "hongze/hongze_clpt/utils" "strings" ) // GetCompanyPermission 获取公司对应的权限名称 func GetCompanyPermission(companyId int) (permissionStr string, err error) { permissionStr, err = models.GetCompanyPermission(companyId) if err != nil { return } permissionStr = strings.Replace(permissionStr, "(主观)", "", -1) permissionStr = strings.Replace(permissionStr, "(客观)", "", -1) return } // GetCompanyPermissionUpgrade 获取公司对应的升级权限名称 func GetCompanyPermissionUpgrade(companyId int) (permissionStr string, err error) { permissionStr, err = models.GetCompanyPermissionByUserTrip(companyId) if err != nil { return } permissionStr = strings.Replace(permissionStr, "(主观)", "", -1) permissionStr = strings.Replace(permissionStr, "(客观)", "", -1) return } // 获取用户对应的权限申请状态 func GetUserHasPermission(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) { //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"` uid := user.UserId applyCount, e := models.GetApplyRecordCount(uid) if e != nil { err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error()) return } if user.CompanyId <= 1 { if applyCount == 0 { hasPermission = 5 } else { hasPermission = 6 } } else { companyPermission, e := models.GetCompanyPermission(user.CompanyId) if e != nil { err = errors.New("GetCompanyPermission, Err: " + e.Error()) return } if companyPermission != "" { if applyCount > 0 { hasPermission = 4 } else { //获取权益销售信息 如果是FICC的客户类型,则默认他申请过 sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error()) return } if sellerItemQy != nil { hasPermission = 3 sellerName = sellerItemQy.Mobile sellerMobile = sellerItemQy.RealName } else { hasPermission = 2 } } } else { hasPermission = 2 } } popupMsg = "需要升级行业套餐权限才可参与此活动,请联系对口销售" return } // 获取用户对应的权限申请状态 文章详情 func GetUserHasPermissionArticle(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) { //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"` uid := user.UserId applyCount, e := models.GetApplyRecordCount(uid) if e != nil { err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error()) return } if user.CompanyId <= 1 { if applyCount == 0 { hasPermission = 5 } else { hasPermission = 4 } } else { companyPermission, e := models.GetCompanyPermission(user.CompanyId) if e != nil { err = errors.New("GetCompanyPermission, Err: " + e.Error()) return } if companyPermission != "" { if applyCount > 0 { hasPermission = 3 } else { hasPermission = 2 //获取权益销售信息 如果是FICC的客户类型,则默认他申请过 sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error()) return } if sellerItemQy != nil { sellerName = sellerItemQy.Mobile sellerMobile = sellerItemQy.RealName } } } else { hasPermission = 2 } } popupMsg = "需要升级行业套餐权限才可查看此报告,请联系对口销售" return } // 获取用户对应的权限简单版 func GetUserHasPermissionSimple(user *models.WxUserItem) (hasPermission int, err error) { //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"` uid := user.UserId applyCount, e := models.GetApplyRecordCount(uid) if e != nil { err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error()) return } if user.CompanyId <= 1 { if applyCount == 0 { hasPermission = 5 } else { hasPermission = 6 } } else { companyPermission, e := models.GetCompanyPermission(user.CompanyId) if e != nil { err = errors.New("GetCompanyPermission, Err: " + e.Error()) return } if companyPermission != "" { hasPermission = 1 } else { hasPermission = 3 } } return } // GetPermissionNameMap 权限名称与权限ID的map func GetPermissionNameMap() (mapItem map[int]string, err error) { list, e := models.GetChartPermissionListRai() if e != nil { err = e return } mapPermissionName := make(map[int]string) for _, v := range list { mapPermissionName[v.ChartPermissionId] = v.PermissionName } mapItem = mapPermissionName return } func GetPermissionNameIcoMap() (mapItem map[int]string, err error) { list, e := models.GetChartPermissionListRai() if e != nil { err = e return } mapPermissionName := make(map[int]string) for _, v := range list { mapPermissionName[v.ChartPermissionId] = v.ImageUrlM } mapItem = mapPermissionName return }