no commit message

This commit is contained in:
annnj-company
2026-04-23 18:25:35 +08:00
parent c99511182a
commit 03a870c384
6 changed files with 239 additions and 17 deletions

View File

@@ -1624,11 +1624,70 @@ function apiErrMsg($msg = '请勿异常操作', $code = 99999) {
}
function writeLog($log = '', $level = "writelog") {
$logConfig = Config::pull('log');
$logConfig = \think\facade\Config::pull('log');
$logConfig['level'][] = $level;
$logConfig['apart_level'][] = $level;
Log::init($logConfig);
Log::write($log, $level);
\think\facade\Log::init($logConfig);
\think\facade\Log::write($log, $level);
}
/**
* 推送消息给所有WebSocket客户端
* @param string $eventName 事件名称
* @param array $data 推送的数据
* @return bool
*/
function pushToAllClients($eventName, $data) {
$socketUrl = 'http://127.0.0.1:2121';
$postData = [
'type' => 'broadcast',
'event' => $eventName,
'data' => json_encode($data)
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($postData),
'timeout' => 5
]
];
$context = stream_context_create($options);
$result = file_get_contents($socketUrl, false, $context);
writeLog("Push result - event: $eventName, data: " . json_encode($data) . ", result: '$result'", 'push_log');
return $result === 'ok';
}
/**
* 推送未回价数量更新
* @param int $count 未回价数量
* @return bool
*/
function pushUnreturnedPriceCount($count) {
return pushToAllClients('updateUnreturnedCount', ['count' => $count]);
}
/**
* 获取未回价数量
* @return int
*/
function getUnreturnedPriceCount() {
$Inquiry = new \app\model\Inquiry();
return $Inquiry->where('return_price_status', 2)->where('status', 1)->count();
}
/**
* 获取未回价数量并推送给所有客户端
* @return bool
*/
function fetchAndPushUnreturnedPriceCount() {
$count = getUnreturnedPriceCount();
return pushUnreturnedPriceCount($count);
}