From 3abfb798c5b596f8c589096c73d16e430aa7738c Mon Sep 17 00:00:00 2001 From: TL Date: Tue, 26 Jul 2022 18:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Repositories/CustomerRepo.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/beike/Repositories/CustomerRepo.php b/beike/Repositories/CustomerRepo.php index 2ecc35f9..4a91c287 100644 --- a/beike/Repositories/CustomerRepo.php +++ b/beike/Repositories/CustomerRepo.php @@ -13,6 +13,7 @@ namespace Beike\Repositories; use Beike\Models\Customer; use Beike\Models\CustomerWishlist; +use Beike\Models\Product; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; @@ -142,9 +143,20 @@ class CustomerRepo return $customer->wishlists()->with('product.description')->paginate(20); } + /** + * @param $product, 商品id或对象 + * @param $customer, 顾客id或对象 + * @return int + */ public static function inWishlist($product, $customer) { - + if ($product instanceof Product) { + $product = $product->id; + } + if (!$customer instanceof Customer) { + $customer = Customer::query()->findOrFail($customer); + } + return $customer->wishlists()->where('product_id', $product)->count(); } }