清晰的代码

10 篇文章 0 订阅
<?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 '';
       }
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值