From 7b3df951529e1b46c1c040cf16e718eb36eb7345 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Sun, 28 Sep 2025 16:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/GetDeviceListV1Controller.php | 7 +++++-- .../wechat/GetWechatsOnDevicesV1Controller.php | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php index 78a21c1a..cef4d96f 100644 --- a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php @@ -71,14 +71,17 @@ class GetDeviceListV1Controller extends BaseController */ protected function getDeviceList(array $where): \think\Paginator { + + $companyId = $this->getUserInfo('companyId'); $query = DeviceModel::alias('d') ->field([ 'd.id', 'd.imei', 'd.memo', 'd.alive', 'l.wechatId', 'a.nickname', 'a.alias', 'a.avatar', '0 totalFriend' ]) - ->leftJoin('device_wechat_login l', 'd.id = l.deviceId and l.alive =' . DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE . ' and l.companyId = d.companyId') - ->leftJoin('wechat_account a', 'l.wechatId = a.wechatId') + ->join('(SELECT MAX(id) AS id, deviceId FROM ck_device_wechat_login WHERE companyId='.$companyId.' GROUP BY deviceId) dwl_max','dwl_max.deviceId = d.id') + ->join('device_wechat_login l','l.id = dwl_max.id') + ->join('wechat_account a', 'l.wechatId = a.wechatId') ->order('d.id desc'); foreach ($where as $key => $value) { diff --git a/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php b/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php index 15f1714b..05ac93ca 100644 --- a/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php +++ b/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php @@ -12,6 +12,7 @@ use app\common\model\WechatCustomer as WechatCustomerModel; use app\common\model\WechatFriendShip as WechatFriendShipModel; use app\cunkebao\controller\BaseController; use library\ResponseHelper; +use think\Db; /** * 微信控制器 @@ -63,7 +64,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController */ protected function getWechatAddFriendStatus(string $wechatId): int { - return 1; + return Db::name('device_wechat_login')->where(['wechatId' => $wechatId])->order('id DESC')->value('alive'); } /** @@ -164,7 +165,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController return DeviceWechatLoginModel::where( [ 'companyId' => $this->getUserInfo('companyId'), - 'alive' => DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE, +// 'alive' => DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE, ] ) ->where('deviceId', 'in', $deviceIds) @@ -179,7 +180,12 @@ class GetWechatsOnDevicesV1Controller extends BaseController */ protected function getLatestActiveTime(string $wechatId): string { - return date('Y-m-d H:i:s', strtotime('-1 day')); + $wechatAccountId = Db::table('s2_wechat_account')->where(['wechatId' => $wechatId])->value('id'); + if (empty($wechatAccountId)){ + return '-'; + } + $time = Db::table('s2_wechat_message')->where('wechatAccountId',$wechatAccountId)->order('id DESC')->value('wechatTime'); + return !empty($time) ? date('Y-m-d H:i:s', $time) : '-'; } /** @@ -217,7 +223,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController [ 'w.id', 'w.nickname', 'w.avatar', 'w.wechatId', 'CASE WHEN w.alias IS NULL OR w.alias = "" THEN w.wechatId ELSE w.alias END AS wechatAccount', - 'l.deviceId' + 'l.deviceId','l.alive' ] ) ->join('device_wechat_login l', 'w.wechatId = l.wechatId AND l.companyId = '. $this->getUserInfo('companyId'))