diff --git a/app/adminapi/controller/quality/QualityDetectionTempController.php b/app/adminapi/controller/quality/QualityDetectionTempController.php new file mode 100644 index 000000000..580789066 --- /dev/null +++ b/app/adminapi/controller/quality/QualityDetectionTempController.php @@ -0,0 +1,108 @@ +dataLists(new QualityDetectionTempLists()); + } + + + /** + * @notes 添加质量检测模板 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function add() + { + $params = (new QualityDetectionTempValidate())->post()->goCheck('add'); + $result = QualityDetectionTempLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(QualityDetectionTempLogic::getError()); + } + + + /** + * @notes 编辑质量检测模板 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function edit() + { + $params = (new QualityDetectionTempValidate())->post()->goCheck('edit'); + $result = QualityDetectionTempLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(QualityDetectionTempLogic::getError()); + } + + + /** + * @notes 删除质量检测模板 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function delete() + { + $params = (new QualityDetectionTempValidate())->post()->goCheck('delete'); + QualityDetectionTempLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取质量检测模板详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function detail() + { + $params = (new QualityDetectionTempValidate())->goCheck('detail'); + $result = QualityDetectionTempLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/quality/QualityDetectionTempLists.php b/app/adminapi/lists/quality/QualityDetectionTempLists.php new file mode 100644 index 000000000..0395a7ec1 --- /dev/null +++ b/app/adminapi/lists/quality/QualityDetectionTempLists.php @@ -0,0 +1,86 @@ + ['node', 'serial_number'], + ]; + } + + + /** + * @notes 获取质量检测模板列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function lists(): array + { + return QualityDetectionTemp::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'node', 'serial_number', 'standard_duration', 'remark', 'file', 'add_user', 'update_user']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $item['node_text'] = $item->node_text; + $org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty(); + $item['org_name'] = $org['name']; + $item['dept_name'] = $dept['name']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取质量检测模板数量 + * @return int + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function count(): int + { + return QualityDetectionTemp::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/quality/QualityDetectionTempLogic.php b/app/adminapi/logic/quality/QualityDetectionTempLogic.php new file mode 100644 index 000000000..dcc336c58 --- /dev/null +++ b/app/adminapi/logic/quality/QualityDetectionTempLogic.php @@ -0,0 +1,132 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'node' => $params['node'], + 'serial_number' => $params['serial_number'], + 'standard_duration' => $params['standard_duration'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + 'add_user' => $admin_id, + 'update_user' => $admin_id, + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑质量检测模板 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + QualityDetectionTemp::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'node' => $params['node'], + 'serial_number' => $params['serial_number'], + 'standard_duration' => $params['standard_duration'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + 'update_user' => $admin_id, + 'update_time' => time(), + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除质量检测模板 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public static function delete(array $params): bool + { + return QualityDetectionTemp::destroy($params['id']); + } + + + /** + * @notes 获取质量检测模板详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public static function detail($params): array + { + $data = QualityDetectionTemp::findOrEmpty($params['id'])->toArray(); + if(empty($data)) return []; + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id'); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['add_user_name'] = $admin[$data['add_user']]; + $data['update_user_name'] = $admin[$data['update_user']]; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/quality/QualityDetectionTempValidate.php b/app/adminapi/validate/quality/QualityDetectionTempValidate.php new file mode 100644 index 000000000..6271cb35d --- /dev/null +++ b/app/adminapi/validate/quality/QualityDetectionTempValidate.php @@ -0,0 +1,138 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'node' => 'require|checkNode', + 'file' => 'checkFile', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'node.require' => '请选择质量检测节点', + ]; + + + /** + * @notes 添加场景 + * @return QualityDetectionTempValidate + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return QualityDetectionTempValidate + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return QualityDetectionTempValidate + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return QualityDetectionTempValidate + * @author likeadmin + * @date 2023/12/21 15:41 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkOrg($value): bool|string + { + $data = Orgs::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '组织不存在'; + } + return true; + } + + public function checkDept($value,$rule,$data): bool|string + { + $dept = Dept::where('id',$value)->findOrEmpty(); + if($dept->isEmpty()){ + return '部门不存在'; + } + if($dept['org_id'] != $data['org_id']){ + return '部门不属于当前选择的组织'; + } + return true; + } + + public function checkFile($value): bool|string + { + if($value != ''){ + $file = json_decode($value,true); + if(empty($file)){ + return '附件必须是json数组'; + } + } + return true; + } + + public function checkNode($value): bool|string + { + $dictData = DictData::where('type_value','quality_detection_node')->column('value'); + if(!in_array($value,$dictData)){ + return '质量检测节点无效'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/quality/QualityDetectionTemp.php b/app/common/model/quality/QualityDetectionTemp.php new file mode 100644 index 000000000..b234e837f --- /dev/null +++ b/app/common/model/quality/QualityDetectionTemp.php @@ -0,0 +1,43 @@ +column('name','value'); + return $dictData[$data['node']]; + } +} \ No newline at end of file