feat: 微客宝H5客户端 - 基础架构+核心页面
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Care\CareProfile;
|
||||
use App\Models\Care\CareRecord;
|
||||
use App\Models\Crm\Contract;
|
||||
use App\Models\Crm\Customer;
|
||||
use App\Models\Meal\DailyMealPlan;
|
||||
use App\Models\Nanny\NannyOrder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* 首页汇总数据
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
/** @var Customer $customer */
|
||||
$customer = $request->user();
|
||||
|
||||
// 当前客户基本信息
|
||||
$customerInfo = [
|
||||
'name' => $customer->name,
|
||||
'phone' => $customer->phone,
|
||||
'expected_date' => $customer->expected_date,
|
||||
'actual_date' => $customer->actual_date,
|
||||
];
|
||||
|
||||
// 护理档案 → 最新护理记录3条
|
||||
$careProfile = CareProfile::withoutGlobalScope('store')
|
||||
->where('customer_id', $customer->id)
|
||||
->first();
|
||||
|
||||
$careRecords = [];
|
||||
if ($careProfile) {
|
||||
$careRecords = CareRecord::withoutGlobalScope('store')
|
||||
->where('care_profile_id', $careProfile->id)
|
||||
->with('nurse:id,name')
|
||||
->latest('recorded_at')
|
||||
->limit(3)
|
||||
->get();
|
||||
}
|
||||
|
||||
// 今日膳食
|
||||
$todayMeals = DailyMealPlan::withoutGlobalScope('store')
|
||||
->where('customer_id', $customer->id)
|
||||
->whereDate('plan_date', today())
|
||||
->get();
|
||||
|
||||
// 当前合同(最新1条)
|
||||
$contract = Contract::withoutGlobalScope('store')
|
||||
->where('customer_id', $customer->id)
|
||||
->latest()
|
||||
->first(['id', 'contract_no', 'status', 'start_date', 'end_date', 'total_amount']);
|
||||
|
||||
// 月嫂信息(进行中派单)
|
||||
$nannyOrder = NannyOrder::withoutGlobalScope('store')
|
||||
->where('customer_id', $customer->id)
|
||||
->where('status', 2)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($nannyOrder) {
|
||||
$nannyOrder->load('nanny:id,name,level,phone');
|
||||
}
|
||||
|
||||
return $this->success(compact(
|
||||
'customerInfo',
|
||||
'careRecords',
|
||||
'todayMeals',
|
||||
'contract',
|
||||
'nannyOrder'
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user