From 5633aa3631226b443bdbf0e79759244ca3fecbd6 Mon Sep 17 00:00:00 2001 From: weizong song Date: Wed, 5 Jul 2023 19:27:39 +0800 Subject: [PATCH] up --- app/Customer.php | 5 ++++ .../Admin/StatisticsController.php | 3 +- .../statistics/customer-balance.blade.php | 28 ++++++------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/Customer.php b/app/Customer.php index 981f758..bf54bd1 100644 --- a/app/Customer.php +++ b/app/Customer.php @@ -120,6 +120,11 @@ class Customer extends Authenticatable implements JWTSubject return $this->hasMany(Balance::class, "customer_id"); } + public function oneBalance() + { + return $this->hasOne(Balance::class, "customer_id"); + } + public function recharges() { return $this->hasMany(Recharge::class, "customer_id")->whereNotNull("paid_at"); diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index 968f673..7bdaae5 100755 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ b/app/Http/Controllers/Admin/StatisticsController.php @@ -255,11 +255,12 @@ class StatisticsController extends CommonController DB::enableQueryLog(); //todo:子订单的数量增加,用更省查询时间的方式获取项目相关数据 $customers = (new Customer()) + ->whereNull("deleted_at") ->with([ "patients" => function ($query) use ($before_datetime) { $query->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")->orderBy("id", "desc"); }, - "balances" => function ($query) use ($before_datetime) { + "oneBalance" => function ($query) use ($before_datetime) { $query->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")->orderBy("id", "desc"); } ]) diff --git a/resources/views/admin/statistics/customer-balance.blade.php b/resources/views/admin/statistics/customer-balance.blade.php index 2e84a79..4d66d8d 100755 --- a/resources/views/admin/statistics/customer-balance.blade.php +++ b/resources/views/admin/statistics/customer-balance.blade.php @@ -35,35 +35,25 @@ 客户手机号 客户家属 截止日期 - 充值汇总 - 退款汇总 - 扣款汇总 - 已到帐未结算余额表 + 未结算余额 @foreach($customers as $item) + @if(!$item->oneBalance) + @continue + @elseif (!($item->oneBalance->balance > 0)) + @continue + @endif + {{ $loop->iteration }} {{ $item->mobile }} - {{ $item->patients->count() ? $item->patients->first()->name : "无" }} + {{ $item->patients->count() ? $item->patients->last()->name : "无" }} {{ date("Y-m-d H:i:s",$before_datetime) }} - {{ $item->balances->filter(function($item) { return $item->belongs_type == "App\Models\Recharge"; })->sum("money") }} - {{ $item->balances->filter(function($item) { return $item->belongs_type == "App\Models\Refund"; })->sum("money") }} - {{ $item->balances->filter(function($item) { return $item->belongs_type == "App\Models\OrderItems"; })->sum("money") }} - balances->first()->balance ? "text-danger" : "" }}">{{ $item->balances->sum("money") }} + {{ $item->oneBalance->balance }} @endforeach - -   -   -   -   -   -   - 总计 - {{ $customers->each(function($customer) { $customer->balance = $customer->balances->sum("money"); })->sum("balance") }} -