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

93 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare (strict_types = 1);
namespace app\admin\controller;
use app\AdminController;
use Webman\Http\Request;
use app\admin\model\PdmPartlist as PdmPartlistModel;
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* pdm_partlist
* BOM查询
* <!--partlist-->
* Class PdmPartlist
* @package app\admin\controller
*/
class PdmPartlist extends AdminController
{
/**
* PdmPartlist模型对象
* @var \app\admin\model\PdmPartlist
*/
public function __construct()
{
parent::__construct();
$this->model = new PdmPartlistModel;
}
/**
* 默认生成的方法为index/add/edit/del/status 五个方法
* 当创建CURD的时候DIY的函数体和模板为空请自行编写代码
*/
/**
* 字典首页
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function index(): \support\Response
{
// $post = input();
// $post = request()->post();
$post = request()->all();
// $post['partnumber'] = input('partnumber');
$pid = input('pid');
$limit = input('limit') ?? 10;
$page = input('page') ?? 1;
if ($pid == null) {
$pid = (string)$this->model->minId();
}
if (request()->isAjax()) {
// 生成查询数据
$pid = !str_contains($pid, ',') ? $pid : explode(',',$pid);
$where[] = ['pid','in',$pid];
if (!empty($post['keyword'])) {
$where[] = ['partnumber|reference|content|item','like','%'.$post['keyword'].'%'];
// $where[] = ['reference','like','%'.$post['keyword'].'%'];
// $where[] = ['content','like','%'.$post['keyword'].'%'];
// $where[] = ['item','like','%'.$post['keyword'].'%'];
}else{
// $where[] = ['pid','in',$pid];
// $where[] = ['partnumber','like','%'.$post['partnumber'].'%'];
}
$count = $this->model->where($where)->count();
$list = $this->model->where($where)->limit((int)$limit)->page((int)$page)->select()
->each(function($item,$key) use ($pid){
if ($key == 0 && $pid == '0') {
$item['LAY_CHECKED'] = true;
}
// throw new \Exception(json_encode($item->admin['nickname']));
$item['creator'] = $item->admin ==null?'': $item->admin['nickname'];
// $item['purchasecode'] = $item->partitemview == null?'': $item->partitemview['purchasecode'];
$item->partitemview ;
return $item;
});
// throw new \Exception(json_encode($list));
return $this->success('查询成功', null, $list, $count);
}
return view('/pdm_partlist/index',[ 'pid' => $pid]);
}
}