188 行
5.0 KiB
PHP
188 行
5.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\model\ContentModel;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 质检报告管理
|
|
* Class Content
|
|
* @package app\admin\controller\Content
|
|
*/
|
|
class Content extends Backend
|
|
{
|
|
|
|
/**
|
|
* 模型对象
|
|
* @var \app\common\model\ContentModel
|
|
*/
|
|
protected $model = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new ContentModel();
|
|
}
|
|
|
|
/**
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
*/
|
|
|
|
/**
|
|
* 获取列表
|
|
* @return mixed|string|\think\response\Json
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function index()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('param.page/d', 1);
|
|
$rows = input('param.rows/d', 20);
|
|
$key = input('param.keyword', '');
|
|
$type = input('param.type', '');
|
|
$status = input('param.status', '');
|
|
$startTime = input('param.start_time', '');
|
|
$endTime = input('param.end_time', '');
|
|
$rid = input('param.rid/d');
|
|
$date = input('param.date');
|
|
$result = $this->model->getLists([
|
|
'keyword' => $key,
|
|
'type' => $type,
|
|
'status' => $status,
|
|
'start_time' => $startTime,
|
|
'end_time' => $endTime,
|
|
'rid' => $rid,
|
|
'date' => $date,
|
|
], $rows, $page);
|
|
|
|
// 仓库
|
|
$result['granaryList'] = Db::name('granary')
|
|
->field(['id', 'name'])
|
|
->select();
|
|
|
|
return json($result);
|
|
}
|
|
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* 更改状态
|
|
* @return \think\response\Json
|
|
*/
|
|
public function status()
|
|
{
|
|
$data = input('param.');
|
|
$editData = [
|
|
'id' => $data['id'],
|
|
'status' => $data['status']
|
|
];
|
|
|
|
if ($this->model->edit($editData)) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '更改成功'
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 400,
|
|
'msg' => '更改失败'
|
|
]);
|
|
}
|
|
}
|
|
|
|
// 添加/编辑
|
|
public function add()
|
|
{
|
|
$data = input('post.');
|
|
if (!empty($data)) {
|
|
$data['content'] = json_encode($data['content']);
|
|
|
|
// 添加
|
|
if (empty($data['id'])) {
|
|
unset($data['id']);
|
|
$data['create_time'] = time();
|
|
if ($this->model->add($data)) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '添加成功'
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 400,
|
|
'msg' => '添加失败'
|
|
]);
|
|
}
|
|
}
|
|
|
|
// 编辑
|
|
if ($this->model->edit($data)) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '编辑成功'
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 400,
|
|
'msg' => '编辑失败'
|
|
]);
|
|
}
|
|
}
|
|
|
|
$id = input('param.id/d', 0);
|
|
|
|
$this->assign([
|
|
'id' => $id,
|
|
]);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 获取编辑数据
|
|
public function getContent()
|
|
{
|
|
$id = input('param.id/d');
|
|
$data = [];
|
|
// 读取内容
|
|
if (!empty($id)) {
|
|
$data = $this->model->getItem($id)->toArray();
|
|
$data['content'] = json_decode($data['content'], true);
|
|
}
|
|
|
|
$granaryList = Db::name('granary')
|
|
->field(['id', 'name'])
|
|
->select();;
|
|
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '获取成功',
|
|
'data' => [
|
|
'detail' => $data,
|
|
'granaryList' => $granaryList
|
|
]
|
|
]);
|
|
}
|
|
|
|
// 删除
|
|
public function dell()
|
|
{
|
|
$id = input('id');
|
|
if (!empty($id)) {
|
|
$ids = strpos($id, ',') !== false ? explode(',', $id) : [$id];
|
|
foreach ($ids as $v) {
|
|
if (!$this->model->getItem((int)$v)) {
|
|
return json(['code' => 401, 'msg' => '您要删除的质检报告不存在']);
|
|
}
|
|
}
|
|
foreach ($ids as $v) {
|
|
$this->model->del(['id' => $v]);
|
|
}
|
|
return json(['code' => 200, 'msg' => '删除成功']);
|
|
}
|
|
}
|
|
|
|
}
|