From eb3a01f6d9ef71e93d5b5f68d7fe94a288f5059e Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Thu, 22 Feb 2024 18:35:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=88=86=E6=88=B7=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PersonChangeController.php | 54 +++++++++++++++++++ app/Admin/Controllers/PersonController.php | 14 ++--- app/Admin/routes.php | 2 + app/Models/Filters/PersonChangeFilter.php | 12 +++++ app/Models/Filters/PersonFilter.php | 2 +- app/Models/Person.php | 8 +++ app/Models/PersonChange.php | 16 ++++++ app/Services/Admin/PersonChangeService.php | 22 ++++++++ app/Services/Admin/PersonService.php | 20 ++++++- .../2024_01_29_110440_create_people_table.php | 18 +++---- database/seeders/migrations/PersonSeeder.php | 22 ++++---- lang/zh_CN/admin.php | 4 ++ 12 files changed, 164 insertions(+), 30 deletions(-) create mode 100644 app/Admin/Controllers/PersonChangeController.php create mode 100644 app/Models/Filters/PersonChangeFilter.php create mode 100644 app/Services/Admin/PersonChangeService.php diff --git a/app/Admin/Controllers/PersonChangeController.php b/app/Admin/Controllers/PersonChangeController.php new file mode 100644 index 0000000..ec46c51 --- /dev/null +++ b/app/Admin/Controllers/PersonChangeController.php @@ -0,0 +1,54 @@ +baseCRUD()->tableLayout('fixed') + ->headerToolbar([ + amis('reload')->align('right'), + amis('filter-toggler')->align('right'), + ]) + ->filter($this->baseFilter()->labelWidth('80px')->body([ + + ])) + ->columns([ + amis()->TableColumn('person.organized_body.name', __('admin.persons.organized_body'))->width('100px'), + amis()->TableColumn('person.name', __('admin.persons.name'))->width('100px')->copyable(), + amis()->TableColumn('extends_mark', __('admin.person_changes.extends_mark')), + amis()->TableColumn('phone', __('admin.person_changes.phone')), + amis()->TableColumn('created_at', __('admin.created_at'))->type('datetime')->sortable(true), + ]); + + return $this->baseList($crud); + } + + public function form(): Form + { + return $this->baseForm()->body([ + + ]); + } + + public function detail(): Form + { + return $this->baseDetail()->body([ + + ]); + } +} \ No newline at end of file diff --git a/app/Admin/Controllers/PersonController.php b/app/Admin/Controllers/PersonController.php index 16121f6..b3f2fba 100644 --- a/app/Admin/Controllers/PersonController.php +++ b/app/Admin/Controllers/PersonController.php @@ -155,12 +155,12 @@ class PersonController extends AdminController amis()->TextControl('card_address')->placeholder('详细地址'), ]), amis()->GroupControl()->mode('horizontal')->body([ - amis()->SelectControl('nation', __('admin.persons.nation'))->options(Keyword::where('parent_key', 'nation')->pluck('name', 'id')->toArray())->clearable(true)->required()->searchable(), - amis()->SelectControl('political_face', __('admin.persons.political_face'))->options(Keyword::where('parent_key', 'political_face')->pluck('name', 'id')->toArray())->clearable(true)->required(), + amis()->SelectControl('nation_id', __('admin.persons.nation'))->options(Keyword::where('parent_key', 'nation')->pluck('name', 'id')->toArray())->clearable(true)->required()->searchable(), + amis()->SelectControl('political_face_id', __('admin.persons.political_face'))->options(Keyword::where('parent_key', 'political_face')->pluck('name', 'id')->toArray())->clearable(true)->required(), ]), amis()->GroupControl()->mode('horizontal')->body([ - amis()->SelectControl('educational_level', __('admin.persons.educational_level'))->options(Keyword::where('parent_key', 'educational_level')->pluck('name', 'id')->toArray())->clearable(true)->required(), - amis()->SelectControl('marry_state', __('admin.persons.marry_state'))->options(Keyword::where('parent_key', 'marry_state')->pluck('name', 'id')->toArray())->clearable(true)->required(), + amis()->SelectControl('educational_level_id', __('admin.persons.educational_level'))->options(Keyword::where('parent_key', 'educational_level')->pluck('name', 'id')->toArray())->clearable(true)->required(), + amis()->SelectControl('marry_state_id', __('admin.persons.marry_state'))->options(Keyword::where('parent_key', 'marry_state')->pluck('name', 'id')->toArray())->clearable(true)->required(), ]), amis()->GroupControl()->mode('horizontal')->body([ amis()->NestedSelectControl('house_building', __('admin.persons.house_building'))->source(admin_url('api/keywords/tree-list?parent_name=housing_estate&has_owner=0'))->labelField('name')->valueField('id')->onlyLeaf(true)->clearable(true), @@ -173,11 +173,11 @@ class PersonController extends AdminController amis()->FieldSetControl()->title('户籍信息')->className('mt-10')->body([ amis()->GroupControl()->mode('horizontal')->body([ amis()->TextControl('domicile_code', __('admin.persons.domicile_code'))->required(), - amis()->SelectControl('organized_body', __('admin.persons.organized_body'))->options(Keyword::where('parent_key', 'organized_body')->pluck('name', 'id')->toArray())->clearable(true)->required(), + amis()->SelectControl('organized_body_id', __('admin.persons.organized_body'))->options(Keyword::where('parent_key', 'organized_body')->pluck('name', 'id')->toArray())->clearable(true)->required(), ]), amis()->GroupControl()->mode('horizontal')->body([ amis()->SwitchControl('has_benefit', __('admin.persons.has_benefit'))->value(false)->required(), - amis()->SelectControl('domicile', __('admin.persons.domicile'))->options(Keyword::where('parent_key', 'domicile')->pluck('name', 'id')->toArray())->clearable(true)->required(), + amis()->SelectControl('domicile_id', __('admin.persons.domicile'))->options(Keyword::where('parent_key', 'domicile')->pluck('name', 'id')->toArray())->clearable(true)->required(), ]), amis()->GroupControl()->mode('horizontal')->body([ $this->masterPicker('master', '', '输入 户主姓名 进行筛选,忽略则为添加户主')->disabledOn('this.id > 0'), @@ -347,7 +347,7 @@ class PersonController extends AdminController } /** - * 分户-todo + * 分户 */ public function splitMasterForm() { diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 42471cd..cf3a42f 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -41,6 +41,8 @@ Route::group([ $router->resource('persons', \App\Admin\Controllers\PersonController::class); $router->post('split_master', [\App\Admin\Controllers\PersonController::class, 'doSplitMaster']); + $router->resource('person_changes', \App\Admin\Controllers\PersonChangeController::class); + //数据管理 $router->resource('financial_cate', \App\Admin\Controllers\KeywordController::class); diff --git a/app/Models/Filters/PersonChangeFilter.php b/app/Models/Filters/PersonChangeFilter.php new file mode 100644 index 0000000..e92e838 --- /dev/null +++ b/app/Models/Filters/PersonChangeFilter.php @@ -0,0 +1,12 @@ +value('lv') == 3) + if(Keyword::where('id', $houseBuilding)->value('lv') == 3) { return $this->where('building', $houseBuilding); }else{ diff --git a/app/Models/Person.php b/app/Models/Person.php index 7200e85..fffaaca 100644 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -27,11 +27,14 @@ class Person extends Model parent::boot(); // 监听 人口 的创建事件,用于初始化 位置信息 static::created(function ($person) { + //处理户主信息 if(empty($person->master_id) && $person->master_connect){ $person->master_id = $person->id; $person->is_master = 1; $person->save(); } + //处理新增时变动记录-todo + }); static::saving(function ($person) { if($person->origin_city_code){ @@ -66,6 +69,11 @@ class Person extends Model return $this->belongsTo(static::class, 'master_id'); } + public function organizedBody() + { + return $this->belongsTo(Keyword::class, 'organized_body_id'); + } + //年龄 protected function age():Attribute { diff --git a/app/Models/PersonChange.php b/app/Models/PersonChange.php index 533df1a..a5bb52d 100644 --- a/app/Models/PersonChange.php +++ b/app/Models/PersonChange.php @@ -4,10 +4,12 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use EloquentFilter\Filterable; class PersonChange extends Model { use HasFactory; + use Filterable; public const TYPE_IN = 1; //迁入 public const TYPE_BIRTH = 2; //出生 @@ -18,6 +20,10 @@ class PersonChange extends Model public const TYPE_MIGRATE = 7; //迁移 public const TYPE_CHANGE = 8; //变更户主 + protected $casts = [ + 'extends' => 'array', + ]; + public static function typeMap() { return [ @@ -31,4 +37,14 @@ class PersonChange extends Model self::TYPE_CHANGE =>'变更户主', ]; } + + protected function serializeDate(\DateTimeInterface $date) + { + return $date->format('Y-m-d H:i:s'); + } + + public function person() + { + return $this->belongsTo(Person::class, 'person_id'); + } } diff --git a/app/Services/Admin/PersonChangeService.php b/app/Services/Admin/PersonChangeService.php new file mode 100644 index 0000000..97d1eee --- /dev/null +++ b/app/Services/Admin/PersonChangeService.php @@ -0,0 +1,22 @@ +value('parent_id') ?:0; + $data['building_id'] = $data['house_building']; + } + foreach ($data as $k => $v) { if (!in_array($k, $columns)) { continue; @@ -63,6 +71,12 @@ class PersonService extends BaseService $data['avatar'] = $this->saveImage('avatar', 'persons/avatar')[0] ?? ''; } + if(isset($data['house_building'])) + { + $data['housing_estate_id'] = Keyword::where('id', $data['house_building'])->value('parent_id') ?:0; + $data['building_id'] = $data['house_building']; + } + foreach ($data as $k => $v) { if (!in_array($k, $columns)) { continue; @@ -113,11 +127,11 @@ class PersonService extends BaseService continue; } - $changeMark = (isset($extends['splited_at']) ? $extends['splited_at'] : '某日'). (isset($extends['split_reason']) ? ('因' .$extends['split_reason']) : '').'分户, '; + $changeMark = (isset($extends['splited_at']) ? $extends['splited_at'] : '某日'). '日,' .(isset($extends['split_reason']) ? ('因' .$extends['split_reason']) : '').'分户,'; if($newMaster['id'] == $person['id']){ $changeMark .= '成为新户主'; }else{ - $changeMark .= '户主由['.$person["master"]["name"].']变更为['.$newMaster["name"].'], 与户主关系更新为['.$person['new_master_connect'].']'; + $changeMark .= '户主由【'.$person["master"]["name"].']变更为['.$newMaster["name"].'】,与户主关系更新为【'.$person['new_master_connect'].'】'; } $personChangeLogs[] = [ 'person_id' => $person['id'], @@ -128,6 +142,8 @@ class PersonService extends BaseService 'new_master' => $newMaster['id'], 'extends_mark' => $changeMark, 'remark' => isset($extends['remark']) ? $extends['remark'] : null, + 'created_at' => now(), + 'updated_at' => now() ]; Person::where('id', $person['id'])->update([ diff --git a/database/migrations/2024_01_29_110440_create_people_table.php b/database/migrations/2024_01_29_110440_create_people_table.php index 967df37..8ef3c3b 100644 --- a/database/migrations/2024_01_29_110440_create_people_table.php +++ b/database/migrations/2024_01_29_110440_create_people_table.php @@ -33,17 +33,17 @@ return new class extends Migration $table->unsignedBigInteger('card_area_id')->nullable()->comment('户籍-区'); $table->string('card_address')->nullable()->comment('户籍-街道详细地址'); $table->string('card_complete_address')->nullable()->comment('户籍-完整地址'); - $table->unsignedBigInteger('housing_estate')->nullable()->comment('小区'); - $table->unsignedBigInteger('building')->nullable()->comment('楼栋'); + $table->unsignedBigInteger('housing_estate_id')->nullable()->comment('小区'); + $table->unsignedBigInteger('building_id')->nullable()->comment('楼栋'); $table->string('house_number')->nullable()->comment('门牌号'); $table->string('house_complete_address')->nullable()->comment('小区完整地址'); $table->string('real_address')->nullable()->comment('实际居住地址'); - $table->unsignedBigInteger('nation')->nullable()->comment('民族'); - $table->unsignedBigInteger('political_face')->nullable()->comment('政治面貌'); - $table->unsignedBigInteger('educational_level')->nullable()->comment('文化程度'); - $table->unsignedBigInteger('marry_state')->nullable()->comment('婚姻状况'); - $table->unsignedBigInteger('job_cate')->nullable()->comment('工种'); + $table->unsignedBigInteger('nation_id')->nullable()->comment('民族'); + $table->unsignedBigInteger('political_face_id')->nullable()->comment('政治面貌'); + $table->unsignedBigInteger('educational_level_id')->nullable()->comment('文化程度'); + $table->unsignedBigInteger('marry_state_id')->nullable()->comment('婚姻状况'); + $table->unsignedBigInteger('job_cate_id')->nullable()->comment('工种'); $table->string('job')->nullable()->comment('职业'); $table->string('health')->nullable()->comment('身体状况'); $table->string('phone')->nullable()->comment('联系方式'); @@ -51,10 +51,10 @@ return new class extends Migration $table->unsignedTinyInteger('type')->nullable()->comment('类型11-出生人口,12-迁入人口(11、12统称户籍人口),2-流动人口,3-留守人口,4-境外人口'); $table->unsignedTinyInteger('has_benefit')->default(0)->comment('是否享受福利'); - $table->unsignedBigInteger('organized_body')->nullable()->comment('社别'); + $table->unsignedBigInteger('organized_body_id')->nullable()->comment('社别'); $table->string('t_ids')->nullable()->comment('标签'); - $table->unsignedBigInteger('domicile')->nullable()->comment('户籍类型'); + $table->unsignedBigInteger('domicile_id')->nullable()->comment('户籍类型'); $table->string('domicile_code')->nullable()->comment('户籍编号'); $table->unsignedBigInteger('master_id')->nullable()->default(0)->comment('户主ID'); $table->unsignedTinyInteger('is_master')->default(0)->comment('是否户主'); diff --git a/database/seeders/migrations/PersonSeeder.php b/database/seeders/migrations/PersonSeeder.php index cfe66ae..0715c21 100644 --- a/database/seeders/migrations/PersonSeeder.php +++ b/database/seeders/migrations/PersonSeeder.php @@ -56,17 +56,17 @@ class PersonSeeder extends Seeder 'origin_complete_address' => $person->nativePlace, 'card_complete_address' => $person->birthAddr, - 'housing_estate' => null, - 'building' => null, + 'housing_estate_id' => null, + 'building_id' => null, 'house_number' => null, 'house_complete_address' => null, 'real_address' => null, - 'nation' => Keyword::where('parent_key', 'nation')->where('oid', $person->folkId)->value('id'), - 'political_face' => Keyword::where('parent_key', 'political_face')->where('oid', $person->politicsId)->value('id'), - 'educational_level' => Keyword::where('parent_key', 'educational_level')->where('oid', $person->educationId)->value('id'), - 'marry_state' => Keyword::where('parent_key', 'marry_state')->where('name', $person->marryStatus)->value('id'), - 'job_cate' => Keyword::where('parent_key', 'job_cate')->where('name', $person->workType)->value('id'), + 'nation_id' => Keyword::where('parent_key', 'nation')->where('oid', $person->folkId)->value('id'), + 'political_face_id' => Keyword::where('parent_key', 'political_face')->where('oid', $person->politicsId)->value('id'), + 'educational_level_id' => Keyword::where('parent_key', 'educational_level')->where('oid', $person->educationId)->value('id'), + 'marry_state_id' => Keyword::where('parent_key', 'marry_state')->where('name', $person->marryStatus)->value('id'), + 'job_cate_id' => Keyword::where('parent_key', 'job_cate')->where('name', $person->workType)->value('id'), 'job' => $person->career, 'health'=> $person->health, 'phone' => $person->phone, @@ -74,9 +74,9 @@ class PersonSeeder extends Seeder 'type'=>$person->type, 'has_benefit' => $person->benefit == '是' ? 1:0, - 'organized_body' => Keyword::where('parent_key', 'organized_body')->where('oid', $person->societyId)->value('id'), + 'organized_body_id' => Keyword::where('parent_key', 'organized_body')->where('oid', $person->societyId)->value('id'), - 'domicile'=> Keyword::where('parent_key', 'domicile')->where('oid', $person->houseHoldTypeId)->value('id'), + 'domicile_id'=> Keyword::where('parent_key', 'domicile')->where('oid', $person->houseHoldTypeId)->value('id'), 'domicile_code' => $person->houseHoldNumber, 'master_id' => $person->houseHoldMasterId, 'is_master' => $person->houseHoldMasterRelative == '户主' ? 1:0, @@ -127,11 +127,11 @@ class PersonSeeder extends Seeder $housingEstate = Keyword::where('parent_key', 'housing_estate')->where('oid', $person->courtId)->first(); $building = Keyword::where('parent_key', 'like', 'housing_estate%')->where('oid', $person->buildingId ?:0)->first(); if($housingEstate){ - $_person['housing_estate'] = $housingEstate->id; + $_person['housing_estate_id'] = $housingEstate->id; $houseCompleteAddress .= $housingEstate->name; } if($building){ - $_person['building'] = $building->id; + $_person['building_id'] = $building->id; $houseCompleteAddress .= $building->name; } $_person['house_number'] = $person->door; diff --git a/lang/zh_CN/admin.php b/lang/zh_CN/admin.php index ef559bd..a757f31 100644 --- a/lang/zh_CN/admin.php +++ b/lang/zh_CN/admin.php @@ -379,4 +379,8 @@ return [ //分户操作 'split_master' => '分户', ], + 'person_changes'=>[ + 'extends_mark'=>'变动明细', + 'phone'=>'联系方式' + ] ];