88
99namespace App \Services ;
1010
11+ use App \Http \Repository \ApiRepository ;
1112use App \Http \Repository \MultithreadingRepository ;
1213use App \Models \ApiExcel ;
13- use App \Models \ApiExcelLogs ;
1414use Hhxsv5 \LaravelS \Swoole \WebSocketHandlerInterface ;
1515use Swoole \Http \Request ;
1616use Swoole \WebSocket \Frame ;
2121 */
2222class WebSocketService implements WebSocketHandlerInterface
2323{
24+ public $ perPage = 10 ;
25+
2426 // 声明没有参数的构造函数
2527 public function __construct ()
2628 {
@@ -37,10 +39,13 @@ public function onOpen($server, $request)
3739 // \Log::info('New WebSocket connection', [$request->fd, request()->all(), session()->getId(), session('xxx'), session(['yyy' => time()])]);
3840 // 1. 根据 api_excel 的 id 查询总数,
3941 $ req = $ request ->get ;
42+ $ this ->perPage = isset ($ req ['perPage ' ]) ? intval ($ req ['perPage ' ]) : 10 ;
43+
4044 $ action = $ req ['action ' ] ?? '' ;
4145 switch ($ action ) {
4246 case 'api_excel ' :
43-
47+ return $ this ->apiExcel ();
48+ break ;
4449 }
4550
4651 if (isset ($ req ['id ' ]) && $ req ['id ' ] == floor ($ req ['id ' ])) {
@@ -91,4 +96,24 @@ public function outJson($code = 200, $data = [], $reason = 'success')
9196
9297 return json_encode (['code ' => $ code , 'reason ' => $ reason , 'data ' => $ data ], JSON_UNESCAPED_UNICODE );
9398 }
99+
100+ private function apiExcel ()
101+ {
102+ $ user_id = auth ('api ' )->user ()['id ' ];
103+
104+ // 查询对应用户的上传数据
105+ $ where = [];
106+ if ($ user_id != 1 ) {
107+ $ where = ['uid ' => $ user_id ];
108+ }
109+ $ list = ApiExcel::with ('apiParam ' )->where ($ where )->orderBy ('id ' , 'desc ' )->paginate ($ this ->perPage );
110+ // 获取完成进度情况
111+ $ list = ApiRepository::getInstent ()->workProgress ($ list );
112+
113+ $ appUrl = env ('APP_URL ' ) ?? '' ;
114+ $ collect = collect (['appUrl ' => $ appUrl ]);
115+ $ items = $ collect ->merge ($ list );
116+
117+ return $ this ->outJson (200 , $ items );
118+ }
94119}
0 commit comments