|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Models\Bed;
|
|
|
|
|
use App\Models\OrderItems;
|
|
|
|
|
use App\Models\Orders;
|
|
|
|
|
use App\Models\Paramedic;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
|
|
|
|
|
class HomeController extends CommonController
|
|
|
|
|
{
|
|
|
|
|
public $bladePath = "admin";
|
|
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
// $month = date("Y-m");
|
|
|
|
|
// $order_items = OrderItems::whereHas("order")->whereRaw("DATE_FORMAT(`service_date`,'%Y-%m') = '{$month}'")
|
|
|
|
|
// ->where("total", ">", 0)->get();
|
|
|
|
|
// $order_items_count = $order_items->count();
|
|
|
|
|
// $total = $order_items->sum("total");
|
|
|
|
|
// $orders_count = $order_items->groupBy("order_id")->count();
|
|
|
|
|
//
|
|
|
|
|
// foreach ($order_items as &$item) {
|
|
|
|
|
// $item = $item->calculateFee();
|
|
|
|
|
// }
|
|
|
|
|
// $total_paramedic = $order_items->sum("paramedic_total");
|
|
|
|
|
// $fee = $total - $total_paramedic;
|
|
|
|
|
// $laravel_duration = microtime(true) - LARAVEL_START;
|
|
|
|
|
|
|
|
|
|
return view($this->bladePath . ".home");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 统计
|
|
|
|
|
*/
|
|
|
|
|
public function statistic()
|
|
|
|
|
{
|
|
|
|
|
// 护工陪护
|
|
|
|
|
$paramedic = [
|
|
|
|
|
'total' => Paramedic::count(),
|
|
|
|
|
'has_accompany' => Paramedic::whereHas('ongoingOrders')->count(),
|
|
|
|
|
'no_accompany' => Paramedic::whereDoesntHave('ongoingOrders')->count(),
|
|
|
|
|
'accompany_order' => Orders::where('status', Orders::STATUS_ONGOING)->count(),
|
|
|
|
|
];
|
|
|
|
|
// 床位陪护
|
|
|
|
|
$bed = [
|
|
|
|
|
'total' => Bed::count(),
|
|
|
|
|
'has_accompany' => Bed::whereHas('onGoingOrder')->count(),
|
|
|
|
|
'no_accompany' => Bed::whereDoesntHave('onGoingOrder')->count(),
|
|
|
|
|
];
|
|
|
|
|
// 陪护统计表
|
|
|
|
|
$project = Project::get();
|
|
|
|
|
foreach ($project as $item) {
|
|
|
|
|
$item->total = Orders::where('project_id', $item->id)->count();
|
|
|
|
|
}
|
|
|
|
|
// 最新陪护单
|
|
|
|
|
$lastOrder = Orders::with('project')
|
|
|
|
|
->where('status', Orders::STATUS_UNCONFIRMED)
|
|
|
|
|
->orderBy('id', 'desc')
|
|
|
|
|
->limit(8)
|
|
|
|
|
->get();
|
|
|
|
|
// 最新出院信息
|
|
|
|
|
$outOrder = Orders::with('project')
|
|
|
|
|
->where('status', Orders::STATUS_FINISHED)
|
|
|
|
|
->orderBy('id', 'desc')
|
|
|
|
|
->limit(8)
|
|
|
|
|
->get();
|
|
|
|
|
// 最新投诉信息
|
|
|
|
|
$tip = Orders::with('project')
|
|
|
|
|
->whereNotNull('comment')
|
|
|
|
|
->orderBy('id', 'desc')
|
|
|
|
|
->limit(8)
|
|
|
|
|
->get();
|
|
|
|
|
// 上月满意度评价分析
|
|
|
|
|
$satisfied = Orders::with('project', 'paramedic')
|
|
|
|
|
->whereNotNull('comment')
|
|
|
|
|
->where('created_at', 'like', '%' . date('Y-m', strtotime('-1 month') . '%'))
|
|
|
|
|
->orderBy('score', 'desc')
|
|
|
|
|
->limit(8)
|
|
|
|
|
->get();
|
|
|
|
|
// 本月营收分析
|
|
|
|
|
$income = Project::get();
|
|
|
|
|
foreach ($income as $item) {
|
|
|
|
|
$item->total = Orders::where('project_id', $item->id)
|
|
|
|
|
->where('created_at', 'like', '%' . date('Y-m') . '%')
|
|
|
|
|
->where('status', Orders::STATUS_FINISHED)
|
|
|
|
|
->sum('paid_total');
|
|
|
|
|
}
|
|
|
|
|
// 本月陪护订单
|
|
|
|
|
$monthAccompany = Project::get();
|
|
|
|
|
foreach ($income as $item) {
|
|
|
|
|
$item->total = Orders::where('project_id', $item->id)
|
|
|
|
|
->where('created_at', 'like', '%' . date('Y-m') . '%')
|
|
|
|
|
->count();
|
|
|
|
|
}
|
|
|
|
|
return $this->ajaxSuccess('获取成功', compact('paramedic', 'bed', 'project',
|
|
|
|
|
'lastOrder', 'outOrder', 'tip', 'satisfied', 'income', 'monthAccompany'));
|
|
|
|
|
}
|
|
|
|
|
}
|