update
This commit is contained in:
parent
1519295afb
commit
e98c9743fc
@ -172,4 +172,300 @@
|
||||
$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']])->update(['delete_time'=>time()]);
|
||||
Db::name('oa_flow_record')->where(['action_id'=>$param['id']])->update(['delete_time'=>time()]);
|
||||
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');
|
||||
}
|
||||
|
||||
public function check(){
|
||||
$params = $this->request->post(['id','check','content']);
|
||||
if(empty($params['id'])){
|
||||
return $this->fail('缺少数据主键');
|
||||
}
|
||||
if(empty($params['check']) || !in_array($params['check'],[1,2,3])){
|
||||
return $this->fail('审核参数错误');
|
||||
}
|
||||
if(empty($params['content'])){
|
||||
return $this->fail('请填写审核意见');
|
||||
}
|
||||
$data = Db::name('oa_approve')->where('id',$params['id'])->find();
|
||||
if(empty($data)){
|
||||
return $this->fail('数据信息不存在');
|
||||
}
|
||||
$flow = Db::name('oa_flow')->where('id',$data['flow_id'])->find();
|
||||
//撤销
|
||||
if($params['check'] == 3){
|
||||
if($data['admin_id'] != $this->adminId){
|
||||
return $this->fail('你不是该申请的发起者,无权撤销');
|
||||
}
|
||||
//撤销审核,数据操作
|
||||
$param['check_status'] = 4;
|
||||
$param['check_admin_ids'] ='';
|
||||
$param['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' => $flow['type'],
|
||||
'check_time' => time(),
|
||||
'status' => $param['check'],
|
||||
'content' => $param['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']])->find();
|
||||
$check_admin_ids = explode(",", strval($data['check_admin_ids']));
|
||||
if (!in_array($this->adminId, $check_admin_ids)){
|
||||
return $this->fail('您没权限审核该审批');
|
||||
}
|
||||
//拒绝审核,数据操作
|
||||
$param['check_status'] = 3;
|
||||
$param['last_admin_id'] = $this->adminId;
|
||||
$param['flow_admin_ids'] = $data['flow_admin_ids'].$this->adminId.',';
|
||||
$param['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)])->find();
|
||||
if($prev_step){
|
||||
//存在上一步审核
|
||||
$param['check_step_sort'] = $prev_step['sort'];
|
||||
$param['check_admin_ids'] = $prev_step['flow_uids'];
|
||||
$param['check_status'] = 1;
|
||||
}
|
||||
else{
|
||||
//不存在上一步审核,审核初始化步骤
|
||||
$param['check_step_sort'] = 0;
|
||||
$param['check_admin_ids'] = '';
|
||||
$param['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' => $flow['type'],
|
||||
'check_time' => time(),
|
||||
'status' => $param['check'],
|
||||
'content' => $param['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']])->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']])->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)])->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' => $flow['type'],
|
||||
'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)])->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($param['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' => $flow['type'],
|
||||
'check_time' => time(),
|
||||
'status' => $params['check'],
|
||||
'content' => $params['content'],
|
||||
'create_time' => time()
|
||||
);
|
||||
Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);
|
||||
return $this->success('ok');
|
||||
}
|
||||
else{
|
||||
return $this->fail('fail');
|
||||
}
|
||||
}
|
||||
return $this->fail();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user