<?php


namespace common\util;


use common\models\BaseUser;
use common\models\LwtCompanyInfoBase;

class Role
{
    /**
     * 判断是否是客户
     * @param BaseUser $userInfo
     * @return bool
     */
    public static function isCommonUser(BaseUser $userInfo)
    {
        $result = false;
        if ($userInfo->category == 1) {
            $result = true;
        }
        return $result;
    }

    public static function getCommonUserCompanyScanId(BaseUser $userInfo)
    {
        $LwtCompanyInfo = LwtCompanyInfoBase::findOne(["company_name" => $userInfo->company]);
        if ($LwtCompanyInfo) {
            $scan_id = $LwtCompanyInfo->scan_id;
        } else {
            $scan_id = $userInfo->login_name;
        }
        return $scan_id;
    }

    public static function ifCommonUserAddScanId(BaseUser $userInfo)
    {
        $addParams = [];
        if (self::isCommonUser($userInfo)) {
            $addParams["scan_id"] = $userInfo->CompanyScanId;
        }
        return $addParams;
    }
}