diff --git a/app/adminapi/controller/quality/QualitySpecificationController.php b/app/adminapi/controller/quality/QualitySpecificationController.php new file mode 100644 index 000000000..c6a37bd29 --- /dev/null +++ b/app/adminapi/controller/quality/QualitySpecificationController.php @@ -0,0 +1,108 @@ +<?php +// +---------------------------------------------------------------------- +// | likeadmin快速开发前后端分离管理后台(PHP版) +// +---------------------------------------------------------------------- +// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 +// | 开源版本可自由商用,可去除界面版权logo +// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin +// | github下载:https://github.com/likeshop-github/likeadmin +// | 访问官网:https://www.likeadmin.cn +// | likeadmin团队 版权所有 拥有最终解释权 +// +---------------------------------------------------------------------- +// | author: likeadminTeam +// +---------------------------------------------------------------------- + + +namespace app\adminapi\controller\quality; + + +use app\adminapi\controller\BaseAdminController; +use app\adminapi\lists\quality\QualitySpecificationLists; +use app\adminapi\logic\quality\QualitySpecificationLogic; +use app\adminapi\validate\quality\QualitySpecificationValidate; + + +/** + * 质量规范控制器 + * Class QualitySpecificationController + * @package app\adminapi\controller\quality + */ +class QualitySpecificationController extends BaseAdminController +{ + + + /** + * @notes 获取质量规范列表 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function lists() + { + return $this->dataLists(new QualitySpecificationLists()); + } + + + /** + * @notes 添加质量规范 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function add() + { + $params = (new QualitySpecificationValidate())->post()->goCheck('add'); + $result = QualitySpecificationLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(QualitySpecificationLogic::getError()); + } + + + /** + * @notes 编辑质量规范 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function edit() + { + $params = (new QualitySpecificationValidate())->post()->goCheck('edit'); + $result = QualitySpecificationLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(QualitySpecificationLogic::getError()); + } + + + /** + * @notes 删除质量规范 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function delete() + { + $params = (new QualitySpecificationValidate())->post()->goCheck('delete'); + QualitySpecificationLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取质量规范详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function detail() + { + $params = (new QualitySpecificationValidate())->goCheck('detail'); + $result = QualitySpecificationLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/quality/QualitySpecificationLists.php b/app/adminapi/lists/quality/QualitySpecificationLists.php new file mode 100644 index 000000000..5118a454c --- /dev/null +++ b/app/adminapi/lists/quality/QualitySpecificationLists.php @@ -0,0 +1,86 @@ +<?php +// +---------------------------------------------------------------------- +// | likeadmin快速开发前后端分离管理后台(PHP版) +// +---------------------------------------------------------------------- +// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 +// | 开源版本可自由商用,可去除界面版权logo +// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin +// | github下载:https://github.com/likeshop-github/likeadmin +// | 访问官网:https://www.likeadmin.cn +// | likeadmin团队 版权所有 拥有最终解释权 +// +---------------------------------------------------------------------- +// | author: likeadminTeam +// +---------------------------------------------------------------------- + +namespace app\adminapi\lists\quality; + + +use app\adminapi\lists\BaseAdminDataLists; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\quality\QualitySpecification; +use app\common\lists\ListsSearchInterface; + + +/** + * 质量规范列表 + * Class QualitySpecificationLists + * @package app\adminapi\listsquality + */ +class QualitySpecificationLists extends BaseAdminDataLists implements ListsSearchInterface +{ + + + /** + * @notes 设置搜索条件 + * @return \string[][] + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function setSearch(): array + { + return [ + '%like%' => ['name', 'type', 'release_dept'], + + ]; + } + + + /** + * @notes 获取质量规范列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function lists(): array + { + return QualitySpecification::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'name', 'type', 'release_date', 'release_dept', 'content', 'file']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $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/20 16:30 + */ + public function count(): int + { + return QualitySpecification::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/quality/QualitySpecificationLogic.php b/app/adminapi/logic/quality/QualitySpecificationLogic.php new file mode 100644 index 000000000..d02da2da5 --- /dev/null +++ b/app/adminapi/logic/quality/QualitySpecificationLogic.php @@ -0,0 +1,133 @@ +<?php +// +---------------------------------------------------------------------- +// | likeadmin快速开发前后端分离管理后台(PHP版) +// +---------------------------------------------------------------------- +// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 +// | 开源版本可自由商用,可去除界面版权logo +// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin +// | github下载:https://github.com/likeshop-github/likeadmin +// | 访问官网:https://www.likeadmin.cn +// | likeadmin团队 版权所有 拥有最终解释权 +// +---------------------------------------------------------------------- +// | author: likeadminTeam +// +---------------------------------------------------------------------- + +namespace app\adminapi\logic\quality; + + +use app\common\model\auth\Admin; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\quality\QualitySpecification; +use app\common\logic\BaseLogic; +use think\facade\Db; + + +/** + * 质量规范逻辑 + * Class QualitySpecificationLogic + * @package app\adminapi\logic\quality + */ +class QualitySpecificationLogic extends BaseLogic +{ + + + /** + * @notes 添加质量规范 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public static function add(array $params,$admin_id): bool + { + Db::startTrans(); + try { + QualitySpecification::create([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'name' => $params['name'], + 'type' => $params['type'], + 'release_date' => strtotime($params['release_date']), + 'release_dept' => $params['release_dept'], + 'content' => $params['content'], + '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/20 16:30 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + QualitySpecification::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'name' => $params['name'], + 'type' => $params['type'], + 'release_date' => $params['release_date'], + 'release_dept' => $params['release_dept'], + 'content' => $params['content'], + '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/20 16:30 + */ + public static function delete(array $params): bool + { + return QualitySpecification::destroy($params['id']); + } + + + /** + * @notes 获取质量规范详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public static function detail($params): array + { + $data = QualitySpecification::findOrEmpty($params['id'])->toArray(); + $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/QualitySpecificationValidate.php b/app/adminapi/validate/quality/QualitySpecificationValidate.php new file mode 100644 index 000000000..3efb9e4d4 --- /dev/null +++ b/app/adminapi/validate/quality/QualitySpecificationValidate.php @@ -0,0 +1,129 @@ +<?php +// +---------------------------------------------------------------------- +// | likeadmin快速开发前后端分离管理后台(PHP版) +// +---------------------------------------------------------------------- +// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 +// | 开源版本可自由商用,可去除界面版权logo +// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin +// | github下载:https://github.com/likeshop-github/likeadmin +// | 访问官网:https://www.likeadmin.cn +// | likeadmin团队 版权所有 拥有最终解释权 +// +---------------------------------------------------------------------- +// | author: likeadminTeam +// +---------------------------------------------------------------------- + +namespace app\adminapi\validate\quality; + + +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\validate\BaseValidate; + + +/** + * 质量规范验证器 + * Class QualitySpecificationValidate + * @package app\adminapi\validate\quality + */ +class QualitySpecificationValidate extends BaseValidate +{ + + /** + * 设置校验规则 + * @var string[] + */ + protected $rule = [ + 'id' => 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'name' => 'require', + 'release_date' => 'dateFormat:Y-m-d', + 'file' => 'checkFile' + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'name.require' => '请填写规范名称', + 'release_date.dateFormat' => '发布时间格式错误', + ]; + + /** + * @notes 添加场景 + * @return QualitySpecificationValidate + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return QualitySpecificationValidate + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return QualitySpecificationValidate + * @author likeadmin + * @date 2023/12/20 16:30 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return QualitySpecificationValidate + * @author likeadmin + * @date 2023/12/20 16:30 + */ + 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; + } + +} \ No newline at end of file diff --git a/app/common/model/quality/QualitySpecification.php b/app/common/model/quality/QualitySpecification.php new file mode 100644 index 000000000..386189052 --- /dev/null +++ b/app/common/model/quality/QualitySpecification.php @@ -0,0 +1,42 @@ +<?php +// +---------------------------------------------------------------------- +// | likeadmin快速开发前后端分离管理后台(PHP版) +// +---------------------------------------------------------------------- +// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 +// | 开源版本可自由商用,可去除界面版权logo +// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin +// | github下载:https://github.com/likeshop-github/likeadmin +// | 访问官网:https://www.likeadmin.cn +// | likeadmin团队 版权所有 拥有最终解释权 +// +---------------------------------------------------------------------- +// | author: likeadminTeam +// +---------------------------------------------------------------------- + +namespace app\common\model\quality; + + +use app\common\model\BaseModel; +use think\model\concern\SoftDelete; + + +/** + * 质量规范模型 + * Class QualitySpecification + * @package app\common\model\quality + */ +class QualitySpecification extends BaseModel +{ + use SoftDelete; + protected $name = 'quality_specification'; + protected $deleteTime = 'delete_time'; + + public function getReleaseDateAttr($value): string + { + return !empty($value) ? date('Y-m-d',$value) : ''; + } + + public function getFileAttr($value) + { + return json_decode($value,true); + } +} \ No newline at end of file