no commit message

This commit is contained in:
annnj-company
2026-04-27 10:10:35 +08:00
parent 68a0b1ab22
commit 6fc3e6b64f
19 changed files with 1058 additions and 64 deletions

View File

@@ -59,7 +59,9 @@ class Base extends Controller {
*/
public function isAdmin()
{
return in_array("Biz_system_admin", $this->userInfo['roleCode']);
return in_array("Biz_system_admin", $this->userInfo['roleCode']) ||
in_array("admin", $this->userInfo['roleCode']) ||
in_array("COM_TOP_ADMIN", $this->userInfo['roleCode']);
}
/**

View File

@@ -95,6 +95,7 @@ class Estimate extends Base
// }
$where[] = ['i.is_simple', '=', 0];
$where[] = ['i.estimate_status', '=', $estimate_status];
$where[] = ['i.status', 'in', [9, 10, 11, 12]];
$start_time && $where[] = ['i.create_time', '>=', $start_time . " 00:00:00"];
$end_time && $where[] = ['i.create_time', '<=', $end_time . " 23:59:59"];
$is_multiple && $where[] = ['i.is_multiple', '=', $is_multiple];
@@ -540,6 +541,10 @@ class Estimate extends Base
if (!$in_upd) {
return $this->buildFailed('操作失败!');
}
// 推送预估数量更新给所有客户端
fetchAndPushEstimatePendingCount();
return $this->buildSuccess();
}

View File

@@ -44,6 +44,56 @@ class Pending extends Base
return $this->buildSuccess(['count' => $count]);
}
/**
* 获取报告制作数量status=9
* @return \think\Response
*/
public function getReportPendingCount()
{
$Inquiry = new Inquiry();
// 查询 status = 9 的数量
$count = $Inquiry->where('status', 9)->count();
return $this->buildSuccess(['count' => $count]);
}
/**
* 获取所有预估状态数量
* @return \think\Response
*/
public function getEstimatePendingCount()
{
$Inquiry = new Inquiry();
// 待制作status=9
$pendingCount = $Inquiry->where('status', 9)->count();
// 二审待制作status=10 且 estimate_status=2
$secondReviewCount = $Inquiry->where('status', 10)
->where('estimate_status', '=', '2', false)
->count();
// 三审待制作status=10 且 estimate_status=3
$thirdReviewCount = $Inquiry->where('status', 10)
->where('estimate_status', '=', '3', false)
->count();
// 待签章status=11
$signCount = $Inquiry->where('status', 11)->count();
// 总和
$total = $pendingCount + $secondReviewCount + $thirdReviewCount + $signCount;
return $this->buildSuccess([
'pending' => $pendingCount,
'secondReview' => $secondReviewCount,
'thirdReview' => $thirdReviewCount,
'sign' => $signCount,
'total' => $total
]);
}
//询价编号前缀 - 住宅
const INQUERY_NUMBER_RESIDENCE_PREFIX = "GZ01";
@@ -3687,6 +3737,9 @@ class Pending extends Base
return $this->buildFailed("确认回价失败");
}
// 推送预估数量更新到前端
fetchAndPushEstimatePendingCount();
return $this->buildSuccess();
}

View File

@@ -47,6 +47,15 @@ class Property_cert_info extends Base
if ($result['code'] == -1) {
return $this->buildFailed($result['msg']);
}
// 发起查勘成功后,推送查勘跟进中数量更新
error_log("=== reqApplySurvey 推送调试 ===");
error_log("用户ID: " . $this->userInfo['user_id']);
error_log("是否管理员: " . ($this->isAdmin() ? 'true' : 'false'));
$pushResult = fetchAndPushSurveyFollowCount($this->userInfo['user_id'], $this->isAdmin());
error_log("推送结果: " . ($pushResult ? '成功' : '失败'));
return $this->buildSuccess('发起查勘成功');
}

View File

