161 lines
5.7 KiB
PHP
161 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\controller\works\finance;
|
|
|
|
use app\adminapi\controller\BaseAdminController;
|
|
use app\adminapi\validate\works\finance\InvoiceValidate;
|
|
use app\common\model\auth\Admin;
|
|
use app\common\model\dept\Dept;
|
|
use think\facade\Db;
|
|
|
|
class InvoiceController extends BaseAdminController
|
|
{
|
|
public function add(){
|
|
$params = (new InvoiceValidate())->post()->goCheck('add');
|
|
$params['admin_id'] = $this->adminId;
|
|
$params['annex'] = !empty($params['annex']) ? json_encode($params['annex']) : null;
|
|
$params['create_time'] = time();
|
|
$params['check_status'] = 0;
|
|
$params['check_step_sort'] = 0;
|
|
$flow = Db::name('oa_flow')->where('id',$params['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 (empty($params['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{
|
|
$params['check_admin_ids'] = $leader;
|
|
}
|
|
}else{
|
|
$params['check_admin_ids'] = $flow_list[0]['flow_uids'];
|
|
}
|
|
$aid = Db::name('oa_invoice')->strict(false)->field(true)->insertGetId($params);
|
|
foreach ($flow_list as $key => &$value){
|
|
$value['action_id'] = $aid;
|
|
$value['sort'] = $key;
|
|
$value['create_time'] = time();
|
|
$value['type'] = 3;
|
|
}
|
|
Db::name('oa_flow_step')->strict(false)->field(true)->insertAll($flow_list);
|
|
}
|
|
else{
|
|
$aid = Db::name('oa_invoice')->strict(false)->field(true)->insertGetId($params);
|
|
$flow_step = array(
|
|
'action_id' => $aid,
|
|
'flow_uids' => $params['check_admin_ids'],
|
|
'create_time' => time(),
|
|
'type' => 2
|
|
);
|
|
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',3)->order('id asc')->find();
|
|
//添加提交申请记录
|
|
$checkData=array(
|
|
'action_id' => $aid,
|
|
'check_user_id' => $this->adminId,
|
|
'content' => '提交申请',
|
|
'check_time' => time(),
|
|
'create_time' => time(),
|
|
'type' => 3,
|
|
'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(){
|
|
$params = (new InvoiceValidate())->post()->goCheck('edit');
|
|
$params['admin_id'] = $this->adminId;
|
|
$params['annex'] = !empty($params['annex']) ? json_encode($params['annex']) : null;
|
|
$params['create_time'] = time();
|
|
$params['check_status'] = 0;
|
|
$params['check_step_sort'] = 0;
|
|
$flow = Db::name('oa_flow')->where('id',$params['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("当前审批流程未设置完全");
|
|
}
|
|
}
|
|
//删除原来的审核流程和审核记录
|
|
Db::name('oa_flow_step')->where(['action_id'=>$params['id'],'type'=>3])->update(['delete_time'=>time()]);
|
|
Db::name('oa_flow_record')->where(['action_id'=>$params['id'],'type'=>3])->update(['delete_time'=>time()]);
|
|
if (empty($params['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{
|
|
$params['check_admin_ids'] = $leader;
|
|
}
|
|
}else{
|
|
$params['check_admin_ids'] = $flow_list[0]['flow_uids'];
|
|
}
|
|
Db::name('oa_invoice')->where('id',$params['id'])->strict(false)->field(true)->update($params);
|
|
foreach ($flow_list as $key => &$value){
|
|
$value['action_id'] = $params['id'];
|
|
$value['sort'] = $key;
|
|
$value['create_time'] = time();
|
|
$value['type'] = 3;
|
|
}
|
|
Db::name('oa_flow_step')->strict(false)->field(true)->insertAll($flow_list);
|
|
}
|
|
else{
|
|
Db::name('oa_invoice')->where('id',$params['id'])->strict(false)->field(true)->insertGetId($params);
|
|
$flow_step = array(
|
|
'action_id' => $params['id'],
|
|
'flow_uids' => $params['check_admin_ids'],
|
|
'create_time' => time(),
|
|
'type' => 3
|
|
);
|
|
Db::name('oa_flow_step')->strict(false)->field(true)->insertGetId($flow_step);
|
|
}
|
|
$step_id = Db::name('oa_flow_step')->where('action_id',$params['id'])->where('type',3)->order('id asc')->find();
|
|
//添加提交申请记录
|
|
$checkData=array(
|
|
'action_id' => $params['id'],
|
|
'check_user_id' => $this->adminId,
|
|
'content' => '提交申请',
|
|
'check_time' => time(),
|
|
'create_time' => time(),
|
|
'type' => 3,
|
|
'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 lists(){
|
|
|
|
}
|
|
} |