Merge branch 'master' of /mnt/git/v2.tiantianxinye.365care

master
songweizong 4 months ago
commit 18d092e35a

@ -518,13 +518,22 @@ class StatisticsController extends CommonController
$list = []; $list = [];
foreach ($productItem as $item) { foreach ($productItem as $item) {
foreach ($factor as $factor_item) { foreach ($factor as $factor_item) {
$total = OrderItems::where('product_item_id', $item->id) $query = OrderItems::where('product_item_id', $item->id)
->whereIn("bed_id", $bedIds) ->whereIn("bed_id", $bedIds)
->whereRaw("factors like '%\"factor_item_id\": {$factor_item->id}%'") ->whereRaw("factors like '%\"factor_item_id\": {$factor_item->id}%'")
->whereNotNull('paid_at') ->whereNotNull('paid_at')
->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'") ->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'");
->sum('total');
$totalPrice = $item->price + $factor_item->price; $total = $query->sum('total');
$count = $query->count();
// 如果有实际订单数据,使用平均单价;否则使用理论价格
if ($count > 0 && $total > 0) {
$totalPrice = round($total / $count, 2);
} else {
$totalPrice = $item->price + $factor_item->price;
}
$list[] = [ $list[] = [
'name' => $totalPrice . '元/天', 'name' => $totalPrice . '元/天',
'total_price' => $totalPrice, 'total_price' => $totalPrice,

Loading…
Cancel
Save