设备详情

This commit is contained in:
柳清爽
2025-03-31 15:38:10 +08:00
parent c4698bd22a
commit dbf20fd870
4 changed files with 257 additions and 106 deletions

View File

@@ -222,15 +222,7 @@ class Device extends Controller
'msg' => '设备不存在'
]);
}
// 检查设备是否属于用户所在公司
if ($info['companyId'] != $userInfo['companyId']) {
return json([
'code' => 403,
'msg' => '您没有权限查看该设备'
]);
}
return json([
'code' => 200,
'msg' => '获取成功',

View File

@@ -109,9 +109,61 @@ class Device extends Model
*/
public static function getDeviceInfo($id)
{
return self::where('id', $id)
->where('isDeleted', 0)
// 查询设备基础信息与关联的微信账号信息
$device = self::alias('d')
->field([
'd.id', 'd.imei', 'd.memo', 'd.alive', 'd.taskConfig', 'd.lastUpdateTime',
'w.id as wechatId', 'w.thirtyDayMsgCount', 'w.totalFriend', 'd.extra'
])
->leftJoin('tk_wechat_account w', 'd.imei = w.imei')
->where('d.id', $id)
->where('d.isDeleted', 0)
->find();
// 如果设备存在,处理额外信息
if ($device) {
// 解析电量信息
$battery = 0;
if (!empty($device['extra'])) {
$extra = json_decode($device['extra'], true);
if (is_array($extra) && isset($extra['battery'])) {
$battery = intval($extra['battery']);
}
}
$device['battery'] = $battery;
// 解析taskConfig字段获取功能开关
$features = [
'autoAddFriend' => false,
'autoReply' => false,
'contentSync' => false,
'aiChat' => false
];
if (!empty($device['taskConfig'])) {
$taskConfig = json_decode($device['taskConfig'], true);
if (is_array($taskConfig)) {
// 映射taskConfig中的字段到前端需要的features
$features['autoAddFriend'] = isset($taskConfig['autoAddFriend']) ? (bool)$taskConfig['autoAddFriend'] : false;
$features['autoReply'] = isset($taskConfig['autoReply']) ? (bool)$taskConfig['autoReply'] : false;
$features['contentSync'] = isset($taskConfig['momentsSync']) ? (bool)$taskConfig['momentsSync'] : false;
$features['aiChat'] = isset($taskConfig['aiChat']) ? (bool)$taskConfig['aiChat'] : false;
}
}
$device['features'] = $features;
unset($device['extra']);
unset($device['taskConfig']);
// 格式化最后活跃时间
$device['lastUpdateTime'] = !empty($device['lastUpdateTime']) ? date('Y-m-d H:i:s', strtotime($device['lastUpdateTime'])) : date('Y-m-d H:i:s');
// 确保totalFriend和thirtyDayMsgCount有值防止NULL
$device['totalFriend'] = intval($device['totalFriend'] ?? 0);
$device['thirtyDayMsgCount'] = intval($device['thirtyDayMsgCount'] ?? 0);
}
return $device;
}
/**