From 3747375a926563dfdf0f9ee28997b35ad813c40e Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 23 Feb 2022 11:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86N+1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Resources/AfterSaleSimpleResource.php | 4 +++- .../Api/Http/Resources/ArticleResource.php | 4 +++- .../Api/Http/Resources/ArticleSimpleResource.php | 4 +++- .../Api/Http/Resources/CouponResource.php | 1 - .../Dealer/DealerEarningSimpleResource.php | 4 +++- .../Http/Resources/Dealer/DealerFansResource.php | 16 ++++++++++++---- app/Endpoint/Api/Http/Resources/FansResource.php | 16 ++++++++++++---- .../Api/Http/Resources/MessageResource.php | 4 +++- 8 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/Endpoint/Api/Http/Resources/AfterSaleSimpleResource.php b/app/Endpoint/Api/Http/Resources/AfterSaleSimpleResource.php index 5fb51b7b..0d1da76e 100644 --- a/app/Endpoint/Api/Http/Resources/AfterSaleSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/AfterSaleSimpleResource.php @@ -16,7 +16,9 @@ class AfterSaleSimpleResource extends JsonResource { return [ 'id' => $this->id, - 'order_sn' => $this->whenLoaded('order')?->sn, + 'order_sn' => $this->whenLoaded('order', function () { + return $this->order->sn; + }, ''), 'product'=>[ 'name' => $this->orderProduct->name, 'cover' => $this->orderProduct->cover, diff --git a/app/Endpoint/Api/Http/Resources/ArticleResource.php b/app/Endpoint/Api/Http/Resources/ArticleResource.php index b8f5d763..dc6a897a 100644 --- a/app/Endpoint/Api/Http/Resources/ArticleResource.php +++ b/app/Endpoint/Api/Http/Resources/ArticleResource.php @@ -22,7 +22,9 @@ class ArticleResource extends JsonResource 'content'=>$this->content, 'points'=> $this->points, 'likes' => $this->likes, - 'like_status' => $this->whenLoaded('likesInfo', $this->likesInfo->count() > 0), + 'like_status' => $this->whenLoaded('likesInfo', function () { + return $this->likesInfo->count() > 0; + }, false), 'has_read' => $this->hasRead($request->user()), 'media_type'=> $this->media_type, 'media_content'=> json_decode($this->media_content, true), diff --git a/app/Endpoint/Api/Http/Resources/ArticleSimpleResource.php b/app/Endpoint/Api/Http/Resources/ArticleSimpleResource.php index e9736a6a..789d25bb 100644 --- a/app/Endpoint/Api/Http/Resources/ArticleSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/ArticleSimpleResource.php @@ -21,7 +21,9 @@ class ArticleSimpleResource extends JsonResource 'cover' => $this->cover, 'points'=> $this->points, 'likes' => $this->likes, - 'like_status' => $this->whenLoaded('likesInfo', $this->likesInfo->count() > 0), + 'like_status' => $this->whenLoaded('likesInfo', function () { + return $this->likesInfo->count() > 0; + }, false), 'jump_type' => $this->jump_type, 'jump_link' => (string) $this->jump_link, 'created_at' => $this->created_at->toDateTimeString(), diff --git a/app/Endpoint/Api/Http/Resources/CouponResource.php b/app/Endpoint/Api/Http/Resources/CouponResource.php index 0c0f10e2..2fdee74c 100644 --- a/app/Endpoint/Api/Http/Resources/CouponResource.php +++ b/app/Endpoint/Api/Http/Resources/CouponResource.php @@ -20,7 +20,6 @@ class CouponResource extends JsonResource 'type' => $this->type, 'amount' => $this->amount, 'threshold' => $this->threshold, - // 'receive_status' => $this->whenLoaded('likesInfo', $this->likesInfo->count() > 0), ]; } } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php index 6117815c..29517787 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php @@ -22,7 +22,9 @@ class DealerEarningSimpleResource extends JsonResource 'status' => $this->status_format, 'status_name' => $this->status_name, 'is_payer' => $this->payer_id ? ($this->payer_id == $request->user()->id) : false, - 'beneficiary_phone' => (string) $this->whenLoaded('user', $this->user->phone, ''), + 'beneficiary_phone' => (string) $this->whenLoaded('user', function () { + return $this->user?->phone ?? ''; + }, ''), // 'settle_at' ]; } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/DealerFansResource.php b/app/Endpoint/Api/Http/Resources/Dealer/DealerFansResource.php index 25174055..09450b61 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/DealerFansResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/DealerFansResource.php @@ -17,10 +17,18 @@ class DealerFansResource extends JsonResource return [ 'id' => $this->id, 'phone' => $this->phone, - 'nickname' => (string) $this->whenLoaded('userInfo', $this->userInfo->nickname, ''), - 'avatar' => (string) $this->whenLoaded('userInfo', $this->userInfo->avatar, ''), - 'team_sales_value' => (string) $this->whenLoaded('dealer', $this->dealer->team_sales_value, 0), - 'lvl_name' => (string) $this->whenLoaded('dealer', $this->dealer->lvl_text, '未知'), + 'nickname' => (string) $this->whenLoaded('userInfo', function () { + return $this->userInfo->nickname; + }, ''), + 'avatar' => (string) $this->whenLoaded('userInfo', function () { + return $this->userInfo->avatar; + }, ''), + 'team_sales_value' => (string) $this->whenLoaded('dealer', function () { + return $this->dealer->team_sales_value; + }, 0), + 'lvl_name' => (string) $this->whenLoaded('dealer', function () { + return $this->dealer->lvl_text; + }, '未知'), ]; } } diff --git a/app/Endpoint/Api/Http/Resources/FansResource.php b/app/Endpoint/Api/Http/Resources/FansResource.php index 1a7d4ea6..343f932e 100644 --- a/app/Endpoint/Api/Http/Resources/FansResource.php +++ b/app/Endpoint/Api/Http/Resources/FansResource.php @@ -16,10 +16,18 @@ class FansResource extends JsonResource { return [ 'phone' => $this->phone, - 'nickname' => (string) $this->whenLoaded('userInfo', $this->userInfo->nickname, ''), - 'avatar' => (string) $this->whenLoaded('userInfo', $this->userInfo->avatar, ''), - 'value' => (string) $this->whenLoaded('userInfo', $this->userInfo->growth_value, 0), - 'level_name' => (string) $this->whenLoaded('userInfo', $this->userInfo->agent_level_name, '未知'), + 'nickname' => (string) $this->whenLoaded('userInfo', function () { + return $this->userInfo->nickname; + }, ''), + 'avatar' => (string) $this->whenLoaded('userInfo', function () { + return $this->userInfo->avatar; + }, ''), + 'value' => (string) $this->whenLoaded('userInfo', function () { + return $this->userInfo->growth_value; + }, 0), + 'level_name' => (string) $this->whenLoaded('userInfo', function () { + return $this->userInfo->agent_level_name; + }, '未知'), ]; } } diff --git a/app/Endpoint/Api/Http/Resources/MessageResource.php b/app/Endpoint/Api/Http/Resources/MessageResource.php index 26179b7f..362b1fc3 100644 --- a/app/Endpoint/Api/Http/Resources/MessageResource.php +++ b/app/Endpoint/Api/Http/Resources/MessageResource.php @@ -22,7 +22,9 @@ class MessageResource extends JsonResource 'ext' => $this->ext, 'jump_type' => $this->jump_type, 'jump_link' => (string) $this->jump_link, - 'has_read' => $this->whenLoaded('logs', $this->logs->count()>0), + 'has_read' => $this->whenLoaded('logs', function () { + return $this->logs->count() > 0; + }, false), 'created_at'=> $this->created_at->toDateTimeString(), ]; }