Files
swiftadmin/app/admin/controller/system/Dictionary.php

77 lines
2.4 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
2023-04-25 20:11:49 +08:00
2022-08-19 19:48:37 +08:00
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Dictionary as DictionaryModel;
2022-11-28 19:11:12 +08:00
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
2022-08-19 19:48:37 +08:00
/**
* 字典管理
* Class Dictionary
* @package app\admin\controller\system
*/
class Dictionary extends AdminController
{
public function __construct()
{
parent::__construct();
$this->model = new DictionaryModel();
}
/**
* 字典首页
2022-11-28 19:11:12 +08:00
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
2022-08-19 19:48:37 +08:00
*/
public function index(): \support\Response
{
$post = input();
$pid = input('pid');
2023-06-25 16:56:18 +08:00
$limit = input('limit') ?? 10;
$page = input('page') ?? 1;
2022-08-19 19:48:37 +08:00
if ($pid == null) {
$pid = (string)$this->model->minId();
}
if (request()->isAjax()) {
// 生成查询数据
2022-11-28 19:11:12 +08:00
$pid = !str_contains($pid, ',') ? $pid : explode(',',$pid);
2022-08-19 19:48:37 +08:00
$where[] = ['pid','in',$pid];
if (!empty($post['name'])) {
$where[] = ['name','like','%'.$post['name'].'%'];
}
$count = $this->model->where($where)->count();
2022-11-28 22:34:17 +08:00
$list = $this->model->where($where)->limit((int)$limit)->page((int)$page)->select()
2022-08-19 19:48:37 +08:00
->each(function($item,$key) use ($pid){
if ($key == 0 && $pid == '0') {
$item['LAY_CHECKED'] = true;
}
return $item;
});
return $this->success('查询成功', null, $list, $count);
}
return view('/system/dictionary/index',[ 'pid' => $pid]);
}
}