638 lines
25 KiB
PHP
638 lines
25 KiB
PHP
<?php
|
||
|
||
namespace app\oa\controller\works\bgsp;
|
||
|
||
use app\oa\controller\BaseAdminController;
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\works\bgsp\OaFlow;
|
||
use app\common\model\works\bgsp\OaFlowType;
|
||
use think\facade\Db;
|
||
|
||
class OaApproveController extends BaseAdminController
|
||
{
|
||
public function lists(){
|
||
$params = $this->request->get(['type','page_no','page_size']);
|
||
$page_no = !empty($params['page_no']) ? $params['page_no'] : 1;
|
||
$page_size = !empty($params['page_size']) ? $params['page_size'] : 15;
|
||
if(empty($params['type']) || !in_array($params['type'],[1,2,3,4,5])){
|
||
return $this->fail("参数错误");
|
||
}
|
||
$where = [];
|
||
if($params['type'] == 1){
|
||
$where[] = ['check_status','in','0,1,2,3,4'];
|
||
}
|
||
if($params['type'] == 2){
|
||
$where[] = ['check_status','=',0];
|
||
}
|
||
if($params['type'] == 3){
|
||
$where[] = ['check_status','=',2];
|
||
}
|
||
if($params['type'] == 4){
|
||
$where[] = ['check_status','=',3];
|
||
}
|
||
if($params['type'] == 5){
|
||
$where[] = ['check_status','=',1];
|
||
}
|
||
$lists = Db::name('oa_approve')->field('id,type,flow_id,admin_id,check_admin_ids,check_status,create_time')->where('admin_id',$this->adminId)->where($where)
|
||
->page($page_no, $page_size)->order('id desc')->select()->each(function($data){
|
||
$admin = Admin::field('name,dept_id')->where('id',$data['admin_id'])->findOrEmpty();
|
||
$dept = Dept::where('id',$admin['dept_id'])->value('name');
|
||
$flow_type = OaFlowType::where('id',$data['type'])->value('title');
|
||
$check_admin_users = Admin::where('id','in',$data['check_admin_ids'])->column('name');
|
||
$data['user_name'] = $admin['name'];
|
||
$data['dept_name'] = $dept ?? '';
|
||
$data['type_name'] = $flow_type ?? '';
|
||
$data['check_admin_users'] = !empty($check_admin_users) ? implode(',',$check_admin_users) : '';
|
||
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
|
||
$data['check_status_text'] = match ($data['check_status']){
|
||
0=>'待审核',1=>'审核中',2=>'审核通过',3=>'审核不通过',4=>'撤销审核'
|
||
};
|
||
return $data;
|
||
})->toArray();
|
||
$count = Db::name('oa_approve')->where($where)->where('admin_id',$this->adminId)->count();
|
||
return $this->success('成功', compact('count', 'lists', 'page_no', 'page_size'));
|
||
}
|
||
|
||
public function detail(){
|
||
$params = $this->request->get(['id']);
|
||
if(empty($params['id'])){
|
||
return $this->fail("参数错误");
|
||
}
|
||
$data = Db::name('oa_approve')->where('id',$params['id'])->find();
|
||
$data['extends'] = !empty($data['extends']) ? json_decode($data['extends'],true) : [];
|
||
$data['check_status_text'] = match ($data['check_status']){
|
||
0=>'待审核',1=>'审核中',2=>'审核通过',3=>'审核不通过',4=>'撤销审核'
|
||
};
|
||
$check_admin_users = Admin::where('id','in',$data['check_admin_ids'])->column('name');
|
||
$copy_users = Admin::where('id','in',$data['copy_uids'])->column('name');
|
||
$data['check_admin_users'] = !empty($check_admin_users) ? implode(',',$check_admin_users) : '';
|
||
$data['copy_users'] = !empty($copy_users) ? implode(',',$copy_users) : '';
|
||
$data['flow_info'] = OaFlow::where('id',$data['flow_id'])->findOrEmpty();
|
||
$data['record'] = Db::name('oa_flow_record')->field('check_user_id,check_time,status,content')->where('action_id',$params['id'])->where('type',1)->order('id desc')->select()->each(function($data){
|
||
$data['check_time'] = date('Y-m-d H:i:s',$data['check_time']);
|
||
$user = Admin::where('id',$data['check_user_id'])->value('name');
|
||
$data['check_user_name'] = $user ?? '';
|
||
$data['status_text'] = match ($data['status']){
|
||
0=>'提交',1=>'通过',2=>'拒绝',3=>'撤销'
|
||
};
|
||
return $data;
|
||
})->toArray();
|
||
$step = Db::name('oa_flow_step')->field('id,action_id,flow_uids,flow_type,sort')->where('action_id',$params['id'])->where('type',1)->order('sort asc')->select()->toArray();
|
||
foreach ($step as $key => &$val) {
|
||
$user_id_info = Admin::field('id,name')->where('id','in',$val['flow_uids'])->select()->toArray();
|
||
foreach ($user_id_info as $k => &$v) {
|
||
$v['check_time'] = 0;
|
||
$v['content'] = '';
|
||
$v['status'] = 0;
|
||
$check_array = Db::name('oa_flow_record')->where(['check_user_id' => $v['id'],'step_id' => $val['id'],'type'=>1])->order('check_time desc')->select()->toArray();
|
||
if(!empty($check_array)){
|
||
$checked = $check_array[0];
|
||
$v['check_time'] = date('Y-m-d H:i', $checked['check_time']);
|
||
$v['content'] = $checked['content'];
|
||
$v['status'] = $checked['status'];
|
||
}
|
||
}
|
||
$check_list = Db::name('oa_flow_record')
|
||
->field('f.*,a.name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.check_user_id', 'left')
|
||
->where(['f.step_id' => $val['id']])->where('f.status','>',0)->select()->toArray();
|
||
foreach ($check_list as $kk => &$vv) {
|
||
$vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
|
||
}
|
||
$val['user_id_info'] = $user_id_info;
|
||
$val['check_list'] = $check_list;
|
||
}
|
||
$data['steps'] = $step;
|
||
return $this->data($data);
|
||
}
|
||
|
||
public function add()
|
||
{
|
||
$param = $this->request->post(['flow_id','check_admin_ids','copy_uids','extends']);
|
||
if(empty($param['flow_id'])){
|
||
return $this->fail("请选择审批流程");
|
||
}
|
||
$flow = Db::name('oa_flow')->where('id',$param['flow_id'])->find();
|
||
if(empty($flow)){
|
||
return $this->fail("审批流程信息不存在");
|
||
}
|
||
if($flow['check_type'] == 2){
|
||
if(empty($param['check_admin_ids'])){
|
||
return $this->fail("请选择审核人");
|
||
}
|
||
}else{
|
||
if(empty($flow['flow_list'])){
|
||
return $this->fail("当前审批流程未设置完全");
|
||
}
|
||
}
|
||
if($flow['type'] == 1){
|
||
if(!empty($param['extends']['KSSJ']['value']) && !empty($param['extends']['JSSJ']['value'])){
|
||
$kssj = $param['extends']['KSSJ']['value'];
|
||
$jssj = $param['extends']['JSSJ']['value'];
|
||
//SELECT * FROM vx_live_room where info ->> 'name' like '%测试%'
|
||
$has = Db::name('oa_approve')->whereRaw("extends->'$.KSSJ.value' = '{$kssj}' and extends->'$.JSSJ.value' = '{$jssj}'")->find();
|
||
if(!empty($has)){
|
||
return $this->fail('当前时间已有请假申请');
|
||
}
|
||
}
|
||
}
|
||
$param['admin_id'] = $this->adminId;
|
||
$param['create_time'] = time();
|
||
$param['type'] = $flow['flow_cate'];
|
||
$param['extends'] = !empty($param['extends']) ? json_encode($param['extends']) : null;
|
||
$param['copy_uids'] = !empty($param['copy_uids']) ? $param['copy_uids'] : $flow['copy_uids'];
|
||
if (empty($param['check_admin_ids'])) {
|
||
$flow_list = unserialize($flow['flow_list']);
|
||
if($flow_list[0]['flow_type'] == 1){
|
||
//获取部门负责人
|
||
$dept = Admin::where('id',$this->adminId)->value('dept_id');
|
||
if(empty($dept)){
|
||
return $this->fail('当前用户未设置部门,请联系管理员');
|
||
}
|
||
$leader = Dept::where('id',$dept)->value('leader_id');
|
||
if(empty($leader)){
|
||
return $this->fail('当前部门负责人还未设置,请联系管理员');
|
||
}else{
|
||
$param['check_admin_ids'] = $leader;
|
||
}
|
||
}else{
|
||
$param['check_admin_ids'] = $flow_list[0]['flow_uids'];
|
||
}
|
||
$aid = Db::name('oa_approve')->strict(false)->field(true)->insertGetId($param);
|
||
foreach ($flow_list as $key => &$value){
|
||
$value['action_id'] = $aid;
|
||
$value['sort'] = $key;
|
||
$value['create_time'] = time();
|
||
$value['type'] = 1;
|
||
}
|
||
Db::name('oa_flow_step')->strict(false)->field(true)->insertAll($flow_list);
|
||
}
|
||
else{
|
||
$aid = Db::name('oa_approve')->strict(false)->field(true)->insertGetId($param);
|
||
$flow_step = array(
|
||
'action_id' => $aid,
|
||
'flow_uids' => $param['check_admin_ids'],
|
||
'create_time' => time(),
|
||
'type' => 1
|
||
);
|
||
Db::name('oa_flow_step')->strict(false)->field(true)->insertGetId($flow_step);
|
||
}
|
||
$step_id = Db::name('oa_flow_step')->where('action_id',$aid)->where('type',1)->order('id asc')->find();
|
||
//添加提交申请记录
|
||
$checkData=array(
|
||
'action_id' => $aid,
|
||
'check_user_id' => $this->adminId,
|
||
'content' => '提交申请',
|
||
'check_time' => time(),
|
||
'create_time' => time(),
|
||
'type' => 1,
|
||
'step_id' => $step_id['id']
|
||
);
|
||
$record_id = Db::name('oa_flow_record')->strict(false)->field(true)->insertGetId($checkData);
|
||
return $record_id ? $this->success('ok') : $this->fail('fail');
|
||
}
|
||
|
||
public function edit(){
|
||
$param = $this->request->post(['id','flow_id','check_admin_ids','copy_uids','extends']);
|
||
if(empty($param['id'])){
|
||
return $this->fail("id参数错误");
|
||
}
|
||
$data = Db::name('oa_approve')->where('id',$param['id'])->find();
|
||
if(empty($data)){
|
||
return $this->fail("数据信息不存在");
|
||
}
|
||
if(empty($param['flow_id'])){
|
||
return $this->fail("请选择审批流程");
|
||
}
|
||
$flow = Db::name('oa_flow')->where('id',$param['flow_id'])->find();
|
||
if(empty($flow)){
|
||
return $this->fail("审批流程信息不存在");
|
||
}
|
||
if($flow['check_type'] == 2){
|
||
if(empty($param['check_admin_ids'])){
|
||
return $this->fail("请选择审核人");
|
||
}
|
||
}else{
|
||
if(empty($flow['flow_list'])){
|
||
return $this->fail("当前审批流程未设置完全");
|
||
}
|
||
}
|
||
$param['type'] = $flow['flow_cate'];
|
||
$param['extends'] = !empty($param['extends']) ? json_encode($param['extends']) : null;
|
||
$param['update_time'] = time();
|
||
$param['check_status'] = 0;
|
||
$param['check_step_sort'] = 0;
|
||
//删除原来的审核流程和审核记录
|
||
Db::name('oa_flow_step')->where(['action_id'=>$param['id']])->where('type',1)->update(['delete_time'=>time()]);
|
||
Db::name('oa_flow_record')->where(['action_id'=>$param['id']])->where('type',1)->update(['delete_time'=>time(),'is_invalid'=>1]);
|
||
if (empty($param['check_admin_ids'])) {
|
||
$flow_list = unserialize($flow['flow_list']);
|
||
if($flow_list[0]['flow_type'] == 1){
|
||
//获取部门负责人
|
||
$dept = Admin::where('id',$this->adminId)->value('dept_id');
|
||
if(empty($dept)){
|
||
return $this->fail('当前用户未设置部门,请联系管理员');
|
||
}
|
||
$leader = Dept::where('id',$dept)->value('leader_id');
|
||
if(empty($leader)){
|
||
return $this->fail('当前部门负责人还未设置,请联系管理员');
|
||
}else{
|
||
$param['check_admin_ids'] = $leader;
|
||
}
|
||
}else{
|
||
$param['check_admin_ids'] = $flow_list[0]['flow_uids'];
|
||
}
|
||
Db::name('oa_approve')->where('id',$param['id'])->strict(false)->field(true)->update($param);
|
||
foreach ($flow_list as $key => &$value){
|
||
$value['action_id'] = $param['id'];
|
||
$value['sort'] = $key;
|
||
$value['create_time'] = time();
|
||
$value['type'] = 1;
|
||
}
|
||
Db::name('oa_flow_step')->strict(false)->field(true)->insertAll($flow_list);
|
||
}
|
||
else{
|
||
Db::name('oa_approve')->where('id',$param['id'])->strict(false)->field(true)->update($param);
|
||
$flow_step = array(
|
||
'action_id' => $param['id'],
|
||
'flow_uids' => $param['check_admin_ids'],
|
||
'create_time' => time(),
|
||
'type' => 1,
|
||
);
|
||
Db::name('oa_flow_step')->strict(false)->field(true)->insertGetId($flow_step);
|
||
}
|
||
$step_id = Db::name('oa_flow_step')->where('action_id',$param['id'])->order('id asc')->find();
|
||
//添加提交申请记录
|
||
$checkData=array(
|
||
'action_id' => $param['id'],
|
||
'check_user_id' => $this->adminId,
|
||
'content' => '重新提交申请',
|
||
'check_time' => time(),
|
||
'create_time' => time(),
|
||
'type' => 1,
|
||
'step_id' => $step_id['id']
|
||
);
|
||
$record_id = Db::name('oa_flow_record')->strict(false)->field(true)->insertGetId($checkData);
|
||
return $record_id ? $this->success('ok') : $this->fail('fail');
|
||
}
|
||
|
||
public function check(){
|
||
$params = $this->request->post(['id','check','content','check_node','check_admin_ids']);
|
||
if(empty($params['id'])){
|
||
return $this->fail('缺少数据主键');
|
||
}
|
||
if(empty($params['check']) || !in_array($params['check'],[1,2,3])){
|
||
return $this->fail('审核参数错误');
|
||
}
|
||
$data = Db::name('oa_approve')->where('id',$params['id'])->find();
|
||
if(empty($data)){
|
||
return $this->fail('数据信息不存在');
|
||
}
|
||
//撤销
|
||
if($params['check'] == 3){
|
||
if($data['admin_id'] != $this->adminId){
|
||
return $this->fail('你不是该申请的发起者,无权撤销');
|
||
}
|
||
//撤销审核,数据操作
|
||
$params['check_status'] = 4;
|
||
$params['check_admin_ids'] ='';
|
||
$params['check_step_sort'] = 0;
|
||
$res = Db::name('oa_approve')->strict(false)->field('check_step_sort,check_status,check_admin_ids')->update($params);
|
||
if($res){
|
||
$checkData=array(
|
||
'action_id' => $params['id'],
|
||
'step_id' => 0,
|
||
'check_user_id' => $this->adminId,
|
||
'type' => 1,
|
||
'check_time' => time(),
|
||
'status' => $params['check'],
|
||
'content' => $params['content'] ?? '',
|
||
'create_time' => time()
|
||
);
|
||
Db::name('oa_flow_record')->strict(false)->field(true)->insertGetId($checkData);
|
||
return $this->success('ok');
|
||
}else{
|
||
return $this->fail('fail');
|
||
}
|
||
}
|
||
//拒绝
|
||
if($params['check'] == 2){
|
||
//当前审核节点详情
|
||
$step = Db::name('oa_flow_step')->where(['action_id'=>$params['id'],'sort'=>$data['check_step_sort'],'type'=>1])->find();
|
||
$check_admin_ids = explode(",", strval($data['check_admin_ids']));
|
||
if (!in_array($this->adminId, $check_admin_ids)){
|
||
return $this->fail('您没权限审核该审批');
|
||
}
|
||
//拒绝审核,数据操作
|
||
$params['check_status'] = 3;
|
||
$params['last_admin_id'] = $this->adminId;
|
||
$params['flow_admin_ids'] = $data['flow_admin_ids'].$this->adminId.',';
|
||
$params['check_admin_ids'] = '';
|
||
if($step['flow_type'] == 4){
|
||
//获取上一步的审核信息
|
||
$prev_step = Db::name('oa_flow_step')->where(['action_id'=>$params['id'],'sort'=>($data['check_step_sort']-1),'type'=>1])->find();
|
||
if($prev_step){
|
||
//存在上一步审核
|
||
$params['check_step_sort'] = $prev_step['sort'];
|
||
$params['check_admin_ids'] = $prev_step['flow_uids'];
|
||
$params['check_status'] = 1;
|
||
}
|
||
else{
|
||
//不存在上一步审核,审核初始化步骤
|
||
$params['check_step_sort'] = 0;
|
||
$params['check_admin_ids'] = '';
|
||
$params['check_status'] = 0;
|
||
}
|
||
}
|
||
$res = Db::name('oa_approve')->strict(false)->field('check_step_sort,check_status,last_admin_id,flow_admin_ids,check_admin_ids')->update($params);
|
||
if($res){
|
||
$checkData=array(
|
||
'action_id' => $params['id'],
|
||
'step_id' => $step['id'],
|
||
'check_user_id' => $this->adminId,
|
||
'type' => 1,
|
||
'check_time' => time(),
|
||
'status' => $params['check'],
|
||
'content' => $params['content'] ?? '',
|
||
'create_time' => time()
|
||
);
|
||
Db::name('oa_flow_record')->strict(false)->field(true)->insertGetId($checkData);
|
||
return $this->success('ok');
|
||
}
|
||
else{
|
||
return $this->fail('fail');
|
||
}
|
||
}
|
||
//通过
|
||
if($params['check'] == 1){
|
||
//当前审核节点详情
|
||
$step = Db::name('oa_flow_step')->where(['action_id'=>$params['id'],'sort'=>$data['check_step_sort'],'type'=>1])->find();
|
||
$check_admin_ids = explode(",", strval($data['check_admin_ids']));
|
||
if (!in_array($this->adminId, $check_admin_ids)){
|
||
return $this->fail('您没权限审核该审批');
|
||
}
|
||
//多人会签审批
|
||
if($step['flow_type'] == 3){
|
||
//查询当前会签记录数
|
||
$check_count = Db::name('oa_flow_record')->where(['action_id'=>$params['id'],'step_id'=>$step['id'],'type'=>1])->count();
|
||
//当前会签记应有记录数
|
||
$flow_count = explode(',', $step['flow_uids']);
|
||
if(($check_count+1) >=count($flow_count)){
|
||
$next_step = Db::name('oa_flow_step')->where(['action_id'=>$params['id'],'sort'=>($data['check_step_sort']+1),'type'=>1])->find();
|
||
if($next_step){
|
||
//存在下一步审核
|
||
if($next_step['flow_type'] == 1){
|
||
//获取部门负责人
|
||
$dept = Admin::where('id',$data['admin_id'])->value('dept_id');
|
||
if(empty($dept)){
|
||
return $this->fail('当前用户未设置部门,请联系管理员');
|
||
}
|
||
$leader = Dept::where('id',$dept)->value('leader_id');
|
||
if(empty($leader)){
|
||
return $this->fail('当前部门负责人还未设置,请联系管理员');
|
||
}else{
|
||
$params['check_admin_ids'] = $leader;
|
||
}
|
||
}else{
|
||
$params['check_admin_ids'] = $next_step['flow_uids'];
|
||
}
|
||
$params['check_step_sort'] = $data['check_step_sort']+1;
|
||
$params['check_status'] = 1;
|
||
}else{
|
||
//不存在下一步审核,审核结束
|
||
$params['check_status'] = 2;
|
||
$params['check_admin_ids'] ='';
|
||
}
|
||
}else{
|
||
$params['check_status'] = 1;
|
||
$params['check_admin_ids'] = $step['flow_uids'];
|
||
}
|
||
}else if($step['flow_type'] == 0){
|
||
//自由人审批
|
||
if($params['check_node'] == 2){
|
||
$next_step = $data['check_step_sort']+1;
|
||
$flow_step = array(
|
||
'action_id' => $params['id'],
|
||
'sort' => $next_step,
|
||
'type' => 1,
|
||
'flow_uids' => $params['check_admin_ids'],
|
||
'create_time' => time()
|
||
);
|
||
$fid = Db::name('oa_flow_step')->strict(false)->field(true)->insertGetId($flow_step);
|
||
//下一步审核步骤
|
||
$params['check_step_sort'] = $next_step;
|
||
$params['check_status'] = 1;
|
||
}
|
||
else{
|
||
//不存在下一步审核,审核结束
|
||
$params['check_status'] = 2;
|
||
$params['check_admin_ids'] ='';
|
||
}
|
||
}else{
|
||
$next_step = Db::name('oa_flow_step')->where(['action_id'=>$params['id'],'sort'=>($data['check_step_sort']+1),'type'=>1])->find();
|
||
if($next_step){
|
||
//存在下一步审核
|
||
if($next_step['flow_type'] == 1){
|
||
//获取部门负责人
|
||
$dept = Admin::where('id',$data['admin_id'])->value('dept_id');
|
||
if(empty($dept)){
|
||
return $this->fail('当前用户未设置部门,请联系管理员');
|
||
}
|
||
$leader = Dept::where('id',$dept)->value('leader_id');
|
||
if(empty($leader)){
|
||
return $this->fail('当前部门负责人还未设置,请联系管理员');
|
||
}else{
|
||
$params['check_admin_ids'] = $leader;
|
||
}
|
||
}
|
||
else{
|
||
$params['check_admin_ids'] = $next_step['flow_uids'];
|
||
}
|
||
$params['check_step_sort'] = $data['check_step_sort']+1;
|
||
$params['check_status'] = 1;
|
||
}
|
||
else{
|
||
//不存在下一步审核,审核结束
|
||
$params['check_status'] = 2;
|
||
$params['check_admin_ids'] ='';
|
||
}
|
||
}
|
||
if($params['check_status'] == 1 && empty($params['check_admin_ids'])){
|
||
return $this->fail('找不到下一步的审批人,该审批流程设置有问题,请联系HR或者管理员');
|
||
}
|
||
//审核通过数据操作
|
||
$params['last_admin_id'] = $this->adminId;
|
||
$params['flow_admin_ids'] = $data['flow_admin_ids'].$this->adminId.',';
|
||
$res = Db::name('oa_approve')->strict(false)->field('check_step_sort,check_status,last_admin_id,flow_admin_ids,check_admin_ids')->update($params);
|
||
if($res){
|
||
$checkData=array(
|
||
'action_id' => $params['id'],
|
||
'step_id' => $step['id'],
|
||
'check_user_id' => $this->adminId,
|
||
'type' => 1,
|
||
'check_time' => time(),
|
||
'status' => $params['check'],
|
||
'content' => $params['content'] ?? '',
|
||
'create_time' => time()
|
||
);
|
||
Db::name('oa_flow_record')->strict(false)->field(true)->insertGetId($checkData);
|
||
return $this->success('ok');
|
||
}
|
||
else{
|
||
return $this->fail('fail');
|
||
}
|
||
}
|
||
return $this->fail();
|
||
}
|
||
|
||
public function copy(){
|
||
$params = $this->request->get();
|
||
$user_id = $this->adminId;
|
||
//查询条件
|
||
$map = [];
|
||
$map[] = ['f.check_status', '=', 2];
|
||
$map[] = ['', 'exp', Db::raw("FIND_IN_SET('{$user_id}',f.copy_uids)")];
|
||
$page_no = !empty($params['page_no']) ? $params['page_no'] : 1;
|
||
$page_size = !empty($params['page_size']) ? $params['page_size'] : 15;
|
||
$lists = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->where($map)
|
||
->order('f.id desc')
|
||
->group('f.id')
|
||
->page($page_no, $page_size)->select()
|
||
->each(function($item){
|
||
$item['create_time'] = date('Y-m-d H:i', $item['create_time']);
|
||
if($item['check_status']<2 && !empty($item['check_admin_ids'])){
|
||
$check_user = Db::name('admin')->where('id','in',$item['check_admin_ids'])->column('name');
|
||
$item['check_admin_users'] = implode(',',$check_user);
|
||
}
|
||
$item['check_status_text'] = match ($item['check_status']){
|
||
0=>'待审核',1=>'审核中',2=>'审核通过',3=>'审核不通过',4=>'撤销审核'
|
||
};
|
||
return $item;
|
||
})->toArray();
|
||
$count = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->where($map)->count();
|
||
return $this->success('成功', compact('count', 'lists', 'page_no', 'page_size'));
|
||
}
|
||
|
||
public function lst(){
|
||
$params = $this->request->get();
|
||
$user_id = $this->adminId;
|
||
$status = !empty($params['status']) ? $params['status'] : 0;
|
||
//查询条件
|
||
$map1 = [];
|
||
$map2 = [];
|
||
$map1[] = ['', 'exp', Db::raw("FIND_IN_SET('{$user_id}',f.check_admin_ids)")];
|
||
$map2[] = ['', 'exp', Db::raw("FIND_IN_SET('{$user_id}',f.flow_admin_ids)")];
|
||
|
||
$page_no = !empty($params['page_no']) ? $params['page_no'] : 1;
|
||
$page_size = !empty($params['page_size']) ? $params['page_size'] : 15;
|
||
$lists = [];
|
||
$count = 0;
|
||
if($status == 0){
|
||
$lists = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->whereOr([$map1,$map2])
|
||
->order('f.id desc')
|
||
->group('f.id')
|
||
->page($page_no, $page_size)->select()
|
||
->each(function($item){
|
||
$item['create_time'] = date('Y-m-d H:i', $item['create_time']);
|
||
if($item['check_status']<2 && !empty($item['check_admin_ids'])){
|
||
$check_user = Db::name('admin')->where('id','in',$item['check_admin_ids'])->column('name');
|
||
$item['check_admin_users'] = implode(',',$check_user);
|
||
}
|
||
$item['check_status_text'] = match ($item['check_status']){
|
||
0=>'待审核',1=>'审核中',2=>'审核通过',3=>'审核不通过',4=>'撤销审核'
|
||
};
|
||
return $item;
|
||
})->toArray();
|
||
$count = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->whereOr([$map1,$map2])->count();
|
||
}
|
||
|
||
if($status == 1){
|
||
$lists = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->where($map1)
|
||
->order('f.id desc')
|
||
->group('f.id')
|
||
->page($page_no, $page_size)->select()
|
||
->each(function($item){
|
||
$item['create_time'] = date('Y-m-d H:i', $item['create_time']);
|
||
if($item['check_status']<2 && !empty($item['check_admin_ids'])){
|
||
$check_user = Db::name('admin')->where('id','in',$item['check_admin_ids'])->column('name');
|
||
$item['check_admin_users'] = implode(',',$check_user);
|
||
}
|
||
$item['check_status_text'] = match ($item['check_status']){
|
||
0=>'待审核',1=>'审核中',2=>'审核通过',3=>'审核不通过',4=>'撤销审核'
|
||
};
|
||
return $item;
|
||
})->toArray();
|
||
$count = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->where($map1)->count();
|
||
}
|
||
if($status == 2){
|
||
$lists = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->where($map2)
|
||
->order('f.id desc')
|
||
->group('f.id')
|
||
->page($page_no, $page_size)->select()
|
||
->each(function($item, $key){
|
||
$item['create_time'] = date('Y-m-d H:i', $item['create_time']);
|
||
if($item['check_status']<2 && !empty($item['check_admin_ids'])){
|
||
$check_user = Db::name('admin')->where('id','in',$item['check_admin_ids'])->column('name');
|
||
$item['check_admin_users'] = implode(',',$check_user);
|
||
}
|
||
$item['check_status_text'] = match ($item['check_status']){
|
||
0=>'待审核',1=>'审核中',2=>'审核通过',3=>'审核不通过',4=>'撤销审核'
|
||
};
|
||
return $item;
|
||
})->toArray();
|
||
$count = Db::name('oa_approve')
|
||
->field('f.*,a.name as user_name,d.name as dept_name,t.title as type_name')
|
||
->alias('f')
|
||
->join('admin a', 'a.id = f.admin_id', 'left')
|
||
->join('dept d', 'd.id = a.dept_id', 'left')
|
||
->join('oa_flow_type t', 't.id = f.type', 'left')
|
||
->where($map2)->count();
|
||
}
|
||
return $this->success('成功', compact('count', 'lists', 'page_no', 'page_size'));
|
||
}
|
||
|
||
} |