From ceb0aa06862ffb87ee206b290521ea3ec814fa1e Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Mon, 15 Aug 2022 18:42:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8E=E5=8F=B0=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=20https://guangdagit.com/beike/beikeshop/issues/76?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Admin/Http/Resources/ProductResource.php | 15 +++++++++------ beike/Models/Product.php | 5 ----- beike/Repositories/ProductRepo.php | 3 +++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/beike/Admin/Http/Resources/ProductResource.php b/beike/Admin/Http/Resources/ProductResource.php index 8207a0c1..02d3bc41 100644 --- a/beike/Admin/Http/Resources/ProductResource.php +++ b/beike/Admin/Http/Resources/ProductResource.php @@ -2,6 +2,7 @@ namespace Beike\Admin\Http\Resources; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class ProductResource extends JsonResource @@ -9,22 +10,24 @@ class ProductResource extends JsonResource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array */ - public function toArray($request) + public function toArray($request): array { + $masterSku = $this->master_sku; + $data = [ 'id' => $this->id, 'images' => array_map(function ($image) { return thumbnail($image); }, $this->images ?? []), 'name' => $this->description->name ?? '', - 'price_formatted' => $this->price_formatted, + 'price_formatted' => currency_format($masterSku->price), 'active' => $this->active, 'position' => $this->position, - 'created_at' => (string)$this->created_at, - 'deleted_at' => (string)$this->deleted_at, + 'created_at' => time_format($this->created_at), + 'deleted_at' => time_format($this->deleted_at), 'url_edit' => admin_route('products.edit', $this->id), ]; diff --git a/beike/Models/Product.php b/beike/Models/Product.php index a0bd4ec2..5cdc4201 100644 --- a/beike/Models/Product.php +++ b/beike/Models/Product.php @@ -59,11 +59,6 @@ class Product extends Base return $this->hasOne(CustomerWishlist::class)->where('customer_id', current_customer() ? current_customer()->id : 0); } - public function getPriceFormattedAttribute(): string - { - return '$' . $this->price; - } - public function getUrlAttribute() { return shop_route('products.show', ['product' => $this]); diff --git a/beike/Repositories/ProductRepo.php b/beike/Repositories/ProductRepo.php index 41e95de2..409a357e 100644 --- a/beike/Repositories/ProductRepo.php +++ b/beike/Repositories/ProductRepo.php @@ -120,6 +120,9 @@ class ProductRepo $builder->onlyTrashed(); } + $sort = $data['sort'] ?? 'updated_at'; + $order = $data['order'] ?? 'desc'; + $builder->orderBy($sort, $order); return $builder; }