This commit is contained in:
weiz 2024-01-31 16:57:57 +08:00
parent 7d6b9cb9c6
commit 54b4f4344d
6 changed files with 585 additions and 3 deletions

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\oa;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\oa\FlowLists;
use app\adminapi\logic\oa\FlowLogic;
use app\adminapi\validate\oa\FlowValidate;
/**
* 审批流程控制器
* Class FlowController
* @package app\adminapi\controller\oa
*/
class FlowController extends BaseAdminController
{
/**
* @notes 获取审批流程列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function lists()
{
return $this->dataLists(new FlowLists());
}
/**
* @notes 添加审批流程
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function add()
{
$params = (new FlowValidate())->post()->goCheck('add');
$result = FlowLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(FlowLogic::getError());
}
/**
* @notes 编辑审批流程
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function edit()
{
$params = (new FlowValidate())->post()->goCheck('edit');
$result = FlowLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(FlowLogic::getError());
}
/**
* @notes 删除审批流程
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function delete()
{
$params = (new FlowValidate())->post()->goCheck('delete');
FlowLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取审批流程详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function detail()
{
$params = (new FlowValidate())->goCheck('detail');
$result = FlowLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,91 @@
<?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\oa;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\oa\Flow;
use app\common\lists\ListsSearchInterface;
use app\common\model\oa\FlowType;
/**
* 审批流程列表
* Class FlowLists
* @package app\adminapi\listsoa
*/
class FlowLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function setSearch(): array
{
return [
'=' => ['check_type', 'status'],
'%like%' => ['name'],
];
}
/**
* @notes 获取审批流程列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function lists(): array
{
return Flow::where($this->searchWhere)
->field(['id', 'name', 'flow_cate', 'check_type', 'remark', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$flow_cate = FlowType::field('type,title,org_id,department_ids')->where('id',$data['flow_cate'])->findOrEmpty();
$org = Orgs::field('name')->where('id',$flow_cate['org_id'])->findOrEmpty();
$dept = Dept::where('id','in',$flow_cate['department_ids'])->column('name');
$data['check_type'] = $data->check_type_text;
$data['status'] = $data->status_text;
$data['flow_type'] = $flow_cate->type_text;
$data['flow_cate'] = $flow_cate['title'];
$data['org_name'] = $org['name'];
$data['dept_name'] = implode(',',$dept);
})
->toArray();
}
/**
* @notes 获取审批流程数量
* @return int
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function count(): int
{
return Flow::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,128 @@
<?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\oa;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\oa\Flow;
use app\common\logic\BaseLogic;
use app\common\model\oa\FlowType;
use think\facade\Db;
/**
* 审批流程逻辑
* Class FlowLogic
* @package app\adminapi\logic\oa
*/
class FlowLogic extends BaseLogic
{
/**
* @notes 添加审批流程
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/31 14:44
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Flow::create([
'name' => $params['name'],
'flow_cate' => $params['flow_cate'],
'check_type' => $params['check_type'],
'remark' => $params['remark'] ?? '',
'flow_list' => $params['check_type'] != 2 ? json_encode($params['flow_list']) : null,
'status' => 2,
'copy_uids' => implode(',',$params['copy_uids']),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑审批流程
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/31 14:44
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Flow::where('id', $params['id'])->update([
'name' => $params['name'],
'flow_cate' => $params['flow_cate'],
'check_type' => $params['check_type'],
'remark' => $params['remark'] ?? '',
'flow_list' => $params['check_type'] != 2 ? json_encode($params['flow_list']) : null,
'status' => $params['status'],
'copy_uids' => implode(',',$params['copy_uids']),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除审批流程
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/31 14:44
*/
public static function delete(array $params): bool
{
return Flow::destroy($params['id']);
}
/**
* @notes 获取审批流程详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/31 14:44
*/
public static function detail($params): array
{
$data = Flow::field('id,name,flow_cate,check_type,remark,flow_list,status,copy_uids')->findOrEmpty($params['id']);
$flow_cate = FlowType::field('type,org_id,department_ids')->where('id',$data['flow_cate'])->findOrEmpty();
$org = Orgs::field('name')->where('id',$flow_cate['org_id'])->findOrEmpty();
$dept = Dept::where('id','in',$flow_cate['department_ids'])->column('name');
$data['check_type'] = (string)$data['check_type'];
$data['status'] = (string)$data['status'];
$data['flow_type'] = (string)$flow_cate['type'];
$data['org_name'] = $org['name'];
$data['dept_name'] = implode(',',$dept);
return $data->toArray();
}
}

View File

@ -129,13 +129,13 @@ class FlowTypeValidate extends BaseValidate
if(!is_array($value)){ if(!is_array($value)){
return '应用部门数据格式错误'; return '应用部门数据格式错误';
} }
foreach($value as $v){ foreach($value as $k=>$v){
$dept = Dept::where('id',$v)->findOrEmpty(); $dept = Dept::where('id',$v)->findOrEmpty();
if($dept->isEmpty()){ if($dept->isEmpty()){
return '部门不存在'; return '第'.($k+1).'个部门信息不存在';
} }
if($dept['org_id'] != $data['org_id']) { if($dept['org_id'] != $data['org_id']) {
return '部门信息无效'; return '第'.($k+1).'个部门不属于当前所选择的组织';
} }
} }
return true; return true;

View File

@ -0,0 +1,208 @@
<?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\auth\Admin;
use app\common\model\dict\DictData;
use app\common\model\oa\FlowType;
use app\common\validate\BaseValidate;
/**
* 审批流程验证器
* Class FlowValidate
* @package app\adminapi\validate\oa
*/
class FlowValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'name' => 'require',
'flow_cate' => 'require|checkFlowCate',
'check_type' => 'require|checkCheckType',
'flow_list' => 'requireCallback:check_require|checkFlowList',
'status' => 'require|checkStatus',
'copy_uids' => 'array|checkCopyUids',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'name' => '审批流名称',
'flow_cate' => '审批类型',
'check_type' => '审批流类型',
'flow_list' => '审批流程',
'status' => '状态',
'copy_uids' => '抄送人',
];
/**
* @notes 添加场景
* @return FlowValidate
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function sceneAdd()
{
return $this->remove('id',true)->remove('status',true);
}
/**
* @notes 编辑场景
* @return FlowValidate
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function sceneEdit()
{
return $this->only(['id','name','flow_cate','check_type','flow_list','status','copy_uids']);
}
/**
* @notes 删除场景
* @return FlowValidate
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return FlowValidate
* @author likeadmin
* @date 2024/01/31 14:44
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkFlowCate($value): bool|string
{
$data = FlowType::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '审批类型信息不存在';
}
return true;
}
public function checkCheckType($value): bool|string
{
$dict = DictData::where('type_value','flow_check_type')->column('value');
if(!in_array($value,$dict)){
return '审批流类型值无效';
}
return true;
}
public function check_require($value, $data): bool
{
if($data['check_type'] != 2){
return true;
}
return false;
}
public function checkFlowList($value,$rule,$data): bool|string
{
if(!is_array($value)){
return '审批流程数据格式错误';
}
//固定审批
if($data['check_type'] == 1){
$dict = DictData::where('type_value','flow_step_flow_type')->column('value');
foreach($value as $k=>$v){
if(empty($v['flow_step'])){
return '请选择审批步骤类型';
}else{
if(!in_array($v['flow_step'],$dict)){
return '审批步骤类型值无效';
}
}
if($v['flow_step'] == 2 || $v['flow_step'] == 3){
if(empty($v['flow_user'])){
return '审批流程第'.($k+1).'行的指定人未选择';
}
if(!is_array($v['flow_user'])){
return '审批流程第'.($k+1).'行的指定人数据格式错误';
}
foreach($v['flow_user'] as $k2 => $v2){
$admin = Admin::where('id',$v2)->findOrEmpty();
if($admin->isEmpty()){
return '审批流程第'.($k+1).'行的第'.($k2+1).'个指定人信息不存在';
}
}
}
}
}
if($data['check_type'] == 3){
foreach($value as $k=>$v){
if(empty($v['flow_step'])){
return '请填写审批步骤名称';
}
if(empty($v['flow_user'])){
return '审批流程第'.($k+1).'行的指定人未选择';
}
if(!is_array($v['flow_user'])){
return '审批流程第'.($k+1).'行的指定人数据格式错误';
}
foreach($v['flow_user'] as $k2 => $v2){
$admin = Admin::where('id',$v2)->findOrEmpty();
if($admin->isEmpty()){
return '审批流程第'.($k+1).'行的第'.($k2+1).'个指定人信息不存在';
}
}
}
}
return true;
}
public function checkCopyUids($value): bool|string
{
foreach($value as $k=>$v){
$admin = Admin::where('id',$v)->findOrEmpty();
if($admin->isEmpty()){
return '第'.($k+1).'个抄送人信息不存在';
}
}
return true;
}
public function checkStatus($value){
$dict = DictData::where('type_value','flow_type_status')->column('value');
if(!in_array($value,$dict)){
return '状态值无效';
}
return true;
}
}

View File

@ -0,0 +1,47 @@
<?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\oa;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
/**
* 审批流程模型
* Class Flow
* @package app\common\model\oa
*/
class Flow extends BaseModel
{
use SoftDelete;
protected $name = 'flow';
protected $deleteTime = 'delete_time';
public function getCheckTypeTextAttr($value,$data){
$dict = DictData::where('type_value','flow_check_type')->column('name','value');
return !empty($data['check_type']) ? $dict[$data['check_type']] : '';
}
public function getStatusTextAttr($value,$data){
$dict = DictData::where('type_value','flow_type_status')->column('name','value');
return !empty($data['status']) ? $dict[$data['status']] : '';
}
public function getFlowListAttr($value){
return !empty($value) ? json_decode($value,true) : '';
}
}