From 73f7c172860e361d12b4f99f16c9ae814800abfa Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Wed, 24 Jan 2024 09:39:29 +0800 Subject: [PATCH] update --- .../ProjectSalaryPaymentController.php | 9 +++ .../project/ProjectSalaryDetailLists.php | 40 +++++++++- .../project/ProjectSalaryPaymentLogic.php | 75 +++++++++++-------- .../project/ProjectSalaryPaymentValidate.php | 7 ++ 4 files changed, 97 insertions(+), 34 deletions(-) diff --git a/app/adminapi/controller/project/ProjectSalaryPaymentController.php b/app/adminapi/controller/project/ProjectSalaryPaymentController.php index 40ff67e49..f586b5c22 100644 --- a/app/adminapi/controller/project/ProjectSalaryPaymentController.php +++ b/app/adminapi/controller/project/ProjectSalaryPaymentController.php @@ -58,6 +58,15 @@ class ProjectSalaryPaymentController extends BaseAdminController } return $this->fail(ProjectSalaryPaymentLogic::getError()); } + + public function edit() { + $params = (new ProjectSalaryPaymentValidate())->post()->goCheck('edit'); + $result = ProjectSalaryPaymentLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectSalaryPaymentLogic::getError()); + } /** diff --git a/app/adminapi/lists/project/ProjectSalaryDetailLists.php b/app/adminapi/lists/project/ProjectSalaryDetailLists.php index c66ef418d..6e759e0c6 100644 --- a/app/adminapi/lists/project/ProjectSalaryDetailLists.php +++ b/app/adminapi/lists/project/ProjectSalaryDetailLists.php @@ -44,7 +44,9 @@ class ProjectSalaryDetailLists extends BaseAdminDataLists implements ListsSearch */ public function setSearch(): array { - return []; + return [ + '=' => ['salary_payment_id'], + ]; } @@ -59,7 +61,23 @@ class ProjectSalaryDetailLists extends BaseAdminDataLists implements ListsSearch */ public function lists(): array { - return ProjectSalaryDetail::where($this->searchWhere) + $prarms = $this->request->get(['payment_code','project_name','project_code']); + $where = []; + if(isset($prarms['payment_code']) && $prarms['payment_code'] != ''){ + $salary_payment_ids = ProjectSalaryPayment::where('payment_code','like','%'.$prarms['payment_code'].'%')->column('id'); + $where[] = ['salary_payment_id','in',$salary_payment_ids]; + } + if(isset($prarms['project_name']) && $prarms['project_name'] != ''){ + $project_ids = Project::where('name','like','%'.$prarms['project_name'].'%')->column('id'); + $salary_payment_ids = ProjectSalaryPayment::where('project_id','in',$project_ids)->column('id'); + $where[] = ['salary_payment_id','in',$salary_payment_ids]; + } + if(isset($prarms['project_code']) && $prarms['project_code'] != ''){ + $project_ids = Project::where('name','like','%'.$prarms['project_code'].'%')->column('id'); + $salary_payment_ids = ProjectSalaryPayment::where('project_id','in',$project_ids)->column('id'); + $where[] = ['salary_payment_id','in',$salary_payment_ids]; + } + return ProjectSalaryDetail::where($this->searchWhere)->where($where) ->field(['id', 'salary_payment_id', 'person_id', 'apply_date', 'apply_amount', 'remark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -102,7 +120,23 @@ class ProjectSalaryDetailLists extends BaseAdminDataLists implements ListsSearch */ public function count(): int { - return ProjectSalaryDetail::where($this->searchWhere)->count(); + $prarms = $this->request->get(['payment_code','project_name','project_code']); + $where = []; + if(isset($prarms['payment_code']) && $prarms['payment_code'] != ''){ + $salary_payment_ids = ProjectSalaryPayment::where('payment_code','like','%'.$prarms['payment_code'].'%')->column('id'); + $where[] = ['salary_payment_id','in',$salary_payment_ids]; + } + if(isset($prarms['project_name']) && $prarms['project_name'] != ''){ + $project_ids = Project::where('name','like','%'.$prarms['project_name'].'%')->column('id'); + $salary_payment_ids = ProjectSalaryPayment::where('project_id','in',$project_ids)->column('id'); + $where[] = ['salary_payment_id','in',$salary_payment_ids]; + } + if(isset($prarms['project_code']) && $prarms['project_code'] != ''){ + $project_ids = Project::where('name','like','%'.$prarms['project_code'].'%')->column('id'); + $salary_payment_ids = ProjectSalaryPayment::where('project_id','in',$project_ids)->column('id'); + $where[] = ['salary_payment_id','in',$salary_payment_ids]; + } + return ProjectSalaryDetail::where($this->searchWhere)->where($where)->count(); } } \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectSalaryPaymentLogic.php b/app/adminapi/logic/project/ProjectSalaryPaymentLogic.php index 2312500c3..3a43d9447 100644 --- a/app/adminapi/logic/project/ProjectSalaryPaymentLogic.php +++ b/app/adminapi/logic/project/ProjectSalaryPaymentLogic.php @@ -46,7 +46,6 @@ class ProjectSalaryPaymentLogic extends BaseLogic { Db::startTrans(); try { - $payment_detail = $params['payment_detail'];//json_decode($params['payment_detail'],true); $res = ProjectSalaryPayment::create([ 'payment_code' => data_unique_code('项目工资付款单'), 'project_id' => $params['project_id'], @@ -55,7 +54,7 @@ class ProjectSalaryPaymentLogic extends BaseLogic 'remark' => $params['remark'] ?? '', 'annex' => $params['annex']? json_encode($params['annex']) : null, ]); - foreach($payment_detail as $v){ + foreach($params['payment_detail'] as $v){ ProjectSalaryDetail::create([ 'salary_payment_id' => $res->id, 'person_id' => $v['person_id'], @@ -73,6 +72,47 @@ class ProjectSalaryPaymentLogic extends BaseLogic } } + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectSalaryPayment::where('id', $params['id'])->update([ + 'project_id' => $params['project_id'], + 'payment_type' => $params['payment_type'], + 'apply_date' => strtotime($params['apply_date']), + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex']? json_encode($params['annex']) : null, + 'update_time' => time(), + ]); + foreach($params['payment_detail'] as $v){ + if(isset($v['id']) && $v['id'] != ''){ + ProjectSalaryDetail::where('id',$v['id'])->update([ + 'salary_payment_id' => $params['id'], + 'person_id' => $v['person_id'], + 'apply_date' => strtotime($params['apply_date']), + 'apply_amount' => $v['apply_amount'], + 'remark' => $v['remark'] ?? '', + 'update_time' => time(), + ]); + }else{ + ProjectSalaryDetail::create([ + 'salary_payment_id' => $params['id'], + 'person_id' => $v['person_id'], + 'apply_date' => strtotime($params['apply_date']), + 'apply_amount' => $v['apply_amount'], + 'remark' => $v['remark'] ?? '', + ]); + } + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + /** * @notes 获取工资付款详情 @@ -83,39 +123,12 @@ class ProjectSalaryPaymentLogic extends BaseLogic */ public static function detail($params): array { - $data = ProjectSalaryPayment::field('id,payment_code,project_id,payment_type,apply_date,remark,annex')->findOrEmpty($params['id'])->toArray(); + $data = ProjectSalaryPayment::field('id,payment_code,project_id,payment_type,apply_date,remark,annex')->findOrEmpty($params['id']); $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; //总工资付款 $data['total_amount'] = ProjectSalaryDetail::where('salary_payment_id',$data['id'])->sum('apply_amount'); - $data['payment_detail'] = ProjectSalaryDetail::field('person_id,apply_amount,remark')->where('salary_payment_id',$data['id']) - ->select()->each(function($item){ - $person = ProjectPersonnel::field('name,idcard,work_type,deposit_bank,bank_no')->where('id',$item['person_id'])->findOrEmpty(); - $item['person_name'] = $person['name']; - $item['person_idcard'] = $person['idcard']; - $item['person_work_type_text'] = $person->work_type_text; - $item['person_deposit_bank'] = $person['deposit_bank']; - $item['person_bank_no'] = $person['bank_no']; - //总考勤收入 - $daily_income = ProjectAttendanceDetail::where('person_id',$item['person_id'])->sum('daily_income'); - //总施工收入 - $build_report_details = BuildReportDetail::field('report_id,work_num')->where('person_id',$item['person_id'])->select()->each(function($item2){ - $report = BuildReport::field('plan_id')->where('id',$item2['report_id'])->findOrEmpty(); - $plan = BuildPlan::field('price')->where('id',$report['plan_id'])->findOrEmpty(); - $item2['amount'] = $item2['work_num'] * $plan['price']; - })->toArray(); - $work_income = 0; - foreach($build_report_details as $v){ - $work_income += $v['amount']; - } - $item['total_income'] = $daily_income + $work_income; - //总支出 - $item['total_pay_out'] = ProjectSalaryDetail::where('person_id',$item['person_id'])->sum('apply_amount'); - $item['balance'] = $item['total_income'] - $item['total_pay_out']; - return $item; - }) - ->toArray(); - return $data; + return $data->toArray(); } } \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectSalaryPaymentValidate.php b/app/adminapi/validate/project/ProjectSalaryPaymentValidate.php index df8ec2bdc..80d60afb5 100644 --- a/app/adminapi/validate/project/ProjectSalaryPaymentValidate.php +++ b/app/adminapi/validate/project/ProjectSalaryPaymentValidate.php @@ -18,6 +18,7 @@ namespace app\adminapi\validate\project; use app\common\model\dict\DictData; use app\common\model\project\Project; use app\common\model\project\ProjectPersonnel; +use app\common\model\project\ProjectSalaryDetail; use app\common\validate\BaseValidate; @@ -131,6 +132,12 @@ class ProjectSalaryPaymentValidate extends BaseValidate return '工资支付明细数据格式错误'; } foreach($payment_detail as $v) { + if(isset($v['id']) && $v['id'] != ''){ + $info = ProjectSalaryDetail::where('id',$v['id'])->findOrEmpty(); + if($info->isEmpty()){ + return '工资支付明细信息不存在'; + } + } if(empty($v['person_id'])){ return '请选择项目人员'; }else{