2024-09-01 11:10:22 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
declare (strict_types = 1);
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\AdminController;
|
|
|
|
|
|
use Webman\Http\Request;
|
2024-12-29 22:18:05 +08:00
|
|
|
|
use app\admin\model\PdmSymbol as PdmSymbolModel;
|
|
|
|
|
|
use support\Response;
|
2024-09-01 11:10:22 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* pdm_symbol
|
|
|
|
|
|
* 原理符号
|
2024-12-29 22:18:05 +08:00
|
|
|
|
* <!--partmanage-->
|
2024-09-01 11:10:22 +08:00
|
|
|
|
* Class PdmSymbol
|
|
|
|
|
|
* @package app\admin\controller
|
|
|
|
|
|
*/
|
|
|
|
|
|
class PdmSymbol extends AdminController
|
|
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* PdmSymbol模型对象
|
2024-12-29 22:18:05 +08:00
|
|
|
|
* @var \app\admin\model\PdmSymbol
|
2024-09-01 11:10:22 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
|
{
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
$this->model = new PdmSymbolModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 默认生成的方法为index/add/edit/del/status 五个方法
|
|
|
|
|
|
* 当创建CURD的时候,DIY的函数体和模板为空,请自行编写代码
|
|
|
|
|
|
*/
|
2024-12-29 22:18:05 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取资源列表
|
|
|
|
|
|
* return Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function index(): Response
|
|
|
|
|
|
{
|
|
|
|
|
|
if (request()->isAjax()) {
|
|
|
|
|
|
list($count, $list) = PdmSymbol::dataList(request()->all());
|
|
|
|
|
|
// $rules = list_to_tree($list,'id','pid','children',0);
|
|
|
|
|
|
$lists = list_to_tree($list,'id','pid','children',0);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success('获取成功', '/',$lists, $count);
|
|
|
|
|
|
// return $this->success('获取成功', '/');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return view('/pdm_symbol/index');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取资源列表
|
|
|
|
|
|
* @param array $params
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
* @throws DataNotFoundException
|
|
|
|
|
|
* @throws DbException
|
|
|
|
|
|
* @throws ModelNotFoundException
|
|
|
|
|
|
*/
|
2025-01-13 22:28:27 +08:00
|
|
|
|
public static function dataList(array $params): array // static 限定后, $this-> 不可用。
|
2024-12-29 22:18:05 +08:00
|
|
|
|
{
|
2025-01-06 00:06:03 +08:00
|
|
|
|
// $where = array();
|
|
|
|
|
|
// if (!empty($params['status'])) {
|
|
|
|
|
|
// // $where[] = ['status','=',$params['status']];
|
|
|
|
|
|
// $where[]=['status','=',$params['status']==1?0:1];
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (!empty($params['keyword'])) {
|
|
|
|
|
|
// $where[] = ['symbolname|view|attachment|content','like','%'.$params['keyword'].'%'];
|
|
|
|
|
|
// }
|
|
|
|
|
|
// $count = $this->model->where($where)->count();
|
|
|
|
|
|
// $list = $this->model->where($where)->order('sort asc')->select()->toArray();
|
|
|
|
|
|
|
2025-01-13 22:28:27 +08:00
|
|
|
|
$controller = new PdmSymbol();
|
|
|
|
|
|
|
|
|
|
|
|
$where = $controller->buildSelectParams();
|
|
|
|
|
|
$count = $controller->model->where($where)->count();
|
|
|
|
|
|
$fieldList = $controller->model->getFields();
|
2025-01-06 00:06:03 +08:00
|
|
|
|
$order = !array_key_exists('sort', $fieldList) ? 'id' : 'sort';
|
2025-01-13 22:28:27 +08:00
|
|
|
|
$subQuery = $controller->model->field('id')->where($where)->order($order, 'asc')->buildSql();
|
2025-01-06 00:06:03 +08:00
|
|
|
|
$subQuery = '( SELECT object.id FROM ' . $subQuery . ' AS object )';
|
|
|
|
|
|
// $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select()->toArray(); // 如果是'desc' list_to_tree 函数返回为空!
|
2025-01-13 22:28:27 +08:00
|
|
|
|
$list = $controller->model->with($controller->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select(); // 如果是'desc' list_to_tree 函数返回为空!
|
2025-01-06 00:06:03 +08:00
|
|
|
|
|
2024-12-29 22:18:05 +08:00
|
|
|
|
foreach($list as $key => $value){
|
|
|
|
|
|
// throw new \Exception(json_encode($value));
|
|
|
|
|
|
// throw new \Exception(json_encode($list[$key]->admin['nickname']));
|
2025-01-06 00:06:03 +08:00
|
|
|
|
// $list[$key]['creator'] =__($list[$key]->admin['nickname']);
|
|
|
|
|
|
$list[$key]->admin;
|
2024-12-29 22:18:05 +08:00
|
|
|
|
}
|
2025-01-06 00:06:03 +08:00
|
|
|
|
$list = $list->toArray();
|
|
|
|
|
|
if(!empty($list) && is_array($list)){
|
|
|
|
|
|
$nodeid = array();
|
|
|
|
|
|
foreach($list as $key => $value){
|
|
|
|
|
|
if($value['pid'] == 0 ){
|
|
|
|
|
|
$nodeid[] = $value['id'];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// throw new \Exception(json_encode($pidlist));
|
|
|
|
|
|
foreach($list as $key => $value){
|
|
|
|
|
|
if(!in_array($value['pid'],$nodeid) && $value['pid'] > 0){
|
|
|
|
|
|
$nodeid[] = $value['pid'];
|
2025-01-13 22:28:27 +08:00
|
|
|
|
$nodevalue = $controller->model->find($value['pid']);
|
2025-01-06 00:06:03 +08:00
|
|
|
|
// throw new \Exception(json_encode($nodevalue));
|
2025-01-13 22:28:27 +08:00
|
|
|
|
$nodevalue = $controller->model->find($value['pid'])->toArray();
|
2025-01-06 00:06:03 +08:00
|
|
|
|
// throw new \Exception(json_encode($nodevalue));
|
|
|
|
|
|
// throw new \Exception(json_encode($list));
|
|
|
|
|
|
if(!empty($nodevalue)){
|
|
|
|
|
|
$list[] = &$nodevalue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$list = list_sort_by($list,'id','asc');
|
|
|
|
|
|
// usort($list, function($a, $b) {
|
|
|
|
|
|
// return $a['id'] <=> $b['id']; // 对 'id' 进行升序排序
|
|
|
|
|
|
// });
|
|
|
|
|
|
// throw new \Exception(json_encode($list));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// throw new \Exception(json_encode($list));
|
|
|
|
|
|
|
|
|
|
|
|
return [$count, $list];
|
2024-12-29 22:18:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 添加节点数据
|
|
|
|
|
|
* @return Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function add(): Response
|
|
|
|
|
|
{
|
|
|
|
|
|
if (request()->isPost()) {
|
|
|
|
|
|
$post = \request()->post();
|
|
|
|
|
|
// validate(\app\common\validate\system\AdminRules::class . '.add')->check($post);
|
|
|
|
|
|
$userid = get_admin_id();
|
|
|
|
|
|
$post['creatorid'] = $userid ;
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->model->create($post)) {
|
|
|
|
|
|
return $this->success('添加FootPrint成功!');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$data = $this->getTableFields();
|
|
|
|
|
|
$data['pid'] = input('pid', 0);
|
|
|
|
|
|
// $data['auth'] = 1;
|
|
|
|
|
|
// $data['type'] = 1;
|
|
|
|
|
|
|
|
|
|
|
|
list($count, $list) = PdmSymbol::dataList(request()->all());
|
|
|
|
|
|
return view('/pdm_symbol/add', [
|
|
|
|
|
|
'data' => $data,
|
|
|
|
|
|
'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 编辑节点数据
|
|
|
|
|
|
* @return Response
|
|
|
|
|
|
* @throws DbException
|
|
|
|
|
|
* @throws DataNotFoundException
|
|
|
|
|
|
* @throws ModelNotFoundException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function edit(): Response
|
|
|
|
|
|
{
|
|
|
|
|
|
$id = input('id', 0);
|
|
|
|
|
|
$data = $this->model->find($id);
|
|
|
|
|
|
if (request()->isPost()) {
|
|
|
|
|
|
$post = \request()->post();
|
|
|
|
|
|
// validate(\app\common\validate\system\AdminRules::class . '.edit')->check($post);
|
|
|
|
|
|
if ($this->model->update($post)) {
|
|
|
|
|
|
return $this->success('更新Symbol成功!');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
list($count, $list) = PdmSymbol::dataList(request()->all());
|
|
|
|
|
|
return view('/pdm_symbol/add', [
|
|
|
|
|
|
'data' => $data,
|
|
|
|
|
|
'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除节点数据
|
|
|
|
|
|
* @return Response
|
|
|
|
|
|
* @throws DbException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function del(): Response
|
|
|
|
|
|
{
|
|
|
|
|
|
$id = input('id');
|
|
|
|
|
|
if (!empty($id)) {
|
|
|
|
|
|
// 查询子节点
|
|
|
|
|
|
if ($this->model->where('pid',$id)->count()) {
|
|
|
|
|
|
return $this->error('当前分类存在子项!');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除单个
|
|
|
|
|
|
if ($this->model::destroy($id)) {
|
|
|
|
|
|
return $this->success('删除Symbol成功!');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->error('删除失败,请检查您的参数!');
|
|
|
|
|
|
}
|
2024-09-01 11:10:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|