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

@@ -138,6 +138,9 @@ class Bussiness extends Base
$res = $inquiryService->createInquiry($data);
if($res['code'] == 1){
\think\facade\Log::write('Bussiness/save: 开始推送未回价数量', 'push_debug');
$result = \fetchAndPushUnreturnedPriceCount();
\think\facade\Log::write('Bussiness/save: 推送结果: ' . ($result ? '成功' : '失败'), 'push_debug');
return $this->buildSuccess();
}
return $this->buildFailed($res['code'], $res['msg']);

View File

@@ -30,6 +30,19 @@ use app\model\ReportDetail as ReportDetailModel;
class Pending extends Base
{
/**
* 获取未回价数量return_price_status=2
* @return \think\Response
*/
public function getUnreturnedPriceCount()
{
$Inquiry = new Inquiry();
// 查询 return_price_status = 2 的数量
$count = $Inquiry->where('return_price_status', 2)->where('status', 1)->count();
return $this->buildSuccess(['count' => $count]);
}
//询价编号前缀 - 住宅
const INQUERY_NUMBER_RESIDENCE_PREFIX = "GZ01";

View File

@@ -156,12 +156,13 @@ class InquiryService extends CommonService
$inquiry->product_id = $data['product_id'];
// $inquiry->type = $data['type']; // 2025-12-15 annnj 注释掉type字段
$inquiry->is_multiple = count($data['details']) > 1;
$inquiry->status = Inquiry::STATUS_CREATED;
$inquiry->create_time = date('Y-m-d H:i:s');
$inquiry->update_time = date('Y-m-d H:i:s');
$inquiry->sort = getSort($data['buss_user_id']);
$inquiry->create_time_unix = time();
$inquiry->loan_type = $data['loan_type'];
$inquiry->status = Inquiry::STATUS_CREATED;
$inquiry->return_price_status = 2;
$inquiry->create_time = date('Y-m-d H:i:s');
$inquiry->update_time = date('Y-m-d H:i:s');
$inquiry->sort = getSort($data['buss_user_id']);
$inquiry->create_time_unix = time();
$inquiry->loan_type = $data['loan_type'];
$inquiry->report_obj_type = $data['report_obj_type'];
$reportClassRes = EnumCfg::findByFullName(EnumCfg::reportClass, $data['loan_type']);
if (!empty($reportClassRes)) {

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);
}

View File

@@ -16,10 +16,21 @@ class Push
$last_online_count = 0;
// 记录最后一次广播的在线页面数
$last_online_page_count = 0;
// 模拟推送的数值(这里可以从数据库或其他地方获取)
$push_value = 0;
// PHPSocketIO服务
$sender_io = new SocketIO(2120);
// 定时任务每3秒更新一次数值并推送给所有客户端
\Workerman\Lib\Timer::add(3, function() use (&$push_value, $sender_io) {
// 模拟数值变化(可以替换为实际的业务逻辑)
$push_value = rand(100, 1000);
// 向所有连接的客户端推送数值
$sender_io->emit('push_value', ['value' => $push_value]);
});
// 客户端发起连接事件时设置连接socket的各种事件回调
$sender_io->on('connection', function($socket){
$sender_io->on('connection', function($socket) use (&$push_value){
// 当客户端发来登录事件时触发
$socket->on('login', function ($uid)use($socket){
global $uidConnectionMap, $last_online_count, $last_online_page_count;