This commit is contained in:
weiz 2024-04-10 11:40:17 +08:00
parent 08c250b8d8
commit 05e9226d7a
6 changed files with 122 additions and 73 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();
}
@ -187,51 +194,51 @@
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 删除造价项目台账

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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) : '';