DiverseYouthNightSchool/application/api/controller/school/worker/Base.php

49 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace app\api\controller\school\worker;
use app\common\controller\Api;
use app\common\model\school\classes\ClassesLib;
use app\common\model\school\classes\Teacher;
use app\common\model\school\classes\Verification;
class Base extends Api
{
protected $classes_lib_ids = [];
2024-12-18 18:47:13 +08:00
protected $shop_id = 0;
/**
* 初始化操作
* @access protected
*/
protected function _initialize()
{
parent::_initialize();
// 判断员工权限
$this->check_worker_auth();
}
protected function check_worker_auth(){
//判断登录用户是否是员工
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
if(!$user_id)$this->error("请登录后再访问该接口!",['errcode'=>30002], 401);
2024-12-18 18:47:13 +08:00
2024-12-18 09:37:26 +08:00
try{
2024-12-18 18:47:13 +08:00
$this->shop_id = ClassesLib::checkOptionAuth(0,$user_id,"user");
2024-12-18 09:37:26 +08:00
}catch (\Exception $e){
$this->error($e->getMessage(),['errcode'=>30003]);
}
$this->classes_lib_ids = (new ClassesLib)->getClassesAuthIds($user_id);
2024-12-18 09:37:26 +08:00
//如果没有任何可管理的classes_lib_id 则返回错误
2024-12-18 18:47:13 +08:00
if(!$this->classes_lib_ids && !$this->shop_id)$this->error("您没有员工权限访问该接口!",['errcode'=>30003]);
2024-12-18 09:37:26 +08:00
}
}