From 7f0e3319e761d76a110237cdb4c6aeb6468b24b8 Mon Sep 17 00:00:00 2001 From: liyinglin Date: Wed, 3 Jan 2024 19:07:35 +0800 Subject: [PATCH] 1 --- .../Admin/StatisticsController.php | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index c1de405..50c8d8c 100755 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ b/app/Http/Controllers/Admin/StatisticsController.php @@ -405,12 +405,17 @@ class StatisticsController extends CommonController $query->whereIn('id', $areaId); } })->paginate(10); + + $product = Product::where('project_id', $project_id)->first(); + $productItem = ProductItems::where('product_id', $product->id)->get(); + $factor = FactorItems::where('factor_id', $product->factor_id)->get(); + foreach ($data as $item) { // 获取所有床位id $bedIds = Bed::where('area_id', $item->id)->pluck('id'); $order = Orders::whereIn('bed_id', $bedIds)->where('status', 100)->get(); $item->order_total = $order->sum('total'); - $item->lies = $this->getLies($project_id, $order->pluck('id')); + $item->lies = $this->getLies($bedIds, $productItem, $factor); } // 获取所有列 $lie = array_column($data[0]->lies, 'name'); @@ -420,20 +425,22 @@ class StatisticsController extends CommonController /** * 获取动态列 */ - public function getLies($project_id, $orderIds) + public function getLies($bedIds, $productItem, $factor) { - $product = Product::where('project_id', $project_id)->first(); - $productItem = ProductItems::where('product_id', $product->id)->get(); - $factor = FactorItems::where('factor_id', $product->factor_id)->get(); $list = []; foreach ($productItem as $item) { - foreach ($factor as $v) { + foreach ($factor as $factor_item) { + $total = OrderItems::where('product_item_id', $item->id) + ->whereIn("bed_id", $bedIds) + ->whereRaw("factors like '%\"factor_item_id\": $factor_item->id%'") + ->sum('total'); + $list [] = [ - 'name' => $item->price + $v->price . '元/天', - 'total_price' => $item->price + $v->price, + 'name' => $item->price + $factor_item->price . '元/天', + 'total_price' => $item->price + $factor_item->price, 'product_item_id' => $item->id, - 'factor_item_id' => $v->id, - 'total' => $this->lieToMoney($item->id, $v->id, $orderIds) + 'factor_item_id' => $factor_item->id, + 'total' => $total ]; } }