liyinglin 2 years ago
parent 0d8ff2d35a
commit 7f0e3319e7

@ -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
];
}
}

Loading…
Cancel
Save