Skip to content

Commit f4d909e

Browse files
committed
fix: 提供数据方法
1 parent f23eb0d commit f4d909e

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

laravel/app/Services/WebSocketService.php

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,33 @@ public function onOpen($server, $request)
4444
$action = $req['action'] ?? '';
4545
switch ($action) {
4646
case 'api_excel':
47-
return $this->apiExcel();
48-
break;
49-
}
50-
51-
if (isset($req['id']) && $req['id'] == floor($req['id'])) {
52-
while (true) {
53-
// 3. 输出完成率
54-
$rate = MultithreadingRepository::getInstent()->completionRate($req['id']);
55-
$data = $this->outJson(200, ['rate' => $rate]);
56-
$server->push($request->fd, $data);
57-
sleep(3);
58-
59-
if ($rate >= 100) {
60-
break;
47+
while (true) {
48+
$data = $this->apiExcel();
49+
$server->push($request->fd, $data);
50+
sleep(5);
51+
$state = ApiExcel::where('state', 1)->first();
52+
if (!$state) {
53+
break;
54+
}
6155
}
62-
}
63-
} else {
64-
$server->push($request->fd, $this->outJson(200, ['rate' => '100']));
6556
}
57+
return '';
58+
59+
// if (isset($req['id']) && $req['id'] == floor($req['id'])) {
60+
// while (true) {
61+
// // 3. 输出完成率
62+
// $rate = MultithreadingRepository::getInstent()->completionRate($req['id']);
63+
// $data = $this->outJson(200, ['rate' => $rate]);
64+
// $server->push($request->fd, $data);
65+
// sleep(3);
66+
//
67+
// if ($rate >= 100) {
68+
// break;
69+
// }
70+
// }
71+
// } else {
72+
// $server->push($request->fd, $this->outJson(200, ['rate' => '100']));
73+
// }
6674

6775
// throw new \Exception('an exception');// 此时抛出的异常上层会忽略,并记录到Swoole日志,需要开发者try/catch捕获处理
6876
}
@@ -97,6 +105,11 @@ public function outJson($code = 200, $data = [], $reason = 'success')
97105
return json_encode(['code' => $code, 'reason' => $reason, 'data' => $data], JSON_UNESCAPED_UNICODE);
98106
}
99107

108+
/**
109+
* 获取api_excel 列表-完成率
110+
*
111+
* @return array
112+
*/
100113
private function apiExcel()
101114
{
102115
$user_id = auth('api')->user()['id'];

0 commit comments

Comments
 (0)