Merge pull request 'QualityEvent' (#60) from zhangwei into dev
Reviewed-on: #60
This commit is contained in:
commit
4cdd24ef98
108
app/adminapi/controller/quality/QualityEventController.php
Normal file
108
app/adminapi/controller/quality/QualityEventController.php
Normal file
@ -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\QualityEventLists;
|
||||||
|
use app\adminapi\logic\quality\QualityEventLogic;
|
||||||
|
use app\adminapi\validate\quality\QualityEventValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 质量事件控制器
|
||||||
|
* Class QualityEventController
|
||||||
|
* @package app\adminapi\controller\quality
|
||||||
|
*/
|
||||||
|
class QualityEventController extends BaseAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取质量事件列表
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function lists()
|
||||||
|
{
|
||||||
|
return $this->dataLists(new QualityEventLists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加质量事件
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function add()
|
||||||
|
{
|
||||||
|
$params = (new QualityEventValidate())->post()->goCheck('add');
|
||||||
|
$result = QualityEventLogic::add($params,$this->adminId);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('添加成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(QualityEventLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑质量事件
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function edit()
|
||||||
|
{
|
||||||
|
$params = (new QualityEventValidate())->post()->goCheck('edit');
|
||||||
|
$result = QualityEventLogic::edit($params,$this->adminId);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('编辑成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(QualityEventLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除质量事件
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$params = (new QualityEventValidate())->post()->goCheck('delete');
|
||||||
|
QualityEventLogic::delete($params);
|
||||||
|
return $this->success('删除成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取质量事件详情
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function detail()
|
||||||
|
{
|
||||||
|
$params = (new QualityEventValidate())->goCheck('detail');
|
||||||
|
$result = QualityEventLogic::detail($params);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
91
app/adminapi/lists/quality/QualityEventLists.php
Normal file
91
app/adminapi/lists/quality/QualityEventLists.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?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\project\Project;
|
||||||
|
use app\common\model\quality\QualityEvent;
|
||||||
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 质量事件列表
|
||||||
|
* Class QualityEventLists
|
||||||
|
* @package app\adminapi\listsquality
|
||||||
|
*/
|
||||||
|
class QualityEventLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 设置搜索条件
|
||||||
|
* @return \string[][]
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function setSearch(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'=' => ['happen_date'],
|
||||||
|
'%like%' => ['name', 'type'],
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取质量事件列表
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function lists(): array
|
||||||
|
{
|
||||||
|
return QualityEvent::where($this->searchWhere)
|
||||||
|
->field(['id', 'org_id', 'dept_id', 'project_id', 'name', 'type', 'happen_date', 'content', 'remark', 'file'])
|
||||||
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
|
->order(['id' => 'desc'])
|
||||||
|
->select()->each(function($item){
|
||||||
|
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
|
||||||
|
$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'];
|
||||||
|
$item['project_name'] = $project['name'];
|
||||||
|
$item['project_code'] = $project['project_code'];
|
||||||
|
return $item;
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取质量事件数量
|
||||||
|
* @return int
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return QualityEvent::where($this->searchWhere)->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
140
app/adminapi/logic/quality/QualityEventLogic.php
Normal file
140
app/adminapi/logic/quality/QualityEventLogic.php
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
<?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\project\Project;
|
||||||
|
use app\common\model\quality\QualityEvent;
|
||||||
|
use app\common\logic\BaseLogic;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 质量事件逻辑
|
||||||
|
* Class QualityEventLogic
|
||||||
|
* @package app\adminapi\logic\quality
|
||||||
|
*/
|
||||||
|
class QualityEventLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加质量事件
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public static function add(array $params,$admin_id): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
QualityEvent::create([
|
||||||
|
'org_id' => $params['org_id'],
|
||||||
|
'dept_id' => $params['dept_id'],
|
||||||
|
'project_id' => $params['project_id'],
|
||||||
|
'name' => $params['name'],
|
||||||
|
'type' => $params['type'],
|
||||||
|
'happen_date' => strtotime($params['happen_date']),
|
||||||
|
'content' => $params['content'],
|
||||||
|
'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 09:42
|
||||||
|
*/
|
||||||
|
public static function edit(array $params,$admin_id): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
QualityEvent::where('id', $params['id'])->update([
|
||||||
|
'org_id' => $params['org_id'],
|
||||||
|
'dept_id' => $params['dept_id'],
|
||||||
|
'project_id' => $params['project_id'],
|
||||||
|
'name' => $params['name'],
|
||||||
|
'type' => $params['type'],
|
||||||
|
'happen_date' => strtotime($params['happen_date']),
|
||||||
|
'content' => $params['content'],
|
||||||
|
'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 09:42
|
||||||
|
*/
|
||||||
|
public static function delete(array $params): bool
|
||||||
|
{
|
||||||
|
return QualityEvent::destroy($params['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取质量事件详情
|
||||||
|
* @param $params
|
||||||
|
* @return array
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public static function detail($params): array
|
||||||
|
{
|
||||||
|
$data = QualityEvent::findOrEmpty($params['id'])->toArray();
|
||||||
|
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||||
|
$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['project_name'] = $project['name'];
|
||||||
|
$data['project_code'] = $project['project_code'];
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
141
app/adminapi/validate/quality/QualityEventValidate.php
Normal file
141
app/adminapi/validate/quality/QualityEventValidate.php
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<?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\model\project\Project;
|
||||||
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 质量事件验证器
|
||||||
|
* Class QualityEventValidate
|
||||||
|
* @package app\adminapi\validate\quality
|
||||||
|
*/
|
||||||
|
class QualityEventValidate extends BaseValidate
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置校验规则
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
'id' => 'require',
|
||||||
|
'org_id' => 'require|checkOrg',
|
||||||
|
'dept_id' => 'require|checkDept',
|
||||||
|
'project_id' => 'require|checkProject',
|
||||||
|
'name' => 'require',
|
||||||
|
'happen_date' => 'dateFormat:Y-m-d',
|
||||||
|
'file' => 'checkFile',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $message = [
|
||||||
|
'id.require' => '缺少必要参数',
|
||||||
|
'org_id.require' => '请选择组织',
|
||||||
|
'dept_id.require' => '请选择部门',
|
||||||
|
'project_id.require' => '请选择项目',
|
||||||
|
'name.require' => '请填写事件名称',
|
||||||
|
'happen_date.dateFormat' => '发生日期格式错误',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加场景
|
||||||
|
* @return QualityEventValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function sceneAdd()
|
||||||
|
{
|
||||||
|
return $this->remove('id',true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑场景
|
||||||
|
* @return QualityEventValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function sceneEdit()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除场景
|
||||||
|
* @return QualityEventValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
public function sceneDelete()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 详情场景
|
||||||
|
* @return QualityEventValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/21 09:42
|
||||||
|
*/
|
||||||
|
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 checkProject($value): bool|string
|
||||||
|
{
|
||||||
|
$data = Project::where('id',$value)->findOrEmpty();
|
||||||
|
if($data->isEmpty()){
|
||||||
|
return '项目不存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkFile($value): bool|string
|
||||||
|
{
|
||||||
|
if($value != ''){
|
||||||
|
$file = json_decode($value,true);
|
||||||
|
if(empty($file)){
|
||||||
|
return '附件必须是json数组';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
42
app/common/model/quality/QualityEvent.php
Normal file
42
app/common/model/quality/QualityEvent.php
Normal file
@ -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 QualityEvent
|
||||||
|
* @package app\common\model\quality
|
||||||
|
*/
|
||||||
|
class QualityEvent extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
protected $name = 'quality_event';
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public function getFileAttr($value)
|
||||||
|
{
|
||||||
|
return json_decode($value,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHappenDateAttr($value): string
|
||||||
|
{
|
||||||
|
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user