diff --git a/app/adminapi/controller/works/bgsp/OaApproveController.php b/app/adminapi/controller/works/bgsp/OaApproveController.php index 756f0b232..b2dcab389 100644 --- a/app/adminapi/controller/works/bgsp/OaApproveController.php +++ b/app/adminapi/controller/works/bgsp/OaApproveController.php @@ -72,7 +72,7 @@ }; return $data; })->toArray(); - $step = Db::name('oa_flow_step')->field('id,action_id,flow_uids,flow_type')->where('action_id',$params['id'])->where('type',1)->order('sort asc')->select()->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) { diff --git a/app/adminapi/controller/works/finance/InvoiceController.php b/app/adminapi/controller/works/finance/InvoiceController.php new file mode 100644 index 000000000..f51dfabc8 --- /dev/null +++ b/app/adminapi/controller/works/finance/InvoiceController.php @@ -0,0 +1,161 @@ +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(){ + + } + } \ No newline at end of file diff --git a/app/adminapi/validate/works/finance/InvoiceValidate.php b/app/adminapi/validate/works/finance/InvoiceValidate.php new file mode 100644 index 000000000..e385f077c --- /dev/null +++ b/app/adminapi/validate/works/finance/InvoiceValidate.php @@ -0,0 +1,117 @@ + 'require', + 'code' => 'require', + 'cash_type' => 'require|in:1,2,3,4,5,6,7', + 'is_cash' => 'require|in:0,1,2', + 'amount' => 'require|float', + 'type' => 'require|in:1,2', + 'invoice_subject' => 'require', + 'invoice_type' => 'require|in:1,2,3', + 'invoice_title' => 'require', + 'invoice_phone' => 'mobile', + 'invoice_account' => 'number', + 'flow_id' => 'require|checkFlow', + 'check_remark' => 'require', + 'annex' => 'checkAnnex', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'require', + 'code' => '发票号码', + 'cash_type' => '付款方式', + 'is_cash' => '是否到账', + 'amount' => '发票金额', + 'type' => '抬头类型', + 'invoice_subject' => '发票主体', + 'invoice_type' => '发票类型', + 'invoice_title' => '开票抬头', + 'invoice_phone' => '电话号码', + 'invoice_account' => '银行账号', + 'flow_id' => '审批流程id', + 'check_remark' => '撤销的理由', + 'annex' => '附件', + ]; + + /** + * @notes 添加场景 + * @return InvoiceValidate + * @author likeadmin + * @date 2024/05/24 14:16 + */ + public function sceneAdd() + { + return $this->only(['amount','type','invoice_subject','invoice_type','invoice_title','invoice_phone','invoice_tax','invoice_bank','invoice_account','invoice_banking','invoice_address','remark','annex','flow_id']); + } + + + /** + * @notes 编辑场景 + * @return InvoiceValidate + * @author likeadmin + * @date 2024/05/24 14:16 + */ + public function sceneEdit() + { + return $this->only(['id','amount','type','invoice_subject','invoice_type','invoice_title','invoice_phone','invoice_tax','invoice_bank','invoice_account','invoice_banking','invoice_address','remark','annex','flow_id']); + } + + + /** + * @notes 删除场景 + * @return InvoiceValidate + * @author likeadmin + * @date 2024/05/24 14:16 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return InvoiceValidate + * @author likeadmin + * @date 2024/05/24 14:16 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + /** + * @notes 详情场景 + * @return InvoiceValidate + * @author likeadmin + * @date 2024/05/24 14:16 + */ + public function scenePay() + { + return $this->only(['id']); + } + + public function checkFlow($value): bool|string { + $data = OaFlow::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '审批流程信息不存在'; + } + if($data['type'] != 5){ + return '当前审批流信息不属于报销审批类型'; + } + return true; + } + } \ No newline at end of file