package services import ( "errors" "fmt" "hongze/hongze_api/models" "hongze/hongze_api/utils" "strconv" ) func CheckUserPermission(userId int) (status int, err error) { if userId > 0 { wxUser, err := models.GetWxUserItemByUserId(userId) if err != nil { if err.Error() == utils.ErrNoRow() { status = 40001 err = errors.New("用户信息不存在:userId:" + strconv.Itoa(userId)) return status, err } status = 40001 err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error()) return status, err } if wxUser == nil { status = 40001 err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId)) return status, err } companyId := wxUser.CompanyId if companyId <= 1 { status = 40001 return status, err } fmt.Println("companyId", companyId) companyProduct, err := models.GetCompanyById(companyId) if err != nil { status = 40001 err = errors.New("获取客户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error()) return status, err } if len(companyProduct) == 0 { status = 40001 err = errors.New("客户信息不存在:userId:" + strconv.Itoa(userId)) return status, err } for _, v := range companyProduct { if v.Status == utils.COMPANY_STATUS_FORMAL || //正式 v.Status == utils.COMPANY_STATUS_TRY_OUT || //试用 v.Status == utils.COMPANY_STATUS_FOREVER { //永续 status = 0 break } else { status = 40002 err = errors.New("非付费用户" + strconv.Itoa(userId)) } } } else { status = 40001 err = errors.New("用户id错误") } return }