修复客服嵌入问题并更新前端构建产物
- 管理端前端设备判定改为按宽高比(嵌入竖屏容器时正确使用手机版布局) - 统计上报跨源读取 parent.location 报错防护(降级用 referrer) - 续接会话时校验客服在线,离线不再误入聊天页 - 聊天记录整理与消息发送的用户资料缺失空值防护,避免接口 400 - entrypoint 数据库导入加空库守卫,容器重启/线上更新不再重置数据
This commit is contained in:
+6
-6
@@ -23,15 +23,15 @@
|
||||
this.handleMatchMedia()
|
||||
},
|
||||
handleMatchMedia () {
|
||||
const matchMedia = window.matchMedia
|
||||
// 竖屏(宽高比 < 1)走手机版布局,横屏走 PC 布局。
|
||||
// 嵌入竖屏 iframe(如游戏内客服)时由宿主容器形状决定,不受绝对宽度阈值影响
|
||||
const w = document.documentElement.clientWidth || window.innerWidth
|
||||
const h = document.documentElement.clientHeight || window.innerHeight
|
||||
|
||||
if (matchMedia('(max-width: 600px)').matches) {
|
||||
var deviceWidth = document.documentElement.clientWidth || window.innerWidth;
|
||||
let css = 'calc(100vw/7.5)'
|
||||
if (h > 0 && w / h < 1) {
|
||||
const css = 'calc(100vw/7.5)'
|
||||
document.documentElement.style.fontSize = css;
|
||||
this.setDevice('Mobile')
|
||||
} else if (matchMedia('(max-width: 992px)').matches) {
|
||||
this.setDevice('Tablet')
|
||||
} else {
|
||||
this.setDevice('Desktop')
|
||||
}
|
||||
|
||||
@@ -175,10 +175,17 @@ export default {
|
||||
} else if (ua.indexOf('Netscape') != -1) {
|
||||
browser = 'Netscape';
|
||||
}
|
||||
// 跨源 iframe 嵌入时读取 parent.location 会抛 SecurityError,降级用 referrer
|
||||
let source = '';
|
||||
try {
|
||||
source = window.parent.location.href;
|
||||
} catch (e) {
|
||||
source = window.document.referrer;
|
||||
}
|
||||
userStatistics({
|
||||
ip: window.returnCitySN ? window.returnCitySN.cip : '',
|
||||
path: window.location.href,
|
||||
source: window.parent.location.href,
|
||||
source: source,
|
||||
browser: browser
|
||||
});
|
||||
},
|
||||
|
||||
@@ -176,16 +176,17 @@ class ChatServiceDialogueRecordServices extends BaseServices
|
||||
}
|
||||
|
||||
if (!$item['avatar'] && !$item['nickname']) {
|
||||
if ($item['userThis']['id'] == $item['user_id']) {
|
||||
// isset 空值防护:chat_user 行缺失时关联为 null,直接取 ['id'] 会抛异常导致整个接口 400
|
||||
if (isset($item['userThis']['id']) && $item['userThis']['id'] == $item['user_id']) {
|
||||
$item['nickname'] = $item['userThis']['nickname'] ?? '';
|
||||
$item['avatar'] = $item['userThis']['avatar'] ?? '';
|
||||
} else if ($item['userTO']['id'] == $item['user_id']) {
|
||||
} else if (isset($item['userTO']['id']) && $item['userTO']['id'] == $item['user_id']) {
|
||||
$item['nickname'] = $item['userTO']['nickname'] ?? '';
|
||||
$item['avatar'] = $item['userTO']['avatar'] ?? '';
|
||||
} else if ($item['userTO']['id'] == $item['to_user_id']) {
|
||||
} else if (isset($item['userTO']['id']) && $item['userTO']['id'] == $item['to_user_id']) {
|
||||
$item['nickname'] = $item['userTO']['nickname'] ?? '';
|
||||
$item['avatar'] = $item['userTO']['avatar'] ?? '';
|
||||
} else if ($item['userThis']['id'] == $item['to_user_id']) {
|
||||
} else if (isset($item['userThis']['id']) && $item['userThis']['id'] == $item['to_user_id']) {
|
||||
$item['nickname'] = $item['userThis']['nickname'] ?? '';
|
||||
$item['avatar'] = $item['userThis']['avatar'] ?? '';
|
||||
}
|
||||
|
||||
@@ -199,8 +199,8 @@ class ChatServiceServices extends BaseServices
|
||||
}
|
||||
$userInfo = $userInfo->toArray();
|
||||
}
|
||||
//获取当前分配客服
|
||||
$toUserId = $this->dao->count(['appid' => $appId, 'status' => 1, 'user_id' => $toUserId]) ? $toUserId : 0;
|
||||
//获取当前分配客服(续接已有会话也要求客服在线,离线时走重新分配/留言逻辑)
|
||||
$toUserId = $this->dao->count(['appid' => $appId, 'status' => 1, 'online' => 1, 'user_id' => $toUserId]) ? $toUserId : 0;
|
||||
if (!$toUserId && $kefuId) {
|
||||
$toUserId = $this->dao->value(['appid' => $appId, 'status' => 1, 'id' => $kefuId], 'user_id');
|
||||
}
|
||||
|
||||
@@ -235,7 +235,8 @@ class KefuServices extends BaseServices
|
||||
/** @var ChatUserServices $userService */
|
||||
$userService = app()->make(ChatUserServices::class);
|
||||
$_userInfo = $userService->getUserInfo($data['user_id'], ['nickname', 'avatar', 'version', 'is_tourist', 'online']);
|
||||
$isTourist = $_userInfo['is_tourist'];
|
||||
// 空值兜底:客户端缓存的 user_id 对应的 chat_user 行可能已不存在(如数据重置),缺失时按游客处理,避免发送接口 400
|
||||
$isTourist = $_userInfo['is_tourist'] ?? 0;
|
||||
$data['nickname'] = $_userInfo['nickname'] ?? '';
|
||||
$data['avatar'] = $_userInfo['avatar'] ?? '';
|
||||
|
||||
@@ -304,8 +305,8 @@ class KefuServices extends BaseServices
|
||||
}
|
||||
if ($fds && ($newUserInfo['to_user_id'] ?? 0) != $userId && $res) {
|
||||
|
||||
$data['recored']['nickname'] = $_userInfo['nickname'];
|
||||
$data['recored']['avatar'] = $_userInfo['avatar'];
|
||||
$data['recored']['nickname'] = $_userInfo['nickname'] ?? '';
|
||||
$data['recored']['avatar'] = $_userInfo['avatar'] ?? '';
|
||||
$data['recored']['online'] = isset($userInfo) ? 1 : 0;
|
||||
|
||||
$allUnMessagesCount = $logServices->getMessageNum([
|
||||
|
||||
+3
-3
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+50
-46
File diff suppressed because one or more lines are too long
@@ -40,9 +40,17 @@ done
|
||||
echo " MySQL is ready!"
|
||||
|
||||
echo "==> Importing database schema..."
|
||||
mysql -h "${DB_HOSTNAME:-mysql}" -u "${DB_USERNAME:-root}" -p"${DB_PASSWORD:-root}" --default-character-set=utf8mb4 "${DB_DATABASE:-crmeb_chat}" < /var/www/html/public/install/crmeb_clean.sql 2>/dev/null && \
|
||||
echo " Database schema imported." || \
|
||||
echo " Database may already be initialized (ignoring errors)."
|
||||
# 仅在空库(无任何业务表)时导入初始化 SQL,避免容器重启/线上更新代码时重置数据库。
|
||||
# 如需重置数据:docker compose down -v 清掉数据卷后重新启动即可触发导入。
|
||||
TABLE_COUNT=$(mysql -h "${DB_HOSTNAME:-mysql}" -u "${DB_USERNAME:-root}" -p"${DB_PASSWORD:-root}" -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='${DB_DATABASE:-crmeb_chat}';" 2>/dev/null || echo 0)
|
||||
if [ "${TABLE_COUNT:-0}" != "0" ]; then
|
||||
echo " Database already initialized (found ${TABLE_COUNT} tables), skipping import to protect existing data."
|
||||
else
|
||||
echo " Empty database detected, importing crmeb_clean.sql..."
|
||||
mysql -h "${DB_HOSTNAME:-mysql}" -u "${DB_USERNAME:-root}" -p"${DB_PASSWORD:-root}" --default-character-set=utf8mb4 "${DB_DATABASE:-crmeb_chat}" < /var/www/html/public/install/crmeb_clean.sql 2>/dev/null && \
|
||||
echo " Database schema imported." || \
|
||||
echo " Database import failed."
|
||||
fi
|
||||
|
||||
echo "==> Skipping install wizard..."
|
||||
touch /var/www/html/public/install/install.lock
|
||||
|
||||
Reference in New Issue
Block a user