From ebc9a42c92075f8a194f4b13ed2930c2ed3f897f Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 21 Nov 2022 11:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=A7=E9=87=8F=E4=BA=A7?= =?UTF-8?q?=E5=80=BC=E5=BE=80=E4=B8=87=E8=BF=9B=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Resources/CropYieldResource.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/Http/Resources/CropYieldResource.php b/app/Http/Resources/CropYieldResource.php index e7b8194..b45cfb0 100644 --- a/app/Http/Resources/CropYieldResource.php +++ b/app/Http/Resources/CropYieldResource.php @@ -26,11 +26,11 @@ class CropYieldResource extends JsonResource 'crop_id' => $this->crop_id, 'time_year' => $this->time_year, 'quarter' => $this->quarter, - 'yield' => $this->yield.$this->whenLoaded('crop', function () { + 'yield' => $this->formatNumber($this->yield).$this->whenLoaded('crop', function () { return $this->crop?->unit ?? ''; }, ''), - 'output' => $this->output.'元', - 'cultivated' => $this->cultivated.'亩', + 'output' => $this->formatNumber($this->output).'元', + 'cultivated' => $this->formatNumber($this->cultivated).'亩', 'extends' => $this->extends, 'created_by' => $this->whenLoaded('createdBy', function () { return $this->createdBy?->name; @@ -38,4 +38,12 @@ class CropYieldResource extends JsonResource 'created_at' => strtotime($this->created_at) ?? 0, //录入时间 ]; } + + private function formatNumber($number){ + if($number > 10000){ + return round($number/10000).'万'; + }else{ + return $number; + } + } }