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

166 lines
5.5 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
{
$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);
$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 static 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'].'%'];
2024-08-18 21:55:49 +08:00
}
$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();
2024-08-18 21:55:49 +08:00
foreach ($list as $key => $value) {
$list[$key]['mfgname'] = __($value['mfgname']);
}
2024-08-18 21:55:49 +08:00
// $users = array();
// $users = $model->usernames();
2024-08-18 21:55:49 +08:00
// // 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'].'|'. __('未知用户');
// }
// }
// }
return [$count, $list->toArray()];
}
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),
]);
}
}