From 05e9226d7ae35fffcf704872e4ef787537be3327 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Wed, 10 Apr 2024 11:40:17 +0800 Subject: [PATCH] update --- .../lists/cost_project/CostProjectLists.php | 56 +++++++-- .../MarketingProjectFilingDetailLists.php | 2 + .../logic/cost_project/CostProjectLogic.php | 115 ++++++++++-------- .../MarketingProjectFilingDetailLogic.php | 2 + .../cost_project/CostProjectValidate.php | 9 +- app/common/model/cost_project/CostProject.php | 11 +- 6 files changed, 122 insertions(+), 73 deletions(-) diff --git a/app/adminapi/lists/cost_project/CostProjectLists.php b/app/adminapi/lists/cost_project/CostProjectLists.php index 8333ad42b..37d345e5b 100644 --- a/app/adminapi/lists/cost_project/CostProjectLists.php +++ b/app/adminapi/lists/cost_project/CostProjectLists.php @@ -18,7 +18,13 @@ use app\adminapi\lists\BaseAdminDataLists; use app\common\lists\ListsExcelInterface; use app\common\lists\ListsSearchInterface; + use app\common\model\auth\Admin; use app\common\model\cost_project\CostProject; + use app\common\model\dept\Dept; + use app\common\model\GeoCity; + use app\common\model\GeoProvince; + use app\common\model\marketing\MarketingContract; + use app\common\model\marketing\MarketingCustom; use app\common\model\ProjectCommission; use app\common\model\zjzx_finance\ZjzxInvoice; use app\common\model\zjzx_finance\ZjzxRefund; @@ -66,27 +72,53 @@ ->where($this->searchWhere) ->field('p.*') ->limit($this->limitOffset, $this->limitLength) - ->with(['contract']) ->order(['id' => 'desc']) ->select() - ->each(function ($item) { - $item['person_text'] = $item->person_text; - $item['total_invoice_amount'] = ZjzxInvoice::where('project_id', $item['id'])->sum('apply_amount'); - $item['total_refund_amount'] = ZjzxRefund::where('project_id', $item['id'])->sum('amount'); - $item['total_pay_amount'] = ProjectCommission::where('project_id', $item['id'])->sum('bczfze'); + ->each(function ($res) { + $contract = MarketingContract::field('contract_name')->where('id', $res['contract_id'])->findOrEmpty(); + $province = GeoProvince::field('province_name')->where('province_code', $res['province'])->findOrEmpty(); + $city = GeoCity::field('city_name')->where('city_code', $res['city'])->findOrEmpty(); + $dept = Dept::field('name')->where('id', $res['depar'])->findOrEmpty(); + $admin = Admin::field('name')->where('id', $res['principal'])->findOrEmpty(); + $custom = MarketingCustom::field('name')->where('id', $res['aunit'])->findOrEmpty(); + $res['contract_name'] = $contract?->contract_name; + $res['types_text'] = $res->types_text; + $res['industry_text'] = $res->industry_text; + $res['province_name'] = $province?->province_name; + $res['city_name'] = $city?->city_name; + $res['dept_name'] = $dept?->name; + $res['principal_name'] = $admin?->name; + $res['person_text'] = $res->person_text; + $res['aunit_name'] = $custom?->name; + $res['total_invoice_amount'] = ZjzxInvoice::where('project_id', $res['id'])->sum('apply_amount'); + $res['total_refund_amount'] = ZjzxRefund::where('project_id', $res['id'])->sum('amount'); + $res['total_pay_amount'] = ProjectCommission::where('project_id', $res['id'])->sum('bczfze'); }) ->toArray(); } return CostProject::where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) - ->with(['contract']) ->order(['id' => 'desc']) ->select() - ->each(function ($item) { - $item['person_text'] = $item->person_text; - $item['total_invoice_amount'] = ZjzxInvoice::where('project_id', $item['id'])->sum('apply_amount'); - $item['total_refund_amount'] = ZjzxRefund::where('project_id', $item['id'])->sum('amount'); - $item['total_pay_amount'] = ProjectCommission::where('project_id', $item['id'])->sum('bczfze'); + ->each(function ($res) { + $contract = MarketingContract::field('contract_name')->where('id', $res['contract_id'])->findOrEmpty(); + $province = GeoProvince::field('province_name')->where('province_code', $res['province'])->findOrEmpty(); + $city = GeoCity::field('city_name')->where('city_code', $res['city'])->findOrEmpty(); + $dept = Dept::field('name')->where('id', $res['depar'])->findOrEmpty(); + $admin = Admin::field('name')->where('id', $res['principal'])->findOrEmpty(); + $custom = MarketingCustom::field('name')->where('id', $res['aunit'])->findOrEmpty(); + $res['contract_name'] = $contract?->contract_name; + $res['types_text'] = $res->types_text; + $res['industry_text'] = $res->industry_text; + $res['province_name'] = $province?->province_name; + $res['city_name'] = $city?->city_name; + $res['dept_name'] = $dept?->name; + $res['principal_name'] = $admin?->name; + $res['person_text'] = $res->person_text; + $res['aunit_name'] = $custom?->name; + $res['total_invoice_amount'] = ZjzxInvoice::where('project_id', $res['id'])->sum('apply_amount'); + $res['total_refund_amount'] = ZjzxRefund::where('project_id', $res['id'])->sum('amount'); + $res['total_pay_amount'] = ProjectCommission::where('project_id', $res['id'])->sum('bczfze'); }) ->toArray(); diff --git a/app/adminapi/lists/marketing/MarketingProjectFilingDetailLists.php b/app/adminapi/lists/marketing/MarketingProjectFilingDetailLists.php index b848562b3..4b0be632c 100644 --- a/app/adminapi/lists/marketing/MarketingProjectFilingDetailLists.php +++ b/app/adminapi/lists/marketing/MarketingProjectFilingDetailLists.php @@ -67,7 +67,9 @@ $data['contract_code'] = $contract['contract_code']; $data['const_area'] = $contract->const_area_text; $data['business_nature'] = $contract->business_nature_text; + $data['filing_role'] = (string)$data['filing_role']; $data['filing_role_text'] = $data->filing_role_text; + $data['status'] = (string)$data['status']; $data['status_text'] = $data->status_text; }) ->toArray(); diff --git a/app/adminapi/logic/cost_project/CostProjectLogic.php b/app/adminapi/logic/cost_project/CostProjectLogic.php index 2c12b65f7..d7c724c9e 100644 --- a/app/adminapi/logic/cost_project/CostProjectLogic.php +++ b/app/adminapi/logic/cost_project/CostProjectLogic.php @@ -17,13 +17,14 @@ use app\common\logic\BaseLogic; use app\common\model\ApprovalIssuanceAchievementDocuments; + use app\common\model\auth\Admin; use app\common\model\cost_project\CostProject; - use app\common\model\cost_project\CostProjectPerson; use app\common\model\DataReception; use app\common\model\dept\Dept; use app\common\model\GeoCity; use app\common\model\GeoProvince; use app\common\model\marketing\MarketingContract; + use app\common\model\marketing\MarketingCustom; use app\common\model\project_process_management\ApplyWithSeal; use app\common\model\project_process_management\JianliProjectProgressReport; use app\common\model\project_process_management\ProjectChangeVisa; @@ -157,16 +158,22 @@ */ public static function detail($params): array { - $res = CostProject::with(['contract'])->findOrEmpty($params['id']); - $res['person_text'] = $res->person_text; - $res['types_text'] = $res->types_text; - $res['industry_nature_text'] = $res['contract']->industry_nature_text; + $res = CostProject::withoutField('update_time,delete_time')->findOrEmpty($params['id']); + $contract = MarketingContract::field('contract_name')->where('id', $res['contract_id'])->findOrEmpty(); $province = GeoProvince::field('province_name')->where('province_code', $res['province'])->findOrEmpty(); $city = GeoCity::field('city_name')->where('city_code', $res['city'])->findOrEmpty(); $dept = Dept::field('name')->where('id', $res['depar'])->findOrEmpty(); - $res['province_name'] = $province['province_name']; - $res['city_name'] = $city['city_name']; - $res['dept_name'] = $dept['name']; + $admin = Admin::field('name')->where('id', $res['principal'])->findOrEmpty(); + $custom = MarketingCustom::field('name')->where('id', $res['aunit'])->findOrEmpty(); + $res['contract_name'] = $contract?->contract_name; + $res['types_text'] = $res->types_text; + $res['industry_text'] = $res->industry_text; + $res['province_name'] = $province?->province_name; + $res['city_name'] = $city?->city_name; + $res['dept_name'] = $dept?->name; + $res['principal_name'] = $admin?->name; + $res['person_text'] = $res->person_text; + $res['aunit_name'] = $custom?->name; return $res->toArray(); } @@ -186,52 +193,52 @@ } return $datas; } - - public static function createProject($data) - { - Db::startTrans(); - try { - $res = CostProject::create([ - 'project_num' => generate_sn(CostProject::class, 'project_num'), - 'project_name' => $data['project_name'], - 'contract_id' => $data['contract_id'], - 'types' => $data['types'], - 'industry' => $data['industry'], - 'province' => $data['province'], - 'city' => $data['city'], - 'address' => $data['address'], - 'starting' => $data['starting'], - 'endtime' => $data['endtime'], - 'jhgq' => $data['jhgq'], - 'depar' => $data['depar'], - 'principal' => $data['principal'], - 'invest' => $data['invest'], - 'budget' => $data['budget'], - 'cost' => $data['cost'], - 'approval' => $data['approval'], - 'aunit' => $data['aunit'], - 'Acontact' => $data['Acontact'], - 'acontactnum' => $data['acontactnum'], - 'date' => $data['date'], - 'generalize' => $data['generalize'], - 'note' => $data['note'], - 'remark' => $data['remark'], - 'annex' => $data['annex'] - ]); - if ($data['person_id']) { - $arr = []; - $person_id = explode(',', $data['person_id']); - (new CostProjectPerson)->delete($person_id); - foreach ($person_id as $k => $v) { - $arr[] = ['cost_project_id' => $data->id, $v]; - } - $arr ?? (new CostProjectPerson)->saveAll($arr); - } - return $res; - } catch (\Exception $e) { - return false; - } - } + +// public static function createProject($data) +// { +// Db::startTrans(); +// try { +// $res = CostProject::create([ +// 'project_num' => generate_sn(CostProject::class, 'project_num'), +// 'project_name' => $data['project_name'], +// 'contract_id' => $data['contract_id'], +// 'types' => $data['types'], +// 'industry' => $data['industry'], +// 'province' => $data['province'], +// 'city' => $data['city'], +// 'address' => $data['address'], +// 'starting' => $data['starting'], +// 'endtime' => $data['endtime'], +// 'jhgq' => $data['jhgq'], +// 'depar' => $data['depar'], +// 'principal' => $data['principal'], +// 'invest' => $data['invest'], +// 'budget' => $data['budget'], +// 'cost' => $data['cost'], +// 'approval' => $data['approval'], +// 'aunit' => $data['aunit'], +// 'Acontact' => $data['Acontact'], +// 'acontactnum' => $data['acontactnum'], +// 'date' => $data['date'], +// 'generalize' => $data['generalize'], +// 'note' => $data['note'], +// 'remark' => $data['remark'], +// 'annex' => $data['annex'] +// ]); +// if ($data['person_id']) { +// $arr = []; +// $person_id = explode(',', $data['person_id']); +// (new CostProjectPerson)->delete($person_id); +// foreach ($person_id as $k => $v) { +// $arr[] = ['cost_project_id' => $data->id, $v]; +// } +// $arr ?? (new CostProjectPerson)->saveAll($arr); +// } +// return $res; +// } catch (\Exception $e) { +// return false; +// } +// } /** * @notes 删除造价项目台账 diff --git a/app/adminapi/logic/marketing/MarketingProjectFilingDetailLogic.php b/app/adminapi/logic/marketing/MarketingProjectFilingDetailLogic.php index 2aad619ad..7b3642c22 100644 --- a/app/adminapi/logic/marketing/MarketingProjectFilingDetailLogic.php +++ b/app/adminapi/logic/marketing/MarketingProjectFilingDetailLogic.php @@ -116,7 +116,9 @@ $data['contract_code'] = $contract['contract_code']; $data['const_area'] = $contract->const_area_text; $data['business_nature'] = $contract->business_nature_text; + $data['filing_role'] = (string)$data['filing_role']; $data['filing_role_text'] = $data->filing_role_text; + $data['status'] = (string)$data['status']; $data['status_text'] = $data->status_text; return $data->toArray(); } diff --git a/app/adminapi/validate/cost_project/CostProjectValidate.php b/app/adminapi/validate/cost_project/CostProjectValidate.php index 265fa87f2..027b0bfc8 100644 --- a/app/adminapi/validate/cost_project/CostProjectValidate.php +++ b/app/adminapi/validate/cost_project/CostProjectValidate.php @@ -74,7 +74,7 @@ */ public function sceneAdd() { - return $this->only(['project_num', 'project_name', 'contract_id', 'starting', 'endtime', 'jhgq', 'principal', 'invest', 'aunit', 'annex']); + return $this->remove('id', true); } @@ -86,7 +86,6 @@ */ public function sceneEdit() { - return $this->only(['id', 'project_num', 'project_name', 'contract_id', 'starting', 'endtime', 'jhgq', 'principal', 'invest', 'aunit', 'annex']); } @@ -127,4 +126,10 @@ return !in_array($value, $dict) ? '咨询类型数据值无效' : true; } + public function checkIndustry($value): bool|string + { + $dict = DictData::where('type_value', 'cost_consultation_industry_nature')->column('value'); + return !in_array($value, $dict) ? '行业数据值无效' : true; + } + } \ No newline at end of file diff --git a/app/common/model/cost_project/CostProject.php b/app/common/model/cost_project/CostProject.php index ffb887782..4014a275b 100644 --- a/app/common/model/cost_project/CostProject.php +++ b/app/common/model/cost_project/CostProject.php @@ -39,17 +39,18 @@ return $this->hasOne(MarketingContract::class, 'id', 'contract_id'); } - public function CostProjectContract() - { - return $this->hasOne(MarketingContract::class, 'id', 'contract_id'); - } - public function getTypesTextAttr($value, $data) { $dict = DictData::where('type_value', 'consultation_type')->column('name', 'value'); return !empty($data['types']) ? $dict[$data['types']] : ''; } + public function getIndustryTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_industry_nature')->column('name', 'value'); + return !empty($data['industry']) ? $dict[$data['industry']] : ''; + } + public function getPersonAttr($value) { return !empty($value) ? json_decode($value, true) : '';