2022-02-24 17:44:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\controller;
|
|
|
|
|
|
|
|
use app\admin\library\Auth;
|
2022-03-13 04:44:45 +00:00
|
|
|
use think\db\exception\PDOException;
|
2022-02-26 08:34:07 +00:00
|
|
|
use think\facade\Cookie;
|
2022-03-13 04:44:45 +00:00
|
|
|
use think\facade\Db;
|
2022-02-24 17:44:00 +00:00
|
|
|
|
|
|
|
class Backend extends Api
|
|
|
|
{
|
|
|
|
protected $noNeedLogin = [];
|
|
|
|
protected $noNeedPermission = [];
|
2022-03-08 16:15:32 +00:00
|
|
|
protected $preExcludeFields = [];
|
2022-02-24 17:44:00 +00:00
|
|
|
|
2022-02-26 20:55:27 +00:00
|
|
|
/**
|
|
|
|
* 权限类实例
|
|
|
|
* @var Auth
|
|
|
|
*/
|
2022-02-24 17:44:00 +00:00
|
|
|
protected $auth = null;
|
|
|
|
|
|
|
|
protected $model = null;
|
2022-02-26 08:34:07 +00:00
|
|
|
|
2022-03-10 14:50:16 +00:00
|
|
|
/**
|
|
|
|
* 权重(排序)字段
|
|
|
|
*/
|
|
|
|
protected $weighField = 'weigh';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 表格拖拽排序时,两个权重相等则自动重新整理
|
|
|
|
* config/buildadmin.php文件中的auto_sort_eq_weight为默认值
|
|
|
|
* null=取默认值,false=关,true=开
|
|
|
|
*/
|
|
|
|
protected $autoSortEqWeight = null;
|
|
|
|
|
2022-03-09 10:12:15 +00:00
|
|
|
/**
|
|
|
|
* 快速搜索字段
|
|
|
|
*/
|
2022-02-26 08:34:07 +00:00
|
|
|
protected $quickSearchField = 'id';
|
|
|
|
|
2022-03-11 17:29:06 +00:00
|
|
|
/**
|
|
|
|
* 是否开启模型验证
|
|
|
|
*/
|
|
|
|
protected $modelValidate = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 是否开启模型场景验证
|
|
|
|
*/
|
|
|
|
protected $modelSceneValidate = false;
|
|
|
|
|
2022-03-08 16:15:32 +00:00
|
|
|
/**
|
|
|
|
* 引入traits
|
|
|
|
* traits内实现了index、add、edit等方法
|
|
|
|
*/
|
|
|
|
use \app\admin\library\traits\Backend;
|
|
|
|
|
2022-03-09 10:12:15 +00:00
|
|
|
public function initialize()
|
2022-02-26 08:34:07 +00:00
|
|
|
{
|
2022-03-09 10:12:15 +00:00
|
|
|
parent::initialize();
|
2022-03-13 04:44:45 +00:00
|
|
|
|
|
|
|
// 检测数据库连接
|
|
|
|
try {
|
|
|
|
Db::execute("SELECT 1");
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
$this->error(mb_convert_encoding($e->getMessage(), 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'));
|
|
|
|
}
|
|
|
|
|
2022-02-26 08:34:07 +00:00
|
|
|
$this->auth = Auth::instance();
|
2022-03-09 10:12:15 +00:00
|
|
|
$routePath = $this->controllerPath . '/' . $this->request->action(true);
|
2022-02-26 20:55:27 +00:00
|
|
|
$token = $this->request->server('HTTP_BATOKEN', $this->request->request('batoken', Cookie::get('batoken') ?: false));
|
2022-02-27 16:44:12 +00:00
|
|
|
if (!$this->auth->actionInArr($this->noNeedLogin)) {
|
2022-02-26 08:34:07 +00:00
|
|
|
$this->auth->init($token);
|
|
|
|
if (!$this->auth->isLogin()) {
|
|
|
|
$this->error(__('Please login first'), [
|
2022-02-28 20:54:57 +00:00
|
|
|
'routeName' => 'adminLogin'
|
|
|
|
], 302);
|
2022-02-26 08:34:07 +00:00
|
|
|
}
|
2022-02-27 16:44:12 +00:00
|
|
|
if (!$this->auth->actionInArr($this->noNeedPermission)) {
|
2022-03-09 10:12:15 +00:00
|
|
|
if (!$this->auth->check($routePath)) {
|
2022-02-27 16:44:12 +00:00
|
|
|
$this->error(__('You have no permission'), [
|
2022-03-01 12:40:44 +00:00
|
|
|
'routeName' => 'admin'
|
2022-02-28 20:54:57 +00:00
|
|
|
], 302);
|
2022-02-27 16:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-26 08:34:07 +00:00
|
|
|
} else {
|
|
|
|
if ($token) {
|
|
|
|
$this->auth->init($token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-08 08:31:49 +00:00
|
|
|
|
2022-03-13 13:23:43 +00:00
|
|
|
public function queryBuilder()
|
2022-03-08 08:31:49 +00:00
|
|
|
{
|
2022-03-14 13:46:51 +00:00
|
|
|
$quickSearch = $this->request->get("quick_search/s", '');
|
|
|
|
$page = $this->request->get("page/d", 1);
|
|
|
|
$limit = $this->request->get("limit/d", 10);
|
|
|
|
|
|
|
|
$where = [];
|
|
|
|
$alias = [];
|
|
|
|
if (!empty($this->model)) {
|
|
|
|
$tableName = $this->model->getTable();
|
|
|
|
$alias[$tableName] = $tableName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// print_r($alias);
|
2022-03-08 08:31:49 +00:00
|
|
|
|
2022-03-14 13:46:51 +00:00
|
|
|
// 构建好where等返回
|
2022-03-08 08:31:49 +00:00
|
|
|
}
|
2022-02-24 17:44:00 +00:00
|
|
|
}
|