私域操盘手 - 设备关联微信的微信数据内容由原先的模拟数据填充业务逻辑,调整部分页面的数据展示
This commit is contained in:
@@ -891,7 +891,7 @@ export default function DeviceDetailPage() {
|
|||||||
<span className="text-sm">好友总数</span>
|
<span className="text-sm">好友总数</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-2xl font-bold text-blue-600 mt-2">
|
<div className="text-2xl font-bold text-blue-600 mt-2">
|
||||||
{device.totalFriend || 0}
|
{(device.totalFriend || 0).toLocaleString()}
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
<Card className="p-4">
|
<Card className="p-4">
|
||||||
@@ -900,7 +900,7 @@ export default function DeviceDetailPage() {
|
|||||||
<span className="text-sm">消息数量</span>
|
<span className="text-sm">消息数量</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-2xl font-bold text-blue-600 mt-2">
|
<div className="text-2xl font-bold text-blue-600 mt-2">
|
||||||
{device.thirtyDayMsgCount || 0}
|
{(device.thirtyDayMsgCount || 0).toLocaleString()}
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -719,7 +719,7 @@ export default function DevicesPage() {
|
|||||||
<span className="mr-1">IMEI:</span>
|
<span className="mr-1">IMEI:</span>
|
||||||
<ImeiDisplay imei={device.imei} containerWidth={180} />
|
<ImeiDisplay imei={device.imei} containerWidth={180} />
|
||||||
</div>
|
</div>
|
||||||
<div className="text-sm text-gray-500">微信号: {device.wechatId || "未绑定"}</div>
|
<div className="text-sm text-gray-500">微信号: {device.wechatId || "未绑定或微信离线"}</div>
|
||||||
<div className="flex items-center justify-between mt-1 text-sm">
|
<div className="flex items-center justify-between mt-1 text-sm">
|
||||||
<span className="text-gray-500">好友数: {device.totalFriend}</span>
|
<span className="text-gray-500">好友数: {device.totalFriend}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -437,11 +437,11 @@ export default function TrafficPoolPage() {
|
|||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<Card className="p-4">
|
<Card className="p-4">
|
||||||
<div className="text-sm text-gray-500">流量池总数</div>
|
<div className="text-sm text-gray-500">流量池总数</div>
|
||||||
<div className="text-2xl font-bold text-blue-600">{stats.totalCount}</div>
|
<div className="text-2xl font-bold text-blue-600">{stats.totalCount.toLocaleString()}</div>
|
||||||
</Card>
|
</Card>
|
||||||
<Card className="p-4">
|
<Card className="p-4">
|
||||||
<div className="text-sm text-gray-500">今日新增</div>
|
<div className="text-sm text-gray-500">今日新增</div>
|
||||||
<div className="text-2xl font-bold text-green-600">{stats.todayAddCount}</div>
|
<div className="text-2xl font-bold text-green-600">{stats.todayAddCount.toLocaleString()}</div>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -763,7 +763,7 @@ export default function WechatAccountDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
{accountSummary && (
|
{accountSummary && (
|
||||||
<>
|
<>
|
||||||
<div className="text-2xl font-bold text-blue-600">{accountSummary.activityLevel.dayTimes}次/天</div>
|
<div className="text-2xl font-bold text-blue-600">{accountSummary.activityLevel.dayTimes.toLocaleString()}次/天</div>
|
||||||
<div className="text-sm text-gray-500 mt-1">总聊天数:{accountSummary.activityLevel.allTimes.toLocaleString()}</div>
|
<div className="text-sm text-gray-500 mt-1">总聊天数:{accountSummary.activityLevel.allTimes.toLocaleString()}</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -1010,7 +1010,7 @@ export default function WechatAccountDetailPage() {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<ScrollArea className="max-h-[400px]">
|
<ScrollArea className="max-h-[400px]">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{accountSummary?.restrictions?.length > 0 ? (
|
{(accountSummary?.restrictions && accountSummary.restrictions.length > 0) ? (
|
||||||
accountSummary.restrictions.map((record) => (
|
accountSummary.restrictions.map((record) => (
|
||||||
<div key={record.id} className="border-b pb-4 last:border-0">
|
<div key={record.id} className="border-b pb-4 last:border-0">
|
||||||
<div className="flex justify-between items-start">
|
<div className="flex justify-between items-start">
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ namespace app\cunkebao\controller\device;
|
|||||||
use app\common\model\Device as DeviceModel;
|
use app\common\model\Device as DeviceModel;
|
||||||
use app\common\model\DeviceTaskconf as DeviceTaskconfModel;
|
use app\common\model\DeviceTaskconf as DeviceTaskconfModel;
|
||||||
use app\common\model\DeviceUser as DeviceUserModel;
|
use app\common\model\DeviceUser as DeviceUserModel;
|
||||||
use app\common\model\DeviceWechatLogin;
|
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||||
use app\common\model\User as UserModel;
|
use app\common\model\User as UserModel;
|
||||||
|
use app\common\model\WechatCustomer as WechatCustomerModel;
|
||||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||||
use app\cunkebao\controller\BaseController;
|
use app\cunkebao\controller\BaseController;
|
||||||
use Eison\Utils\Helper\ArrHelper;
|
use Eison\Utils\Helper\ArrHelper;
|
||||||
@@ -47,10 +48,10 @@ class GetDeviceDetailV1Controller extends BaseController
|
|||||||
protected function parseExtraForBattery(string $extra): int
|
protected function parseExtraForBattery(string $extra): int
|
||||||
{
|
{
|
||||||
if (!empty($extra)) {
|
if (!empty($extra)) {
|
||||||
$extra = json_decode($extra, true);
|
$extra = json_decode($extra);
|
||||||
|
|
||||||
if (is_array($extra) && isset($extra['battery'])) {
|
if ($extra && isset($extra->battery)) {
|
||||||
return intval($extra['battery']);
|
return intval($extra->battery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +84,25 @@ class GetDeviceDetailV1Controller extends BaseController
|
|||||||
return ArrHelper::getValue('autoAddFriend,autoReply,momentsSync,aiChat', [], 0);
|
return ArrHelper::getValue('autoAddFriend,autoReply,momentsSync,aiChat', [], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备最新登录微信的 wechatId
|
||||||
|
*
|
||||||
|
* @param int $deviceId
|
||||||
|
* @return string|null
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
protected function getDeviceLatestWechatLogin(int $deviceId): ?string
|
||||||
|
{
|
||||||
|
return DeviceWechatLoginModel::where(
|
||||||
|
[
|
||||||
|
'companyId' => $this->getUserInfo('companyId'),
|
||||||
|
'deviceId' => $deviceId,
|
||||||
|
'alive' => DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->value('wechatId');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计设备登录微信的好友
|
* 统计设备登录微信的好友
|
||||||
*
|
*
|
||||||
@@ -92,24 +112,43 @@ class GetDeviceDetailV1Controller extends BaseController
|
|||||||
*/
|
*/
|
||||||
protected function getTotalFriend(int $deviceId): int
|
protected function getTotalFriend(int $deviceId): int
|
||||||
{
|
{
|
||||||
$companyId = $this->getUserInfo('companyId');
|
$ownerWechatId = $this->getDeviceLatestWechatLogin($deviceId);
|
||||||
|
|
||||||
$ownerWechatId = DeviceWechatLogin::where(compact('companyId', 'deviceId'))->order('createTime desc')->value('wechatId');
|
|
||||||
|
|
||||||
if ($ownerWechatId) {
|
if ($ownerWechatId) {
|
||||||
return WechatFriendShipModel::where(['ownerWechatId' => $ownerWechatId])->count();
|
return WechatFriendShipModel::where(
|
||||||
|
[
|
||||||
|
'companyId' => $this->getUserInfo('companyId'),
|
||||||
|
'ownerWechatId' => $ownerWechatId
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO 获取设备绑定微信的消息总数
|
* 获取设备绑定微信的消息总数
|
||||||
*
|
*
|
||||||
|
* @param int $deviceId
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function getThirtyDayMsgCount(): 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +173,7 @@ class GetDeviceDetailV1Controller extends BaseController
|
|||||||
$device['battery'] = $this->parseExtraForBattery($device['extra']);
|
$device['battery'] = $this->parseExtraForBattery($device['extra']);
|
||||||
$device['features'] = $this->getTaskConfig($id);
|
$device['features'] = $this->getTaskConfig($id);
|
||||||
$device['totalFriend'] = $this->getTotalFriend($id);
|
$device['totalFriend'] = $this->getTotalFriend($id);
|
||||||
$device['thirtyDayMsgCount'] = $this->getThirtyDayMsgCount();
|
$device['thirtyDayMsgCount'] = $this->getThirtyDayMsgCount($id);
|
||||||
|
|
||||||
// 设备最后活跃时间为设备状态更新时间
|
// 设备最后活跃时间为设备状态更新时间
|
||||||
$device['lastUpdateTime'] = date('Y-m-d H:i:s', $device['lastUpdateTime']);
|
$device['lastUpdateTime'] = date('Y-m-d H:i:s', $device['lastUpdateTime']);
|
||||||
@@ -147,6 +186,7 @@ class GetDeviceDetailV1Controller extends BaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备详情
|
* 获取设备详情
|
||||||
|
*
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
@@ -158,9 +198,9 @@ class GetDeviceDetailV1Controller extends BaseController
|
|||||||
$this->checkUserDevicePermission($id);
|
$this->checkUserDevicePermission($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$resultSet = $this->getDeviceInfo($id);
|
return ResponseHelper::success(
|
||||||
|
$this->getDeviceInfo($id)
|
||||||
return ResponseHelper::success($resultSet);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device;
|
|||||||
|
|
||||||
use app\common\model\Device as DeviceModel;
|
use app\common\model\Device as DeviceModel;
|
||||||
use app\common\model\DeviceUser as DeviceUserModel;
|
use app\common\model\DeviceUser as DeviceUserModel;
|
||||||
|
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||||
use app\common\model\User as UserModel;
|
use app\common\model\User as UserModel;
|
||||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||||
use app\cunkebao\controller\BaseController;
|
use app\cunkebao\controller\BaseController;
|
||||||
@@ -73,10 +74,10 @@ class GetDeviceListV1Controller extends BaseController
|
|||||||
->field([
|
->field([
|
||||||
'd.id', 'd.imei', 'd.memo', 'd.alive',
|
'd.id', 'd.imei', 'd.memo', 'd.alive',
|
||||||
'l.wechatId',
|
'l.wechatId',
|
||||||
'wa.nickname', 'wa.alias', '0 totalFriend'
|
'a.nickname', 'a.alias', '0 totalFriend'
|
||||||
])
|
])
|
||||||
->leftJoin('device_wechat_login l', 'd.id = l.deviceId')
|
->leftJoin('device_wechat_login l', 'd.id = l.deviceId and l.alive =' . DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE)
|
||||||
->leftJoin('wechat_account wa', 'l.wechatId = wa.wechatId')
|
->leftJoin('wechat_account a', 'l.wechatId = a.wechatId')
|
||||||
->order('d.id desc');
|
->order('d.id desc');
|
||||||
|
|
||||||
foreach ($where as $key => $value) {
|
foreach ($where as $key => $value) {
|
||||||
@@ -105,7 +106,13 @@ class GetDeviceListV1Controller extends BaseController
|
|||||||
$sections = $item->toArray();
|
$sections = $item->toArray();
|
||||||
|
|
||||||
if ($item->wechatId) {
|
if ($item->wechatId) {
|
||||||
$sections['totalFriend'] = WechatFriendShipModel::where(['ownerWechatId' => $item->wechatId])->count();
|
$sections['totalFriend'] = WechatFriendShipModel::where(
|
||||||
|
[
|
||||||
|
'ownerWechatId' => $item->wechatId,
|
||||||
|
'companyId' => $this->getUserInfo('companyId')
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($resultSets, $sections);
|
array_push($resultSets, $sections);
|
||||||
|
|||||||
Reference in New Issue
Block a user