底层添加路由
This commit is contained in:
77
Server/application/api/config/route.php
Normal file
77
Server/application/api/config/route.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// store模块路由配置
|
||||
|
||||
use think\facade\Route;
|
||||
|
||||
// 定义RESTful风格的API路由
|
||||
Route::group('v1', function () {
|
||||
Route::group('api', function () {
|
||||
// Account控制器路由
|
||||
Route::group('account', function () {
|
||||
Route::get('list', 'app\\api\\controller\\AccountController@getList'); // 获取账号列表 √
|
||||
Route::post('create', 'app\\api\\controller\\AccountController@createAccount'); // 创建账号 √
|
||||
Route::post('department/create', 'app\\api\\controller\\AccountController@createDepartment'); // 创建部门 √
|
||||
Route::get('department/list', 'app\\api\\controller\\AccountController@getDepartmentList'); // 获取部门列表 √
|
||||
});
|
||||
|
||||
// Device控制器路由
|
||||
Route::group('device', function () {
|
||||
Route::get('list', 'app\\api\\controller\\DeviceController@getList'); // 获取设备列表 √
|
||||
//Route::get('add/:accountId', 'app\\api\\controller\\DeviceController@addDevice'); // 生成设备二维码
|
||||
Route::post('add', 'app\\api\\controller\\DeviceController@addDevice'); // 生成设备二维码(POST方式) √
|
||||
});
|
||||
|
||||
// FriendTask控制器路由
|
||||
Route::group('friend-task', function () {
|
||||
Route::get('list', 'app\\api\\controller\\FriendTaskController@getList'); // 获取添加好友记录列表 √
|
||||
Route::post('add', 'app\\api\\controller\\FriendTaskController@addFriendTask'); // 添加好友任务 √
|
||||
});
|
||||
|
||||
// Moments控制器路由
|
||||
Route::group('moments', function () {
|
||||
Route::post('add-job', 'app\\api\\controller\\MomentsController@addJob'); // 发布朋友圈
|
||||
Route::get('list', 'app\\api\\controller\\MomentsController@getList'); // 获取朋友圈任务列表 √
|
||||
});
|
||||
|
||||
// Stats控制器路由
|
||||
Route::group('stats', function () {
|
||||
Route::get('basic-data', 'app\\api\\controller\\StatsController@basicData'); // 账号基本信息
|
||||
Route::get('fans-statistics', 'app\\api\\controller\\StatsController@FansStatistics'); // 好友统计
|
||||
});
|
||||
|
||||
// User控制器路由
|
||||
Route::group('user', function () {
|
||||
Route::post('login', 'app\\api\\controller\\UserController@login'); // 登录 √
|
||||
Route::post('token', 'app\\api\\controller\\UserController@getNewToken'); // 获取新的token √
|
||||
Route::get('info', 'app\\api\\controller\\UserController@getAccountInfo'); // 获取商户基本信息 √
|
||||
Route::post('modify-pwd', 'app\\api\\controller\\UserController@modifyPwd'); // 修改密码
|
||||
Route::get('logout', 'app\\api\\controller\\UserController@logout'); // 登出 √
|
||||
Route::get('verify-code', 'app\\api\\controller\\UserController@getVerifyCode'); // 获取验证码 √
|
||||
});
|
||||
|
||||
// WebSocket控制器路由
|
||||
Route::group('websocket', function () {
|
||||
Route::post('send-personal', 'app\\api\\controller\\WebSocketController@sendPersonal'); // 个人消息发送 √
|
||||
Route::post('send-community', 'app\\api\\controller\\WebSocketController@sendCommunity'); // 发送群消息 √
|
||||
Route::get('get-moments', 'app\\api\\controller\\WebSocketController@getMoments'); // 获取指定账号朋友圈信息 √
|
||||
Route::get('get-moment-source', 'app\\api\\controller\\WebSocketController@getMomentSourceRealUrl'); // 获取指定账号朋友圈图片地址
|
||||
});
|
||||
|
||||
// WechatChatroom控制器路由
|
||||
Route::group('chatroom', function () {
|
||||
Route::get('list', 'app\\api\\controller\\WechatChatroomController@getList'); // 获取微信群聊列表 √
|
||||
//Route::get('members/:wechatChatroomId', 'app\\api\\controller\\WechatChatroomController@listChatroomMember'); // 获取群成员列表 √
|
||||
// Route::get('sync', 'app\\api\\controller\\WechatChatroomController@syncChatrooms'); // 同步微信群聊数据 √
|
||||
});
|
||||
|
||||
// Wechat控制器路由
|
||||
Route::group('wechat', function () {
|
||||
Route::get('list', 'app\\api\\controller\\WechatController@getList'); // 获取微信账号列表 √
|
||||
});
|
||||
|
||||
// WechatFriend控制器路由
|
||||
Route::group('friend', function () {
|
||||
Route::get('list', 'app\\api\\controller\\WechatFriendController@getList'); // 获取微信好友列表数据 √
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\CompanyAccountModel;
|
||||
use app\api\model\CompanyModel;
|
||||
use think\facade\Request;
|
||||
|
||||
class AccountController extends BaseController
|
||||
@@ -186,6 +187,73 @@ class AccountController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getDepartmentList()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', ''));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 设置请求参数
|
||||
$isAll = $this->request->param('isAll', 'false');
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取部门列表
|
||||
$url = $this->baseUrl . 'api/Department/tenantDepartmentsForSelect?isAll=' . $isAll;
|
||||
$result = requestCurl($url, [], 'GET', $header, 'json');
|
||||
|
||||
// 处理返回结果
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$this->saveDepartment($item);
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response, '获取部门列表成功');
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取部门列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存部门数据到数据库
|
||||
* @param array $item 部门数据
|
||||
*/
|
||||
private function saveDepartment($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : 0,
|
||||
'name' => isset($item['name']) ? $item['name'] : '',
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
];
|
||||
|
||||
// 使用imei作为唯一性判断
|
||||
$department= CompanyModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($department) {
|
||||
$department->save($data);
|
||||
} else {
|
||||
CompanyModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 保存账号数据到数据库
|
||||
* @param array $item 账号数据
|
||||
|
||||
@@ -150,18 +150,17 @@ class UserController extends BaseController
|
||||
}
|
||||
|
||||
$headerData = ['client:' . self::CLIENT_TYPE];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
try {
|
||||
$result = requestCurl($this->baseUrl . 'api/Account/self', [], 'GET', $header);
|
||||
$result = requestCurl($this->baseUrl . 'api/Account/self', [], 'GET', $header,'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
if (!empty($response['account'])) {
|
||||
$accountData = $response['account'];
|
||||
|
||||
// 准备数据库字段映射,保持驼峰命名
|
||||
$dbData = [
|
||||
'accountId' => $accountData['id'],
|
||||
'tenantId' => $accountData['id'],
|
||||
'realName' => $accountData['realName'],
|
||||
'nickname' => $accountData['nickname'],
|
||||
'memo' => $accountData['memo'],
|
||||
@@ -169,7 +168,7 @@ class UserController extends BaseController
|
||||
'userName' => $accountData['userName'],
|
||||
'secret' => $accountData['secret'],
|
||||
'accountType' => $accountData['accountType'],
|
||||
'departmentId' => $accountData['departmentId'],
|
||||
'companyId' => $accountData['departmentId'],
|
||||
'useGoogleSecretKey' => $accountData['useGoogleSecretKey'],
|
||||
'hasVerifyGoogleSecret' => $accountData['hasVerifyGoogleSecret'],
|
||||
'updateTime' => time()
|
||||
|
||||
@@ -6,5 +6,6 @@ use think\Model;
|
||||
|
||||
class CompanyAccountModel extends Model
|
||||
{
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'company_account';
|
||||
}
|
||||
10
Server/application/api/model/CompanyModel.php
Normal file
10
Server/application/api/model/CompanyModel.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class CompanyModel extends Model {
|
||||
// 设置表名
|
||||
protected $name = 'company';
|
||||
}
|
||||
@@ -5,5 +5,6 @@ namespace app\api\model;
|
||||
use think\Model;
|
||||
|
||||
class DeviceModel extends Model {
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'device';
|
||||
}
|
||||
@@ -6,5 +6,6 @@ use think\Model;
|
||||
|
||||
class FriendTaskModel extends Model
|
||||
{
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'friend_task';
|
||||
}
|
||||
@@ -6,5 +6,6 @@ use think\Model;
|
||||
|
||||
class WechatAccountModel extends Model
|
||||
{
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'wechat_account';
|
||||
}
|
||||
@@ -6,5 +6,6 @@ use think\Model;
|
||||
|
||||
class WechatChatroomMemberModel extends Model
|
||||
{
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'wechat_chatroom_member';
|
||||
}
|
||||
@@ -6,5 +6,6 @@ use think\Model;
|
||||
|
||||
class WechatChatroomModel extends Model
|
||||
{
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'wechat_chatroom';
|
||||
}
|
||||
@@ -6,5 +6,6 @@ use think\Model;
|
||||
|
||||
class WechatFriendModel extends Model
|
||||
{
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'wechat_friend';
|
||||
}
|
||||
Reference in New Issue
Block a user