@@ -2848,6 +2848,55 @@ EOF;
return $page;
}
/**
* 获取报告制作数量统计
* @return \think\response\Json
*/
public function getReportProduceCount() {
$pendingCount = Db::name('report')
->alias('r')
->join('inquiry i', 'r.quot_id = i.id', 'LEFT')
->where('r.report_source', 1)
->where('r.status', 1)
->where('r.create_time', 'gt', '2025-02-01 00:00:00');
$pending = $pendingCount->count();
// 二审待制作:以 pg_report 为主表review_status=1 且 status=2关联 pg_inquiry
$secondReviewCount = Db::name('report')
->alias('r')
->join('inquiry i', 'r.quot_id = i.id', 'LEFT')
->where('r.report_source', 1)
->where('r.review_status', 1)
->where('r.status', 2)
->where('r.create_time', 'gt', '2025-02-01 00:00:00')
->where('i.status', 7)
->group('r.quot_id');
$secondReview = $secondReviewCount->count();
// 三审待制作:以 pg_report 为主表review_status=2 且 review2_status=1 且 status=2关联 pg_inquiry
$thirdReviewCount = Db::name('report')
->alias('r')
->join('inquiry i', 'r.quot_id = i.id', 'LEFT')
->where('r.report_source', 1)
->where('r.review_status', 2)
->where('r.review2_status', 1)
->where('r.create_time', 'gt', '2025-02-01 00:00:00')
->where('r.status', 2);
$thirdReview = $thirdReviewCount->count();
// 计算总数
$total = $pending + $secondReview + $thirdReview;
return $this->buildSuccess([
'pending' => $pending,
'secondReview' => $secondReview,
'thirdReview' => $thirdReview,
'total' => $total
]);
}
public function cancelAntiCounterfeitCode()
{
$reportid = $this->request->post("reportid");

View File

@@ -561,9 +561,29 @@ class Survey extends Base
if (is_array($list)) {
$refer = array();
foreach ($list as $key => $data) {
// 跳过空数据或非数组数据
if (!is_array($data) || empty($data)) {
continue;
}
// 确保主键字段存在
if (!isset($data[$pk])) {
continue;
}
$refer[$data[$pk]] = &$list[$key];
}
foreach ($list as $key => $data) {
// 跳过空数据或非数组数据
if (!is_array($data) || empty($data)) {
continue;
}
// 确保父ID字段存在
if (!isset($data[$pid])) {
continue;
}
// 确保code字段存在
if (!isset($data['code'])) {
continue;
}
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[$data['code']] = &$list[$key];
@@ -759,4 +779,53 @@ class Survey extends Base
}
}
/**
* 获取查勘跟进中数量(当前登录人)
* @return \think\Response
*/
public function surveyFollowCount()
{
// 检查用户信息
if (empty($this->userInfo)) {
error_log("surveyFollowCount: userInfo is empty");
return $this->buildFailed('用户信息不存在');
}
// 检查用户ID
if (!isset($this->userInfo['user_id'])) {
error_log("surveyFollowCount: user_id is not set");
return $this->buildFailed('用户ID不存在');
}
$Survey = new SurveyModel();
// 如果是管理员admin 或 COM_TOP_ADMIN不限制 user_id
if ($this->isAdmin()) {
$count = $Survey->alias('s')
->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER')
->where('i.status', 4)
->where('s.status', 2)
->where('s.assign_time', 'gt', '2025-02-01 00:00:00')
->group('s.id')
->count();
} else {
// 非管理员,只统计当前用户的查勘
$userId = $this->userInfo['user_id'];
$count = $Survey->alias('s')
->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER')
->where('i.status', 4)
->where('s.status', 2)
->where('s.user_id', $userId)
->where('s.assign_time', 'gt', '2025-02-01 00:00:00')
->group('s.id')
->count();
}
error_log("surveyFollowCount: count = $count, userId = " . $this->userInfo['user_id'] . ", isAdmin = " . ($this->isAdmin() ? 'true' : 'false'));
return $this->buildSuccess([
'count' => $count
]);
}
}

View File

@@ -95,7 +95,7 @@ class SurveyService extends CommonService
}
//更新订单状态:查勘待派单
if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => new \DateTime])) {
if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => date('Y-m-d H:i:s')])) {
Db::rollback();
return ['code'=>-1, 'msg'=>'更新订单状态失败'];
}
@@ -146,7 +146,7 @@ class SurveyService extends CommonService
}
//更新订单状态:查勘待派单
if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => new \DateTime])) {
if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => date('Y-m-d H:i:s')])) {
Db::rollback();
return ['code'=>-1, 'msg'=>'更新订单状态失败'];
}

View File

