This commit is contained in:
weiz 2024-02-02 17:58:30 +08:00
parent 5086034044
commit aa0e450e64
6 changed files with 420 additions and 128 deletions

View File

@ -39,9 +39,10 @@ class FlowApproveController extends BaseAdminController
*/
public function lists()
{
$res = addApprove('项目出差申请',9,'app\common\model\project\ProjectTripApply','app\adminapi\logic\project\ProjectTripApplyLogic',1,1,2);
halt($res);
return $this->dataLists(new FlowApproveLists());
// $res = addApprove('项目年假申请',9,'app\common\model\project\ProjectTripApply','app\adminapi\logic\project\ProjectTripApplyLogic',3,4,2);
// halt($res);
$params = (new FlowApproveValidate())->get()->goCheck('lists');
return $this->dataLists(new FlowApproveLists($params['type']));
}
@ -57,6 +58,26 @@ class FlowApproveController extends BaseAdminController
$result = FlowApproveLogic::detail($params);
return $this->data($result);
}
//撤销申请
public function revoke() {
$params = (new FlowApproveValidate())->post()->goCheck('revoke');
$result = FlowApproveLogic::revoke($params,$this->adminId);
if (true === $result) {
return $this->success('撤销成功', [], 1, 1);
}
return $this->fail(FlowApproveLogic::getError());
}
//审核
public function check(){
$params = (new FlowApproveValidate())->post()->goCheck('check');
$result = FlowApproveLogic::check($params,$this->adminId);
if (true === $result) {
return $this->success('审核成功', [], 1, 1);
}
return $this->fail(FlowApproveLogic::getError());
}
}

View File

@ -16,8 +16,13 @@ namespace app\adminapi\lists\oa;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\oa\Flow;
use app\common\model\oa\FlowApprove;
use app\common\lists\ListsSearchInterface;
use app\common\model\oa\FlowStep;
use app\common\model\oa\FlowType;
/**
@ -27,9 +32,15 @@ use app\common\lists\ListsSearchInterface;
*/
class FlowApproveLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
protected int $list_type; //列表类型 1我发起的 2我处理的 3抄送我的
public function __construct($list_type)
{
parent::__construct();
$this->list_type = $list_type;
}
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
@ -38,7 +49,7 @@ class FlowApproveLists extends BaseAdminDataLists implements ListsSearchInterfac
public function setSearch(): array
{
return [
'=' => ['check_status']
];
}
@ -54,11 +65,54 @@ class FlowApproveLists extends BaseAdminDataLists implements ListsSearchInterfac
*/
public function lists(): array
{
return FlowApprove::where($this->searchWhere)
->field(['id', 'flow_type_id', 'flow_id', 'content_id', 'content_model', 'create_user'])
$where = [];
switch ($this->list_type){
case 1: //我发起的
$where[] = ['create_user','=',$this->adminId];
break;
case 2: //我处理的
$approve_ids = FlowStep::whereFindInSet('flow_user',$this->adminId)->column('approve_id');
$where[] = ['id','in',$approve_ids];
break;
case 3: //抄送我的
$flow_ids = Flow::whereFindInSet('copy_uids',$this->adminId)->column('id');
$where[] = ['flow_id','in',$flow_ids];
break;
}
return FlowApprove::where($this->searchWhere)->where($where)
->field(['id', 'title', 'flow_type_id', 'flow_id', 'create_user', 'check_status', 'create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->select()->each(function($data){
//获取审批类型
$flow_type = FlowType::field('title')->where('id',$data['flow_type_id'])->findOrEmpty();
//获取审批流程信息
$flow = Flow::field('name,copy_uids')->where('id',$data['flow_id'])->findOrEmpty();
//获取创建人信息
$create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty();
//获取抄送人信息
$copy = Admin::where('id','in',$flow['copy_uids'])->column('name');
//当前审核人
$current_check_user = '';
//获取审核步骤
FlowStep::field('flow_step,flow_user,is_active')->where('approve_id',$data['id'])->order('sort asc')->select()->each(function($item)use(&$current_check_user){
if($item['is_active'] == 1){
if($item['flow_step'] == 0){
$current_check_user = '';
}else{
$flow_user = Admin::where('id','in',$item['flow_user'])->column('name');
$current_check_user = implode(',',$flow_user);
}
}
})->toArray();
$data['flow_type_name'] = $flow_type['title'];
$data['flow_name'] = $flow['name'];
$data['check_status'] = $data->check_status_text;
$data['current_check_user'] = $current_check_user;
$data['create_user'] = $create_user['name'];
$data['copy_user'] = implode(',',$copy);
unset($data['flow_type_id'],$data['flow_id']);
})
->toArray();
}
@ -71,7 +125,21 @@ class FlowApproveLists extends BaseAdminDataLists implements ListsSearchInterfac
*/
public function count(): int
{
return FlowApprove::where($this->searchWhere)->count();
$where = [];
switch ($this->list_type){
case 1: //我发起的
$where[] = ['create_user','=',$this->adminId];
break;
case 2: //我处理的
$approve_ids = FlowStep::whereFindInSet('flow_user',$this->adminId)->column('approve_id');
$where[] = ['id','in',$approve_ids];
break;
case 3: //抄送我的
$flow_ids = Flow::whereFindInSet('copy_uids',$this->adminId)->column('id');
$where[] = ['flow_id','in',$flow_ids];
break;
}
return FlowApprove::where($this->searchWhere)->where($where)->count();
}
}

