更新数据关联查询,以及基本的数据的编辑,部分有待进一步完善。
This commit is contained in:
@@ -5,6 +5,7 @@ namespace app\admin\controller;
|
||||
use app\AdminController;
|
||||
use Webman\Http\Request;
|
||||
use app\admin\model\PdmPartitemIndex as PdmPartitemIndexModel;
|
||||
use app\admin\model\PdmParttype as PdmParttypeModel;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
@@ -58,35 +59,90 @@ class PdmPartitemIndex extends AdminController
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function dataList(array $params): array
|
||||
public function dataList(array $params): array
|
||||
{
|
||||
$where = array();
|
||||
if (!empty($params['partnumber'])) {
|
||||
$where[] = ['partnumber','like','%'.$params['partnumber'].'%'];
|
||||
}
|
||||
if (!empty($params['content'])) {
|
||||
$where[] = ['content','like','%'.$params['content'].'%'];
|
||||
}
|
||||
$model = new PdmPartitemIndexModel();
|
||||
// $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['partnumber'])) {
|
||||
// $where[] = ['partnumber','like','%'.$params['partnumber'].'%'];
|
||||
// }
|
||||
// if (!empty($params['content'])) {
|
||||
// $where[] = ['content','like','%'.$params['content'].'%'];
|
||||
// }
|
||||
// $model = new PdmPartitemIndexModel();
|
||||
// // $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();
|
||||
// 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 == null?'': $list[$key]->admin['nickname']);
|
||||
// $list[$key]['parttype'] =__($list[$key]->parttype ==null?'': $list[$key]->parttype['name']);
|
||||
// $list[$key]['mfg_name'] =__($list[$key]->mfgname == null ?'': $list[$key]->mfgname['mfgname']);
|
||||
// // if($list[$key]->mfgname == null){
|
||||
// // $list[$key]['mfg_name'] ='';
|
||||
// // }else{
|
||||
// // $list[$key]['mfg_name'] =$list[$key]->mfgname['mfgname'];
|
||||
// // }
|
||||
|
||||
// }
|
||||
|
||||
// return [$count, $list->toArray()];
|
||||
|
||||
$page = (int)input('page', 1);
|
||||
$limit = (int)input('limit', 18);
|
||||
$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, 'desc')->limit($limit)->page($page)->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 == null?'': $list[$key]->admin['nickname']);
|
||||
$list[$key]['parttype'] =__($list[$key]->parttype ==null?'': $list[$key]->parttype['name']);
|
||||
$list[$key]['mfg_name'] =__($list[$key]->mfgname == null ?'': $list[$key]->mfgname['mfgname']);
|
||||
$list[$key]['parttype'] =__($list[$key]->pdmParttype ==null?'': $list[$key]->pdmParttype['name']);
|
||||
$list[$key]['mfg_name'] =__($list[$key]->pdmMfgName == null ?'': $list[$key]->pdmMfgName['mfgname']);
|
||||
$list[$key]['mpn'] =__($list[$key]->pdmPurchasecode == null ?'': $list[$key]->pdmPurchasecode['mpn']);
|
||||
|
||||
// if($list[$key]->mfgname == null){
|
||||
// $list[$key]['mfg_name'] ='';
|
||||
// }else{
|
||||
// $list[$key]['mfg_name'] =$list[$key]->mfgname['mfgname'];
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach($list as $key => $value){
|
||||
if(!in_array($value['pid'],$nodeid) && $value['pid'] > 0){
|
||||
$nodeid[] = $value['pid'];
|
||||
$nodevalue = $this->model->find($value['pid']);
|
||||
$nodevalue = $this->model->find($value['pid'])->toArray();
|
||||
|
||||
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));
|
||||
}
|
||||
return [$count, $list];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,6 +151,8 @@ class PdmPartitemIndex extends AdminController
|
||||
*/
|
||||
public function add(): Response
|
||||
{
|
||||
$parttype = PdmParttypeModel::select()->toArray();
|
||||
|
||||
if (request()->isPost()) {
|
||||
$post = \request()->post();
|
||||
// validate(\app\common\validate\system\AdminRules::class . '.add')->check($post);
|
||||
@@ -114,7 +172,9 @@ class PdmPartitemIndex extends AdminController
|
||||
list($count, $list) = PdmPartitemIndex::dataList(request()->all());
|
||||
return view('/pdm_partitem_index/add', [
|
||||
'data' => $data,
|
||||
'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
|
||||
'parttype' => json_encode( list_to_tree($parttype), JSON_UNESCAPED_UNICODE),
|
||||
// 'parttype' => $this->parttype,
|
||||
'list' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -129,6 +189,15 @@ class PdmPartitemIndex extends AdminController
|
||||
{
|
||||
$id = input('id', 0);
|
||||
$data = $this->model->find($id);
|
||||
$parttypeid = $data['parttypeid'];
|
||||
|
||||
// $parems['id'] = input('parttypeid', 0);
|
||||
$parems = PdmParttypeModel::find($parttypeid)->toArray();
|
||||
// throw new \Exception(json_encode($parems));
|
||||
// $parttype = PdmParttypeModel::find($parttypeid);
|
||||
list($count, $parttype) = \app\admin\controller\PdmParttype::dataList($parems);
|
||||
// $parttype = PdmParttypeModel::select()->toArray();
|
||||
|
||||
if (request()->isPost()) {
|
||||
$post = \request()->post();
|
||||
// validate(\app\common\validate\system\AdminRules::class . '.edit')->check($post);
|
||||
@@ -137,10 +206,14 @@ class PdmPartitemIndex extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
list($count, $list) = PdmPartitemIndex::dataList(request()->all());
|
||||
list($count, $list) = PdmPartitemIndex::dataList(request()->all());
|
||||
// throw new \Exception(json_encode($parttype));
|
||||
// throw new \Exception( json_encode(list_to_tree($parttype)));
|
||||
return view('/pdm_partitem_index/add', [
|
||||
'data' => $data,
|
||||
'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
|
||||
'parttype' => json_encode( list_to_tree($parttype), JSON_UNESCAPED_UNICODE),
|
||||
// 'parttype' => json_encode( $parttype, JSON_UNESCAPED_UNICODE),
|
||||
'list' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user