45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Models\{User, Agent};
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
|
|
class UserCompany extends Form implements LazyRenderable
|
|
{
|
|
use LazyWidget;
|
|
public function handle(array $input)
|
|
{
|
|
$id = $this->payload['id'] ?? 0;
|
|
$user = User::findOrFail($id);
|
|
try {
|
|
DB::beginTransaction();
|
|
$user->userInfo->update([
|
|
'is_company' => $input['is_company']
|
|
]);
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
return $this->response()->error('操作失败:'.$th->getMessage());
|
|
}
|
|
|
|
return $this->response()->success(__('admin.update_succeeded'))->refresh();
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$id = $this->payload['id'] ?? 0;
|
|
$user = User::with(['userInfo'])->findOrFail($id);
|
|
|
|
$this->radio('is_company', '员工')->value($user->userInfo->is_company)->options([1 => '是', 0 => '否']);
|
|
}
|
|
}
|