View File

@ -2,12 +2,12 @@
namespace app\adminapi\logic\oa;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\oa\Flow;
use app\common\model\oa\FlowApprove;
use app\common\logic\BaseLogic;
use app\common\model\oa\FlowRecord;
use app\common\model\oa\FlowStep;
use think\facade\Db;
/**
@ -30,27 +30,27 @@ class FlowApproveLogic extends BaseLogic
//获取审批内容信息
$content = $data['content_logic']::detail(['id'=>$data['content_id']]);
//获取创建人信息
$create_user = Admin::field('name,dept_id')->where('id',$data['create_user'])->findOrEmpty();
$create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty();
//获取审批流程信息
$flow = Flow::field('name,copy_uids')->where('id',$data['flow_id'])-> findOrEmpty();
//获取抄送人信息
$copy = Admin::where('id','in',$flow['copy_uids'])->column('name');
//当前审核人
$current_check_user = '';
//获取审核步骤
$step = FlowStep::field('flow_step,flow_user')->where('approve_id',$data['id'])->order('sort asc')->select()->each(function($item)use($create_user){
$step = FlowStep::field('flow_step,flow_user,is_active')->where('approve_id',$data['id'])->order('sort asc')->select()->each(function($item)use($create_user,&$current_check_user){
$item['flow_step_text'] = $item->flow_step_text;
if($item['flow_step'] == 0){
$item['flow_step_text'] = $create_user['name'].'创建';
$item['flow_user'] = '';
}else if($item['flow_step'] == 1){
$item['flow_step_text'] = $item->flow_step_text;
$dept = Dept::field('leader')->where('id',$create_user['dept_id'])->findOrEmpty();
$flow_user = Admin::field('name')->where('id',$dept['leader'])->findOrEmpty();
$item['flow_user'] = $flow_user['name'];
}else{
$item['flow_step_text'] = $item->flow_step_text;
$flow_user = Admin::where('id','in',$item['flow_user'])->column('name');
$item['flow_user'] = implode(',',$flow_user);
}
if($item['is_active'] == 1){
$current_check_user = $item['flow_user'];
}
})->toArray();
//获取审批记录
$record = FlowRecord::field('title,content,check_time,status')->where('approve_id',$data['id'])->select()->each(function($item){
@ -58,6 +58,7 @@ class FlowApproveLogic extends BaseLogic
})->toArray();
$data['flow_name'] = $flow['name'];
$data['check_status_text'] = $data->check_status_text;
$data['current_check_user'] = $current_check_user;
$data['create_user_name'] = $create_user['name'];
$data['copy_user'] = implode(',',$copy);
$data['content'] = $content;
@ -66,4 +67,213 @@ class FlowApproveLogic extends BaseLogic
unset($data['flow_id'],$data['content_id'],$data['content_model'],$data['content_logic']);
return $data->toArray();
}
//撤销申请
public static function revoke(array $params,$admin_id): bool
{
$approve_data = FlowApprove::where('id',$params['id'])->findOrEmpty();
if($approve_data->isEmpty()){
self::setError('审批信息不存在');
return false;
}
if($approve_data['check_status'] != 0){
self::setError('审批信息状态不是待审核状态,不可撤回');
return false;
}
if($approve_data['create_user'] != $admin_id){
self::setError('当前登录用户不是该审批信息的创建用户');
return false;
}
$createUser = Admin::field('name')->where('id',$approve_data['create_user'])->findOrEmpty();
Db::startTrans();
try {
$revoke_time = time();
FlowApprove::where('id',$params['id'])->update([
'check_status' => 4,
'update_time' => $revoke_time,
]);
//添加审批数据记录
FlowRecord::create([
'approve_id' => $params['id'],
'step_id' => 0,
'check_user_id' => 0,
'check_time' => $revoke_time,
'status' => 3,
'title' => $createUser['name'].'撤销了此申请',
'content' => $params['revoke_reason'],
'is_invalid' => 0
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
//审核申请
public static function check($params,$admin_id): bool{
$str = $params['check_status'] == 1 ? '通过' : '拒绝';
$check_user = Admin::field('name')->where('id',$admin_id)->findOrEmpty();
$approve_data = FlowApprove::where('id',$params['id'])->findOrEmpty();
if($approve_data['check_status'] == 2 || $approve_data['check_status'] == 3){
self::setError('当前审批信息已审核');
return false;
}
if($approve_data['check_status'] == 4){
self::setError('当前审批信息已撤销');
return false;
}
//获取当前审批信息的审批步骤
$current_step = FlowStep::where('approve_id',$params['id'])->where('is_active',1)->findOrEmpty();
$current_check_user = explode(',',$current_step['flow_user']);
//获取当前审批信息的步骤总数
$step_count = FlowStep::where('approve_id',$params['id'])->count();
if(!in_array($admin_id,$current_check_user)){
self::setError('当前登录用户不是此审批信息的审核人');
return false;
}
//判断当前用户是否审核过该条记录
$check_record = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('check_user_id',$admin_id)->findOrEmpty();
if(!$check_record->isEmpty()){
self::setError('你已经审核过该条信息,无需重复审核');
return false;
}
//审批时间
$check_time = time();
Db::startTrans();
try {
//判断当前审批步骤类型
switch($current_step['flow_step']){
case 1://当前部门负责人审批
//判断当前审核步骤是否是最后一步;
//1、如果是最后一步如果当前用户审核通过则将该记录设置为审核通过如果当前用户未审核通过则则将该记录设置为审核不通过流程结束
//2、如果不是最后一步如果当前用户审核通过则将该记录设置为审核中流程进入下一步如果当前用户未审核通过则则将该记录设置为审核不通过流程结束
if(($current_step['sort']+1) == $step_count){
FlowApprove::where('id',$params['id'])->update([
'check_status' => $params['check_status'] == 1 ? 2 : 3,
'update_time' => $check_time,
]);
}else{
FlowApprove::where('id',$params['id'])->update([
'check_status' => $params['check_status'] == 1 ? 1 : 3,
'update_time' => $check_time,
]);
//设置下一步
if($params['check_status'] == 1){
FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
}
}
break;
case 2: //指定人或签
//判断当前记录除当前用户外,是否都审批了,
//1、如果都审批了则判断其他用户是否有审批通过的
//1-1、如果其他用户都没有审批通过则判断当前用户是否审批通过通过如果当前用户审批通过则判断当前审核步骤是否是最后一步
//1-1-1-1、如果是最后一步则该记录审批通过流程结束
//1-1-1-2、如果不是最后一步则该记录设置为审批中流程设置为下一步
//1-1-2、如果当前用户审批不通过则该记录审批不通过流程结束
//1-2、如果其他用户有一位审批通过则不管当前用户是否审批通过则判断当前审核步骤是否是最后一步如果是最后一步该记录设置为审核通过如果不是最后一步该记录设置为审核中流程设置为下一步
//2、如果没审批完则不管当前用户是否审批通过也不管当前审核步骤是否是最后一步该记录都设置为审批中不设置下一步操作
//获取当前记录的审核记录数
$check_record_count = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->count();
//获取但前记录的已经通过的记录
$check_record_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',1)->findOrEmpty();
//判断当前记录除当前用户外,是否都审批了,
if(count($current_check_user)-1 == $check_record_count){
//判断有没有审核通过的
if($check_record_pass->isEmpty()){//没有审核通过的
if($params['check_status'] == 1){
if(($current_step['sort']+1) == $step_count){
$approve_check_status = 2;
}else{
$approve_check_status = 1;
//设置下一步
FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
}
}else{
$approve_check_status = 3;
}
}else{//有审核通过的
if(($current_step['sort']+1) == $step_count){
$approve_check_status = 2;
}else{
$approve_check_status = 1;
//设置下一步
FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
}
}
}else{
//没审批完,该记录都设置为审批中
$approve_check_status = 1;
}
FlowApprove::where('id',$params['id'])->update([
'check_status' => $approve_check_status,
'update_time' => $check_time,
]);
break;
case 3: //指定人会签
//判断当前记录除当前用户外,是否都审批了,
//1、如果都审批了则判断其他用户是否有未审批通过的
//1-1、如果其他用户都审批通过则判断当前用户是否审批通过通过如果当前用户审批通过则判断当前审核步骤是否是最后一步
//1-1-1-1、如果是最后一步则该记录审批通过流程结束
//1-1-1-2、如果不是最后一步则该记录设置为审批中流程设置为下一步
//1-1-2、如果当前用户审批不通过则该记录审批不通过流程结束
//1-2、如果其他用户有一位审批不通过则不管当前用户是否审批通过该记录设置为审核不通过流程结束
//2、如果没审批完则判断当前用户是否审批通过如果当前用户审批通过则将记录设置为审批中如果当前用户审批不通过则将记录设置为审批不通过
//获取当前记录的审核记录数
$check_record_count = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->count();
//获取但前记录的未通过的记录
$check_record_not_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',2)->findOrEmpty();
//判断当前记录除当前用户外,是否都审批了,
if(count($current_check_user)-1 == $check_record_count){
//判断有没有审核不通过的
if($check_record_not_pass->isEmpty()){//没有审核不通过的
if($params['check_status'] == 1){
if(($current_step['sort']+1) == $step_count){
$approve_check_status = 2;
}else{
$approve_check_status = 1;
//设置下一步
FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
}
}else{
$approve_check_status = 3;
}
}else{//有审核不通过的
$approve_check_status = 3;
}
}else{
//没审批完,则判断当前用户是否审批通过,如果当前用户审批通过,则将记录设置为审批中,如果当前用户审批不通过,则将记录设置为审批不通过
$approve_check_status = $params['check_status'] == 1 ? 1 : 3;
}
FlowApprove::where('id',$params['id'])->update([
'check_status' => $approve_check_status,
'update_time' => $check_time,
]);
break;
}
//添加审批数据记录
FlowRecord::create([
'approve_id' => $params['id'],
'step_id' => $current_step['id'],
'check_user_id' => $admin_id,
'check_time' => $check_time,
'status' => $params['check_status'],
'title' => $check_user['name'].$str.'了此申请',
'content' => $params['check_reason'],
'is_invalid' => 0
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -1,104 +1,89 @@
<?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\oa;
use app\common\validate\BaseValidate;
/**
* 日常审批验证器
* Class FlowApproveValidate
* @package app\adminapi\validate\oa
*/
class FlowApproveValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'flow_type_id' => 'require',
'flow_id' => 'require',
'content_id' => 'require',
'content_model' => 'require',
'create_user' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'flow_type_id' => '审批类型id',
'flow_id' => '审批流程id',
'content_id' => '提交内容id',
'content_model' => '提交内容数据模型',
'create_user' => '创建人',
];
/**
* @notes 添加场景
* @return FlowApproveValidate
* @author likeadmin
* @date 2024/02/01 11:26
*/
public function sceneAdd()
{
return $this->only(['flow_type_id','flow_id','content_id','content_model','create_user']);
}
/**
* @notes 编辑场景
* @return FlowApproveValidate
* @author likeadmin
* @date 2024/02/01 11:26
*/
public function sceneEdit()
{
return $this->only(['id','flow_type_id','flow_id','content_id','content_model','create_user']);
}
/**
* @notes 删除场景
* @return FlowApproveValidate
* @author likeadmin
* @date 2024/02/01 11:26
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return FlowApproveValidate
* @author likeadmin
* @date 2024/02/01 11:26
*/
public function sceneDetail()
{
return $this->only(['id']);
}
<?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\oa;
use app\common\model\dict\DictData;
use app\common\validate\BaseValidate;
/**
* 日常审批验证器
* Class FlowApproveValidate
* @package app\adminapi\validate\oa
*/
class FlowApproveValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'type' => 'require|in:1,2,3',
'revoke_reason' => 'require',
'check_reason' => 'require',
'check_status' => 'require|checkStatus|in:1,2'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'type' => '列表类型',
'revoke_reason' => '撤销理由',
'check_reason' => '审批意见',
'check_status' => '审批状态'
];
/**
* @notes 详情场景
* @return FlowApproveValidate
* @author likeadmin
* @date 2024/02/01 11:26
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function sceneRevoke()
{
return $this->only(['id','revoke_reason']);
}
public function sceneCheck()
{
return $this->only(['id','check_reason','check_status']);
}
public function sceneLists()
{
return $this->only(['type']);
}
public function checkStatus($value){
$dict = DictData::where('type_value','flow_record_status')->column('value');
if(!in_array($value,$dict)){
return '审批状态值无效';
}
return true;
}
}

View File

@ -2,7 +2,8 @@
// 应用公共文件
use app\common\model\auth\Admin;
use app\common\model\oa\Flow;
use app\common\model\dept\Dept;
use app\common\model\oa\Flow;
use app\common\model\oa\FlowApprove;
use app\common\model\oa\FlowRecord;
use app\common\model\oa\FlowStep;
@ -360,7 +361,7 @@ function daysBetweenDates($start_date,$end_date): bool|int
}
function addApprove($title,$content_id,$content_model,$content_logic,$flow_type_id,$flow_id,$create_user_id){
$createUser = Admin::field('name')->where('id',$create_user_id)->findOrEmpty();
$createUser = Admin::field('name,dept_id')->where('id',$create_user_id)->findOrEmpty();
//获取审批流程信息
$flowData = Flow::where('id',$flow_id)->findOrEmpty();
Db::startTrans();
@ -375,17 +376,23 @@ function addApprove($title,$content_id,$content_model,$content_logic,$flow_type_
'flow_id' => $flow_id,
'create_user' => $create_user_id,
'check_status' => 0,
'current_step' => 0,
'total_step' => count($flowData['flow_list']) + 1
]);
$flowStepData = [];
foreach($flowData['flow_list'] as $k=>$v){
//获取部门负责人id
if($v['flow_step'] == 1){
$dept = Dept::field('leader')->where('id',$createUser['dept_id'])->findOrEmpty();
$flow_user = $dept['leader'];
}else{
$flow_user = implode(',',$v['flow_user']);
}
$flowStepData[] = [
'approve_id' => $approveRes->id,
'flow_name' => $flowData['name'],
'flow_step' => $v['flow_step'],
'flow_user' => $v['flow_step'] != 1 ? implode(',',$v['flow_user']) : 0,
'flow_user' => $flow_user,
'sort' => $k+1,
'is_active' => $k==0 ? 1 : 0,
];
}
array_unshift($flowStepData, [
@ -394,6 +401,7 @@ function addApprove($title,$content_id,$content_model,$content_logic,$flow_type_
'flow_step' => 0,
'flow_user' => 0,
'sort' => 0,
'is_active' => 0,
]);
//添加审批步骤
foreach($flowStepData as $v){

View File

@ -32,7 +32,7 @@ class FlowRecord extends BaseModel
protected $deleteTime = 'delete_time';
public function getStatusTextAttr($value,$data){
$dict = DictData::where('type_value','check_status')->column('name','value');
$dict = DictData::where('type_value','flow_record_status')->column('name','value');
return $dict[$data['status']];
}