@@ -1650,6 +1650,11 @@ function pushToAllClients($eventName, $data) {
'data' => json_encode($data)
];
error_log("=== 推送调试 ===");
error_log("目标地址: $socketUrl");
error_log("事件名称: $eventName");
error_log("推送数据: " . json_encode($data));
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
@@ -1660,9 +1665,11 @@ function pushToAllClients($eventName, $data) {
];
$context = stream_context_create($options);
$result = file_get_contents($socketUrl, false, $context);
$result = @file_get_contents($socketUrl, false, $context);
writeLog("Push result - event: $eventName, data: " . json_encode($data) . ", result: '$result'", 'push_log');
error_log("推送结果: '" . ($result !== false ? $result : 'false') . "'");
writeLog("Push result - event: $eventName, data: " . json_encode($data) . ", result: '" . ($result !== false ? $result : 'false') . "'", 'push_log');
return $result === 'ok';
}
@@ -1694,5 +1701,187 @@ function fetchAndPushUnreturnedPriceCount() {
return pushUnreturnedPriceCount($count);
}
/**
* 推送预估数量更新
* @param array $counts 预估数量数组
* @return bool
*/
function pushEstimatePendingCount($counts) {
return pushToAllClients('updateEstimatePendingCount', $counts);
}
/**
* 获取预估数量
* @return array
*/
function getEstimatePendingCount() {
$Inquiry = new \app\model\Inquiry();
// 待制作status=9
$pendingCount = $Inquiry->where('status', 9)->count();
// 二审待制作status=10 且 estimate_status=2兼容字符串和数字类型
$secondReviewCount = $Inquiry->where('status', 10)
->where('estimate_status', '=', '2', false)
->count();
// 三审待制作status=10 且 estimate_status=3兼容字符串和数字类型
$thirdReviewCount = $Inquiry->where('status', 10)
->where('estimate_status', '=', '3', false)
->count();
// 待签章status=11
$signCount = $Inquiry->where('status', 11)->count();
// 总和
$total = $pendingCount + $secondReviewCount + $thirdReviewCount + $signCount;
return [
'pending' => $pendingCount,
'secondReview' => $secondReviewCount,
'thirdReview' => $thirdReviewCount,
'sign' => $signCount,
'total' => $total
];
}
/**
* 获取预估数量并推送给所有客户端
* @return bool
*/
function fetchAndPushEstimatePendingCount() {
$counts = getEstimatePendingCount();
return pushEstimatePendingCount($counts);
}
/**
* 推送查勘跟进中数量更新(推送刷新事件,让客户端主动获取自己的数量)
* @param int $count 查勘跟进中数量(当前用户的数量,用于发起者立即显示)
* @return bool
*/
function pushSurveyFollowCount($count) {
// 推送刷新事件,让所有客户端重新获取自己的查勘数量
return pushToAllClients('updateSurveyFollowCount', ['refresh' => true, 'count' => $count]);
}
/**
* 推送报告制作数量更新
* @param array $counts 报告制作数量数组
* @return bool
*/
function pushReportProduceCount($counts) {
// 推送刷新事件,让所有客户端重新获取自己的报告制作数量
return pushToAllClients('updateReportProduceCount', ['refresh' => true, 'counts' => $counts]);
}
/**
* 获取报告制作数量并推送给所有客户端
* @param int $userId 用户ID
* @param bool $isAdmin 是否管理员
* @return bool
*/
function fetchAndPushReportProduceCount($userId, $isAdmin = false) {
$pendingCount = Db::name('report')
->alias('r')
->join('inquiry i', 'r.quot_id = i.id', 'LEFT')
->where('r.report_source', 1)
->where('r.status', 1)
->where('r.create_time', 'gt', '2025-02-01 00:00:00');
$pending = $pendingCount->count();
// 二审待制作:以 pg_report 为主表review_status=1 且 status=2关联 pg_inquiry
$secondReviewCount = Db::name('report')
->alias('r')
->join('inquiry i', 'r.quot_id = i.id', 'LEFT')
->where('r.report_source', 1)
->where('r.review_status', 1)
->where('r.status', 2)
->where('r.create_time', 'gt', '2025-02-01 00:00:00')
->where('i.status', 7)
->group('r.quot_id');
$secondReview = $secondReviewCount->count();
// 三审待制作:以 pg_report 为主表review_status=2 且 review2_status=1 且 status=2关联 pg_inquiry
$thirdReviewCount = Db::name('report')
->alias('r')
->join('inquiry i', 'r.quot_id = i.id', 'LEFT')
->where('r.report_source', 1)
->where('r.review_status', 2)
->where('r.review2_status', 1)
->where('r.create_time', 'gt', '2025-02-01 00:00:00')
->where('r.status', 2);
$thirdReview = $thirdReviewCount->count();
// 计算总数
$total = $pending + $secondReview + $thirdReview;
return [
'pending' => $pending,
'secondReview' => $secondReview,
'thirdReview' => $thirdReview,
'total' => $total
];
error_log("查询到的报告制作数量: " . json_encode($counts));
$pushResult = pushReportProduceCount($counts);
error_log("推送结果: " . ($pushResult ? '成功' : '失败'));
return $pushResult;
}
/**
* 获取查勘跟进中数量(当前登录人)
* @param int $userId 用户ID
* @param bool $isAdmin 是否管理员
* @return int
*/
function getSurveyFollowCount($userId, $isAdmin = false) {
$Survey = new \app\model\Survey();
// 如果是管理员,不限制 user_id
if ($isAdmin) {
$count = $Survey->alias('s')
->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER')
->where('i.status', 4)
->where('s.status', 2)
->where('s.assign_time', 'gt', '2025-02-01 00:00:00')
->count();
} else {
// 非管理员,只统计当前用户的查勘
$count = $Survey->alias('s')
->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER')
->where('i.status', 4)
->where('s.status', 2)
->where('s.user_id', $userId)
->where('s.assign_time', 'gt', '2025-02-01 00:00:00')
->count();
}
return $count;
}
/**
* 获取查勘跟进中数量并推送给所有客户端
* @param int $userId 用户ID
* @param bool $isAdmin 是否管理员
* @return bool
*/
function fetchAndPushSurveyFollowCount($userId, $isAdmin = false) {
error_log("=== fetchAndPushSurveyFollowCount 调试 ===");
error_log("用户ID: $userId");
error_log("是否管理员: " . ($isAdmin ? 'true' : 'false'));
$count = getSurveyFollowCount($userId, $isAdmin);
error_log("查询到的查勘数量: $count");
$pushResult = pushSurveyFollowCount($count);
error_log("推送结果: " . ($pushResult ? '成功' : '失败'));
return $pushResult;
}
$GLOBALS['console'] = '';

