39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Actions;
|
|
|
|
use App\Models\User;
|
|
use Encore\Admin\Actions\RowAction;
|
|
use Encore\Admin\Form;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SetParent extends RowAction
|
|
{
|
|
public $name = '设置推荐人';
|
|
|
|
public function handle(Model $model, Request $request)
|
|
{
|
|
$parent = User::find($request->parent_id);
|
|
$this->row->UpdateRelation($parent);
|
|
|
|
return $this->response()->success('操作成功')->refresh();
|
|
}
|
|
|
|
public function form()
|
|
{
|
|
$this->text('parent_id', '用户序号')->rules(['required', 'numeric', function ($attribute, $value, $fail) {
|
|
$parent = User::find($value);
|
|
if (!$parent) {
|
|
return $fail('未找到账号');
|
|
}
|
|
if (!in_array($parent->identity->identity_id, [2, 3, 4])) {
|
|
return $fail('账号等级不够');
|
|
}
|
|
}], [
|
|
'required' => '用户序号不能为空',
|
|
'numeric' => '用户序号必须为整数',
|
|
], '2');
|
|
}
|
|
}
|