Files
swiftadmin/app/admin/controller/PdmMfgName.php

146 lines
5.2 KiB
PHP
Raw Normal View History

2024-08-18 21:55:49 +08:00
<?php
declare (strict_types = 1);
namespace app\admin\controller;
use app\AdminController;
use Webman\Http\Request;
use app\admin\model\PdmMfgName as PdmMfgNameModel;
2024-08-18 21:55:49 +08:00
use support\Response;
/**
* pdm_mfg_name
* 制造商名录
* <!--partmanage-->
* Class PdmMfgName
* @package app\admin\controller
*/
class PdmMfgName extends AdminController
{
/**
* PdmMfgName模型对象
* @var \app\admin\model\PdmMfgName
2024-08-18 21:55:49 +08:00
*/
public function __construct()
{
parent::__construct();
$this->model = new PdmMfgNameModel;
}
/**
* 默认生成的方法为index/add/edit/del/status 五个方法
* 当创建CURD的时候DIY的函数体和模板为空请自行编写代码
*/
/**
* 获取资源列表
* return Response
*/
public function index(): Response
{
if (request()->isAjax()) {
list($count, $list) = PdmMfgName::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_mfg_name/index');
}
2024-08-18 21:55:49 +08:00
/**
* 获取资源列表
* @param array $params
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function dataList(array $params): array
2024-08-18 21:55:49 +08:00
{
// $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']);
// }
2024-08-18 21:55:49 +08:00
// // $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];
}
2024-08-18 21:55:49 +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(empty($userid)){
// $post['creatorid'] = 'empty';
// }else{
// $post['creatorid'] = 'noneempty' ;
// }
2024-08-18 21:55:49 +08:00
if ($this->model->create($post)) {
return $this->success('添加分类成功!');
2024-08-18 21:55:49 +08:00
}
}
$data = $this->getTableFields();
$data['pid'] = input('pid', 0);
// $data['auth'] = 1;
// $data['type'] = 1;
2024-08-18 21:55:49 +08:00
list($count, $list) = PdmMfgName::dataList(request()->all());
return view('/pdm_mfg_name/add', [
'data' => $data,
'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
]);
}
}