增加mfgname 的管理页面功能
This commit is contained in:
171
app/admin/controller/PdmMfgName.php
Normal file
171
app/admin/controller/PdmMfgName.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\AdminController;
|
||||
use Webman\Http\Request;
|
||||
use app\common\model\PdmMfgName as PdmMfgNameModel;
|
||||
use support\Response;
|
||||
/**
|
||||
* pdm_mfg_name
|
||||
* 制造商名录
|
||||
* <!--partmanage-->
|
||||
* Class PdmMfgName
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class PdmMfgName extends AdminController
|
||||
{
|
||||
/**
|
||||
* PdmMfgName模型对象
|
||||
* @var \app\common\model\PdmMfgName
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->model = new PdmMfgNameModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认生成的方法为index/add/edit/del/status 五个方法
|
||||
* 当创建CURD的时候,DIY的函数体和模板为空,请自行编写代码
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function dataList(array $params): array
|
||||
{
|
||||
$where = array();
|
||||
if (!empty($params['mfgname'])) {
|
||||
$where[] = ['mfgname','like','%'.$params['mfgname'].'%'];
|
||||
}
|
||||
if (!empty($params['status'])) {
|
||||
$where[] = ['status','like','%'.$params['status'].'%'];
|
||||
}
|
||||
$model = new PdmMfgNameModel();
|
||||
$count = $model->where($where)->count();
|
||||
$list = $model->where($where)->order('sort asc')->select()->toArray();
|
||||
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 ($value['createrid'] == $valueuser['id']) {
|
||||
// $list[$key]['createrid'] = __($valueuser['name']);
|
||||
$list[$key]['createrid'] = __($valueuser['nickname']);
|
||||
break;
|
||||
}else{
|
||||
$list[$key]['createrid'] =$list[$key]['createrid'].'|'. __('未知用户');
|
||||
}
|
||||
}
|
||||
}
|
||||
return [$count, $list];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* 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);
|
||||
return $this->success('获取成功', '/',$rules, $count);
|
||||
}
|
||||
return view('/pdm_mfg_name/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加节点数据
|
||||
* @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['createrid'] = $userid ;
|
||||
|
||||
if ($this->model->create($post)) {
|
||||
return $this->success('添加成功!');
|
||||
}else{
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->getTableFields();
|
||||
$data['pid'] = input('pid', 0);
|
||||
$data['auth'] = 1;
|
||||
$data['type'] = 1;
|
||||
|
||||
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),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑节点数据
|
||||
* @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('更新成功!');
|
||||
}else{
|
||||
return $this->error('更新失败!');
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除节点数据
|
||||
* @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('删除菜单成功!');
|
||||
}
|
||||
}
|
||||
return $this->error('删除失败,请检查您的参数!');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user