@ -29,10 +29,10 @@ class ExamineStep extends Common
{
$userModel = new \app\admin\model\User();
$list = $this->where(['flow_id' => $flow_id])->order('order_id asc')->select();
foreach ($list as $k=>$v) {
foreach ($list as $k => $v) {
$list[$k]['user_id_info'] = $userModel->getListByStr($v['user_id']);
}
return $list ? : [];
return $list ?: [];
}
/**
@ -50,19 +50,19 @@ class ExamineStep extends Common
//处理数据
$resSuccess = true;
$dataStep = [];
foreach ($data as $k=>$v) {
if (!intval($v['status']) || (in_array($v['status'],[2,3]) & & !$v['user_id'])) {
foreach ($data as $k => $v) {
if (!intval($v['status']) || (in_array($v['status'], [2, 3]) & & !$v['user_id'])) {
$resSuccess = false;
}
$dataStep[$k]['relation'] = 1;
if (in_array($v['status'],[2,3])) {
if (in_array($v['status'], [2, 3])) {
$dataStep[$k]['user_id'] = $v['user_id'] ? arrayToString($v['user_id']) : ''; //处理user_id
$dataStep[$k]['relation'] = ($v['status'] == 3) ? 1 : 2;
}
if ($v['step']) {
$dataStep[$k]['step_id'] = $v['step'];
}
$dataStep[$k]['order_id'] = $k+1;
$dataStep[$k]['order_id'] = $k + 1;
$dataStep[$k]['flow_id'] = $flow_id;
$dataStep[$k]['status'] = $v['status'];
$dataStep[$k]['create_time'] = time();
@ -75,7 +75,7 @@ class ExamineStep extends Common
$this->saveAll($dataStep);
$this->commit();
return true;
} catch(\Exception $e) {
} catch (\Exception $e) {
$this->error = '审批步骤创建失败';
$this->rollback();
return false;
@ -94,9 +94,9 @@ class ExamineStep extends Common
public function orderData($flow_id)
{
$step_list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id')->select();
foreach ($step_list as $k=> $v) {
foreach ($step_list as $k => $v) {
$data = [];
$data = ['step_id' => $v['step_id'],'order_id' => $k];
$data = ['step_id' => $v['step_id'], 'order_id' => $k];
db('admin_examine_step')->update($data);
}
}
@ -114,7 +114,7 @@ class ExamineStep extends Common
public function nextStepUser($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id)
{
$res = nextCheckData($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id);
return $res ? : [];
return $res ?: [];
}
/**
@ -136,7 +136,7 @@ class ExamineStep extends Common
$this->error = '参数错误!';
return false;
}
if (in_array($dataInfo['check_status'], ['2','3'])) {
if (in_array($dataInfo['check_status'], ['2', '3'])) {
$this->error = '审批已经结束!';
return false;
}
@ -176,27 +176,61 @@ class ExamineStep extends Common
}
switch (trim($types)) {
case 'oa_examine' : $dataInfo = db('oa_examine')->where(['examine_id' => intval($types_id)])->field('create_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_contract' : $dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_receivables' : $dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_invoice': $dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_purchase': $dataInfo = db('jxc_purchase')->where(['purchase_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_retreat': $dataInfo = db('jxc_retreat')->where(['retreat_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_sale': $dataInfo = db('jxc_sale')->where(['sale_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_salereturn': $dataInfo = db('jxc_salereturn')->where(['salereturn_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_payment': $dataInfo = db('jxc_payment')->where(['payment_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_collection': $dataInfo = db('jxc_collection')->where(['collection_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_inventory': $dataInfo = db('jxc_inventory')->where(['inventory_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_allocation': $dataInfo = db('jxc_allocation')->where(['allocation_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'oa_examine' :
$dataInfo = db('oa_examine')->where(['examine_id' => intval($types_id)])->field('create_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_contract' :
$dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_receivables' :
$dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_invoice':
$dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_purchase':
$dataInfo = db('jxc_purchase')->where(['purchase_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_retreat':
$dataInfo = db('jxc_retreat')->where(['retreat_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_sale':
$dataInfo = db('jxc_sale')->where(['sale_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_salereturn':
$dataInfo = db('jxc_salereturn')->where(['salereturn_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_payment':
$dataInfo = db('jxc_payment')->where(['payment_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_collection':
$dataInfo = db('jxc_collection')->where(['collection_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_inventory':
$dataInfo = db('jxc_inventory')->where(['inventory_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_allocation':
$dataInfo = db('jxc_allocation')->where(['allocation_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_customer_check':
$dataInfo = db('crm_customer_check')->where(['customer_check_id' => intval($types_id)])->field('user_id,create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_business':
$dataInfo = db('crm_business')->where(['business_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
}
$stepInfo = [];
if ($dataInfo['flow_id'] & & !in_array($dataInfo['check_status'],['5'])) {
if ($dataInfo['flow_id'] & & !in_array($dataInfo['check_status'], ['5'])) {
//固定审批流
$stepInfo = db('admin_examine_step')->where(['flow_id' => $dataInfo['flow_id'],'order_id' => $dataInfo['order_id']])->find();
$stepInfo = db('admin_examine_step')->where(['flow_id' => $dataInfo['flow_id'], 'order_id' => $dataInfo['order_id']])->find();
}
if ($types=="crm_customer_check"){
$dataInfo['create_user_id']=$dataInfo['user_id'];
$dataInfo['owner_user_id']=$dataInfo['user_id'];
}
$data = [];
$data['stepInfo'] = $stepInfo;
$data['step_id'] = $stepInfo['step_id'] ? : '';
$data['step_id'] = $stepInfo['step_id'] ?: '';
$data['dataInfo'] = $dataInfo;
return $data;
}
@ -223,10 +257,12 @@ class ExamineStep extends Common
}
break;
case 2 :
case 3 :$examine_user_id_arr = stringToArray($stepInfo['user_id']); break;
case 3 :
$examine_user_id_arr = stringToArray($stepInfo['user_id']);
break;
case 4 :
$order_id = $stepInfo['order_id'] ? $stepInfo['order_id']-1 : 0;
$last_step_id = db('admin_examine_step')->where(['flow_id' => $stepInfo['flow_id'],'order_id' => $order_id])->value('step_id');
$order_id = $stepInfo['order_id'] ? $stepInfo['order_id'] - 1 : 0;
$last_step_id = db('admin_examine_step')->where(['flow_id' => $stepInfo['flow_id'], 'order_id' => $order_id])->value('step_id');
$last_step_info = db('admin_examine_step')->where(['step_id' => $last_step_id])->find();
$last_user_id = $this->getUserByStep($last_step_id, $user_id);
if (count(stringToArray($last_user_id)) !== 1) {
@ -241,9 +277,10 @@ class ExamineStep extends Common
$examine_user_id_arr = stringToArray($examine_user_id);
}
break;
default : $examine_user_id_arr = [];
default :
$examine_user_id_arr = [];
}
return array_unique($examine_user_id_arr) ? ','.implode(',',array_filter(array_unique($examine_user_id_arr))).',' : '';
return array_unique($examine_user_id_arr) ? ',' . implode(',', array_filter(array_unique($examine_user_id_arr))) . ',' : '';
}
/**
@ -257,9 +294,9 @@ class ExamineStep extends Common
if ($types_id == 0 & & $order_id == 0) {
$check_user_ids = [];
} else {
$check_user_ids = db('admin_examine_record')->where(['types' => $types,'types_id' => $types_id,'order_id' => $order_id,'is_end' => 0,'status' => $status])->column('check_user_id');
$check_user_ids = db('admin_examine_record')->where(['types' => $types, 'types_id' => $types_id, 'order_id' => $order_id, 'is_end' => 0, 'status' => $status])->column('check_user_id');
}
return $check_user_ids ? : [];
return $check_user_ids ?: [];
}
/**
@ -270,7 +307,7 @@ class ExamineStep extends Common
*/
public function getUserByPer($types)
{
if (!in_array($types,['oa_examine','crm_contract','crm_receivables'])) {
if (!in_array($types, ['oa_examine', 'crm_contract', 'crm_receivables'])) {
$this->error = '参数错误';
return false;
}
@ -278,10 +315,18 @@ class ExamineStep extends Common
$adminUserId = model('User')->getAdminId(); //管理员ID
//获取有审核权限的user_id
switch ($types) {
case 'oa_examine' : $examine_user_id_arr = $userModel->getUserByPer('oa', 'examine', 'check'); break;
case 'crm_contract' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'contract', 'check'); break;
case 'crm_receivables' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'receivables', 'check'); break;
case 'crm_invoice' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'invoice', 'check'); break;
case 'oa_examine' :
$examine_user_id_arr = $userModel->getUserByPer('oa', 'examine', 'check');
break;
case 'crm_contract' :
$examine_user_id_arr = $userModel->getUserByPer('crm', 'contract', 'check');
break;
case 'crm_receivables' :
$examine_user_id_arr = $userModel->getUserByPer('crm', 'receivables', 'check');
break;
case 'crm_invoice' :
$examine_user_id_arr = $userModel->getUserByPer('crm', 'invoice', 'check');
break;
}
$examine_user_id_arr = $examine_user_id_arr ? array_merge($examine_user_id_arr, $adminUserId) : $adminUserId;
return $examine_user_id_arr;
@ -297,10 +342,10 @@ class ExamineStep extends Common
{
$user_ids = [];
if ($flow_id & & $order_id) {
$stepInfo = db('admin_examine_step')->where(['flow_id' => $flow_id,'order_id' => $order_id])->find();
$stepInfo = db('admin_examine_step')->where(['flow_id' => $flow_id, 'order_id' => $order_id])->find();
$user_ids = $this->getUserByStep($stepInfo['step_id'], $user_id);
}
return $user_ids ? : [];
return $user_ids ?: [];
}
/**
@ -328,11 +373,11 @@ class ExamineStep extends Common
//创建人或负责人或管理员有撤销权限
//if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id || in_array($check_user_id, $admin_user_ids)) {
if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) {
if (!in_array($dataInfo['check_status'],['2','3','4','6'])) {
if (!in_array($dataInfo['check_status'], ['2', '3', '4', '6'])) {
$is_recheck = 1;
}
}
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) & & !in_array($dataInfo['check_status'],['2','3','4','6'])) {
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) & & !in_array($dataInfo['check_status'], ['2', '3', '4', '6'])) {
$is_check = 1;
}
@ -340,7 +385,7 @@ class ExamineStep extends Common
$createUserInfo = $userModel->getUserById($dataInfo['create_user_id']);
$createUserInfo['check_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
if ($dataInfo['check_status'] == 4 & & $dataInfo['create_user_id']!=trim( $dataInfo['check_status'], ',')) {
if ($dataInfo['check_status'] == 4 & & $dataInfo['create_user_id'] != trim($dataInfo['check_status'], ',')) {
$createUserInfo['check_type'] = 2;
$newlist[1]['type'] = '2'; //撤销
$newlist[1]['status'] = '5'; //创建, 前端要求给创建人加一个status字段, 定义为5
@ -351,7 +396,7 @@ class ExamineStep extends Common
$newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$newlist[1]['user_id_info'] = array($createUserInfo);
$newlist[1]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
} elseif ($dataInfo['check_status'] == 4 & & $dataInfo['create_user_id']==trim( $dataInfo['check_status'], ',')){
} elseif ($dataInfo['check_status'] == 4 & & $dataInfo['create_user_id'] == trim($dataInfo['check_status'], ',')) {
$createUserInfo['check_type'] = 3;
$newlist[0]['type'] = '3'; //创建
$newlist[0]['status'] = '5'; //创建, 前端要求给创建人加一个status字段, 定义为5
@ -374,7 +419,7 @@ class ExamineStep extends Common
if ($dataInfo['check_status'] !== 4 || $action !== 'view') {
$list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id asc')->select();
$is_break = false;
foreach ($list as $k=>$v) {
foreach ($list as $k => $v) {
$type = 4;
$examine_user_ids = '';
//判断步骤审批人是否存在
@ -383,7 +428,7 @@ class ExamineStep extends Common
if ($examine_user_arr) {
$newStepInfo = $v;
$user_id_info_arr = [];
foreach ($examine_user_arr as $key=>$val) {
foreach ($examine_user_arr as $key => $val) {
$user_id_info = [];
$user_id_info = $userModel->getUserById($val);
$check_type = 4; //type 0失败, 1通过, 2撤销, 3创建, 4待审核, 5未提交
@ -394,7 +439,7 @@ class ExamineStep extends Common
$check_type = 1;
$type = !empty($dataInfo['check_user_id']) ? 4 : 1;
}
if(in_array($val, $check_user_ids) & & $dataInfo['check_status'] == 2){
if (in_array($val, $check_user_ids) & & $dataInfo['check_status'] == 2) {
$check_type = 1;
$type = 1;
}
@ -408,7 +453,7 @@ class ExamineStep extends Common
}
$fail_check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 0); //拒绝人员
if ($dataInfo['check_status'] == 3) {
if (in_array($val,$fail_check_user_ids)) {
if (in_array($val, $fail_check_user_ids)) {
$is_break = true;
$check_type = 0;
$type = 0;
@ -417,7 +462,7 @@ class ExamineStep extends Common
}
$user_id_info['check_type'] = $check_type;
$check_time = '';
$check_time = db('admin_examine_record')->where(['types' => $types,'types_id' => $types_id,'flow_id' => $flow_id,'order_id' => $v['order_id'],'check_user_id' => $val,'is_end' =>0])->value('check_time');
$check_time = db('admin_examine_record')->where(['types' => $types, 'types_id' => $types_id, 'flow_id' => $flow_id, 'order_id' => $v['order_id'], 'check_user_id' => $val, 'is_end' => 0])->value('check_time');
$user_id_info['check_time'] = !empty($check_time) ? date('Y-m-d H:i:s', $check_time) : '';
$user_id_info_arr[] = $user_id_info;
}
@ -440,10 +485,10 @@ class ExamineStep extends Common
} else {
$newStepList = $newlist;
}
$data['steplist'] = $newStepList ? : [];
$data['steplist'] = $newStepList ?: [];
$data['is_check'] = $is_check;
$data['is_recheck'] = $is_recheck;
return $data ? : [];
return $data ?: [];
}
/**
@ -454,8 +499,8 @@ class ExamineStep extends Common
*/
public function getStepByOrder($flow_id, $order_id)
{
$data = db('admin_examine_step')->where(['flow_id' => $flow_id,'order_id' => $order_id])->find();
return $data ? : [];
$data = db('admin_examine_step')->where(['flow_id' => $flow_id, 'order_id' => $order_id])->find();
return $data ?: [];
}
/**
@ -480,13 +525,13 @@ class ExamineStep extends Common
$dataInfo = $typeInfo['dataInfo'];
//type 0失败, 1通过, 2撤销, 3创建, 4待审核, 5未提交
$i = 0;
if(empty($recordList)){
if (empty($recordList)) {
$createUserInfo = $userModel->getUserById($dataInfo['create_user_id']);
$userList[0]['userInfo'] = $createUserInfo;
$userList[0]['type'] = 3; //创建
$userList[0]['time'] = $dataInfo['update_time'] ? : '';
}else{
foreach ($recordList as $k=>$v) {
$userList[0]['time'] = $dataInfo['update_time'] ?: '';
} else {
foreach ($recordList as $k => $v) {
$userList[$i]['userInfo'] = $userModel->getUserById($v['check_user_id']);
$userList[$i]['type'] = $v['status'];
$userList[$i]['time'] = $v['check_time'];
@ -511,17 +556,17 @@ class ExamineStep extends Common
//创建人或负责人或管理员有撤销权限
// if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id || in_array($check_user_id, $admin_user_ids)) {
if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) {
if (!in_array($dataInfo['check_status'],['2','3','4','5','6'])) {
if (!in_array($dataInfo['check_status'], ['2', '3', '4', '5', '6'])) {
$is_recheck = 1;
}
}
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) & & !in_array($dataInfo['check_status'],['2','3','4','5','6'])) {
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) & & !in_array($dataInfo['check_status'], ['2', '3', '4', '5', '6'])) {
$is_check = 1;
}
$data['steplist'] = $userList;
$data['is_check'] = $is_check;
$data['is_recheck'] = $is_recheck;
return $data ? : [];
return $data ?: [];
}
}