<?php /** * Created by PhpStorm. * User: Administrator * Date: 2021/1/18 * Time: 10:45 */ class companyPowerClassModel { private $companyid; private $old_companyid; private $companyInfo; public function setCompanyid($companyid){ $this->old_companyid = $this->companyid; $this->companyid = $companyid; } public function setCompanyInfo(){ if ($this->companyid > 0 && $this->old_companyid != $this->companyid) { $where = 'id=' . $this->companyid; $this->companyInfo = m('company')->getone($where, '*'); } } public function getCompanyInfo(){ return $this->companyInfo; } public function getCompanyMaxUserNum(){ return $this->companyInfo['sub_account_num']; } private function countCompanyNowUser(){ $where = 'companyid=' . $this->companyid; $info = m('admin')->getone($where, 'count(companyid) as total'); return $info['total']; } public function checkUserLimit(){ //查询当前企业的信息 $this->setCompanyInfo(); //对比返回员工是否超出 $total = $this->countCompanyNowUser(); return $total>=$this->companyInfo['sub_account_num']; } }
调用例子
private function checkUserLimit($companyid){ $companyPowerModel = m('companyPower'); $companyPowerModel->setCompanyid($companyid); $isMax = $companyPowerModel->checkUserLimit(); if($isMax){ return '您的用户数量已满,无法添加。您的最大用户数量是:'.$companyPowerModel->getCompanyMaxUserNum(); }else{ return ''; } }