update
This commit is contained in:
parent
d7c71c15d3
commit
87d5bf2b4b
175
app/adminapi/controller/works/bgsp/OaApproveController.php
Normal file
175
app/adminapi/controller/works/bgsp/OaApproveController.php
Normal file
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller\works\bgsp;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\dept\Dept;
|
||||
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])){
|
||||
return $this->fail("参数错误");
|
||||
}
|
||||
$where = [];
|
||||
if($params['type'] == 2){
|
||||
$where = ['check_status','=',0];
|
||||
}
|
||||
if($params['type'] == 3){
|
||||
$where = ['check_status','=',2];
|
||||
}
|
||||
if($params['type'] == 4){
|
||||
$where = ['check_status','=',3];
|
||||
}
|
||||
$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['record'] = Db::name('oa_flow_record')->field('check_user_id,check_time,status,content')->where('action_id',$params['id'])->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')->where('action_id',$params['id'])->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']])->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']])->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("当前审批流程未设置完全");
|
||||
}
|
||||
}
|
||||
$param['admin_id'] = $this->adminId;
|
||||
$param['create_time'] = time();
|
||||
$param['type'] = $flow['flow_cate'];
|
||||
$param['extends'] = !empty($param['extends']) ? json_encode($param['extends']) : null;
|
||||
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[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'] = $flow['type'];
|
||||
}
|
||||
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()
|
||||
);
|
||||
Db::name('oa_flow_step')->strict(false)->field(true)->insertGetId($flow_step);
|
||||
}
|
||||
$step_id = Db::name('oa_flow_step')->where('action_id',$aid)->order('id asc')->find();
|
||||
//添加提交申请记录
|
||||
$checkData=array(
|
||||
'action_id' => $aid,
|
||||
'check_user_id' => $this->adminId,
|
||||
'content' => '提交申请',
|
||||
'check_time' => time(),
|
||||
'create_time' => time(),
|
||||
'type' => $flow['type'],
|
||||
'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');
|
||||
}
|
||||
}
|
@ -47,7 +47,8 @@ class OaFlowTypeLogic extends BaseLogic
|
||||
'title' => $params['title'],
|
||||
'name' => $params['name'],
|
||||
'icon' => $params['icon'] ?? '',
|
||||
'department_ids' => $params['department_ids'] ?? ''
|
||||
'department_ids' => $params['department_ids'] ?? '',
|
||||
'data' => !empty($params['data']) ? json_encode($params['data']) : null,
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
@ -76,7 +77,8 @@ class OaFlowTypeLogic extends BaseLogic
|
||||
'title' => $params['title'],
|
||||
'name' => $params['name'],
|
||||
'icon' => $params['icon'] ?? '',
|
||||
'department_ids' => $params['department_ids'] ?? ''
|
||||
'department_ids' => $params['department_ids'] ?? '',
|
||||
'data' => !empty($params['data']) ? json_encode($params['data']) : null,
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
|
@ -62,7 +62,7 @@ class OaFlowTypeValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['type','title','name','icon','department_ids']);
|
||||
return $this->only(['type','title','name','icon','department_ids','data']);
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ class OaFlowTypeValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','type','title','name','icon','department_ids']);
|
||||
return $this->only(['id','type','title','name','icon','department_ids','data']);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user