门店端适配新表 及操盘手端工作台优化
This commit is contained in:
@@ -212,6 +212,55 @@ class DeviceController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新设备分组
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function updateaccount()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取参数
|
||||
$id = $this->request->param('id', '');
|
||||
$accountId = $this->request->param('accountId', '');
|
||||
|
||||
if (empty($id)) {
|
||||
return errorJson('设备ID不能为空');
|
||||
}
|
||||
|
||||
if (empty($accountId)) {
|
||||
return errorJson('账号id不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
|
||||
// 发送请求
|
||||
$result = requestCurl($this->baseUrl . 'api/device/updateaccount?accountId=' . $accountId . '&deviceId=' . $id, [], 'PUT', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
|
||||
if(empty($response)){
|
||||
return successJson([],'操作成功');
|
||||
}else{
|
||||
return errorJson([],$response);
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('更新设备分组失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分组列表
|
||||
* @return \think\response\Json
|
||||
|
||||
@@ -3,17 +3,22 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\WechatAccountModel;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 微信账号管理控制器
|
||||
*/
|
||||
class WechatController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取微信账号列表
|
||||
* 获取微信账号列表(主方法)
|
||||
*
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页大小
|
||||
* @param bool $isJob 是否为任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '', $pageSize = '', $isJob = false)
|
||||
public function getList($pageIndex = '', $pageSize = '', $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
@@ -43,17 +48,20 @@ class WechatController extends BaseController
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
|
||||
// 发送请求
|
||||
// 发送请求获取基本信息
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatAccount/list', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
// 保存基本数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveWechatAccount($item);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取并更新微信账号状态信息
|
||||
$this->getListTenantWechatPartial($authorization);
|
||||
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 200, 'msg' => '获取微信账号列表成功', 'data' => $response]);
|
||||
} else {
|
||||
@@ -69,54 +77,178 @@ class WechatController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存微信账号数据到数据库
|
||||
* 获取微信账号状态信息
|
||||
*
|
||||
* @param string $authorization 授权token
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function getListTenantWechatPartial($authorization = '')
|
||||
{
|
||||
// 获取授权token(如果未传入)
|
||||
if (empty($authorization)) {
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 从数据库获取微信账号和设备信息
|
||||
$wechatList = Db::table('s2_wechat_account')
|
||||
->where('isDeleted', 0)
|
||||
->select();
|
||||
|
||||
if (empty($wechatList)) {
|
||||
if (empty($authorization)) { // 只有作为独立API调用时才返回
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => []]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 构造请求参数
|
||||
$wechatAccountIds = [];
|
||||
$deviceIds = [];
|
||||
$accountIds = [];
|
||||
|
||||
foreach ($wechatList as $item) {
|
||||
$wechatAccountIds[] = $item['id'];
|
||||
$deviceIds[] = $item['currentDeviceId'] ?: 0;
|
||||
$accountIds[] = $item['deviceAccountId'] ?: 0;
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
|
||||
$params = [
|
||||
'wechatAccountIdsStr' => json_encode($wechatAccountIds),
|
||||
'deviceIdsStr' => json_encode($deviceIds),
|
||||
'accountIdsStr' => json_encode($accountIds),
|
||||
'groupId' => ''
|
||||
];
|
||||
|
||||
// 发送请求获取状态信息
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatAccount/listTenantWechatPartial', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 如果请求成功并返回数据,则更新数据库
|
||||
if (!empty($response)) {
|
||||
$this->batchUpdateWechatAccounts($response);
|
||||
}
|
||||
|
||||
// 只有作为独立API调用时才返回
|
||||
if (empty($authorization)) {
|
||||
// 返回更新后的数据
|
||||
$updatedWechatList = Db::table('s2_wechat_account')
|
||||
->where('isDeleted', 0)
|
||||
->select();
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => $updatedWechatList]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if (empty($authorization)) { // 只有作为独立API调用时才返回
|
||||
return json(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新微信账号数据
|
||||
*
|
||||
* @param array $data 接口返回的数据
|
||||
*/
|
||||
private function batchUpdateWechatAccounts($data)
|
||||
{
|
||||
// 更新微信账号信息
|
||||
if (!empty($data['totalFriend'])) {
|
||||
// 遍历所有微信账号ID
|
||||
$wechatIds = array_keys($data['totalFriend']);
|
||||
foreach ($wechatIds as $wechatId) {
|
||||
// 构建更新数据
|
||||
$updateData = [
|
||||
'maleFriend' => $data['maleFriend'][$wechatId] ?? 0,
|
||||
'femaleFriend' => $data['femaleFriend'][$wechatId] ?? 0,
|
||||
'unknowFriend' => $data['unknowFriend'][$wechatId] ?? 0,
|
||||
'totalFriend' => $data['totalFriend'][$wechatId] ?? 0,
|
||||
'yesterdayMsgCount' => $data['yesterdayMsgCount'][$wechatId] ?? 0,
|
||||
'sevenDayMsgCount' => $data['sevenDayMsgCount'][$wechatId] ?? 0,
|
||||
'thirtyDayMsgCount' => $data['thirtyDayMsgCount'][$wechatId] ?? 0,
|
||||
'wechatAlive' => isset($data['wechatAlive'][$wechatId]) ? (int)$data['wechatAlive'][$wechatId] : 0,
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 更新数据库
|
||||
Db::table('s2_wechat_account')
|
||||
->where('id', $wechatId)
|
||||
->update($updateData);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新设备状态
|
||||
if (!empty($data['deviceAlive'])) {
|
||||
foreach ($data['deviceAlive'] as $deviceId => $isAlive) {
|
||||
// 更新微信账号的设备状态
|
||||
Db::table('s2_wechat_account')
|
||||
->where('currentDeviceId', $deviceId)
|
||||
->update([
|
||||
'deviceAlive' => (int)$isAlive,
|
||||
'updateTime' => time()
|
||||
]);
|
||||
|
||||
// 更新设备表的状态
|
||||
Db::table('s2_device')
|
||||
->where('id', $deviceId)
|
||||
->update([
|
||||
'alive' => (int)$isAlive,
|
||||
'updateTime' => time()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存微信账号基本数据到数据库
|
||||
*
|
||||
* @param array $item 微信账号数据
|
||||
*/
|
||||
private function saveWechatAccount($item)
|
||||
{
|
||||
// 处理时间字段
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : 0;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : 0;
|
||||
|
||||
// 构建数据
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'wechatId' => $item['wechatId'],
|
||||
'deviceAccountId' => $item['deviceAccountId'],
|
||||
'imei' => $item['imei'],
|
||||
'deviceMemo' => $item['deviceMemo'],
|
||||
'accountUserName' => $item['accountUserName'],
|
||||
'accountRealName' => $item['accountRealName'],
|
||||
'accountNickname' => $item['accountNickname'],
|
||||
'keFuAlive' => $item['keFuAlive'],
|
||||
'deviceAlive' => $item['deviceAlive'],
|
||||
'wechatAlive' => $item['wechatAlive'],
|
||||
'yesterdayMsgCount' => $item['yesterdayMsgCount'],
|
||||
'sevenDayMsgCount' => $item['sevenDayMsgCount'],
|
||||
'thirtyDayMsgCount' => $item['thirtyDayMsgCount'],
|
||||
'totalFriend' => $item['totalFriend'],
|
||||
'maleFriend' => $item['maleFriend'],
|
||||
'femaleFriend' => $item['femaleFriend'],
|
||||
'wechatGroupName' => $item['wechatGroupName'],
|
||||
'tenantId' => $item['tenantId'],
|
||||
'nickname' => $item['nickname'],
|
||||
'alias' => $item['alias'],
|
||||
'avatar' => $item['avatar'],
|
||||
'gender' => $item['gender'],
|
||||
'region' => $item['region'],
|
||||
'signature' => $item['signature'],
|
||||
'bindQQ' => $item['bindQQ'],
|
||||
'bindEmail' => $item['bindEmail'],
|
||||
'bindMobile' => $item['bindMobile'],
|
||||
'currentDeviceId' => $item['currentDeviceId'],
|
||||
'isDeleted' => $item['isDeleted'],
|
||||
'groupId' => $item['groupId'],
|
||||
'memo' => $item['memo'],
|
||||
'wechatVersion' => $item['wechatVersion'],
|
||||
'wechatId' => $item['wechatId'] ?? '',
|
||||
'deviceAccountId' => $item['deviceAccountId'] ?? 0,
|
||||
'imei' => $item['imei'] ?? '',
|
||||
'deviceMemo' => $item['deviceMemo'] ?? '',
|
||||
'accountUserName' => $item['accountUserName'] ?? '',
|
||||
'accountRealName' => $item['accountRealName'] ?? '',
|
||||
'accountNickname' => $item['accountNickname'] ?? '',
|
||||
'wechatGroupName' => $item['wechatGroupName'] ?? '',
|
||||
'alias' => $item['alias'] ?? '',
|
||||
'tenantId' => $item['tenantId'] ?? 0,
|
||||
'nickname' => $item['nickname'] ?? '',
|
||||
'avatar' => $item['avatar'] ?? '',
|
||||
'gender' => $item['gender'] ?? 0,
|
||||
'region' => $item['region'] ?? '',
|
||||
'signature' => $item['signature'] ?? '',
|
||||
'bindQQ' => $item['bindQQ'] ?? '',
|
||||
'bindEmail' => $item['bindEmail'] ?? '',
|
||||
'bindMobile' => $item['bindMobile'] ?? '',
|
||||
'currentDeviceId' => $item['currentDeviceId'] ?? 0,
|
||||
'isDeleted' => $item['isDeleted'] ?? 0,
|
||||
'groupId' => $item['groupId'] ?? 0,
|
||||
'memo' => $item['memo'] ?? '',
|
||||
'wechatVersion' => $item['wechatVersion'] ?? '',
|
||||
'labels' => !empty($item['labels']) ? json_encode($item['labels']) : json_encode([]),
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 保存或更新数据
|
||||
$account = WechatAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
|
||||
Reference in New Issue
Block a user