私域操盘手 - 设备配置信息提供最小访问单元,与设备详情解耦

This commit is contained in:
柳清爽
2025-05-16 18:32:21 +08:00
parent 7111d48886
commit bff2d5eb8b
6 changed files with 385 additions and 209 deletions

View File

@@ -59,29 +59,6 @@ class GetDeviceDetailV1Controller extends BaseController
return 0;
}
/**
* 解析taskConfig字段获取功能开关
*
* @param int $deviceId
* @return int[]
* @throws \Exception
*/
protected function getTaskConfig(int $deviceId): array
{
$conf = DeviceTaskconfModel::alias('c')->field([
'c.autoAddFriend', 'c.autoReply', 'c.momentsSync', 'c.aiChat'
])
->where(
[
'companyId' => $this->getUserInfo('companyId'),
'deviceId' => $deviceId
]
)
->find();
// 未配置时赋予默认关闭的状态
return !is_null($conf) ? $conf->toArray() : ArrHelper::getValue('autoAddFriend,autoReply,momentsSync,aiChat', [], 0);
}
/**
* 获取设备最新登录微信的 wechatId
@@ -102,55 +79,6 @@ class GetDeviceDetailV1Controller extends BaseController
->value('wechatId');
}
/**
* 统计设备登录微信的好友
*
* @param int $deviceId
* @return int
* @throws \Exception
*/
protected function getTotalFriend(int $deviceId): int
{
$ownerWechatId = $this->getDeviceLatestWechatLogin($deviceId);
if ($ownerWechatId) {
return WechatFriendShipModel::where(
[
'companyId' => $this->getUserInfo('companyId'),
'ownerWechatId' => $ownerWechatId
]
)
->count();
}
return 0;
}
/**
* 获取设备绑定微信的消息总数
*
* @param int $deviceId
* @return int
*/
protected function getThirtyDayMsgCount(int $deviceId): int
{
$ownerWechatId = $this->getDeviceLatestWechatLogin($deviceId);
if ($ownerWechatId) {
$activity = (string)WechatCustomerModel::where(
[
'wechatId' => $ownerWechatId,
'companyId' => $this->getUserInfo('companyId')
]
)
->value('activity');
return json_decode($activity)->totalMsgCount ?? 0;
}
return 0;
}
/**
* 获取设备详情
* @param int $id 设备ID
@@ -170,11 +98,6 @@ class GetDeviceDetailV1Controller extends BaseController
}
$device['battery'] = $this->parseExtraForBattery($device['extra']);
$device['features'] = $this->getTaskConfig($id);
$device['totalFriend'] = $this->getTotalFriend($id);
$device['thirtyDayMsgCount'] = $this->getThirtyDayMsgCount($id);
// 设备最后活跃时间为设备状态更新时间
$device['lastUpdateTime'] = date('Y-m-d H:i:s', $device['lastUpdateTime']);
// 删除冗余字段