Kaynağa Gözat

feat:新增权限判断逻辑

Roc 3 yıl önce
ebeveyn
işleme
5f821724e6

+ 53 - 3
controller/user/user.go

@@ -29,7 +29,6 @@ func Login(c *gin.Context) {
 		return
 	}
 	userInfo := userService.GetInfoByClaims(c)
-
 	openId := userInfo.OpenID
 	if openId == "" {
 		response.Fail("参数异常", c)
@@ -84,7 +83,7 @@ func Login(c *gin.Context) {
 // @Accept  json
 // @Product json
 // @Success 200 {string} string 获取验证码成功
-// @Failure 200 {string} string 手机号不能为空,请输入手机号
+// @Failure 400 {string} string 手机号不能为空,请输入手机号
 // @Router /user/get_sms_code [get]
 func GetSmsCode(c *gin.Context) {
 	userInfo := userService.GetInfoByClaims(c)
@@ -119,7 +118,7 @@ func GetSmsCode(c *gin.Context) {
 // @Accept  json
 // @Product json
 // @Success 200 {string} string 获取验证码成功
-// @Failure 200 {string} string 请输入邮箱地址
+// @Failure 400 {string} string 请输入邮箱地址
 // @Router /user/get_email_code [get]
 func GetEmailCode(c *gin.Context) {
 	userInfo := userService.GetInfoByClaims(c)
@@ -150,3 +149,54 @@ func GetEmailCode(c *gin.Context) {
 
 	response.Ok("获取验证码成功", c)
 }
+
+// Info 我的详情
+// @Tags 用户模块
+// @Summary  我的详情
+// @Description 我的详情
+// @securityDefinitions.basic BasicAuth
+// @Param Authorization	header string true "微信登录后获取到的token"
+// @Accept  json
+// @Product json
+// @Success 200 {object} user.Detail "获取成功"
+// @failure 400 {string} string "获取失败"
+// @Router /user/info [get]
+func Info(c *gin.Context) {
+	userInfo := userService.GetInfoByClaims(c)
+	list, err, errMsg := userLogic.GetUserInfo(*userInfo)
+	if err != nil {
+		if errMsg != "" {
+			errMsg = "获取失败"
+		}
+		response.Fail(errMsg, c)
+		return
+	}
+
+	response.OkData("获取成功", list, c)
+}
+
+// GetLastApplyInfo 获取最近一条申请单信息
+// @Tags 用户模块
+// @Summary  获取最近一条申请单信息
+// @Description 获取最近一条申请单信息
+// @securityDefinitions.basic BasicAuth
+// @Param Authorization	header string true "微信登录后获取到的token"
+// @Accept  json
+// @Product json
+// @Success 200 {object} user.Detail "获取成功"
+// @failure 400 {string} string "获取失败"
+// @Router /user/get_seller [get]
+func GetLastApplyInfo(c *gin.Context) {
+	userInfo := userService.GetInfoByClaims(c)
+	userLogic.GetLastApplyInfo(int(userInfo.UserID))
+	//list, err, errMsg := userLogic.GetLastApplyInfo(*userInfo)
+	//if err != nil {
+	//	if errMsg != "" {
+	//		errMsg = "获取失败"
+	//	}
+	//	response.Fail(errMsg, c)
+	//	return
+	//}
+
+	response.OkData("获取成功", "list", c)
+}

+ 3 - 0
core/run_server.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/init_serve"
+	"hongze/hongze_yb/services"
 )
 
 func RunServe() {
@@ -17,6 +18,8 @@ func RunServe() {
 		init_serve.Redis()
 	}
 
+	services.Test()
+
 	// 3.监听端口,默认在8080
 	// Run("里面不指定端口号默认为8080")
 	err := r.Run(fmt.Sprint("0.0.0.0:", global.CONFIG.Serve.Port)) // 监听并在 0.0.0.0:8080 上启动服务

+ 125 - 0
logic/user/user.go

@@ -2,8 +2,13 @@ package user
 
 import (
 	"errors"
+	"hongze/hongze_yb/models/tables/chart_permission"
+	"hongze/hongze_yb/models/tables/company"
+	"hongze/hongze_yb/models/tables/company_product"
 	"hongze/hongze_yb/models/tables/rddp/msg_code"
 	"hongze/hongze_yb/services"
+	companyService "hongze/hongze_yb/services/company"
+	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
 	"time"
 )
@@ -74,3 +79,123 @@ func SendEmailCode(openid, email string) (err error, errMsg string) {
 
 	return
 }
+
+type CompanyPermission struct {
+	Name           string           `json:"name" description:"分类名称"`
+	PermissionList []PermissionList `json:"permission_list" description:"权限列表"`
+}
+
+type PermissionList struct {
+	Name      string    `json:"name" description:"权限名称"`
+	StartDate time.Time `json:"start_date" description:"开始日期"`
+	EndDate   time.Time `json:"end_date" description:"结束日期"`
+	Status    string    `json:"status" description:"状态"`
+}
+
+type Detail struct {
+	CompanyName    string              `json:"company_name" description:"客户名称(公司名称)"`
+	Status         string              `json:"status" description:"客户状态"`
+	RealName       string              `json:"real_name" description:"用户名称"`
+	Mobile         string              `json:"mobile" description:"手机号"`
+	Email          string              `json:"email" description:"邮箱"`
+	PermissionList []CompanyPermission `json:"permission_list" description:"权限列表"`
+}
+
+// GetUserInfo 获取用户我的页面详情数据
+func GetUserInfo(userInfo user.UserInfo) (userDetail Detail, err error, errMsg string) {
+	list := make([]CompanyPermission, 0)
+	companyName := userInfo.Note
+	status := ``
+	if userInfo.CompanyID > 1 {
+		companyInfo, tmpErr := company.GetByCompanyId(userInfo.CompanyID)
+		if tmpErr != nil {
+			err = tmpErr
+			if tmpErr == utils.ErrNoRow {
+				err = errors.New("找不到该客户")
+				errMsg = "找不到该客户"
+				return
+			}
+			errMsg = "系统异常"
+			return
+		}
+		companyName = companyInfo.CompanyName
+
+		companyProduct, tmpErr := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
+
+		//如果有ficc权限,那么就去查询相关权限
+		if tmpErr == nil {
+			status = companyProduct.Status //产品状态
+			//获取所有的权限分类列表
+			allPermissionList, tmpErr := companyService.GetPermissionListByProductId(1)
+			if tmpErr != nil {
+				err = tmpErr
+				return
+			}
+			permissionClassMap := make(map[int]*chart_permission.ChartPermission)
+
+			for _, chartPermission := range allPermissionList {
+				permissionClassMap[int(chartPermission.ChartPermissionID)] = chartPermission
+			}
+
+			// 获取权限列表
+			permissionList, tmpErr := companyService.GetValidPermissionByCompany2ProductId(userInfo.CompanyID, 1)
+			if tmpErr != nil {
+				err = tmpErr
+				return
+			}
+
+			permissionMap := make(map[string][]PermissionList)
+			for _, permission := range permissionList {
+				chartPermission, ok := permissionClassMap[permission.ChartPermissionID]
+				if ok {
+					tmpPermission := PermissionList{
+						Name:      chartPermission.ChartPermissionName,
+						StartDate: permission.StartDate,
+						EndDate:   permission.EndDate,
+						Status:    permission.Status,
+					}
+					if tmpPermissionList, ok2 := permissionMap[chartPermission.ClassifyName]; ok2 {
+						permissionMap[chartPermission.ClassifyName] = append(tmpPermissionList, tmpPermission)
+					} else {
+						tmpPermissionList := make([]PermissionList, 0)
+						permissionMap[chartPermission.ClassifyName] = append(tmpPermissionList, tmpPermission)
+					}
+				}
+			}
+
+			for name, tmpPermissionList := range permissionMap {
+				list = append(list, CompanyPermission{
+					Name:           name,
+					PermissionList: tmpPermissionList,
+				})
+			}
+		}
+
+	}
+	//if Note
+	userDetail = Detail{
+		CompanyName:    companyName, //客户名称(公司名称)
+		Status:         status,      //产品状态
+		RealName:       userInfo.RealName,
+		Mobile:         userInfo.Mobile,
+		Email:          userInfo.Email,
+		PermissionList: list, //权限列表
+	}
+	return
+}
+
+type Record struct {
+	//BusinessCardURL string    `gorm:"column:business_card_url;type:varchar(255);default:''" json:"businessCardUrl"` // 名片
+	//RealName        string    `gorm:"column:real_name;type:varchar(100);default:''" json:"realName"`                // 姓名
+	//CompanyName     string    `gorm:"column:company_name;type:varchar(255);default:''" json:"companyName"`          // 客户备注的公司名称
+	//Mobile          string    `gorm:"column:mobile;type:varchar(20);default:''" json:"mobile"`                      // 手机号
+	BusinessCardURL string `json:"business_card_url"`
+}
+
+//func GetLastApplyInfo(userId int) {
+//	record, err := yb_apply_record.GetLastNotOpRecordByUserId(userId)
+//	if err != nil {
+//
+//	}
+//
+//}

+ 83 - 0
models/tables/admin/admin.go

@@ -0,0 +1,83 @@
+package admin
+
+import "time"
+
+// Admin [...]
+type Admin struct {
+	AdminID                 int64     `gorm:"primaryKey;column:admin_id;type:bigint(20);not null" json:"-"`
+	AdminName               string    `gorm:"uniqueIndex:un;index:name;index:admin_pass;column:admin_name;type:varchar(60);not null" json:"adminName"`
+	RealName                string    `gorm:"column:real_name;type:varchar(60)" json:"realName"`
+	Password                string    `gorm:"index:password;index:admin_pass;column:password;type:varchar(60);not null" json:"password"`
+	LastUpdatedPasswordTime time.Time `gorm:"column:last_updated_password_time;type:datetime" json:"lastUpdatedPasswordTime"`
+	Enabled                 int8      `gorm:"uniqueIndex:un;column:enabled;type:tinyint(1);not null;default:1" json:"enabled"` // 1:有效,0:禁用
+	Email                   string    `gorm:"column:email;type:varchar(60)" json:"email"`
+	LastLoginTime           time.Time `gorm:"column:last_login_time;type:datetime" json:"lastLoginTime"`                                         // 最近登陆时间
+	CreatedTime             time.Time `gorm:"index:created_time;column:created_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createdTime"` // 创建时间
+	LastUpdatedTime         time.Time `gorm:"index:last_updated_time;column:last_updated_time;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"lastUpdatedTime"`
+	Role                    string    `gorm:"column:role;type:varchar(30);default:saller" json:"role"`               // 用户角色
+	Mobile                  string    `gorm:"column:mobile;type:varchar(20)" json:"mobile"`                          // 手机号
+	RoleType                int8      `gorm:"column:role_type;type:tinyint(4);default:0" json:"roleType"`            // 角色类型:1需要录入指标,0:不需要
+	RoleID                  int       `gorm:"column:role_id;type:int(11);default:0" json:"roleId"`                   // 角色id
+	RoleName                string    `gorm:"column:role_name;type:varchar(100)" json:"roleName"`                    // 角色名称
+	RoleTypeCode            string    `gorm:"column:role_type_code;type:varchar(20);default:''" json:"roleTypeCode"` // 角色编码
+	DepartmentID            int       `gorm:"column:department_id;type:int(11);default:0" json:"departmentId"`       // 部门id
+	DepartmentName          string    `gorm:"column:department_name;type:varchar(100)" json:"departmentName"`        // 部门名称
+	GroupID                 int       `gorm:"column:group_id;type:int(11);default:0" json:"groupId"`                 // 分组id
+	GroupName               string    `gorm:"column:group_name;type:varchar(100)" json:"groupName"`                  // 分组名称
+	Authority               int8      `gorm:"column:authority;type:tinyint(4);default:0" json:"authority"`           // 管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
+	Position                string    `gorm:"column:position;type:varchar(100)" json:"position"`                     // 职位
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *Admin) TableName() string {
+	return "admin"
+}
+
+// AdminColumns get sql column name.获取数据库列名
+var AdminColumns = struct {
+	AdminID                 string
+	AdminName               string
+	RealName                string
+	Password                string
+	LastUpdatedPasswordTime string
+	Enabled                 string
+	Email                   string
+	LastLoginTime           string
+	CreatedTime             string
+	LastUpdatedTime         string
+	Role                    string
+	Mobile                  string
+	RoleType                string
+	RoleID                  string
+	RoleName                string
+	RoleTypeCode            string
+	DepartmentID            string
+	DepartmentName          string
+	GroupID                 string
+	GroupName               string
+	Authority               string
+	Position                string
+}{
+	AdminID:                 "admin_id",
+	AdminName:               "admin_name",
+	RealName:                "real_name",
+	Password:                "password",
+	LastUpdatedPasswordTime: "last_updated_password_time",
+	Enabled:                 "enabled",
+	Email:                   "email",
+	LastLoginTime:           "last_login_time",
+	CreatedTime:             "created_time",
+	LastUpdatedTime:         "last_updated_time",
+	Role:                    "role",
+	Mobile:                  "mobile",
+	RoleType:                "role_type",
+	RoleID:                  "role_id",
+	RoleName:                "role_name",
+	RoleTypeCode:            "role_type_code",
+	DepartmentID:            "department_id",
+	DepartmentName:          "department_name",
+	GroupID:                 "group_id",
+	GroupName:               "group_name",
+	Authority:               "authority",
+	Position:                "position",
+}

+ 11 - 0
models/tables/admin/query.go

@@ -0,0 +1,11 @@
+package admin
+
+import (
+	"hongze/hongze_yb/global"
+)
+
+// GetByAdminId 根据admin_id获取系统用户信息
+func GetByAdminId(adminId int) (item *Admin, err error) {
+	err = global.DEFAULT_MYSQL.Where("admin_id =  ? ", adminId).First(&item).Error
+	return
+}

+ 30 - 0
models/tables/chart_permission/query.go

@@ -0,0 +1,30 @@
+package chart_permission
+
+import (
+	"errors"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetListByProductId 根据产品id获取所有权限列表
+func GetListByProductId(productId int64) (list []*ChartPermission, err error) {
+	err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Find(&list).Error
+	return
+}
+
+// GetClassNameListByProductId 根据权限id获取权限分类
+func GetClassNameListByProductId(productId int64) (list []*ChartPermission, err error) {
+	err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Group("classify_name").Find(&list).Error
+	return
+}
+
+// GetByWhereMap 根据查询条件map获取信息
+func GetByWhereMap(where map[string]interface{}) (list []*ChartPermission, err error) {
+	cond, whereVal, buildErr := utils.WhereBuild(where)
+	if buildErr != nil {
+		err = errors.New("系统异常,生成查询语句失败")
+		return
+	}
+	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).Find(&list).Error
+	return
+}

+ 24 - 0
models/tables/company/query.go

@@ -0,0 +1,24 @@
+package company
+
+import (
+	"errors"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetByCompanyId 根据客户id获取信息
+func GetByCompanyId(companyId int64) (item *Company, err error) {
+	err = global.DEFAULT_MYSQL.Where("company_id = ? ", companyId).First(&item).Error
+	return
+}
+
+// GetByWhereMap 根据查询条件map获取信息
+func GetByWhereMap(where map[string]interface{}) (item *Company, err error) {
+	cond, whereVal, buildErr := utils.WhereBuild(where)
+	if buildErr != nil {
+		err = errors.New("系统异常,生成查询语句失败")
+		return
+	}
+	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&item).Error
+	return
+}

+ 30 - 0
models/tables/company_product/query.go

@@ -0,0 +1,30 @@
+package company_product
+
+import (
+	"errors"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetByCompany2ProductId 根据客户id和产品id获取信息
+func GetByCompany2ProductId(companyId, productId int64) (item *CompanyProduct, err error) {
+	err = global.DEFAULT_MYSQL.Where("company_id = ? and product_id", companyId, productId).First(&item).Error
+	return
+}
+
+// GetByEmail 根据邮箱号号获取信息
+func GetByEmail(email string) (item *CompanyProduct, err error) {
+	err = global.DEFAULT_MYSQL.Where("email = ? ", email).First(&item).Error
+	return
+}
+
+// GetByWhereMap 根据查询条件map获取信息
+func GetByWhereMap(where map[string]interface{}) (item *CompanyProduct, err error) {
+	cond, whereVal, buildErr := utils.WhereBuild(where)
+	if buildErr != nil {
+		err = errors.New("系统异常,生成查询语句失败")
+		return
+	}
+	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&item).Error
+	return
+}

+ 9 - 0
models/tables/yb_apply_record/create.go

@@ -0,0 +1,9 @@
+package yb_apply_record
+
+import "hongze/hongze_yb/global"
+
+//  Create 新增记录
+func (ybApplyRecord *YbApplyRecord) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Create(ybApplyRecord).Error
+	return
+}

+ 30 - 0
models/tables/yb_apply_record/query.go

@@ -0,0 +1,30 @@
+package yb_apply_record
+
+import (
+	"errors"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetByWhereMap 根据查询条件map获取信息
+func GetByWhereMap(where map[string]interface{}) (item *YbApplyRecord, err error) {
+	cond, whereVal, buildErr := utils.WhereBuild(where)
+	if buildErr != nil {
+		err = errors.New("系统异常,生成查询语句失败")
+		return
+	}
+	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&item).Error
+	return
+}
+
+// GetByRecordId 根据apply_record_id获取申请记录信息
+func GetByRecordId(recordId int) (item *YbApplyRecord, err error) {
+	err = global.DEFAULT_MYSQL.Where("apply_record_id =  ? ", recordId).First(&item).Error
+	return
+}
+
+// GetLastNotOpRecordByUserId 根据用户id获取最近的一条未被操作过的申请记录信息
+func GetLastNotOpRecordByUserId(userId int) (item *YbApplyRecord, err error) {
+	err = global.DEFAULT_MYSQL.Where("user_id =  ? and op_status=0", userId).Order("apply_record_id desc").First(&item).Error
+	return
+}

+ 65 - 0
models/tables/yb_apply_record/yb_apply_record.go

@@ -0,0 +1,65 @@
+package yb_apply_record
+
+import "time"
+
+// YbApplyRecord 弘则研报客户申请
+type YbApplyRecord struct {
+	ApplyRecordID   int       `gorm:"primaryKey;column:apply_record_id;type:int(11);not null" json:"-"`
+	UserID          int       `gorm:"column:user_id;type:int(11)" json:"userId"`
+	BusinessCardURL string    `gorm:"column:business_card_url;type:varchar(255);default:''" json:"businessCardUrl"` // 名片
+	RealName        string    `gorm:"column:real_name;type:varchar(100);default:''" json:"realName"`                // 姓名
+	CompanyName     string    `gorm:"column:company_name;type:varchar(255);default:''" json:"companyName"`          // 客户备注的公司名称
+	Mobile          string    `gorm:"column:mobile;type:varchar(20);default:''" json:"mobile"`                      // 手机号
+	Email           string    `gorm:"column:email;type:varchar(64);default:''" json:"email"`                        // 邮箱
+	SellerName      string    `gorm:"column:seller_name;type:varchar(64);default:''" json:"sellerName"`             // 销售姓名,多个产品销售用/隔开
+	Status          string    `gorm:"column:status;type:varchar(64);default:''" json:"status"`                      // 用户状态,多个产品状态用/隔开
+	ApplyMethod     int8      `gorm:"column:apply_method;type:tinyint(4)" json:"applyMethod"`                       // 0:未申请,1:已付费客户申请试用,2:非客户申请试用
+	CompanyIDPay    int       `gorm:"column:company_id_pay;type:int(11)" json:"companyIdPay"`                       // 已付费客户公司id
+	CompanyNamePay  string    `gorm:"column:company_name_pay;type:varchar(255);default:''" json:"companyNamePay"`   // 已付费客户公司名称
+	OpStatus        int       `gorm:"column:op_status;type:int(11);default:0" json:"opStatus"`                      // 操作状态,0:未处理,1:已处理
+	DealTime        time.Time `gorm:"column:deal_time;type:datetime" json:"dealTime"`                               // 处理时间
+	SysUserID       int       `gorm:"column:sys_user_id;type:int(11);default:0" json:"sysUserId"`                   // 处理人id
+	CreateTime      time.Time `gorm:"column:create_time;type:datetime" json:"createTime"`                           // 创建时间
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbApplyRecord) TableName() string {
+	return "yb_apply_record"
+}
+
+// YbApplyRecordColumns get sql column name.获取数据库列名
+var YbApplyRecordColumns = struct {
+	ApplyRecordID   string
+	UserID          string
+	BusinessCardURL string
+	RealName        string
+	CompanyName     string
+	Mobile          string
+	Email           string
+	SellerName      string
+	Status          string
+	ApplyMethod     string
+	CompanyIDPay    string
+	CompanyNamePay  string
+	OpStatus        string
+	DealTime        string
+	SysUserID       string
+	CreateTime      string
+}{
+	ApplyRecordID:   "apply_record_id",
+	UserID:          "user_id",
+	BusinessCardURL: "business_card_url",
+	RealName:        "real_name",
+	CompanyName:     "company_name",
+	Mobile:          "mobile",
+	Email:           "email",
+	SellerName:      "seller_name",
+	Status:          "status",
+	ApplyMethod:     "apply_method",
+	CompanyIDPay:    "company_id_pay",
+	CompanyNamePay:  "company_name_pay",
+	OpStatus:        "op_status",
+	DealTime:        "deal_time",
+	SysUserID:       "sys_user_id",
+	CreateTime:      "create_time",
+}

+ 1 - 0
routers/user.go

@@ -13,5 +13,6 @@ func InitUser(r *gin.Engine) {
 		rGroup.POST("/login", user.Login)
 		rGroup.GET("/get_sms_code", user.GetSmsCode)
 		rGroup.GET("/get_email_code", user.GetEmailCode)
+		rGroup.GET("/info", user.Info)
 	}
 }

+ 81 - 2
services/company/permission.go

@@ -1,11 +1,27 @@
 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 int) (list []*company_report_permission.CompanyReportPermission, err error) {
+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
@@ -15,7 +31,7 @@ func GetValidPermissionByCompany2ProductId(companyId, productId int) (list []*co
 }
 
 // GetValidPermissionIdListByCompany2ProductId 根据客户id和产品id获取有效的权限id列表
-func GetValidPermissionIdListByCompany2ProductId(companyId, productId int) (list []int, err error) {
+func GetValidPermissionIdListByCompany2ProductId(companyId, productId int64) (list []int, err error) {
 	companyReportPermissionList, err := GetValidPermissionByCompany2ProductId(companyId, productId)
 	if err != nil {
 		return
@@ -25,3 +41,66 @@ func GetValidPermissionIdListByCompany2ProductId(companyId, productId int) (list
 	}
 	return
 }
+
+// PermissionCheckInfo 权限校验完成后的结果
+type PermissionCheckInfo struct {
+	Name   string `json:"name" description:"销售名称"`
+	Mobile string `json:"mobile" description:"手机号"`
+	Type   string `json:"type" description:"校验失败,没有权限,需要让前端处理的类型,枚举值:apply,contact"`
+}
+
+// CheckPermission 权限校验
+func CheckPermission(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
+}