147 lines
4.6 KiB
PHP
147 lines
4.6 KiB
PHP
<?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\auth\Admin;
|
||
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);
|
||
$flow_list = $data['flow_list'];
|
||
if(!empty($flow_list)){
|
||
foreach($flow_list as &$v){
|
||
if(!empty($v['flow_user'])){
|
||
$flow_user = Admin::field('id,name')->where('id','in',$v['flow_user'])->select()->toArray();
|
||
foreach ($flow_user as &$v2) {
|
||
unset($v2['role_id']);
|
||
}
|
||
$v['flow_user'] = $flow_user;
|
||
}
|
||
}
|
||
}
|
||
$data['flow_list'] = json_encode($flow_list);
|
||
$copy_user = Admin::field('id,name')->where('id','in',$data['copy_uids'])->select()->toArray();
|
||
foreach ($copy_user as &$v) {
|
||
unset($v['role_id']);
|
||
}
|
||
$data['copy_uids'] = $copy_user;
|
||
return $data->toArray();
|
||
}
|
||
} |