Merge pull request '新增项目成员模块' (#35) from zhangwei into dev

Reviewed-on: #35
This commit is contained in:
weiz 2023-12-15 11:02:15 +08:00
commit 5634d9ac0b
7 changed files with 543 additions and 3 deletions

View File

@ -52,7 +52,7 @@ class ProjectController extends BaseAdminController
public function add()
{
$params = (new ProjectValidate())->post()->goCheck('add');
$result = ProjectLogic::add($params);
$result = ProjectLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}

View 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\ProjectMemberLists;
use app\adminapi\logic\project\ProjectMemberLogic;
use app\adminapi\validate\project\ProjectMemberValidate;
/**
* 项目成员控制器
* Class ProjectMemberController
* @package app\adminapi\controller\project
*/
class ProjectMemberController extends BaseAdminController
{
/**
* @notes 获取项目成员列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function lists()
{
return $this->dataLists(new ProjectMemberLists());
}
/**
* @notes 添加项目成员
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function add()
{
$params = (new ProjectMemberValidate())->post()->goCheck('add');
$result = ProjectMemberLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectMemberLogic::getError());
}
/**
* @notes 编辑项目成员
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function edit()
{
$params = (new ProjectMemberValidate())->post()->goCheck('edit');
$result = ProjectMemberLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectMemberLogic::getError());
}
/**
* @notes 删除项目成员
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function delete()
{
$params = (new ProjectMemberValidate())->post()->goCheck('delete');
ProjectMemberLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取项目成员详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function detail()
{
$params = (new ProjectMemberValidate())->goCheck('detail');
$result = ProjectMemberLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,124 @@
<?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\ProjectMember;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\ProjectRoleSet;
/**
* 项目成员列表
* Class ProjectMemberLists
* @package app\adminapi\listsproject
*/
class ProjectMemberLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function setSearch(): array
{
return [];
}
/**
* @notes 获取项目成员列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function lists(): array
{
//project_name project_code project_role_name admin_name
$params = $this->request->param();
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds1 = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds1];
}
if(isset($params['project_code']) && $params['project_code'] != ''){
$projectIds2 = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id');
$where[] = ['project_id','in',$projectIds2];
}
if(isset($params['project_role_name']) && $params['project_role_name'] != ''){
$projectRoleIds = ProjectRoleSet::where('name','like','%'.$params['project_role_name'].'%')->column('id');
$where[] = ['project_role_id','in',$projectRoleIds];
}
if(isset($params['admin_name']) && $params['admin_name'] != ''){
$adminIds = Admin::where('name','like','%'.$params['admin_name'].'%')->column('id');
$where[] = ['admin_id','in',$adminIds];
}
return ProjectMember::where($this->searchWhere)->where($where)
->field(['id', 'project_id', 'project_role_id', 'admin_id', 'working_unit_price', 'remark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
$role = ProjectRoleSet::field('name')->where('id',$item['project_role_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['admin_id'])->findOrEmpty();
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
$item['project_role_name'] = $role['name'];
$item['admin_name'] = $admin['name'];
return $item;
})
->toArray();
}
/**
* @notes 获取项目成员数量
* @return int
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function count(): int
{
$params = $this->request->param();
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds1 = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds1];
}
if(isset($params['project_code']) && $params['project_code'] != ''){
$projectIds2 = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id');
$where[] = ['project_id','in',$projectIds2];
}
if(isset($params['project_role_name']) && $params['project_role_name'] != ''){
$projectRoleIds = ProjectRoleSet::where('name','like','%'.$params['project_role_name'].'%')->column('id');
$where[] = ['project_role_id','in',$projectRoleIds];
}
if(isset($params['admin_name']) && $params['admin_name'] != ''){
$adminIds = Admin::where('name','like','%'.$params['admin_name'].'%')->column('id');
$where[] = ['admin_id','in',$adminIds];
}
return ProjectMember::where($this->searchWhere)->where($where)->count();
}
}

View File

@ -38,7 +38,7 @@ class ProjectLogic extends BaseLogic
* @author likeadmin
* @date 2023/11/12 14:30
*/
public static function add(array $params): bool
public static function add(array $params, $adminId): bool
{
Db::startTrans();
try {
@ -71,7 +71,8 @@ class ProjectLogic extends BaseLogic
'industry' => $params['industry'],
'unit_nature' => $params['unit_nature'],
'annex' => $params['annex'],
'status' => 0
'status' => 0,
'add_user' => $adminId
]);
Db::commit();

View File

@ -0,0 +1,123 @@
<?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\ProjectMember;
use app\common\logic\BaseLogic;
use app\common\model\project\ProjectRoleSet;
use think\facade\Db;
/**
* 项目成员逻辑
* Class ProjectMemberLogic
* @package app\adminapi\logic\project
*/
class ProjectMemberLogic extends BaseLogic
{
/**
* @notes 添加项目成员
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/15 09:59
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ProjectMember::create([
'project_id' => $params['project_id'],
'project_role_id' => $params['project_role_id'],
'admin_id' => $params['admin_id'],
'working_unit_price' => $params['working_unit_price'],
'remark' => $params['remark'],
]);
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/15 09:59
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectMember::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'project_role_id' => $params['project_role_id'],
'admin_id' => $params['admin_id'],
'working_unit_price' => $params['working_unit_price'],
'remark' => $params['remark'],
]);
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/15 09:59
*/
public static function delete(array $params): bool
{
return ProjectMember::destroy($params['id']);
}
/**
* @notes 获取项目成员详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/15 09:59
*/
public static function detail($params): array
{
$data = ProjectMember::field('id,project_id,project_role_id,admin_id,working_unit_price,remark')->findOrEmpty($params['id'])->toArray();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$role = ProjectRoleSet::field('name')->where('id',$data['project_role_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$data['admin_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['project_role_name'] = $role['name'];
$data['admin_name'] = $admin['name'];
return $data;
}
}

View File

@ -0,0 +1,150 @@
<?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\auth\Admin;
use app\common\model\project\Project;
use app\common\model\project\ProjectMember;
use app\common\model\project\ProjectRoleSet;
use app\common\validate\BaseValidate;
/**
* 项目成员验证器
* Class ProjectMemberValidate
* @package app\adminapi\validate\project
*/
class ProjectMemberValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'project_id' => 'require|checkProject',
'project_role_id' => 'require|checkProjectRole',
'admin_id' => 'require|checkAdmin',
'working_unit_price' => 'require|float|egt:0',
];
protected $message = [
'id.require' => '缺少必要参数',
'project_id.require' => '请选择项目',
'project_role_id.require' => '请选择项目角色',
'admin_id.require' => '请选择人员',
'working_unit_price.require' => '请填写工时单价',
'working_unit_price.float' => '工时单价必须是数字',
'working_unit_price.egt' => '工时单价必须大于等于0',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'project_role_id' => '角色名称',
'admin_id' => '人员id',
'working_unit_price' => '工时单价',
];
/**
* @notes 添加场景
* @return ProjectMemberValidate
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectMemberValidate
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectMemberValidate
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectMemberValidate
* @author likeadmin
* @date 2023/12/15 09:59
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = ProjectMember::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkProject($value): bool|string
{
$data = Project::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkProjectRole($value): bool|string
{
$data = ProjectRoleSet::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目角色不存在';
}
return true;
}
public function checkAdmin($value): bool|string
{
$data = Admin::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '人员不存在';
}
return true;
}
}

View 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 ProjectMember
* @package app\common\model\project
*/
class ProjectMember extends BaseModel
{
use SoftDelete;
protected $name = 'project_member';
protected $deleteTime = 'delete_time';
}