更新数据关联查询,以及基本的数据的编辑,部分有待进一步完善。
This commit is contained in:
@@ -37,26 +37,6 @@ class PdmMfgName extends AdminController
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
$params = request()->all();
|
||||
$where = array();
|
||||
if (!empty($params['mfgname'])) {
|
||||
$where[] = ['mfgname','like','%'.$params['mfgname'].'%'];
|
||||
// $where[] = ['mfgname','like','%'.'ABRACON'.'%'];
|
||||
}
|
||||
if (!empty($params['mfgsite'])) {
|
||||
$where[] = ['mfgsite','like','%'.$params['mfgsite'].'%'];
|
||||
}
|
||||
|
||||
// $where[] = ['mfgname','like','%'.'ABRACON'.'%'];
|
||||
$listtemp = $this->model->where($where)->select();
|
||||
// $listtemp = $this->model->where($where);
|
||||
// $listtemp = $this->model->find(1);
|
||||
// throw new \Exception(json_encode($listtemp));
|
||||
// $admin = $this->model->admin()->where($where)->select()->toArray();
|
||||
|
||||
// $admin = $listtemp->admin;
|
||||
// throw new \Exception(json_encode($admin));
|
||||
|
||||
if (request()->isAjax()) {
|
||||
list($count, $list) = PdmMfgName::dataList(request()->all());
|
||||
// $rules = list_to_tree($list,'id','pid','children',0);
|
||||
@@ -77,54 +57,54 @@ class PdmMfgName extends AdminController
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function dataList(array $params): array
|
||||
public function dataList(array $params): array
|
||||
{
|
||||
$where = array();
|
||||
if (!empty($params['mfgname'])) {
|
||||
$where[] = ['mfgname','like','%'.$params['mfgname'].'%'];
|
||||
}
|
||||
if (!empty($params['mfgsite'])) {
|
||||
$where[] = ['mfgsite','like','%'.$params['mfgsite'].'%'];
|
||||
}
|
||||
$model = new PdmMfgNameModel();
|
||||
$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($lists[$key]->admin['nickname']));
|
||||
$list[$key]['creator'] =__($list[$key]->admin['nickname']);
|
||||
}
|
||||
|
||||
|
||||
// $pidlist = array();
|
||||
foreach ($list as $key => $value) {
|
||||
$list[$key]['mfgname'] = __($value['mfgname']);
|
||||
|
||||
}
|
||||
// $users = array();
|
||||
// $users = $model->usernames();
|
||||
|
||||
// // throw new \Exception(json_encode($users));
|
||||
// foreach ($list as $key => $value) {
|
||||
// foreach ($users as $keyuser => $valueuser) {
|
||||
// // if ($users[$keyuser]['id'] == $list[$key]['id']){
|
||||
// // // $list[$key]['creatorid'] = __($users[$keyuser]['nickname']);
|
||||
// // $list[$key]['creatorid'] = __($users[$keyuser]['name']);
|
||||
// // break;
|
||||
// // }
|
||||
// if ($value['creatorid'] == $valueuser['id']) {
|
||||
// // $list[$key]['creatorid'] = __($valueuser['name']);
|
||||
// $list[$key]['creatorid'] = __($valueuser['nickname']);
|
||||
// break;
|
||||
// }else{
|
||||
// $list[$key]['creatorid'] =$list[$key]['creatorid'].'|'. __('未知用户');
|
||||
// }
|
||||
|
||||
// }
|
||||
// $where = array();
|
||||
// if (!empty($params['mfgname'])) {
|
||||
// $where[] = ['mfgname','like','%'.$params['mfgname'].'%'];
|
||||
// }
|
||||
// if (!empty($params['mfgsite'])) {
|
||||
// $where[] = ['mfgsite','like','%'.$params['mfgsite'].'%'];
|
||||
// }
|
||||
// $model = new PdmMfgNameModel();
|
||||
// $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($lists[$key]->admin['nickname']));
|
||||
// $list[$key]['creator'] =__($list[$key]->admin['nickname']);
|
||||
// }
|
||||
|
||||
return [$count, $list->toArray()];
|
||||
|
||||
// // $pidlist = array();
|
||||
// foreach ($list as $key => $value) {
|
||||
// $list[$key]['mfgname'] = __($value['mfgname']);
|
||||
|
||||
// }
|
||||
|
||||
$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, 'asc')->buildSql();
|
||||
$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 函数返回为空!
|
||||
$list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'desc')->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]->admin;
|
||||
}
|
||||
$list = $list->toArray();
|
||||
|
||||
return [$count, $list];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user