智慧教务系统
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.
 
 
 
 
 
 

193 lines
4.6 KiB

<?php
declare(strict_types=1);
namespace app\adminapi\controller\school_approval;
use app\adminapi\controller\BaseAdminApi;
use app\service\school_approval\SchoolApprovalConfigService;
use core\base\BaseAdminController;
use think\facade\Request;
/**
* 审批流配置控制器
* Class Config
* @package app\adminapi\controller\school_approval
*/
class Config extends BaseAdminController
{
/**
* @var SchoolApprovalConfigService
*/
protected $service;
public function initialize()
{
parent::initialize();
$this->service = new SchoolApprovalConfigService();
}
/**
* 获取审批流配置列表
*/
public function lists()
{
$page = input('page', 1);
$limit = input('limit', 10);
$status = input('status', '');
$where = [];
if ($status !== '') {
$where[] = ['status', '=', intval($status)];
}
$config_name = input('config_name', '');
if (!empty($config_name)) {
$where[] = ['config_name', 'like', "%{$config_name}%"];
}
$data = $this->service->getList($where, (int)$page, (int)$limit);
return success($data);
}
/**
* 获取审批流配置详情
*/
public function info()
{
$id = input('id', 0);
if (empty($id)) {
return error('参数错误');
}
$info = $this->service->getInfo((int)$id);
if (empty($info)) {
return error('审批流配置不存在');
}
return success($info);
}
/**
* 添加审批流配置
*/
public function add()
{
$data = Request::only(['config_name', 'description', 'status', 'nodes']);
// 验证参数
if (empty($data['config_name'])) {
return error('配置名称不能为空');
}
if (empty($data['nodes']) || !is_array($data['nodes'])) {
return error('至少需要添加一个审批节点');
}
// 验证节点数据
foreach ($data['nodes'] as $node) {
if (empty($node['node_name'])) {
return error('节点名称不能为空');
}
if (empty($node['approver_type'])) {
return error('审批人类型不能为空');
}
if (empty($node['approver_ids'])) {
return error('审批人不能为空');
}
}
// 设置创建人ID
$data['creator_id'] = $this->request->uid();
try {
$config_id = $this->service->add($data);
return success(['id' => $config_id]);
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
/**
* 编辑审批流配置
*/
public function edit()
{
$data = Request::only(['id', 'config_name', 'description', 'status', 'nodes']);
// 验证参数
if (empty($data['id'])) {
return fail('参数错误');
}
if (empty($data['config_name'])) {
return fail('配置名称不能为空');
}
if (empty($data['nodes']) || !is_array($data['nodes'])) {
return fail('至少需要添加一个审批节点');
}
// 验证节点数据
foreach ($data['nodes'] as $node) {
if (empty($node['node_name'])) {
return fail('节点名称不能为空');
}
if (empty($node['approver_type'])) {
return fail('审批人类型不能为空');
}
if (empty($node['approver_ids'])) {
return fail('审批人不能为空');
}
}
try {
$result = $this->service->edit($data);
return success($result);
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
/**
* 删除审批流配置
*/
public function delete()
{
$id = input('id', 0);
if (empty($id)) {
return fail('参数错误');
}
try {
$result = $this->service->delete((int)$id);
return success($result);
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
/**
* 修改状态
*/
public function changeStatus()
{
$id = input('id', 0);
$status = input('status', 0);
if (empty($id)) {
return fail('参数错误');
}
try {
$result = $this->service->changeStatus($id, $status);
return success($result);
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
}