generated from liutk/owl-admin-base
完成分户动作
parent
7f88707bf2
commit
d94b00b0c7
|
|
@ -15,6 +15,7 @@ use Slowlyo\OwlAdmin\Renderers\Dialog;
|
|||
use Slowlyo\OwlAdmin\Renderers\DrawerAction;
|
||||
use Slowlyo\OwlAdmin\Renderers\DialogAction;
|
||||
use Slowlyo\OwlAdmin\Renderers\LinkAction;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* 人口管理
|
||||
|
|
@ -32,10 +33,12 @@ class PersonController extends AdminController
|
|||
$crud = $this->baseCRUD()->tableLayout('fixed')
|
||||
->headerToolbar([
|
||||
$this->createTypeButton('drawer', '', '50%'),
|
||||
amis()->DialogAction()->icon('fa fa-add')->label('合户')->dialog(
|
||||
amis()->DialogAction()->icon('fas fa-people-arrows')->iconClassName('text-white text-sm')->level('danger')->label('分户')->dialog(
|
||||
amis()->Dialog()->title(__('admin.persons.split_master'))->body($this->splitMasterForm())->size('lg')
|
||||
),
|
||||
amis()->DialogAction()->icon('fas fa-users')->iconClassName('text-white text-sm')->level('success')->label('合户')->dialog(
|
||||
amis()->Dialog()->title('合户')->body($this->mergeMasterForm())->size('lg')
|
||||
),
|
||||
|
||||
amis('reload')->align('right'),
|
||||
amis('filter-toggler')->align('right'),
|
||||
])
|
||||
|
|
@ -44,9 +47,6 @@ class PersonController extends AdminController
|
|||
amis()->SelectControl('organized_body', __('admin.persons.organized_body'))->options(Keyword::where('parent_key', 'organized_body')->pluck('name', 'id')->toArray())
|
||||
->columnRatio(3)->clearable(true),
|
||||
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')->columnRatio(6)->clearable(true),
|
||||
// amis()->TextControl('master.name', __('admin.persons.master_name'))->placeholder(__('admin.persons.master_name')),
|
||||
// amis()->TextControl('name', __('admin.persons.name'))->placeholder(__('admin.persons.name')),
|
||||
// amis()->TextControl('idcard', __('admin.persons.idcard'))->placeholder(__('admin.persons.idcard')),
|
||||
]),
|
||||
amis()->GroupControl()->mode('horizontal')->body([
|
||||
amis()->SelectControl('state', __('admin.persons.state'))->options([
|
||||
|
|
@ -301,21 +301,33 @@ class PersonController extends AdminController
|
|||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function detailActions()
|
||||
{
|
||||
return [
|
||||
//变更户主
|
||||
//迁移
|
||||
//迁出
|
||||
//死亡
|
||||
//变更户主-todo
|
||||
amis()->DialogAction()->level('warning')->label('变更户主')->dialog(
|
||||
amis()->Dialog()->title('变更户主')->body()->size('lg')
|
||||
),
|
||||
//迁移-todo
|
||||
amis()->DialogAction()->level('info')->label('迁移')->dialog(
|
||||
amis()->Dialog()->title('迁移')->body()->size('lg')
|
||||
),
|
||||
//迁出-todo
|
||||
amis()->DialogAction()->level('success')->label('迁出')->dialog(
|
||||
amis()->Dialog()->title('迁出')->body()->size('lg')
|
||||
),
|
||||
//死亡-todo
|
||||
amis()->DialogAction()->level('danger')->label('死亡')->dialog(
|
||||
amis()->Dialog()->title('死亡')->body()->size('lg')
|
||||
),
|
||||
//返回
|
||||
amis()->Button()->actionType('confirm')->label(__('admin.back'))->primary()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 合户
|
||||
* 合户-todo
|
||||
*/
|
||||
public function mergeMasterForm()
|
||||
{
|
||||
|
|
@ -330,20 +342,65 @@ class PersonController extends AdminController
|
|||
]);
|
||||
}
|
||||
|
||||
public function doMergeMaster(){
|
||||
public function doMergeMaster(Request $request){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分户
|
||||
* 分户-todo
|
||||
*/
|
||||
public function splitMasterForm()
|
||||
{
|
||||
|
||||
return amis()->form()->title('')
|
||||
->api(admin_url('split_master'))
|
||||
->body([
|
||||
amis()->GroupControl()->body([
|
||||
$this->masterPicker('split_master_id', '分户对象', '输入 户主姓名 进行筛选')->required(),
|
||||
]),
|
||||
amis()->Divider(),
|
||||
amis()->Service()
|
||||
->api(admin_url('persons?_action=getData&state=1&master[id]=${split_master_id}&perPage=10&no_master=1'))
|
||||
->onEvent([
|
||||
'fetchInited' => [
|
||||
'actions' => [
|
||||
[
|
||||
'actionType'=>'setValue',
|
||||
"componentId" => "new_master_arr",
|
||||
"args" => [
|
||||
'value'=>'${event.data.items}'
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
])
|
||||
->body(
|
||||
amis()->TableControl('new_master_arr', '分户情况')->columnsTogglable(false)->id('new_master_arr')->columns([
|
||||
amis()->TableColumn('name', __('admin.persons.name'))->width('100px'),
|
||||
amis()->TableColumn('idcard', __('admin.persons.idcard')),
|
||||
amis()->TableColumn('master_connect', __('admin.persons.master_connect'))->width('60px'),
|
||||
amis()->CheckboxControl('is_split', '是否分户')->value(false),
|
||||
amis()->RadioControl('is_new_master', '新户主')->disabledOn('! is_split'),
|
||||
amis()->TextControl('new_master_connect', '新关系')->disabledOn('! is_split'),
|
||||
])->required()
|
||||
),
|
||||
amis()->Divider(),
|
||||
amis()->GroupControl()->body([
|
||||
amis()->DateControl('splited_at', '分户日期')->valueFormat('YYYY-MM-DD')->required(),
|
||||
amis()->TextControl('split_reason', '分户原因')->required()
|
||||
]),
|
||||
amis()->GroupControl()->body([
|
||||
amis()->TextControl('phone', '联系方式')->required(),
|
||||
amis()->TextControl('remark', '备注')
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function doSplitMaster(){
|
||||
|
||||
public function doSplitMaster(Request $request)
|
||||
{
|
||||
$res = $this->service->splitMaster($request->input('split_master_id'), $request->input('new_master_arr'), $request->input());
|
||||
|
||||
return $this->autoResponse($res, '分户');
|
||||
}
|
||||
|
||||
private function masterPicker($name = 'master', $label = '', $description = '')
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ Route::group([
|
|||
$router->resource('article_categories', \App\Admin\Controllers\ArticleCategoryController::class);
|
||||
|
||||
$router->resource('persons', \App\Admin\Controllers\PersonController::class);
|
||||
$router->post('split_master', [\App\Admin\Controllers\PersonController::class, 'doSplitMaster']);
|
||||
|
||||
|
||||
//数据管理
|
||||
|
|
|
|||
|
|
@ -21,12 +21,19 @@ class PersonFilter extends ModelFilter
|
|||
public function master($master)
|
||||
{
|
||||
if(isset($master['name'])){
|
||||
return $this->whereHas('master', function(Builder $q) use ($master){
|
||||
$query = $this->whereHas('master', function(Builder $q) use ($master){
|
||||
$q->where('name', $master['name']);
|
||||
});
|
||||
}elseif(isset($master['id'])){
|
||||
$query = $this->where('master_id', $master['id']);
|
||||
}else{
|
||||
return ;
|
||||
$query = $this->where('master_id', 0);
|
||||
}
|
||||
|
||||
if(request('no_master', 0)){
|
||||
$query->where('is_master', 0);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
/**
|
||||
* 身份证
|
||||
|
|
@ -77,7 +84,8 @@ class PersonFilter extends ModelFilter
|
|||
return $this->whereBetween('birthday', $birthday);
|
||||
}
|
||||
|
||||
public function isMaster($isMaster){
|
||||
public function isMaster($isMaster)
|
||||
{
|
||||
return $this->where('is_master', $isMaster);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Person extends Model
|
|||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
$q->orderBy('id', 'asc');
|
||||
$q->orderBy('master_id', 'asc')->orderBy('id', 'asc');
|
||||
}
|
||||
|
||||
//户主
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PersonChange extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const TYPE_IN = 1; //迁入
|
||||
public const TYPE_BIRTH = 2; //出生
|
||||
public const TYPE_OUT = 3; //迁出
|
||||
public const TYPE_DIE = 4; //死亡
|
||||
public const TYPE_MERGE = 5; //合户
|
||||
public const TYPE_SPLIT = 6; //分户
|
||||
public const TYPE_MIGRATE = 7; //迁移
|
||||
public const TYPE_CHANGE = 8; //变更户主
|
||||
|
||||
public static function typeMap()
|
||||
{
|
||||
return [
|
||||
self::TYPE_IN =>'迁入',
|
||||
self::TYPE_BIRTH =>'出生',
|
||||
self::TYPE_OUT =>'迁出',
|
||||
self::TYPE_DIE =>'死亡',
|
||||
self::TYPE_MERGE =>'合户',
|
||||
self::TYPE_SPLIT =>'分户',
|
||||
self::TYPE_MIGRATE =>'迁移',
|
||||
self::TYPE_CHANGE =>'变更户主',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ use App\Models\Filters\PersonFilter;
|
|||
use App\Traits\UploadTrait;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\PersonChange;
|
||||
use DB;
|
||||
|
||||
/**
|
||||
* @method Person getModel()
|
||||
|
|
@ -83,4 +85,68 @@ class PersonService extends BaseService
|
|||
{
|
||||
return $this->query()->whereIn($this->primaryKey(), explode(',', $ids))->update(['valid'=> 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分户
|
||||
*
|
||||
* @param int $masterId
|
||||
* @param array $personArr
|
||||
* @param array $extends
|
||||
*
|
||||
*/
|
||||
public function splitMaster($masterId, $personArr = [], $extends)
|
||||
{
|
||||
$personList = collect($personArr);
|
||||
$newMaster = $personList->first(function ($item) {
|
||||
return isset($item['is_split']) && $item['is_split'] && isset($item['is_new_master']) && $item['is_new_master'];
|
||||
});
|
||||
if(empty($newMaster)){
|
||||
return $this->setError('分户失败,未选择新户主');
|
||||
}
|
||||
try{
|
||||
DB::beginTransaction();
|
||||
$personChangeLogs = [];
|
||||
//遍历分户成员情况, 并更新户主与户主关系
|
||||
|
||||
foreach($personList as $person){
|
||||
if(!$person['is_split']){//是否参与分户
|
||||
continue;
|
||||
}
|
||||
|
||||
$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'].']';
|
||||
}
|
||||
$personChangeLogs[] = [
|
||||
'person_id' => $person['id'],
|
||||
'type' => PersonChange::TYPE_SPLIT,
|
||||
'changed_at' => isset($extends['splited_at']) ? $extends['splited_at'] : null,
|
||||
'reason' => isset($extends['split_reason']) ? $extends['split_reason'] : null,
|
||||
'old_master' => $person['master_id'],
|
||||
'new_master' => $newMaster['id'],
|
||||
'extends_mark' => $changeMark,
|
||||
'remark' => isset($extends['remark']) ? $extends['remark'] : null,
|
||||
];
|
||||
|
||||
Person::where('id', $person['id'])->update([
|
||||
'master_id' => $newMaster['id'],
|
||||
'is_master' => $newMaster['id'] == $person['id'] ? true : false,
|
||||
'master_connect' => isset($person['new_master_connect']) ? $person['new_master_connect'] : ($newMaster['id'] == $person['id'] ? '户主':'')
|
||||
]);
|
||||
}
|
||||
//批量插入人口变动记录
|
||||
count($personChangeLogs) > 0 && PersonChange::insert($personChangeLogs);
|
||||
|
||||
DB::commit();
|
||||
}catch(Throwable $th){
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->setError('系统错误,请刷新后重试');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('person_changes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('person_id');
|
||||
$table->unsignedTinyInteger('type')->comment('变动类型(1-迁入,2-出生,3-迁出(迁出本村),4-死亡,5-合户,6-分户,7-迁移(内部变动),8-更换户主)');
|
||||
$table->timestamp('changed_at')->nullable()->comment('发生时间');
|
||||
$table->string('reason')->nullable()->comment('原因');
|
||||
$table->unsignedBigInteger('old_master')->nullable()->comment('老户主');
|
||||
$table->unsignedBigInteger('new_master')->nullable()->comment('新户主');
|
||||
$table->string('phone')->nullable()->comment('联系电话');
|
||||
$table->text('extends')->nullable()->comment('额外信息');
|
||||
$table->string('extends_mark')->nullable()->comment('额外信息-简述');
|
||||
$table->string('remark')->nullable()->comment('备注');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('person_changes');
|
||||
}
|
||||
};
|
||||
|
|
@ -375,5 +375,8 @@ return [
|
|||
'health' => '身体状况',
|
||||
'phone' => '联系方式',
|
||||
'remark' => '备注',
|
||||
|
||||
//分户操作
|
||||
'split_master' => '分户',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue