微信底层代码提交
This commit is contained in:
96
Server/application/api/controller/AccountController.php
Normal file
96
Server/application/api/controller/AccountController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\CompanyAccountModel;
|
||||
use think\facade\Request;
|
||||
|
||||
class AccountController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取公司账号列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', ''));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'showNormalAccount' => $this->request->param('showNormalAccount', ''),
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'departmentId' => $this->request->param('departmentId', ''),
|
||||
'pageIndex' => $this->request->param('pageIndex', 0),
|
||||
'pageSize' => $this->request->param('pageSize', 12)
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
|
||||
// 发送请求获取公司账号列表
|
||||
$result = requestCurl($this->baseUrl . 'api/Account/myTenantPageAccounts', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveAccount($item);
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取公司账号列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存账号数据到数据库
|
||||
* @param array $item 账号数据
|
||||
*/
|
||||
private function saveAccount($item)
|
||||
{
|
||||
// 将日期时间字符串转换为时间戳
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
|
||||
$deleteTime = isset($item['deleteTime']) ? strtotime($item['deleteTime']) : null;
|
||||
|
||||
$data = [
|
||||
'accountId' => $item['id'],
|
||||
'accountType' => isset($item['accountType']) ? $item['accountType'] : 0,
|
||||
'status' => isset($item['status']) ? $item['status'] : 0,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
||||
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
||||
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
||||
'avatar' => isset($item['avatar']) ? $item['avatar'] : '',
|
||||
'phone' => isset($item['phone']) ? $item['phone'] : '',
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
'createTime' => $createTime,
|
||||
'creator' => isset($item['creator']) ? $item['creator'] : 0,
|
||||
'creatorUserName' => isset($item['creatorUserName']) ? $item['creatorUserName'] : '',
|
||||
'creatorRealName' => isset($item['creatorRealName']) ? $item['creatorRealName'] : '',
|
||||
'departmentId' => isset($item['departmentId']) ? $item['departmentId'] : 0,
|
||||
'departmentName' => isset($item['departmentName']) ? $item['departmentName'] : '',
|
||||
'privilegeIds' => isset($item['privilegeIds']) ? $item['privilegeIds'] : [],
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'hasXiakeAccount' => isset($item['hasXiakeAccount']) ? $item['hasXiakeAccount'] : false,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
'deleteTime' => $deleteTime
|
||||
];
|
||||
|
||||
// 使用accountId作为唯一性判断
|
||||
$account = CompanyAccountModel::where('accountId', $item['id'])->find();
|
||||
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
} else {
|
||||
CompanyAccountModel::create($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user