底层新增部门和账号二合一接口
This commit is contained in:
@@ -10,6 +10,7 @@ Route::group('v1', function () {
|
||||
Route::group('account', function () {
|
||||
Route::get('list', 'app\\api\\controller\\AccountController@getList'); // 获取账号列表 √
|
||||
Route::post('create', 'app\\api\\controller\\AccountController@createAccount'); // 创建账号 √
|
||||
Route::post('createNewAccount', 'app\\api\\controller\\AccountController@createNewAccount'); // 创建新账号(包含创建部门) √
|
||||
Route::post('department/create', 'app\\api\\controller\\AccountController@createDepartment'); // 创建部门 √
|
||||
Route::get('department/list', 'app\\api\\controller\\AccountController@getDepartmentList'); // 获取部门列表 √
|
||||
Route::post('department/update', 'app\\api\\controller\\AccountController@updateDepartment'); // 更新部门 √
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\api\controller;
|
||||
|
||||
use app\api\model\CompanyAccountModel;
|
||||
use app\api\model\CompanyModel;
|
||||
use Library\S2\Logics\AccountLogic;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
@@ -23,6 +24,11 @@ class AccountController extends BaseController
|
||||
*/
|
||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
||||
{
|
||||
|
||||
$api = new AccountLogic();
|
||||
$api->login()->create();
|
||||
|
||||
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
@@ -133,7 +139,7 @@ class AccountController extends BaseController
|
||||
// 发送请求创建账号
|
||||
$result = requestCurl($this->baseUrl . 'api/account/newAccount', $params, 'POST', $header, 'json');
|
||||
|
||||
if (is_int($result)) {
|
||||
if (is_numeric($result)) {
|
||||
return successJson($result);
|
||||
} else {
|
||||
return errorJson($result);
|
||||
@@ -143,6 +149,114 @@ class AccountController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建新账号(包含创建部门)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function createNewAccount()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取参数
|
||||
$departmentName = $this->request->param('departmentName', '');
|
||||
$departmentMemo = $this->request->param('departmentMemo', '');
|
||||
$accountName = $this->request->param('accountName', '');
|
||||
$accountPassword = $this->request->param('accountPassword', '');
|
||||
$accountRealName = $this->request->param('accountRealName', '');
|
||||
$accountNickname = $this->request->param('accountNickname', '');
|
||||
$accountMemo = $this->request->param('accountMemo', '');
|
||||
|
||||
// 验证参数
|
||||
if (empty($departmentName)) {
|
||||
return errorJson('部门名称不能为空');
|
||||
}
|
||||
if (empty($accountName)) {
|
||||
return errorJson('账号名称不能为空');
|
||||
}
|
||||
if (empty($accountPassword)) {
|
||||
return errorJson('账号密码不能为空');
|
||||
}
|
||||
|
||||
// 检查部门是否已存在
|
||||
$existingDepartment = CompanyModel::where('name', $departmentName)->find();
|
||||
if ($existingDepartment) {
|
||||
return errorJson('部门名称已存在');
|
||||
}
|
||||
|
||||
// 检查账号是否已存在
|
||||
$existingAccount = CompanyAccountModel::where('userName', $accountName)->find();
|
||||
if ($existingAccount) {
|
||||
return errorJson('账号名称已存在');
|
||||
}
|
||||
|
||||
// 1. 创建部门
|
||||
$departmentParams = [
|
||||
'name' => $departmentName,
|
||||
'memo' => $departmentMemo,
|
||||
'departmentIdArr' => [914],
|
||||
'parentId' => 914
|
||||
];
|
||||
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
$departmentResult = requestCurl($this->baseUrl . 'api/Department/createDepartment', $departmentParams, 'POST', $header, 'json');
|
||||
|
||||
if (is_numeric($departmentResult)) {
|
||||
// 保存部门到数据库
|
||||
$department = CompanyModel::create([
|
||||
'id' => $departmentResult,
|
||||
'name' => $departmentName,
|
||||
'memo' => $departmentMemo,
|
||||
'tenantId' => 242,
|
||||
'isTop' => 0,
|
||||
'level' => 1,
|
||||
'parentId' => 914,
|
||||
'privileges' => '',
|
||||
'createTime' => time(),
|
||||
'lastUpdateTime' => 0
|
||||
]);
|
||||
} else {
|
||||
return errorJson('创建部门失败:' . $departmentResult);
|
||||
}
|
||||
|
||||
// 2. 创建账号
|
||||
$accountParams = [
|
||||
'userName' => $accountName,
|
||||
'password' => $accountPassword,
|
||||
'realName' => $accountRealName,
|
||||
'nickname' => $accountNickname,
|
||||
'memo' => $accountMemo,
|
||||
'departmentId' => $departmentResult,
|
||||
'departmentIdArr' => [914, $departmentResult]
|
||||
];
|
||||
|
||||
$accountResult = requestCurl($this->baseUrl . 'api/Account/newAccount', $accountParams, 'POST', $header, 'json');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!is_numeric($accountResult)) {
|
||||
// 如果创建账号失败,删除已创建的部门
|
||||
$this->deleteDepartment($accountResult);
|
||||
return errorJson('创建账号失败:' . $accountResult['msg']);
|
||||
}
|
||||
|
||||
return successJson($accountResult,'账号创建成功');
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('创建账号失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************ 部门管理相关接口 ************************/
|
||||
|
||||
/**
|
||||
@@ -213,9 +327,9 @@ class AccountController extends BaseController
|
||||
}
|
||||
|
||||
// 检查部门名称是否已存在
|
||||
$departmentId = CompanyModel::where('name', $name)->value('id');
|
||||
$departmentId = CompanyModel::where('name', $name)->find();
|
||||
if (!empty($departmentId)) {
|
||||
return errorJson('公司名称已存在');
|
||||
return successJson($departmentId);
|
||||
}
|
||||
|
||||
// 构建请求参数
|
||||
@@ -238,7 +352,14 @@ class AccountController extends BaseController
|
||||
$res = CompanyModel::create([
|
||||
'id' => $result,
|
||||
'name' => $name,
|
||||
'memo' => $memo
|
||||
'memo' => $memo,
|
||||
'tenantId' => 242,
|
||||
'isTop' => 0,
|
||||
'level' => 1,
|
||||
'parentId' => 914,
|
||||
'privileges' => '',
|
||||
'createTime' => time(),
|
||||
'lastUpdateTime' => 0
|
||||
]);
|
||||
return successJson($res);
|
||||
} else {
|
||||
@@ -319,7 +440,7 @@ class AccountController extends BaseController
|
||||
* 删除部门
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function deleteDepartment()
|
||||
public function deleteDepartment($id = '')
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
@@ -329,7 +450,7 @@ class AccountController extends BaseController
|
||||
|
||||
try {
|
||||
// 获取并验证部门ID
|
||||
$id = $this->request->param('id', 0);
|
||||
$id = !empty($id) ? $id : $this->request->param('id', '');
|
||||
if (empty($id)) {
|
||||
return errorJson('部门ID不能为空');
|
||||
}
|
||||
@@ -400,8 +521,8 @@ class AccountController extends BaseController
|
||||
'parentId' => isset($item['parentId']) ? $item['parentId'] : 0,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
'privileges' => isset($item['privileges']) ? (is_array($item['privileges']) ? json_encode($item['privileges']) : $item['privileges']) : '',
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : '',
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? $item['lastUpdateTime'] : ''
|
||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? ($item['lastUpdateTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['lastUpdateTime'])) : 0
|
||||
];
|
||||
|
||||
// 使用id作为唯一性判断
|
||||
|
||||
@@ -270,10 +270,10 @@ class DeviceController extends BaseController
|
||||
'currentAccountId' => isset($item['currentAccountId']) ? $item['currentAccountId'] : 0,
|
||||
'imei' => $item['imei'],
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : null,
|
||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
'deletedAndStop' => isset($item['deletedAndStop']) ? $item['deletedAndStop'] : false,
|
||||
'deleteTime' => isset($item['deleteTime']) ? $item['deleteTime'] : null,
|
||||
'deleteTime' => empty($item['isDeleted']) ? 0 : strtotime($item['deleteTime']),
|
||||
'rooted' => isset($item['rooted']) ? $item['rooted'] : false,
|
||||
'xPosed' => isset($item['xPosed']) ? $item['xPosed'] : false,
|
||||
'brand' => isset($item['brand']) ? $item['brand'] : '',
|
||||
@@ -282,7 +282,7 @@ class DeviceController extends BaseController
|
||||
'softwareVersion' => isset($item['softwareVersion']) ? $item['softwareVersion'] : '',
|
||||
'extra' => isset($item['extra']) ? json_encode($item['extra']) : json_encode([]),
|
||||
'phone' => isset($item['phone']) ? $item['phone'] : '',
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? $item['lastUpdateTime'] : null
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? ($item['lastUpdateTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['lastUpdateTime'])) : 0
|
||||
];
|
||||
|
||||
// 使用imei作为唯一性判断
|
||||
|
||||
@@ -88,8 +88,8 @@ class WechatChatroomController extends BaseController
|
||||
'chatroomAvatar' => isset($item['chatroomAvatar']) ? $item['chatroomAvatar'] : '',
|
||||
'members' => is_array($item['members']) ? json_encode($item['members']) : json_encode([]),
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : 0,
|
||||
'deleteTime' => isset($item['deleteTime']) ? $item['deleteTime'] : 0,
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : time(),
|
||||
'deleteTime' => !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : 0,
|
||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||
'accountId' => isset($item['accountId']) ? $item['accountId'] : 0,
|
||||
'accountUserName' => isset($item['accountUserName']) ? $item['accountUserName'] : '',
|
||||
'accountRealName' => isset($item['accountRealName']) ? $item['accountRealName'] : '',
|
||||
@@ -107,12 +107,12 @@ class WechatChatroomController extends BaseController
|
||||
WechatChatroomModel::create($data);
|
||||
}
|
||||
|
||||
// 同时保存群成员数据
|
||||
if (!empty($item['members'])) {
|
||||
foreach ($item['members'] as $member) {
|
||||
$this->saveChatroomMember($member, $item['chatroomId']);
|
||||
}
|
||||
}
|
||||
// // 同时保存群成员数据
|
||||
// if (!empty($item['members'])) {
|
||||
// foreach ($item['members'] as $member) {
|
||||
// $this->saveChatroomMember($member, $item['chatroomId']);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -102,7 +102,7 @@ class WechatFriendController extends BaseController
|
||||
'signature' => $item['signature'],
|
||||
'isDeleted' => $item['isDeleted'],
|
||||
'isPassed' => $item['isPassed'],
|
||||
'deleteTime' => $item['deleteTime'],
|
||||
'deleteTime' => !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : 0,
|
||||
'accountId' => $item['accountId'],
|
||||
'extendFields' => is_array($item['extendFields']) ? json_encode($item['extendFields']) : json_encode([]),
|
||||
'accountUserName' => $item['accountUserName'],
|
||||
@@ -115,13 +115,13 @@ class WechatFriendController extends BaseController
|
||||
'phone' => $item['phone'],
|
||||
'thirdParty' => is_array($item['thirdParty']) ? json_encode($item['thirdParty']) : json_encode([]),
|
||||
'groupId' => $item['groupId'],
|
||||
'passTime' => $item['passTime'],
|
||||
'passTime' => !empty($item['isPassed']) && $item['passTime'] != '0001-01-01T00:00:00' ? strtotime($item['passTime']) : 0,
|
||||
'additionalPicture' => $item['additionalPicture'],
|
||||
'desc' => $item['desc'],
|
||||
'country' => $item['country'],
|
||||
'privince' => isset($item['privince']) ? $item['privince'] : '',
|
||||
'city' => isset($item['city']) ? $item['city'] : '',
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : '',
|
||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
|
||||
use app\common\service\AuthService;
|
||||
|
||||
if (!function_exists('requestCurl')) {
|
||||
/**
|
||||
@@ -27,24 +27,24 @@ if (!function_exists('requestCurl')) {
|
||||
if (!empty($url)) {
|
||||
try {
|
||||
$ch = curl_init();
|
||||
|
||||
|
||||
// 处理GET请求的参数
|
||||
if (strtoupper($method) == 'GET' && !empty($params)) {
|
||||
$url = $url . '?' . dataBuild($params);
|
||||
}
|
||||
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //30秒超时
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||||
|
||||
|
||||
// 处理不同的请求方法
|
||||
if (strtoupper($method) != 'GET') {
|
||||
// 设置请求方法
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
|
||||
|
||||
|
||||
// 处理参数格式
|
||||
if ($type == 'dataBuild') {
|
||||
$params = dataBuild($params);
|
||||
@@ -53,11 +53,11 @@ if (!function_exists('requestCurl')) {
|
||||
} else {
|
||||
$params = dataBuild($params);
|
||||
}
|
||||
|
||||
|
||||
// 设置请求体
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||||
}
|
||||
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //是否验证对等证书,1则验证,0则不验证
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$str = curl_exec($ch);
|
||||
@@ -375,7 +375,13 @@ if (!function_exists('handleApiResponse')) {
|
||||
}
|
||||
|
||||
// 不是JSON格式,直接返回原始数据
|
||||
return $response;
|
||||
if($response == '无效路径或登录状态失效'){
|
||||
\think\facade\Cache::rm('system_refresh_token');
|
||||
AuthService::getSystemAuthorization();
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ class WechatChatroomJob
|
||||
$result = $wechatChatroomController->getlist($pageIndex,$pageSize,true);
|
||||
$response = json_decode($result,true);
|
||||
|
||||
|
||||
// 判断是否成功
|
||||
if ($response['code'] == 200) {
|
||||
$data = $response['data'];
|
||||
|
||||
146
Server/application/library/s2/CurlHandle.php
Normal file
146
Server/application/library/s2/CurlHandle.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace app\library\s2;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\facade\Env;
|
||||
use think\facade\Log;
|
||||
|
||||
class CurlHandle
|
||||
{
|
||||
private $baseUrl = '';
|
||||
private $authorization = '';
|
||||
private $header = [];
|
||||
private $method = 'get';
|
||||
private static $instant = null;
|
||||
|
||||
/**
|
||||
* 获取域名
|
||||
* @return void
|
||||
*/
|
||||
private function getBaseUrl()
|
||||
{
|
||||
$this->baseUrl = Env::get('api.wechat_url');
|
||||
}
|
||||
|
||||
/**
|
||||
* CurlHandle constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->getBaseUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置头部
|
||||
*
|
||||
* @param array $headerData 头部数组
|
||||
* @param string $authorization
|
||||
* @param string $type 类型 默认json (json,plain)
|
||||
* @return array
|
||||
*/
|
||||
public function setHeader($key, $value): CurlHandle
|
||||
{
|
||||
if (is_array($key)) {
|
||||
$this->header = array_merge($this->header, $key);
|
||||
} else {
|
||||
$this->header[$key] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function getHearder(): array
|
||||
{
|
||||
$header = [];
|
||||
|
||||
foreach ($this->header as $key => $value) {
|
||||
$header[] = $key . ':' . $value;
|
||||
}
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
public function setMethod(string $method): CurlHandle
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string $url 请求的链接
|
||||
* @param array $params 请求附带的参数
|
||||
* @param string $method 请求的方式, 支持GET, POST, PUT, DELETE等
|
||||
* @param array $header 头部
|
||||
* @param string $type 数据类型,支持dataBuild、json等
|
||||
* @return bool|string
|
||||
*/
|
||||
public function requestCurl($url, $params = [], $method = 'GET', $type = 'dataBuild')
|
||||
{
|
||||
$str = '';
|
||||
if (!empty($url)) {
|
||||
try {
|
||||
$ch = curl_init();
|
||||
|
||||
// 处理GET请求的参数
|
||||
if (strtoupper($method) == 'GET' && !empty($params)) {
|
||||
$url = $url . '?' . dataBuild($params);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //30秒超时
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHearder());
|
||||
|
||||
// 处理不同的请求方法
|
||||
if (strtoupper($method) != 'GET') {
|
||||
// 设置请求方法
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
|
||||
|
||||
// 处理参数格式
|
||||
if ($type == 'dataBuild') {
|
||||
$params = dataBuild($params);
|
||||
} elseif ($type == 'json') {
|
||||
$params = json_encode($params);
|
||||
} else {
|
||||
$params = dataBuild($params);
|
||||
}
|
||||
|
||||
// 设置请求体
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //是否验证对等证书,1则验证,0则不验证
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$str = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
} catch (Exception $e) {
|
||||
$str = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单例
|
||||
*
|
||||
* @return static|null
|
||||
*/
|
||||
public static function getInstant()
|
||||
{
|
||||
if (self::$instant instanceof self) {
|
||||
return self::$instant;
|
||||
}
|
||||
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\library\s2\interfaces;
|
||||
|
||||
interface AccountInterface
|
||||
{
|
||||
/**
|
||||
* 创建账号
|
||||
*
|
||||
* @param string $accout
|
||||
* @param string $password
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(string $accout, string $password);
|
||||
|
||||
/**
|
||||
* 删除账号
|
||||
*
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(int $id);
|
||||
}
|
||||
13
Server/application/library/s2/interfaces/DeviceInterface.php
Normal file
13
Server/application/library/s2/interfaces/DeviceInterface.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\library\s2\interfaces;
|
||||
|
||||
interface DeviceInterface
|
||||
{
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function getlist(array $params): array;
|
||||
}
|
||||
15
Server/application/library/s2/interfaces/LoginInterface.php
Normal file
15
Server/application/library/s2/interfaces/LoginInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace app\library\s2\interfaces;
|
||||
|
||||
interface LoginInterface
|
||||
{
|
||||
/**
|
||||
* 创建账号
|
||||
*
|
||||
* @param string $accout
|
||||
* @param string $password
|
||||
* @return mixed
|
||||
*/
|
||||
public function login(string $accout, string $password): LoginInterface;
|
||||
}
|
||||
25
Server/application/library/s2/logics/AccountLogic.php
Normal file
25
Server/application/library/s2/logics/AccountLogic.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace app\library\s2\logics;
|
||||
|
||||
use app\library\s2\interfaces\AccountInterface;
|
||||
use app\library\s2\interfaces\LoginInterface;
|
||||
|
||||
class AccountLogic implements AccountInterface, LoginInterface
|
||||
{
|
||||
public function create(string $accout, string $password)
|
||||
{
|
||||
// TODO: Implement create() method.
|
||||
}
|
||||
|
||||
public function login(string $accout, string $password): LoginInterface
|
||||
{
|
||||
// TODO: Implement login() method.
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
// TODO: Implement delete() method.
|
||||
}
|
||||
}
|
||||
217
Server/application/library/s2/logics/DeviceLogic.php
Normal file
217
Server/application/library/s2/logics/DeviceLogic.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace app\library\s2\logics;
|
||||
|
||||
use app\api\model\DeviceModel;
|
||||
use app\common\service\AuthService;
|
||||
use app\library\s2\CurlHandle;
|
||||
use app\library\s2\interfaces\DeviceInterface;
|
||||
use think\facade\Log;
|
||||
use app\api\model\DeviceGroupModel;
|
||||
|
||||
class DeviceLogic implements DeviceInterface
|
||||
{
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getlist(array $params = []): array
|
||||
{
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'accountId' => $params['accountId'] ?? '',
|
||||
'keyword' => $params['keyword'] ?? '',
|
||||
'imei' => $params['imei'] ?? '',
|
||||
'groupId' => $params['groupId'] ?? '',
|
||||
'brand' => $params['brand'] ?? '',
|
||||
'model' => $params['model'] ?? '',
|
||||
'deleteType' => $params['deleteType'] ?? 'unDeleted',
|
||||
'operatingSystem' => $params['operatingSystem'] ?? '',
|
||||
'softwareVersion' => $params['softwareVersion'] ?? '',
|
||||
'phoneAppVersion' => $params['phoneAppVersion'] ?? '',
|
||||
'recorderVersion' => $params['recorderVersion'] ?? '',
|
||||
'contactsVersion' => $params['contactsVersion'] ?? '',
|
||||
'rooted' => $params['rooted'] ?? '',
|
||||
'xPosed' => $params['xPosed'] ?? '',
|
||||
'alive' => $params['alive'] ?? '',
|
||||
'hasWechat' => $params['hasWechat'] ?? '',
|
||||
'departmentId' => $params['departmentId'] ?? '',
|
||||
'pageIndex' => $params['pageIndex'] ?? 0,
|
||||
'pageSize' => $params['pageSize'] ?? 20
|
||||
];
|
||||
|
||||
$JWT = AuthService::getSystemAuthorization();
|
||||
$result = CurlHandle::getInstant()
|
||||
->setHeader('Content-Type', 'text/plain')
|
||||
->setHeader('authorization', 'bearer ' . $JWT)
|
||||
->setMethod('get')
|
||||
->requestCurl('api/Account/myTenantPageAccounts', $params);
|
||||
|
||||
print_r($result);
|
||||
exit();
|
||||
|
||||
$response = handleApiResponse($result);
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveData($item);
|
||||
}
|
||||
}
|
||||
return json_encode(['code' => 200, 'msg' => '获取公司账号列表成功', 'data' => $response]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return json_encode(['code' => 500, 'msg' => '获取公司账号列表失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function saveData($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : '',
|
||||
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
||||
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
||||
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
||||
'groupName' => isset($item['groupName']) ? $item['groupName'] : '',
|
||||
'wechatAccounts' => isset($item['wechatAccounts']) ? json_encode($item['wechatAccounts']) : json_encode([]),
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'lastAliveTime' => isset($item['lastAliveTime']) ? $item['lastAliveTime'] : null,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
'groupId' => isset($item['groupId']) ? $item['groupId'] : 0,
|
||||
'currentAccountId' => isset($item['currentAccountId']) ? $item['currentAccountId'] : 0,
|
||||
'imei' => $item['imei'],
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
'deletedAndStop' => isset($item['deletedAndStop']) ? $item['deletedAndStop'] : false,
|
||||
'deleteTime' => empty($item['isDeleted']) ? 0 : strtotime($item['deleteTime']),
|
||||
'rooted' => isset($item['rooted']) ? $item['rooted'] : false,
|
||||
'xPosed' => isset($item['xPosed']) ? $item['xPosed'] : false,
|
||||
'brand' => isset($item['brand']) ? $item['brand'] : '',
|
||||
'model' => isset($item['model']) ? $item['model'] : '',
|
||||
'operatingSystem' => isset($item['operatingSystem']) ? $item['operatingSystem'] : '',
|
||||
'softwareVersion' => isset($item['softwareVersion']) ? $item['softwareVersion'] : '',
|
||||
'extra' => isset($item['extra']) ? json_encode($item['extra']) : json_encode([]),
|
||||
'phone' => isset($item['phone']) ? $item['phone'] : '',
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? ($item['lastUpdateTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['lastUpdateTime'])) : 0
|
||||
];
|
||||
|
||||
// 使用imei作为唯一性判断
|
||||
$device = DeviceModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($device) {
|
||||
$device->save($data);
|
||||
} else {
|
||||
|
||||
// autoLike:自动点赞
|
||||
// momentsSync:朋友圈同步
|
||||
// autoCustomerDev:自动开发客户
|
||||
// groupMessageDeliver:群消息推送
|
||||
// autoGroup:自动建群
|
||||
|
||||
$data['taskConfig'] = json_encode([
|
||||
'autoLike' => true,
|
||||
'momentsSync' => true,
|
||||
'autoCustomerDev' => true,
|
||||
'groupMessageDeliver' => true,
|
||||
'autoGroup' => true,
|
||||
]);
|
||||
DeviceModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设备数据
|
||||
* @param array $item 设备数据
|
||||
* @return bool
|
||||
*/
|
||||
public function saveDevice($item)
|
||||
{
|
||||
try {
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : '',
|
||||
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
||||
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
||||
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
||||
'groupName' => isset($item['groupName']) ? $item['groupName'] : '',
|
||||
'wechatAccounts' => isset($item['wechatAccounts']) ? json_encode($item['wechatAccounts']) : json_encode([]),
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'lastAliveTime' => isset($item['lastAliveTime']) ? $item['lastAliveTime'] : null,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
'groupId' => isset($item['groupId']) ? $item['groupId'] : 0,
|
||||
'currentAccountId' => isset($item['currentAccountId']) ? $item['currentAccountId'] : 0,
|
||||
'imei' => $item['imei'],
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
'deletedAndStop' => isset($item['deletedAndStop']) ? $item['deletedAndStop'] : false,
|
||||
'deleteTime' => empty($item['isDeleted']) ? 0 : strtotime($item['deleteTime']),
|
||||
'rooted' => isset($item['rooted']) ? $item['rooted'] : false,
|
||||
'xPosed' => isset($item['xPosed']) ? $item['xPosed'] : false,
|
||||
'brand' => isset($item['brand']) ? $item['brand'] : '',
|
||||
'model' => isset($item['model']) ? $item['model'] : '',
|
||||
'operatingSystem' => isset($item['operatingSystem']) ? $item['operatingSystem'] : '',
|
||||
'softwareVersion' => isset($item['softwareVersion']) ? $item['softwareVersion'] : '',
|
||||
'extra' => isset($item['extra']) ? json_encode($item['extra']) : json_encode([]),
|
||||
'phone' => isset($item['phone']) ? $item['phone'] : '',
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? ($item['lastUpdateTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['lastUpdateTime'])) : 0
|
||||
];
|
||||
|
||||
// 使用ID作为唯一性判断
|
||||
$device = DeviceModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($device) {
|
||||
$device->save($data);
|
||||
} else {
|
||||
$data['taskConfig'] = json_encode([
|
||||
'autoLike' => true,
|
||||
'momentsSync' => true,
|
||||
'autoCustomerDev' => true,
|
||||
'groupMessageDeliver' => true,
|
||||
'autoGroup' => true,
|
||||
]);
|
||||
DeviceModel::create($data);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('保存设备数据失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设备分组数据
|
||||
* @param array $item 设备分组数据
|
||||
* @return bool
|
||||
*/
|
||||
public function saveDeviceGroup($item)
|
||||
{
|
||||
try {
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'tenantId' => $item['tenantId'],
|
||||
'groupName' => $item['groupName'],
|
||||
'groupMemo' => $item['groupMemo'],
|
||||
'count' => isset($item['count']) ? $item['count'] : 0,
|
||||
'createTime' => $item['createTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['createTime'])
|
||||
];
|
||||
|
||||
// 使用ID作为唯一性判断
|
||||
$group = DeviceGroupModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($group) {
|
||||
$group->save($data);
|
||||
} else {
|
||||
DeviceGroupModel::create($data);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('保存设备分组数据失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
118
Server/library/s2/logics/DeviceLogic.php
Normal file
118
Server/library/s2/logics/DeviceLogic.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace library\s2\logics;
|
||||
|
||||
use app\api\model\DeviceModel;
|
||||
use app\common\service\AuthService;
|
||||
use library\s2\CurlHandle;
|
||||
use library\s2\Interfaces\DeviceInterface;
|
||||
|
||||
class DeviceLogic implements DeviceInterface
|
||||
{
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getlist(array $params = []): array
|
||||
{
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'accountId' => $params['accountId'] ?? '',
|
||||
'keyword' => $params['keyword'] ?? '',
|
||||
'imei' => $params['imei'] ?? '',
|
||||
'groupId' => $params['groupId'] ?? '',
|
||||
'brand' => $params['brand'] ?? '',
|
||||
'model' => $params['model'] ?? '',
|
||||
'deleteType' => $params['deleteType'] ?? 'unDeleted',
|
||||
'operatingSystem' => $params['operatingSystem'] ?? '',
|
||||
'softwareVersion' => $params['softwareVersion'] ?? '',
|
||||
'phoneAppVersion' => $params['phoneAppVersion'] ?? '',
|
||||
'recorderVersion' => $params['recorderVersion'] ?? '',
|
||||
'contactsVersion' => $params['contactsVersion'] ?? '',
|
||||
'rooted' => $params['rooted'] ?? '',
|
||||
'xPosed' => $params['xPosed'] ?? '',
|
||||
'alive' => $params['alive'] ?? '',
|
||||
'hasWechat' => $params['hasWechat'] ?? '',
|
||||
'departmentId' => $params['departmentId'] ?? '',
|
||||
'pageIndex' => $params['pageIndex'] ?? 0,
|
||||
'pageSize' => $params['pageSize'] ?? 20
|
||||
];
|
||||
|
||||
$JWT = AuthService::getSystemAuthorization();
|
||||
$result = CurlHandle::getInstant()
|
||||
->setHeader('Content-Type', 'text/plain')
|
||||
->setHeader('authorization', 'bearer ' . $JWT)
|
||||
->setMethod('get')
|
||||
->requestCurl('api/Account/myTenantPageAccounts', $params);
|
||||
$response = handleApiResponse($result);
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveData($item);
|
||||
}
|
||||
}
|
||||
return json_encode(['code' => 200, 'msg' => '获取公司账号列表成功', 'data' => $response]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return json_encode(['code' => 500, 'msg' => '获取公司账号列表失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function saveData($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : '',
|
||||
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
||||
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
||||
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
||||
'groupName' => isset($item['groupName']) ? $item['groupName'] : '',
|
||||
'wechatAccounts' => isset($item['wechatAccounts']) ? json_encode($item['wechatAccounts']) : json_encode([]),
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'lastAliveTime' => isset($item['lastAliveTime']) ? $item['lastAliveTime'] : null,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
'groupId' => isset($item['groupId']) ? $item['groupId'] : 0,
|
||||
'currentAccountId' => isset($item['currentAccountId']) ? $item['currentAccountId'] : 0,
|
||||
'imei' => $item['imei'],
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
'deletedAndStop' => isset($item['deletedAndStop']) ? $item['deletedAndStop'] : false,
|
||||
'deleteTime' => empty($item['isDeleted']) ? 0 : strtotime($item['deleteTime']),
|
||||
'rooted' => isset($item['rooted']) ? $item['rooted'] : false,
|
||||
'xPosed' => isset($item['xPosed']) ? $item['xPosed'] : false,
|
||||
'brand' => isset($item['brand']) ? $item['brand'] : '',
|
||||
'model' => isset($item['model']) ? $item['model'] : '',
|
||||
'operatingSystem' => isset($item['operatingSystem']) ? $item['operatingSystem'] : '',
|
||||
'softwareVersion' => isset($item['softwareVersion']) ? $item['softwareVersion'] : '',
|
||||
'extra' => isset($item['extra']) ? json_encode($item['extra']) : json_encode([]),
|
||||
'phone' => isset($item['phone']) ? $item['phone'] : '',
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? ($item['lastUpdateTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['lastUpdateTime'])) : 0
|
||||
];
|
||||
|
||||
// 使用imei作为唯一性判断
|
||||
$device = DeviceModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($device) {
|
||||
$device->save($data);
|
||||
} else {
|
||||
|
||||
// autoLike:自动点赞
|
||||
// momentsSync:朋友圈同步
|
||||
// autoCustomerDev:自动开发客户
|
||||
// groupMessageDeliver:群消息推送
|
||||
// autoGroup:自动建群
|
||||
|
||||
$data['taskConfig'] = json_encode([
|
||||
'autoLike' => true,
|
||||
'momentsSync' => true,
|
||||
'autoCustomerDev' => true,
|
||||
'groupMessageDeliver' => true,
|
||||
'autoGroup' => true,
|
||||
]);
|
||||
DeviceModel::create($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user