新增项目干系人模块

This commit is contained in:
weiz 2023-12-15 13:31:29 +08:00
parent 40ba795813
commit d012f6d962
6 changed files with 555 additions and 13 deletions

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

@ -55,17 +55,13 @@ class ProjectMemberLists extends BaseAdminDataLists implements ListsSearchInterf
*/
public function lists(): array
{
//project_name project_code project_role_name admin_name
//project_name 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];
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds];
}
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];
@ -103,12 +99,8 @@ class ProjectMemberLists extends BaseAdminDataLists implements ListsSearchInterf
$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];
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds];
}
if(isset($params['project_role_name']) && $params['project_role_name'] != ''){
$projectRoleIds = ProjectRoleSet::where('name','like','%'.$params['project_role_name'].'%')->column('id');

@ -0,0 +1,100 @@
<?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\Project;
use app\common\model\project\ProjectStakeholder;
use app\common\lists\ListsSearchInterface;
/**
* 项目干系人列表
* Class ProjectStakeholderLists
* @package app\adminapi\listsproject
*/
class ProjectStakeholderLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/15 11:20
*/
public function setSearch(): array
{
return [
'=' => ['identity'],
'%like%' => ['name','phone'],
];
}
/**
* @notes 获取项目干系人列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/15 11:20
*/
public function lists(): array
{
$params = $this->request->param();
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds];
}
return ProjectStakeholder::where($this->searchWhere)->where($where)
->field(['id', 'project_id', 'name', 'identity', 'superior', 'department', 'station', 'phone', 'email', 'attitude', 'degree_adaptability', '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();
$item['identity_text'] = $item->identity_text;
$item['attitude_text'] = $item->attitude_text;
$item['degree_adaptability_text'] = $item->degree_adaptability_text;
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
return $item;
})
->toArray();
}
/**
* @notes 获取项目干系人数量
* @return int
* @author likeadmin
* @date 2023/12/15 11:20
*/
public function count(): int
{
$params = $this->request->param();
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds];
}
return ProjectStakeholder::where($this->searchWhere)->where($where)->count();
}
}

@ -0,0 +1,130 @@
<?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\Project;
use app\common\model\project\ProjectStakeholder;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 项目干系人逻辑
* Class ProjectStakeholderLogic
* @package app\adminapi\logic\project
*/
class ProjectStakeholderLogic extends BaseLogic
{
/**
* @notes 添加项目干系人
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/15 11:20
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ProjectStakeholder::create([
'project_id' => $params['project_id'],
'name' => $params['name'],
'identity' => $params['identity'],
'superior' => $params['superior'],
'department' => $params['department'],
'station' => $params['station'],
'phone' => $params['phone'],
'email' => $params['email'],
'attitude' => $params['attitude'],
'degree_adaptability' => $params['degree_adaptability'],
'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 11:20
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectStakeholder::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'name' => $params['name'],
'identity' => $params['identity'],
'superior' => $params['superior'],
'department' => $params['department'],
'station' => $params['station'],
'phone' => $params['phone'],
'email' => $params['email'],
'attitude' => $params['attitude'],
'degree_adaptability' => $params['degree_adaptability'],
'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 11:20
*/
public static function delete(array $params): bool
{
return ProjectStakeholder::destroy($params['id']);
}
/**
* @notes 获取项目干系人详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/15 11:20
*/
public static function detail($params): array
{
$data = ProjectStakeholder::field('id,project_id,name,identity,superior,department,station,phone,email,attitude,degree_adaptability,remark')->findOrEmpty($params['id'])->toArray();
$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;
}
}

@ -0,0 +1,161 @@
<?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\model\project\ProjectStakeholder;
use app\common\validate\BaseValidate;
/**
* 项目干系人验证器
* Class ProjectStakeholderValidate
* @package app\adminapi\validate\project
*/
class ProjectStakeholderValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'project_id' => 'require|checkProject',
'name' => 'require',
'identity' => 'require|checkIdentity',
'phone' => 'require|mobile',
'email' => 'email',
'attitude' => 'checkAttitude',
'degree_adaptability' => 'checkDegree'
];
protected $message = [
'id.require' => '缺少必要参数',
'project_id.require' => '请选择项目',
'name.require' => '请填写姓名',
'identity.require' => '请选择身份',
'phone.require' => '请填写电话',
'phone.mobile' => '电话格式错误',
'email.email' => '邮箱格式错误',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'name' => '姓名',
'identity' => '身份',
'phone' => '电话',
];
/**
* @notes 添加场景
* @return ProjectStakeholderValidate
* @author likeadmin
* @date 2023/12/15 11:20
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectStakeholderValidate
* @author likeadmin
* @date 2023/12/15 11:20
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectStakeholderValidate
* @author likeadmin
* @date 2023/12/15 11:20
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectStakeholderValidate
* @author likeadmin
* @date 2023/12/15 11:20
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = ProjectStakeholder::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 checkIdentity($value): bool|string
{
$data = DictData::where('type_value','project_stakeholder_identity')->column('value');
if(!in_array($value,$data)){
return '身份数据值错误';
}
return true;
}
public function checkAttitude($value): bool|string
{
$data = DictData::where('type_value','project_stakeholder_attitude')->column('value');
if(!in_array($value,$data)){
return '对我方态度选项数据值错误';
}
return true;
}
public function checkDegree($value): bool|string
{
$data = DictData::where('type_value','project_stakeholder_degree_adaptability')->column('value');
if(!in_array($value,$data)){
return '工作配合度选项数据值错误';
}
return true;
}
}

@ -0,0 +1,51 @@
<?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 ProjectStakeholder
* @package app\common\model\project
*/
class ProjectStakeholder extends BaseModel
{
use SoftDelete;
protected $name = 'project_stakeholder';
protected $deleteTime = 'delete_time';
public function getIdentityTextAttr($value,$data)
{
$dictData = DictData::where('type_value','project_stakeholder_identity')->column('name','value');
return $dictData[$data['identity']];
}
public function getAttitudeTextAttr($value,$data)
{
$dictData = DictData::where('type_value','project_stakeholder_attitude')->column('name','value');
return $dictData[$data['attitude']];
}
public function getDegreeAdaptabilityTextAttr($value,$data)
{
$dictData = DictData::where('type_value','project_stakeholder_degree_adaptability')->column('name','value');
return $dictData[$data['degree_adaptability']];
}
}