liyinglin 2 years ago
parent 6b95a2873c
commit 336aa9c3f1

@ -21,6 +21,7 @@ use App\Models\OrderItems;
use App\Models\Orders;
use App\Models\Paramedic;
use App\Models\Product;
use App\Models\ProductItems;
use App\Models\Project;
use App\Models\Recharge;
use App\Models\Refund;
@ -408,14 +409,45 @@ class StatisticsController extends CommonController
// 获取所有床位id
$bedIds = Bed::where('area_id', $item->id)->pluck('id');
$order = Orders::whereIn('bed_id', $bedIds)->where('status', 100)->get();
$item->lies = $this->getLies($project_id, $order->pluck('id'));
}
dd($data->toArray());
return view($this->bladePath . ".huli", compact("data"));
}
/**
* 获取动态列
*/
public function getLies($project_id, $orderIds)
{
$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) {
$list[] = [
'name' => $item->price + $v->price . '元/天',
'total_price' => $item->price + $v->price,
'product_item_id' => $item->id,
'factor_item_id' => $v->id,
'total' => $this->lieToMoney($item->id, $v->id, $orderIds)
];
}
}
return $list;
}
/**
* 根据产品子项id和因素子项id算出收入
*/
public function lieToMoney($product_item_id, $factor_item_id, $orderIds)
{
$total = OrderItems::where('product_item_id', $product_item_id)
->whereJsonContains('factors->factor_item_id', $factor_item_id)
->whereIn('order_id', $orderIds)
->sum('total');
return $total;
}
}

Loading…
Cancel
Save