View File

@@ -69,10 +69,19 @@ class Survey extends Base
->order('id desc')
->field('eva_unit_price,eva_total_value,eva_net_value,eva_net_value2')
->find();
$item['eva_unit_price'] = $return_price_info['eva_unit_price'];
$item['eva_total_value'] = $return_price_info['eva_total_value'];
$item['eva_net_value'] = $return_price_info['eva_net_value'];
$item['eva_net_value2'] = $return_price_info['eva_net_value2'];
// 检查是否找到数据
if ($return_price_info) {
$item['eva_unit_price'] = $return_price_info['eva_unit_price'];
$item['eva_total_value'] = $return_price_info['eva_total_value'];
$item['eva_net_value'] = $return_price_info['eva_net_value'];
$item['eva_net_value2'] = $return_price_info['eva_net_value2'];
} else {
// 如果没有找到数据,设置默认值
$item['eva_unit_price'] = null;
$item['eva_total_value'] = null;
$item['eva_net_value'] = null;
$item['eva_net_value2'] = null;
}
$item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']);
$item['survey_status_str'] = getDictionaryName('SURVEY_STATUS', $item['survey_status']);
$item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']);
@@ -576,8 +585,14 @@ class Survey extends Base
->order('id desc')
->field('external_remarks,appraiser_name')
->find();
$item['external_remarks'] = $return_price_info['external_remarks'];
$item['appraiser_name'] = $return_price_info['appraiser_name'];
// 检查是否找到数据
if ($return_price_info) {
$item['external_remarks'] = $return_price_info['external_remarks'];
$item['appraiser_name'] = $return_price_info['appraiser_name'];
} else {
$item['external_remarks'] = null;
$item['appraiser_name'] = null;
}
// $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']);
$item['survey_status_str'] = getDictionaryName('SURVEY_STATUS', $item['status']);
$item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']);

View File

