master
cody 4 months ago
parent 7b517164f6
commit 3c71635801

@ -93,17 +93,29 @@ class StatisticsController extends CommonController
$query->where("project_id", $project_id);
})->pluck("paramedic_id")->toArray();
$query->where("project_id", $project_id)->orWhereIn("id", $order_item_paramedic_ids);
})->with(["orderItems" => function ($query) use ($month, $project_id) {
$query->whereRaw("(DATE_FORMAT(`service_date`,'%Y-%m') = '{$month}' or DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}')")
->where("total", ">", 0)
->whereHas("order", function ($query) use ($project_id) {
$query->where("project_id", $project_id);
})
->with(["order", "product", "productItem", "productParamedicLevel", "paramedic" => function ($query) {
$query->withoutGlobalScope(AdminProjectScope::class);
}, "bed", "room", "building", "area"])
->orderBy("id");
}])->get();
})->with([
"orderItems" => function ($query) use ($month, $project_id) {
$query->whereRaw("(DATE_FORMAT(`service_date`,'%Y-%m') = '{$month}' or DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}')")
->where("total", ">", 0)
->whereHas("order", function ($query) use ($project_id) {
$query->where("project_id", $project_id);
})
->with([
"order",
"product",
"productItem",
"productParamedicLevel",
"paramedic" => function ($query) {
$query->withoutGlobalScope(AdminProjectScope::class);
},
"bed",
"room",
"building",
"area"
])
->orderBy("id");
}
])->get();
$allItems = collect();
foreach ($paramedics as $paramedic) {
@ -207,8 +219,10 @@ class StatisticsController extends CommonController
$factors = json_decode($orderItem->factors, true);
$parent_factors = json_decode($orderItem->order->factors, true);
if (!in_array("所在科室", collect($factors)->pluck("factor_name")->toArray())
&& in_array("所在科室", collect($parent_factors)->pluck("factor_name")->toArray())) {
if (
!in_array("所在科室", collect($factors)->pluck("factor_name")->toArray())
&& in_array("所在科室", collect($parent_factors)->pluck("factor_name")->toArray())
) {
$add = collect($parent_factors)->keyBy("factor_name")["所在科室"];
$factors[] = $add;
$orderItem->update([
@ -299,16 +313,16 @@ class StatisticsController extends CommonController
"patients" => function ($query) use ($before_datetime) {
$query->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")->orderBy("id", "desc");
},
// "oneBalance" => function ($query) use ($before_datetime) {
// "oneBalance" => function ($query) use ($before_datetime) {
// $query->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")->orderBy("id", "desc");
// }
])
// ->whereHas("oneBalance", function ($query) use ($before_datetime) {
// ->whereHas("oneBalance", function ($query) use ($before_datetime) {
// $query->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")->where("balance", ">", 0)->orderBy("id", "desc");
// })
->whereHas("orders", function ($query) use ($before_datetime, $project_id) {
$query
// ->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")
// ->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")
->where("project_id", $project_id);
})
->get();
@ -375,8 +389,12 @@ class StatisticsController extends CommonController
public function huli(Request $request)
{
$projects = (new StatisticsController())->_checkProjects();
$defaultProjectsId = ($projects[0]->id) ?? '';
$projects = $this->_checkProjects();
if (!$projects->count()) {
return $this->error($this->noProjects);
}
$firstProject = $projects->first();
$defaultProjectsId = $firstProject ? $firstProject->id : '';
$project_id = $request->get('project_id', $defaultProjectsId);
$month = request()->month ?? date("Y-m");
@ -389,9 +407,9 @@ class StatisticsController extends CommonController
$areaId = [];
if ($hushizhang) {
$user = auth()->user();
$areaId = AdminAreaLink::where(function ($qeury) use ($project_id) {
$areaId = AdminAreaLink::where(function ($query) use ($project_id) {
if ($project_id) {
$qeury->where('project_id', $project_id);
$query->where('project_id', $project_id);
}
})->where('admin_id', $user->id)->pluck('area_id');
}
@ -403,16 +421,20 @@ class StatisticsController extends CommonController
$data->appends($request->all())->render();
$product = Product::where('project_id', $project_id)->first();
if (!$product) {
return $this->error("该项目下没有找到产品");
}
$productItem = ProductItems::where('product_id', $product->id)->get();
$factor = FactorItems::where('factor_id', $product->statistic_factor_id)->get();
$sumOrderTotal = 0;
foreach ($data as $item) {
// 获取所有床位id
$bedIds = Bed::where('area_id', $item->id)->pluck('id');
// 总和
// 总和 - 使用DATE_FORMAT精确匹配月份
$item->order_total = OrderItems::whereIn('product_item_id', $productItem->pluck('id'))
->whereIn("bed_id", $bedIds)
->where('paid_at', 'like', '%' . $month . '%')
->whereNotNull('paid_at')
->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'")
->sum('total');
$sumOrderTotal += $item->order_total;
// 子项
@ -420,12 +442,15 @@ class StatisticsController extends CommonController
}
// 获取所有列
$lie = [];
if (isset($data[0]->lies)) {
$lie = array_column($data[0]->lies, 'name');
if ($data->total() > 0) {
$firstDataItem = $data->items()[0] ?? null;
if ($firstDataItem && isset($firstDataItem->lies)) {
$lie = array_column($firstDataItem->lies, 'name');
}
}
$months = $this->_getMonths();
return view($this->bladePath . ".huli", compact("sumOrderTotal", "data", "month", "lie", "projects", "project_id"));
return view($this->bladePath . ".huli", compact("sumOrderTotal", "data", "month", "lie", "projects", "project_id", "months"));
}
/**
@ -438,12 +463,14 @@ class StatisticsController extends CommonController
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%'")
->where('paid_at', 'like', '%' . $month . '%')
->whereRaw("factors like '%\"factor_item_id\": {$factor_item->id}%'")
->whereNotNull('paid_at')
->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'")
->sum('total');
$list [] = [
'name' => $item->price + $factor_item->price . '元/天',
'total_price' => $item->price + $factor_item->price,
$totalPrice = $item->price + $factor_item->price;
$list[] = [
'name' => $totalPrice . '元/天',
'total_price' => $totalPrice,
'product_item_id' => $item->id,
'factor_item_id' => $factor_item->id,
'total' => $total

BIN
public/h5/.DS_Store vendored

Binary file not shown.
Loading…
Cancel
Save