Files
CKB-Interface/application/superadmin/controller/company/GetCompanySubusersForProfileController.php
2026-02-04 11:02:33 +08:00

66 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\superadmin\controller\company;
use app\common\model\User as UserModel;
use library\ResponseHelper;
use think\Controller;
/**
* 设备管理控制器
*/
class GetCompanySubusersForProfileController extends Controller
{
/**
* 获取项目下的所有子账号
*
* @return CompanyModel
* @throws \Exception
*/
protected function getSubusers(): array
{
$where = [
'companyId' => $this->request->param('companyId/d', 0),
'isAdmin' => UserModel::ADMIN_OTP
];
return UserModel::alias('u')
->field([
'u.id', 'u.account', 'u.phone', 'u.username', 'u.avatar', 'u.status', 'u.createTime', 'u.typeId'
])
->where($where)
->select()
->toArray();
}
/**
* 获取公司关联的设备列表
*
* @return \think\response\Json
*/
public function index()
{
$users = $this->getSubusers();
foreach ($users as &$user) {
// 处理 createTime如果是时间戳则转换如果是日期字符串则直接使用如果为空则设为空字符串
if (empty($user['createTime'])) {
$user['createTime'] = '';
} elseif (is_numeric($user['createTime']) && $user['createTime'] > 0) {
// 时间戳格式
$user['createTime'] = date('Y-m-d H:i:s', $user['createTime']);
} elseif (is_string($user['createTime'])) {
// 已经是日期字符串格式,直接使用
// 如果格式不正确,尝试转换
$timestamp = strtotime($user['createTime']);
if ($timestamp !== false) {
$user['createTime'] = date('Y-m-d H:i:s', $timestamp);
}
} else {
$user['createTime'] = '';
}
}
return ResponseHelper::success($users);
}
}