新增项目里程碑模块
This commit is contained in:
parent
cb81194486
commit
a3c7998667
108
app/adminapi/controller/project/ProjectMilestonesController.php
Normal file
108
app/adminapi/controller/project/ProjectMilestonesController.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\ProjectMilestonesLists;
|
||||
use app\adminapi\logic\project\ProjectMilestonesLogic;
|
||||
use app\adminapi\validate\project\ProjectMilestonesValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 项目里程碑控制器
|
||||
* Class ProjectMilestonesController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectMilestonesController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目里程碑列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectMilestonesLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加项目里程碑
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectMilestonesValidate())->post()->goCheck('add');
|
||||
$result = ProjectMilestonesLogic::add($params,$this->adminId);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectMilestonesLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑项目里程碑
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectMilestonesValidate())->post()->goCheck('edit');
|
||||
$result = ProjectMilestonesLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectMilestonesLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除项目里程碑
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectMilestonesValidate())->post()->goCheck('delete');
|
||||
ProjectMilestonesLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目里程碑详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectMilestonesValidate())->goCheck('detail');
|
||||
$result = ProjectMilestonesLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
88
app/adminapi/lists/project/ProjectMilestonesLists.php
Normal file
88
app/adminapi/lists/project/ProjectMilestonesLists.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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\auth\Admin;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMilestones;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* 项目里程碑列表
|
||||
* Class ProjectMilestonesLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectMilestonesLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_milestones', 'project_milestones_date'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目里程碑列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProjectMilestones::where($this->searchWhere)
|
||||
->field(['id', 'project_id', 'project_milestones', 'project_milestones_date','add_user'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$item['project_milestones_text'] = $item->project_milestones_text;
|
||||
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
|
||||
$admin = Admin::field('name')->where('id',$item['add_user'])->findOrEmpty();
|
||||
$item['project_name'] = $project['name'];
|
||||
$item['project_code'] = $project['project_code'];
|
||||
$item['add_user_name'] = $admin['name'];
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目里程碑数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProjectMilestones::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
116
app/adminapi/logic/project/ProjectMilestonesLogic.php
Normal file
116
app/adminapi/logic/project/ProjectMilestonesLogic.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?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\auth\Admin;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMilestones;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 项目里程碑逻辑
|
||||
* Class ProjectMilestonesLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectMilestonesLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加项目里程碑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public static function add(array $params,$admin_id): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectMilestones::create([
|
||||
'project_id' => $params['project_id'],
|
||||
'project_milestones' => $params['project_milestones'],
|
||||
'project_milestones_date' => strtotime($params['project_milestones_date']),
|
||||
'add_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/18 14:41
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectMilestones::where('id', $params['id'])->update([
|
||||
'project_id' => $params['project_id'],
|
||||
'project_milestones' => $params['project_milestones'],
|
||||
'project_milestones_date' => strtotime($params['project_milestones_date']),
|
||||
]);
|
||||
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/18 14:41
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectMilestones::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取项目里程碑详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectMilestones::field('id,project_id,project_milestones,project_milestones_date,add_user')->findOrEmpty($params['id']);
|
||||
$data['project_milestones_text'] = $data->project_milestones_text;
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
115
app/adminapi/validate/project/ProjectMilestonesValidate.php
Normal file
115
app/adminapi/validate/project/ProjectMilestonesValidate.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?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\dict\DictData;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 项目里程碑验证器
|
||||
* Class ProjectMilestonesValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectMilestonesValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'project_id' => 'require|checkProject',
|
||||
'project_milestones' => 'require|checkMilestones',
|
||||
'project_milestones_date' => 'require|date',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'project_id.require' => '请选择项目',
|
||||
'project_milestones.require' => '请填写里程碑',
|
||||
'project_milestones_date.require' => '请选择日期',
|
||||
'project_milestones_date.date' => '日期格式错误',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectMilestonesValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectMilestonesValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','project_id','project_milestones','project_milestones_date']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectMilestonesValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectMilestonesValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/18 14:41
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkProject($value): bool|string
|
||||
{
|
||||
$data = Project::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '项目不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkMilestones($value): bool|string
|
||||
{
|
||||
$dictDate = DictData::where('type_value','project_milestones')->column('value');
|
||||
if(!in_array($value,$dictDate)){
|
||||
return '里程碑值错误';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
44
app/common/model/project/ProjectMilestones.php
Normal file
44
app/common/model/project/ProjectMilestones.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?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 app\common\model\dict\DictData;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 项目里程碑模型
|
||||
* Class ProjectMilestones
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectMilestones extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_milestones';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getProjectMilestonesDateAttr($value): string
|
||||
{
|
||||
return date('Y-m-d',$value);
|
||||
}
|
||||
|
||||
public function getProjectMilestonesTextAttr($value,$data)
|
||||
{
|
||||
$dictDate = DictData::where('type_value','project_milestones')->column('name','value');
|
||||
return $dictDate[$data['project_milestones']];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user