Merge pull request '新增项目文档设置模块' (#32) from zhangwei into dev
Reviewed-on: #32
This commit is contained in:
commit
393d3da5e2
108
app/adminapi/controller/project/ProjectDocumentSetController.php
Normal file
108
app/adminapi/controller/project/ProjectDocumentSetController.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\project;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\project\ProjectDocumentSetLists;
|
||||
use app\adminapi\logic\project\ProjectDocumentSetLogic;
|
||||
use app\adminapi\validate\project\ProjectDocumentSetValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 项目文档设置控制器
|
||||
* Class ProjectDocumentSetController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectDocumentSetController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目文档设置列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectDocumentSetLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加项目文档设置
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectDocumentSetValidate())->post()->goCheck('add');
|
||||
$result = ProjectDocumentSetLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectDocumentSetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑项目文档设置
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectDocumentSetValidate())->post()->goCheck('edit');
|
||||
$result = ProjectDocumentSetLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectDocumentSetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除项目文档设置
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectDocumentSetValidate())->post()->goCheck('delete');
|
||||
ProjectDocumentSetLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目文档设置详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectDocumentSetValidate())->goCheck('detail');
|
||||
$result = ProjectDocumentSetLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
95
app/adminapi/lists/project/ProjectDocumentSetLists.php
Normal file
95
app/adminapi/lists/project/ProjectDocumentSetLists.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?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\project;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\project\ProjectDocumentSet;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\ProjectTypeSet;
|
||||
|
||||
|
||||
/**
|
||||
* 项目文档设置列表
|
||||
* Class ProjectDocumentSetLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectDocumentSetLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['is_upload'],
|
||||
'%like%' => ['large_category', 'middle_category', 'small_category', 'name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目文档设置列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$where = [];
|
||||
if(isset($params['project_type_name']) && $params['project_type_name'] != ''){
|
||||
$projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id');
|
||||
$where[] = ['project_type_id','in',$projectTypeIds];
|
||||
}
|
||||
return ProjectDocumentSet::where($this->searchWhere)->where($where)
|
||||
->field(['id', 'project_type_id', 'large_category', 'middle_category', 'small_category', 'name', 'describe', 'is_upload', 'sort'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$projectType = ProjectTypeSet::field('name')->where('id',$item['project_type_id'])->findOrEmpty();
|
||||
$item['project_type_name'] = $projectType['name'];
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目文档设置数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$where = [];
|
||||
if(isset($params['project_type_name']) && $params['project_type_name'] != ''){
|
||||
$projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id');
|
||||
$where[] = ['project_type_id','in',$projectTypeIds];
|
||||
}
|
||||
return ProjectDocumentSet::where($this->searchWhere)->where($where)->count();
|
||||
}
|
||||
|
||||
}
|
122
app/adminapi/logic/project/ProjectDocumentSetLogic.php
Normal file
122
app/adminapi/logic/project/ProjectDocumentSetLogic.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?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\project;
|
||||
|
||||
|
||||
use app\common\model\project\ProjectDocumentSet;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\ProjectTypeSet;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 项目文档设置逻辑
|
||||
* Class ProjectDocumentSetLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectDocumentSetLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加项目文档设置
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectDocumentSet::create([
|
||||
'project_type_id' => $params['project_type_id'],
|
||||
'large_category' => $params['large_category'],
|
||||
'middle_category' => $params['middle_category'],
|
||||
'small_category' => $params['small_category'],
|
||||
'name' => $params['name'],
|
||||
'describe' => $params['describe'],
|
||||
'is_upload' => $params['is_upload'],
|
||||
'sort' => $params['sort'],
|
||||
]);
|
||||
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/14 14:26
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectDocumentSet::where('id', $params['id'])->update([
|
||||
'project_type_id' => $params['project_type_id'],
|
||||
'large_category' => $params['large_category'],
|
||||
'middle_category' => $params['middle_category'],
|
||||
'small_category' => $params['small_category'],
|
||||
'name' => $params['name'],
|
||||
'describe' => $params['describe'],
|
||||
'is_upload' => $params['is_upload'],
|
||||
'sort' => $params['sort'],
|
||||
]);
|
||||
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/14 14:26
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectDocumentSet::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目文档设置详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectDocumentSet::field('id,project_type_id,large_category,middle_category,small_category,name,describe,is_upload,sort')->findOrEmpty($params['id'])->toArray();
|
||||
$projectType = ProjectTypeSet::field('name')->where('id',$data['project_type_id'])->findOrEmpty();
|
||||
$data['project_type_name'] = $projectType['name'];
|
||||
return $data;
|
||||
}
|
||||
}
|
137
app/adminapi/validate/project/ProjectDocumentSetValidate.php
Normal file
137
app/adminapi/validate/project/ProjectDocumentSetValidate.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?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\project;
|
||||
|
||||
|
||||
use app\common\model\project\ProjectDocumentSet;
|
||||
use app\common\model\project\ProjectTypeSet;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 项目文档设置验证器
|
||||
* Class ProjectDocumentSetValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectDocumentSetValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require|checkProjectDoc',
|
||||
'project_type_id' => 'require|checkProjectType',
|
||||
'large_category' => 'require',
|
||||
'middle_category' => 'require',
|
||||
'name' => 'require',
|
||||
'is_upload' => 'require|in:1,2',
|
||||
'sort' => 'require|integer',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'project_type_id.require' => '请选择项目类型',
|
||||
'large_category.require' => '请填写文档大类',
|
||||
'middle_category.require' => '请填写文档中类',
|
||||
'name.require' => '请填写文档名称',
|
||||
'is_upload.require' => '请选择是否必传',
|
||||
'is_upload.in' => '是否必传选项数据值错误',
|
||||
'sort.require' => '请填写排序码',
|
||||
'sort.integer' => '排序码数据格式错误',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'project_type_id' => '项目类型id',
|
||||
'large_category' => '文档大类',
|
||||
'middle_category' => '文档中类',
|
||||
'name' => '文档名称',
|
||||
'is_upload' => '必传 1-是 2-否',
|
||||
'sort' => '排序号',
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectDocumentSetValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectDocumentSetValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectDocumentSetValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectDocumentSetValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/14 14:26
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkProjectDoc($value): bool|string
|
||||
{
|
||||
$data = ProjectDocumentSet::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '数据不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkProjectType($value): bool|string
|
||||
{
|
||||
$data = ProjectTypeSet::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '项目类型不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
34
app/common/model/project/ProjectDocumentSet.php
Normal file
34
app/common/model/project/ProjectDocumentSet.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\project;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 项目文档设置模型
|
||||
* Class ProjectDocumentSet
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectDocumentSet extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_document_set';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user