From 81dce619a5c8dbaacdb044b9a9fc43f2d92edd2d Mon Sep 17 00:00:00 2001 From: TL Date: Mon, 4 Jul 2022 20:18:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Repositories/AddressRepo.php | 17 ++++++++++------- beike/Shop/Services/AddressService.php | 8 +++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/beike/Repositories/AddressRepo.php b/beike/Repositories/AddressRepo.php index 86687b77..d9b5c9ae 100644 --- a/beike/Repositories/AddressRepo.php +++ b/beike/Repositories/AddressRepo.php @@ -22,20 +22,23 @@ class AddressRepo */ public static function create($data) { - $id = Address::query()->insertGetId($data); - return self::find($id); + $address = Address::query()->create($data); + return $address; } /** - * @param $id + * @param $address * @param $data - * @return bool|int + * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|mixed + * @throws \Exception */ - public static function update($id, $data) + public static function update($address, $data) { - $address = Address::query()->find($id); + if (!$address instanceof Address) { + $address = Address::query()->find($address); + } if (!$address) { - throw new \Exception("地址id {$id} 不存在"); + throw new \Exception("地址id {$address} 不存在"); } $address->update($data); return $address; diff --git a/beike/Shop/Services/AddressService.php b/beike/Shop/Services/AddressService.php index 3f3810c8..87ea82e3 100644 --- a/beike/Shop/Services/AddressService.php +++ b/beike/Shop/Services/AddressService.php @@ -26,8 +26,10 @@ class AddressService public static function update($id, $data) { - $address = AddressRepo::update($id, $data); - - return $address; + $address = AddressRepo::find($id); + if ($address->customer_id != current_customer()->customer_id) { + $address; + } + return AddressRepo::update($address, $data); } }