feat(testing): 增加质检报告独立编辑与详情页面,不再使用弹窗
这个提交包含在:
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\controller\GranaryBackend;
|
||||
use app\common\library\GranarySite;
|
||||
use app\common\model\TestingModel;
|
||||
use think\Db;
|
||||
|
||||
@@ -11,7 +12,7 @@ use think\Db;
|
||||
* Class Testing
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Testing extends Backend
|
||||
class Testing extends GranaryBackend
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,8 @@ class Testing extends Backend
|
||||
$startTime = input('param.start_time', '');
|
||||
$endTime = input('param.end_time', '');
|
||||
$season = input('param.season', '');
|
||||
$result = $this->model->getLists([
|
||||
$this->scopeRecords($this->model);
|
||||
$result = $this->model->getLists([
|
||||
'gid' => $gid,
|
||||
'type' => $type,
|
||||
'date' => $date,
|
||||
@@ -60,9 +62,7 @@ class Testing extends Backend
|
||||
], $rows, $page);
|
||||
|
||||
// 仓库
|
||||
$result['granaryList'] = Db::name('granary')
|
||||
->field(['id', 'name', 'varieties'])
|
||||
->select();
|
||||
$result['granaryList'] = GranarySite::granaries($this->granarySites);
|
||||
if (!empty($result['granaryList'])) {
|
||||
foreach ($result['granaryList'] as &$v) {
|
||||
$w = getVarietiesInfo($v['varieties']);
|
||||
@@ -103,55 +103,151 @@ class Testing extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加编辑
|
||||
* 获取仓房列表下拉数据
|
||||
* @return array
|
||||
*/
|
||||
protected function getGranaryOptions()
|
||||
{
|
||||
$granaryList = GranarySite::granaries($this->granarySites);
|
||||
if (!empty($granaryList)) {
|
||||
foreach ($granaryList as &$v) {
|
||||
$w = getVarietiesInfo($v['varieties']);
|
||||
$v['type'] = $w['type'];
|
||||
}
|
||||
}
|
||||
return $granaryList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加(GET返回独立页面,POST执行添加)
|
||||
* @return string|\think\response\Json
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
|
||||
if (!empty($data)) {
|
||||
$content = $data['content'];
|
||||
$date = $data['record_date'];
|
||||
$ruleError = \app\common\library\QualityRule::validate($content);
|
||||
if ($ruleError !== '') {
|
||||
return json(['code' => 400, 'msg' => $ruleError]);
|
||||
}
|
||||
if (!empty($data)) {
|
||||
$content = $data['content'];
|
||||
$date = $data['record_date'];
|
||||
$types = $this->model->getTypeList();
|
||||
$originalRules = isset($types[$data['type']]) ? $types[$data['type']]['content'] : [];
|
||||
if (!empty($data['id'])) {
|
||||
$existing = $this->model->getItem((int)$data['id'], '*', ['testingParams']);
|
||||
if (!$existing) {
|
||||
return json(['code' => 400, 'msg' => '检测记录不存在']);
|
||||
}
|
||||
$existing = $existing->toArray();
|
||||
$originalRules = $existing['testing_params'];
|
||||
$allowedIds = array_column($originalRules, 'id');
|
||||
foreach (is_array($content) ? $content : [] as $item) {
|
||||
if (!is_array($item) || empty($item['id']) || !in_array($item['id'], $allowedIds)) {
|
||||
return json(['code' => 400, 'msg' => '检测参数不属于当前记录,请刷新后重试']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$ruleError = \app\common\library\QualityRule::validate($content, $originalRules);
|
||||
if ($ruleError !== '') {
|
||||
return json(['code' => 400, 'msg' => $ruleError]);
|
||||
}
|
||||
|
||||
// 添加
|
||||
if (empty($data['id'])) {
|
||||
unset($data['id'], $data['content'], $data['record_date']);
|
||||
$data['create_time'] = time();
|
||||
// 添加
|
||||
if (empty($data['id'])) {
|
||||
unset($data['id'], $data['content'], $data['record_date']);
|
||||
$data['create_time'] = time();
|
||||
|
||||
if ($this->model->add($data, $content, $date)) {
|
||||
if ($this->model->add($data, $content, $date)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '添加成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '添加失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑
|
||||
$data['update_time'] = time();
|
||||
unset($data['content'], $data['record_date']);
|
||||
|
||||
if ($this->model->edit($data, $content, $date)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '添加成功'
|
||||
'msg' => '编辑成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '添加失败'
|
||||
'msg' => '编辑失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑
|
||||
$data['update_time'] = time();
|
||||
unset($data['content'], $data['record_date']);
|
||||
|
||||
if ($this->model->edit($data, $content, $date)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '编辑成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '编辑失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$granaryList = $this->getGranaryOptions();
|
||||
$typeList = $this->model->getTypeList();
|
||||
|
||||
$this->assign('item', null);
|
||||
$this->assign('granaryList', $granaryList);
|
||||
$this->assign('typeList', $typeList);
|
||||
$this->assign('siteOptions', $this->granarySites);
|
||||
|
||||
return $this->fetch('edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 独立编辑页面
|
||||
* @param null $ids
|
||||
* @return string
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$id = $ids ? $ids : input('param.id');
|
||||
$item = $this->model->getItem((int)$id, '*', ['granary', 'testingParams']);
|
||||
if (!$item) {
|
||||
$this->error('检测记录不存在');
|
||||
}
|
||||
$item = $item->toArray();
|
||||
|
||||
$granaryList = $this->getGranaryOptions();
|
||||
$typeList = $this->model->getTypeList();
|
||||
|
||||
$this->assign('item', $item);
|
||||
$this->assign('granaryList', $granaryList);
|
||||
$this->assign('typeList', $typeList);
|
||||
$this->assign('siteOptions', $this->granarySites);
|
||||
|
||||
return $this->fetch('edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 独立详情页面
|
||||
* @param null $ids
|
||||
* @return string
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function detail($ids = null)
|
||||
{
|
||||
$id = $ids ? $ids : input('param.id');
|
||||
$item = $this->model->getItem((int)$id, '*', ['granary', 'testingParams']);
|
||||
if (!$item) {
|
||||
$this->error('检测记录不存在');
|
||||
}
|
||||
$item = $item->toArray();
|
||||
|
||||
$granaryList = $this->getGranaryOptions();
|
||||
$typeList = $this->model->getTypeList();
|
||||
|
||||
$this->assign('item', $item);
|
||||
$this->assign('granaryList', $granaryList);
|
||||
$this->assign('typeList', $typeList);
|
||||
$this->assign('siteOptions', $this->granarySites);
|
||||
|
||||
return $this->fetch('detail');
|
||||
}
|
||||
|
||||
// 删除
|
||||
|
||||
在新工单中引用
屏蔽一个用户