You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
3.9 KiB
155 lines
3.9 KiB
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\controller\school_approval;
|
|
|
|
use app\adminapi\controller\BaseAdminApi;
|
|
use app\service\school_approval\SchoolApprovalProcessService;
|
|
use core\base\BaseAdminController;
|
|
use think\facade\Request;
|
|
|
|
/**
|
|
* 审批流程控制器
|
|
* Class Process
|
|
* @package app\adminapi\controller\school_approval
|
|
*/
|
|
class Process extends BaseAdminController
|
|
{
|
|
/**
|
|
* @var SchoolApprovalProcessService
|
|
*/
|
|
protected $service;
|
|
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$this->service = new SchoolApprovalProcessService();
|
|
}
|
|
|
|
/**
|
|
* 获取审批流程列表
|
|
*/
|
|
public function lists()
|
|
{
|
|
$page = input('page', 1);
|
|
$limit = input('limit', 10);
|
|
$status = input('approval_status', '');
|
|
|
|
$where = [];
|
|
if ($status !== '') {
|
|
$where[] = ['approval_status', '=', $status];
|
|
}
|
|
|
|
$process_name = input('process_name', '');
|
|
if (!empty($process_name)) {
|
|
$where[] = ['process_name', 'like', "%{$process_name}%"];
|
|
}
|
|
|
|
// 我发起的审批
|
|
$applicant_id = input('applicant_id', 0);
|
|
if (!empty($applicant_id)) {
|
|
$where[] = ['applicant_id', '=', $applicant_id];
|
|
}
|
|
|
|
// 待我审批的
|
|
$approver_id = input('approver_id', 0);
|
|
if (!empty($approver_id)) {
|
|
$where[] = ['current_approver_id', '=', $approver_id];
|
|
$where[] = ['approval_status', '=', 'pending'];
|
|
}
|
|
|
|
$data = $this->service->getList($where, $page, $limit);
|
|
|
|
return success($data);
|
|
}
|
|
|
|
/**
|
|
* 获取审批流程详情
|
|
*/
|
|
public function info()
|
|
{
|
|
$id = input('id', 0);
|
|
if (empty($id)) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
$info = $this->service->getInfo($id);
|
|
if (empty($info)) {
|
|
return fail('审批流程不存在');
|
|
}
|
|
|
|
return success($info);
|
|
}
|
|
|
|
/**
|
|
* 创建审批流程
|
|
*/
|
|
public function create()
|
|
{
|
|
$data = Request::only(['process_name', 'remarks']);
|
|
$config_id = input('config_id', 0);
|
|
|
|
// 验证参数
|
|
if (empty($data['process_name'])) {
|
|
return fail('流程名称不能为空');
|
|
}
|
|
|
|
if (empty($config_id)) {
|
|
return fail('请选择审批流配置');
|
|
}
|
|
|
|
// 设置申请人ID
|
|
$data['applicant_id'] = $this->user_info['uid'];
|
|
|
|
try {
|
|
$process_id = $this->service->create($data, $config_id);
|
|
return success(['id' => $process_id]);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 审批
|
|
*/
|
|
public function approve()
|
|
{
|
|
$process_id = input('process_id', 0);
|
|
$status = input('status', '');
|
|
$remarks = input('remarks', '');
|
|
|
|
if (empty($process_id)) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
if (empty($status) || !in_array($status, ['approved', 'rejected'])) {
|
|
return fail('请选择审批结果');
|
|
}
|
|
|
|
try {
|
|
$result = $this->service->approve($process_id, $this->user_info['uid'], $status, $remarks);
|
|
return success($result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 撤销审批流程
|
|
*/
|
|
public function cancel()
|
|
{
|
|
$process_id = input('process_id', 0);
|
|
|
|
if (empty($process_id)) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
try {
|
|
$result = $this->service->cancel($process_id, $this->user_info['uid']);
|
|
return success($result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
}
|