更新数据关联查询,以及基本的数据的编辑,部分有待进一步完善。
This commit is contained in:
@@ -58,27 +58,66 @@ class PdmSymbol extends AdminController
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function dataList(array $params): array
|
||||
public function dataList(array $params): array // static 限定后, $this-> 不可用。
|
||||
{
|
||||
$where = array();
|
||||
if (!empty($params['symbolname'])) {
|
||||
$where[] = ['symbolname','like','%'.$params['symbolname'].'%'];
|
||||
}
|
||||
if (!empty($params['content'])) {
|
||||
$where[] = ['content','like','%'.$params['content'].'%'];
|
||||
}
|
||||
$model = new PdmSymbolModel();
|
||||
// $model = $this->model;
|
||||
$count = $model->where($where)->count();
|
||||
// $list = $model->where($where)->order('sort asc')->select()->toArray();
|
||||
$list = $model->where($where)->order('sort asc')->select();
|
||||
// $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();
|
||||
|
||||
$where = $this->buildSelectParams();
|
||||
$count = $this->model->where($where)->count();
|
||||
$fieldList = $this->model->getFields();
|
||||
$order = !array_key_exists('sort', $fieldList) ? 'id' : 'sort';
|
||||
$subQuery = $this->model->field('id')->where($where)->order($order, 'asc')->buildSql();
|
||||
$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 函数返回为空!
|
||||
$list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select(); // 如果是'desc' list_to_tree 函数返回为空!
|
||||
|
||||
foreach($list as $key => $value){
|
||||
// throw new \Exception(json_encode($value));
|
||||
// throw new \Exception(json_encode($list[$key]->admin['nickname']));
|
||||
$list[$key]['creator'] =__($list[$key]->admin['nickname']);
|
||||
// $list[$key]['creator'] =__($list[$key]->admin['nickname']);
|
||||
$list[$key]->admin;
|
||||
}
|
||||
|
||||
return [$count, $list->toArray()];
|
||||
$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'];
|
||||
$nodevalue = $this->model->find($value['pid']);
|
||||
// throw new \Exception(json_encode($nodevalue));
|
||||
$nodevalue = $this->model->find($value['pid'])->toArray();
|
||||
// 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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user