logicComplex(function($q) use ($params) { // // 自定义 join、where、select // return $q->where('status', 1) // ->orderBy('created_at','desc') // ->paginate($params['limit'] ?? 15); // })->toArray(); // } // /** // * 复杂查询示例: // * 只要在 URL 里添加 ?complex_query=1, // * 并传入你需要的任何参数, // * `serviceList()` 就会走到这里来: // */ // protected function complexQuery(Request $request): array // { // // 假设前端传了 date_from、date_to // $from = $request->get('date_from'); // $to = $request->get('date_to'); // // 交给 CrudUtil 执行一个自定义 query // $pager = $this->logicComplex(function($q) use ($from, $to) { // $q->where('status', 1); // if ($from && $to) { // $q->whereBetween('created_at', [$from, $to]); // } // // 再加个排序 // $q->orderBy('created_at','desc'); // // 用 paginate 而不是 listAll // return $q->paginate( // /* perPage */ (int)request()->get('limit',15), // ['*'], // 'page', // (int)request()->get('page',1) // ); // }); // // 把 Paginator 转成数组格式 // return [ // 'total' => $pager->total(), // 'data' => $pager->items(), // ]; // } // protected function afterServiceList(array $res): array // { // // 对列表的 data 做处理 // $res['data'] = array_map(fn($i)=>[...], $res['data']); // return $res; // } // protected function afterServiceShow($item) // { // // 对详情对象处理 // $item['extra']=123; // return $item; // } // afterServiceStore/Update/Destroy 同理 // protected function afterServiceList(mixed $result): array // { // if ($result['records']) { // $result['records'] = array_map(fn($i) => [...$i], $result['records']); // } // return $result; // } }