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

master
songweizong 4 months ago
commit 466bafcccf

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

Loading…
Cancel
Save