From 160b0bd3feb13c47f4ded6cb38e5b3b74f88f0b3 Mon Sep 17 00:00:00 2001 From: TL Date: Fri, 1 Jul 2022 10:10:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E9=A1=BE=E5=AE=A2=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Admin/Http/Controllers/CustomerController.php | 12 +++++------- beike/Repositories/CustomerGroupRepo.php | 3 +-- beike/Repositories/CustomerRepo.php | 5 +++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/beike/Admin/Http/Controllers/CustomerController.php b/beike/Admin/Http/Controllers/CustomerController.php index fa2a87bd..1419d132 100644 --- a/beike/Admin/Http/Controllers/CustomerController.php +++ b/beike/Admin/Http/Controllers/CustomerController.php @@ -66,19 +66,17 @@ class CustomerController extends Controller return json_success('创建成功!', $customer); } - public function destroy(Request $request) + public function destroy(Request $request, int $customerId) { - $customerId = $request->id ?? 0; CustomerRepo::delete($customerId); - return ['success' => true]; + return json_success('删除成功!'); } - public function restore(Request $request) + public function restore(Request $request, int $customerId) { - $customerId = $request->id ?? 0; - Customer::withTrashed()->find($customerId)->restore(); + CustomerRepo::restore($customerId); - return ['success' => true]; + return json_success('恢复成功!'); } } diff --git a/beike/Repositories/CustomerGroupRepo.php b/beike/Repositories/CustomerGroupRepo.php index b28315d1..3055c716 100644 --- a/beike/Repositories/CustomerGroupRepo.php +++ b/beike/Repositories/CustomerGroupRepo.php @@ -22,8 +22,7 @@ class CustomerGroupRepo */ public static function create($data) { - $id = CustomerGroup::query()->insertGetId($data); - return self::find($id); + return CustomerGroup::query()->create($data); } /** diff --git a/beike/Repositories/CustomerRepo.php b/beike/Repositories/CustomerRepo.php index 077b92f5..7ff3829e 100644 --- a/beike/Repositories/CustomerRepo.php +++ b/beike/Repositories/CustomerRepo.php @@ -91,5 +91,10 @@ class CustomerRepo return $builder->paginate(20)->withQueryString(); } + + public static function restore($id) + { + Customer::withTrashed()->find($id)->restore(); + } }