|
|
|
|
@ -156,23 +156,30 @@ class PlanController extends Controller
|
|
|
|
|
$page = request('page');
|
|
|
|
|
$pageSize = request('pageSize');
|
|
|
|
|
$searchInfo = request('searchInfo');
|
|
|
|
|
|
|
|
|
|
// 构建 orders 子查询:每个 plan_id 只保留一条记录(例如 id 最大的)
|
|
|
|
|
$orderSubQuery = DB::table('orders as b')
|
|
|
|
|
->select(DB::raw('MAX(id) as max_order_id'), 'plan_id')
|
|
|
|
|
->whereIn('status', [1, 2, 4])
|
|
|
|
|
->groupBy('plan_id');
|
|
|
|
|
|
|
|
|
|
$list = DB::table('plans as a')
|
|
|
|
|
->select('a.*','b.name as username','b.phone')
|
|
|
|
|
->leftJoin('orders as b', function($join) {
|
|
|
|
|
$join->on('a.id', '=', 'b.plan_id')
|
|
|
|
|
->whereIn('b.status', [2,4]);
|
|
|
|
|
->select('a.*', 'b.name as username', 'b.phone')
|
|
|
|
|
->leftJoinSub($orderSubQuery, 'filtered_orders', function ($join) {
|
|
|
|
|
$join->on('a.id', '=', 'filtered_orders.plan_id');
|
|
|
|
|
})
|
|
|
|
|
->leftJoin('orders as b', 'filtered_orders.max_order_id', '=', 'b.id')
|
|
|
|
|
->where('a.is_del', 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($searchInfo['date'])) {
|
|
|
|
|
$searchInfo['date'] = date('Y-m-d');
|
|
|
|
|
}
|
|
|
|
|
if (isset($searchInfo['plan_type']) and $searchInfo['plan_type']===0) {
|
|
|
|
|
$list = $list->where(['a.type' => 0]);
|
|
|
|
|
if (isset($searchInfo['plan_type']) && $searchInfo['plan_type'] === 0) {
|
|
|
|
|
$list = $list->where('a.type', 0);
|
|
|
|
|
}
|
|
|
|
|
$list = $list->where(['a.date' => $searchInfo['date']]);
|
|
|
|
|
$list = $list->orderBy('a.time', 'asc')->get();
|
|
|
|
|
$list = $list->where('a.date', $searchInfo['date'])
|
|
|
|
|
->orderBy('a.time', 'asc')
|
|
|
|
|
->get();
|
|
|
|
|
$plan_model=DB::table('plan_model_time')
|
|
|
|
|
->select('plan_model_time.*', 'plan_type.name as plan_type_name')
|
|
|
|
|
->leftJoin('plan_type', 'plan_type.id', '=', 'plan_model_time.plan_type_id')
|
|
|
|
|
@ -188,7 +195,7 @@ class PlanController extends Controller
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!empty($searchInfo['plan_type']) and$searchInfo['plan_type']==$v->plan_type_id and $v->type<>0 ){
|
|
|
|
|
if(!empty($searchInfo['plan_type']) and $searchInfo['plan_type']==$v->plan_type_id and $v->type<>0 ){
|
|
|
|
|
$list_l[]=$list[$k];
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
|