@@ -28,30 +28,12 @@ $sender_io->on('connection', function($socket) use (&$push_value){
// 客户端连接时立即发送当前数值
$socket->emit('push_value', ['value' => $push_value]);
// 连接时自动推送最新的未回价数量
try {
// 从ThinkPHP数据库配置文件读取数据库连接信息
$db_config = require __DIR__ . '/config/database.php';
$db_host = isset($db_config['hostname']) ? $db_config['hostname'] : 'localhost';
$db_name = isset($db_config['database']) ? $db_config['database'] : 'pgserver';
$db_user = isset($db_config['username']) ? $db_config['username'] : 'root';
$db_pass = isset($db_config['password']) ? $db_config['password'] : '';
$db_port = isset($db_config['hostport']) ? $db_config['hostport'] : '3306';
$db_charset = isset($db_config['charset']) ? $db_config['charset'] : 'utf8';
// 使用PDO连接数据库查询最新数量
$dsn = "mysql:host=$db_host;port=$db_port;dbname=$db_name;charset=$db_charset";
$pdo = new PDO($dsn, $db_user, $db_pass);
$stmt = $pdo->query('SELECT COUNT(*) as count FROM pg_inquiry WHERE return_price_status = 2');
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$count = $result['count'] ?? 0;
// 推送未回价数量
$socket->emit('updateUnreturnedCount', ['count' => $count]);
error_log("WebSocket连接时推送未回价数量: $count");
} catch (Exception $e) {
error_log("WebSocket连接时获取未回价数量失败: " . $e->getMessage());
}
// 连接时发送刷新事件,让客户端主动获取所有数量(避免重复查询逻辑)
error_log("WebSocket客户端连接发送4个刷新事件");
$socket->emit('updateUnreturnedCount', ['refresh' => true]);
$socket->emit('updateEstimatePendingCount', ['refresh' => true]);
$socket->emit('updateReportProduceCount', ['refresh' => true]);
$socket->emit('updateSurveyFollowCount', ['refresh' => true]);
$socket->on('login', function ($uid)use($socket){
global $uidConnectionMap;
@@ -65,6 +47,24 @@ $sender_io->on('connection', function($socket) use (&$push_value){
++$uidConnectionMap[$uid];
$socket->join($uid);
$socket->uid = $uid;
// 登录时推送刷新事件,让客户端主动获取所有数量
$socket->emit('updateSurveyFollowCount', ['refresh' => true]);
$socket->emit('updateUnreturnedCount', ['refresh' => true]);
$socket->emit('updateEstimatePendingCount', ['refresh' => true]);
$socket->emit('updateReportProduceCount', ['refresh' => true]);
error_log("WebSocket登录时推送用户{$uid}的4个刷新事件");
});
// 处理客户端主动刷新请求
$socket->on('refreshAllCounts', function()use($socket){
error_log("收到客户端刷新请求");
// 发送刷新事件给当前客户端
$socket->emit('updateSurveyFollowCount', ['refresh' => true]);
$socket->emit('updateUnreturnedCount', ['refresh' => true]);
$socket->emit('updateEstimatePendingCount', ['refresh' => true]);
$socket->emit('updateReportProduceCount', ['refresh' => true]);
error_log("已向客户端发送刷新事件(包含报告数量)");
});
$socket->on('disconnect', function () use($socket) {
@@ -128,15 +128,24 @@ $sender_io->on('workerStart', function()use ($sender_io, $http_port){
$event = isset($msgContent['event']) ? $msgContent['event'] : '';
$eventData = isset($msgContent['data']) ? $msgContent['data'] : '';
error_log("Broadcast check - event: '$event', data: '$eventData'");
error_log("=== WebSocket广播调试 ===");
error_log("事件名称: '$event'");
error_log("原始数据: '$eventData'");
if(!empty($event)){
if(is_string($eventData)){
$decoded = json_decode($eventData, true);
$eventData = $decoded !== null ? $decoded : $eventData;
}
$sender_io->emit($event, $eventData);
error_log("Broadcast sent - event: $event, data: " . print_r($eventData, true));
error_log("解码后数据: " . print_r($eventData, true));
// 获取所有连接的客户端并发送消息
// PHPSocketIO 1.x 使用 connections 数组获取所有连接
foreach ($sender_io->connections as $connection) {
$connection->emit($event, $eventData);
}
error_log("广播已发送到所有客户端 - 事件: $event");
return $http_connection->send('ok');
}
}