调整代码格式及使用常量去替换常用值
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\superadmin\controller\Menu;
|
||||
|
||||
use app\common\model\Administrator as AdministratorModel;
|
||||
use app\common\model\Menu as MenuModel;
|
||||
use app\common\model\AdministratorPermissions as AdministratorPermissionsModel;
|
||||
use app\superadmin\controller\BaseController;
|
||||
@@ -69,7 +70,7 @@ class GetMenuTreeController extends BaseController
|
||||
protected function getMenuTree(): array
|
||||
{
|
||||
// 获取所有菜单
|
||||
$allMenus = MenuModel::where('status', 1)->order('sort', 'asc')->select()->toArray();
|
||||
$allMenus = MenuModel::where('status', MenuModel::STATUS_ACTIVE)->order('sort', 'asc')->select()->toArray();
|
||||
|
||||
// 组织成树状结构
|
||||
return $allMenus ? $this->buildMenuTree($allMenus) : [];
|
||||
@@ -84,8 +85,8 @@ class GetMenuTreeController extends BaseController
|
||||
protected function getTopMenusInPermissionIds(array $permissionIds): array
|
||||
{
|
||||
$where = [
|
||||
'parentId' => 0,
|
||||
'status' => 1,
|
||||
'parentId' => MenuModel::TOP_LEVEL,
|
||||
'status' => MenuModel::STATUS_ACTIVE,
|
||||
];
|
||||
|
||||
return MenuModel::where($where)->whereIn('id', $permissionIds)->order('sort', 'asc')->select()->toArray();
|
||||
@@ -99,7 +100,7 @@ class GetMenuTreeController extends BaseController
|
||||
*/
|
||||
protected function getAllChildrenInPermissionIds(array $topMenuIds): array
|
||||
{
|
||||
return MenuModel::where('status', 1)->whereIn('parentId', $topMenuIds)->order('sort', 'asc')->select()->toArray();
|
||||
return MenuModel::where('status', MenuModel::STATUS_ACTIVE)->whereIn('parentId', $topMenuIds)->order('sort', 'asc')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +166,7 @@ class GetMenuTreeController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->getAdminInfo('id') == 1) {
|
||||
if ($this->getAdminInfo('id') == AdministratorModel::MASTER_ID) {
|
||||
$menuTree = $this->getMenuTree();
|
||||
} else {
|
||||
$menuTree = $this->getMenuTreeByPermissions(
|
||||
|
||||
@@ -19,8 +19,8 @@ class GetTopLevelForPermissionController extends BaseController
|
||||
protected function getTopLevelMenus(): array
|
||||
{
|
||||
$where = [
|
||||
'parentId' => 0,
|
||||
'status' => 1
|
||||
'parentId' => MenuModel::TOP_LEVEL,
|
||||
'status' => MenuModel::STATUS_NORMAL
|
||||
];
|
||||
|
||||
return MenuModel::where($where)->field('id, title')->order('sort', 'asc')->select()->toArray();
|
||||
|
||||
@@ -41,15 +41,15 @@ class AddAdministratorController extends BaseController
|
||||
protected function dataValidate(array $params): self
|
||||
{
|
||||
$validate = Validate::make([
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/',
|
||||
'username' => 'require|/\S+/',
|
||||
'password' => 'require|/\S+/',
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/',
|
||||
'username' => 'require|/\S+/',
|
||||
'password' => 'require|/\S+/',
|
||||
'permissionIds' => 'require|array',
|
||||
], [
|
||||
'account.require' => '账号不能为空',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'username.require' => '用户名不能为空',
|
||||
'password.require' => '密码不能为空',
|
||||
'account.require' => '账号不能为空',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'username.require' => '用户名不能为空',
|
||||
'password.require' => '密码不能为空',
|
||||
'permissionIds.require' => '请至少分配一种权限',
|
||||
]);
|
||||
|
||||
@@ -67,7 +67,7 @@ class AddAdministratorController extends BaseController
|
||||
*/
|
||||
protected function checkPermission(): self
|
||||
{
|
||||
if ($this->getAdminInfo('id') != 1) {
|
||||
if ($this->getAdminInfo('id') != AdministratorModel::MASTER_ID) {
|
||||
throw new \Exception('您没有权限添加管理员', 403);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class AddAdministratorController extends BaseController
|
||||
]);
|
||||
} else {
|
||||
return AdministratorPermissionsModel::create([
|
||||
'adminId' => $adminId,
|
||||
'adminId' => $adminId,
|
||||
'permissions' => json_encode($permissionData),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -66,12 +66,12 @@ class DeleteAdministratorController extends BaseController
|
||||
}
|
||||
|
||||
// 只有超级管理员(ID为1)可以删除管理员
|
||||
if ($this->getAdminInfo('id') != 1) {
|
||||
if ($this->getAdminInfo('id') != AdministratorModel::MASTER_ID) {
|
||||
throw new \Exception('您没有权限删除管理员', 403);
|
||||
}
|
||||
|
||||
// 不能删除超级管理员账号
|
||||
if ($adminId == 1) {
|
||||
if ($adminId == AdministratorModel::MASTER_ID) {
|
||||
throw new \Exception('不能删除超级管理员账号', 403);
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class DeleteAdministratorController extends BaseController
|
||||
$validate = Validate::make([
|
||||
'id' => 'require|regex:/^[1-9]\d*$/',
|
||||
], [
|
||||
'id.regex' => '非法请求',
|
||||
'id.regex' => '非法请求',
|
||||
'id.require' => '非法请求',
|
||||
]);
|
||||
|
||||
|
||||
@@ -22,9 +22,10 @@ class GetAdministratorDetailController extends BaseController
|
||||
protected function getAdministrator(int $adminId): AdministratorModel
|
||||
{
|
||||
$admin = AdministratorModel::alias('a')
|
||||
->field(
|
||||
'a.id, a.account, a.username, a.status, a.authId, a.createTime createdAt, a.lastLoginTime lastLogin, p.permissions'
|
||||
)
|
||||
->field([
|
||||
'a.id', 'a.account', 'a.username', 'a.status', 'a.authId', 'a.createTime createdAt', 'a.lastLoginTime lastLogin',
|
||||
'p.permissions'
|
||||
])
|
||||
->leftJoin('administrator_permissions p', 'a.id = p.adminId')
|
||||
->where('a.id', $adminId)
|
||||
->find();
|
||||
@@ -94,10 +95,10 @@ class GetAdministratorDetailController extends BaseController
|
||||
|
||||
return ResponseHelper::success(
|
||||
array_merge($admin->toArray(), [
|
||||
'roleName' => $roleName,
|
||||
'roleName' => $roleName,
|
||||
'permissions' => $permissionIds,
|
||||
'lastLogin' => $admin->lastLogin ? date('Y-m-d H:i', $admin->lastLogin) : '从未登录',
|
||||
'createdAt' => date('Y-m-d H:i', $admin->createdAt),
|
||||
'lastLogin' => $admin->lastLogin ? date('Y-m-d H:i', $admin->lastLogin) : '从未登录',
|
||||
'createdAt' => date('Y-m-d H:i', $admin->createdAt),
|
||||
])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -40,9 +40,9 @@ class GetAdministratorListController extends Controller
|
||||
protected function getAdministratorList(array $where): \think\Paginator
|
||||
{
|
||||
$query = AdministratorModel::alias('a')
|
||||
->field(
|
||||
'id, account, username, status, authId, createTime createdAt, lastLoginTime, lastLoginIp'
|
||||
);
|
||||
->field([
|
||||
'a.id', 'a.account', 'a.username', 'a.status', 'a.authId', 'a.createTime createdAt', 'a.lastLoginTime', 'a.lastLoginIp'
|
||||
]);
|
||||
|
||||
foreach ($where as $key => $value) {
|
||||
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') {
|
||||
@@ -139,13 +139,13 @@ class GetAdministratorListController extends Controller
|
||||
|
||||
foreach ($list->items() as $item) {
|
||||
$section = [
|
||||
'id' => $item->id,
|
||||
'account' => $item->account,
|
||||
'username' => $item->username,
|
||||
'status' => $item->status,
|
||||
'createdAt' => date('Y-m-d H:i:s', $item->createdAt),
|
||||
'lastLogin' => !empty($item->lastLoginTime) ? date('Y-m-d H:i:s', $item->lastLoginTime) : '从未登录',
|
||||
'role' => $this->getRoleName($item->authId),
|
||||
'id' => $item->id,
|
||||
'account' => $item->account,
|
||||
'username' => $item->username,
|
||||
'status' => $item->status,
|
||||
'createdAt' => date('Y-m-d H:i:s', $item->createdAt),
|
||||
'lastLogin' => !empty($item->lastLoginTime) ? date('Y-m-d H:i:s', $item->lastLoginTime) : '从未登录',
|
||||
'role' => $this->getRoleName($item->authId),
|
||||
'permissions' => $this->getPermissions($item->id),
|
||||
];
|
||||
|
||||
@@ -167,7 +167,7 @@ class GetAdministratorListController extends Controller
|
||||
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'list' => $this->makeReturnedResult($result),
|
||||
'list' => $this->makeReturnedResult($result),
|
||||
'total' => $result->total(),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -48,16 +48,16 @@ class UpdateAdministratorController extends BaseController
|
||||
protected function dataValidate(array $params): self
|
||||
{
|
||||
$validate = Validate::make([
|
||||
'id' => 'require|regex:/^[1-9]\d*$/',
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/',
|
||||
'username' => 'require|/\S+/',
|
||||
'password' => '/\S+/',
|
||||
'id' => 'require|regex:/^[1-9]\d*$/',
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/',
|
||||
'username' => 'require|/\S+/',
|
||||
'password' => '/\S+/',
|
||||
'permissionIds' => 'array',
|
||||
], [
|
||||
'id.require' => '缺少必要参数',
|
||||
'account.require' => '账号不能为空',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'username.require' => '用户名不能为空',
|
||||
'id.require' => '缺少必要参数',
|
||||
'account.require' => '账号不能为空',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'username.require' => '用户名不能为空',
|
||||
'permissionIds.array' => '请至少分配一种权限',
|
||||
]);
|
||||
|
||||
@@ -79,11 +79,11 @@ class UpdateAdministratorController extends BaseController
|
||||
{
|
||||
$currentAdminId = $this->getAdminInfo('id');
|
||||
|
||||
if ($currentAdminId != 1 && $currentAdminId != $adminId) {
|
||||
if ($currentAdminId != AdministratorModel::MASTER_ID && $currentAdminId != $adminId) {
|
||||
throw new \Exception('您没有权限修改其他管理员', 403);
|
||||
}
|
||||
|
||||
if ($params['id'] != 1 && empty($params['permissionIds'])) {
|
||||
if ($params['id'] != AdministratorModel::MASTER_ID && empty($params['permissionIds'])) {
|
||||
throw new \Exception('请至少分配一种权限', 403);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class UpdateAdministratorController extends BaseController
|
||||
]);
|
||||
} else {
|
||||
return AdministratorPermissionsModel::create([
|
||||
'adminId' => $adminId,
|
||||
'adminId' => $adminId,
|
||||
'permissions' => json_encode($permissionData),
|
||||
]);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class UpdateAdministratorController extends BaseController
|
||||
$this->udpateAdministrator($params);
|
||||
|
||||
// 如果当前是超级管理员(ID为1),并且修改的不是自己,则更新权限
|
||||
if ($this->getAdminInfo('id') == 1
|
||||
if ($this->getAdminInfo('id') == AdministratorModel::MASTER_ID
|
||||
&& $this->getAdminInfo('id') != $adminId
|
||||
&& !empty($params['permissionIds'])
|
||||
) {
|
||||
|
||||
@@ -7,6 +7,7 @@ use app\superadmin\controller\administrator\DeleteAdministratorController;
|
||||
use library\ResponseHelper;
|
||||
use think\Controller;
|
||||
use think\Validate;
|
||||
use think\facade\Cookie;
|
||||
|
||||
class AuthLoginController extends Controller
|
||||
{
|
||||
@@ -30,7 +31,7 @@ class AuthLoginController extends Controller
|
||||
protected function dataValidate(array $params): self
|
||||
{
|
||||
$validate = Validate::make([
|
||||
'account' => 'require|/\S+/',
|
||||
'account' => 'require|/\S+/',
|
||||
'password' => 'require|/\S+/',
|
||||
]);
|
||||
|
||||
@@ -96,11 +97,11 @@ class AuthLoginController extends Controller
|
||||
{
|
||||
// 获取当前环境
|
||||
$env = app()->env->get('APP_ENV', 'production');
|
||||
|
||||
|
||||
// 获取请求的域名
|
||||
$origin = $this->request->header('origin');
|
||||
$domain = '';
|
||||
|
||||
|
||||
if ($origin) {
|
||||
// 解析域名
|
||||
$parsedUrl = parse_url($origin);
|
||||
@@ -112,7 +113,7 @@ class AuthLoginController extends Controller
|
||||
// 生产环境使用顶级域名
|
||||
$parts = explode('.', $parsedUrl['host']);
|
||||
if (count($parts) > 1) {
|
||||
$domain = '.' . $parts[count($parts)-2] . '.' . $parts[count($parts)-1];
|
||||
$domain = '.' . $parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,11 +121,11 @@ class AuthLoginController extends Controller
|
||||
|
||||
// 设置cookie选项
|
||||
$options = [
|
||||
'expire' => 86400,
|
||||
'path' => '/',
|
||||
'expire' => 86400,
|
||||
'path' => '/',
|
||||
'httponly' => true,
|
||||
'samesite' => 'None', // 允许跨域
|
||||
'secure' => true // 仅 HTTPS 下有效
|
||||
'samesite' => 'None', // 允许跨域
|
||||
'secure' => true // 仅 HTTPS 下有效
|
||||
];
|
||||
|
||||
// 如果有域名,添加到选项
|
||||
@@ -133,8 +134,8 @@ class AuthLoginController extends Controller
|
||||
}
|
||||
|
||||
// 设置cookies
|
||||
\think\facade\Cookie::set('admin_id', $admin->id, $options);
|
||||
\think\facade\Cookie::set('admin_token', $this->createToken($admin), $options);
|
||||
Cookie::set('admin_id', $admin->id, $options);
|
||||
Cookie::set('admin_token', $this->createToken($admin), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,10 +153,10 @@ class AuthLoginController extends Controller
|
||||
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'id' => $admin->id,
|
||||
'name' => $admin->username,
|
||||
'id' => $admin->id,
|
||||
'name' => $admin->username,
|
||||
'account' => $admin->account,
|
||||
'token' => cookie('admin_token')
|
||||
'token' => Cookie::get('admin_token')
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -7,10 +7,12 @@ use app\common\model\Company as CompanyModel;
|
||||
use app\common\model\User as UsersModel;
|
||||
use app\superadmin\controller\BaseController;
|
||||
use Eison\Utils\Helper\ArrHelper;
|
||||
use Exception;
|
||||
use library\ResponseHelper;
|
||||
use library\s2\CurlHandle;
|
||||
use think\Db;
|
||||
use think\facade\Env;
|
||||
use think\response\Json;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
@@ -23,7 +25,7 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $params
|
||||
* @return mixed|null
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function s2CreateUser(array $params): ?array
|
||||
{
|
||||
@@ -38,7 +40,7 @@ class CreateCompanyController extends BaseController
|
||||
$result = json_decode($response, true);
|
||||
|
||||
if ($result['code'] != 200) {
|
||||
throw new \Exception($result['msg'], 210 . $result['code']);
|
||||
throw new Exception($result['msg'], 210 . $result['code']);
|
||||
}
|
||||
|
||||
return $result['data'] ?: null;
|
||||
@@ -63,7 +65,7 @@ class CreateCompanyController extends BaseController
|
||||
$result = json_decode($response, true);
|
||||
|
||||
if ($result['code'] != 200) {
|
||||
throw new \Exception($result['msg'], 210 . $result['code']);
|
||||
throw new Exception($result['msg'], 210 . $result['code']);
|
||||
}
|
||||
|
||||
return $result['data'] ?: null;
|
||||
@@ -74,33 +76,33 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $params
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function dataValidate(array $params): self
|
||||
{
|
||||
$validate = Validate::make([
|
||||
'name' => 'require|max:50|/\S+/',
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/',
|
||||
'name' => 'require|max:50|/\S+/',
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/',
|
||||
'username' => 'require|max:20|/\S+/',
|
||||
'phone' => 'require|regex:/^1[3-9]\d{9}$/',
|
||||
'status' => 'require|in:0,1',
|
||||
'phone' => 'require|regex:/^1[3-9]\d{9}$/',
|
||||
'status' => 'require|in:0,1',
|
||||
'password' => 'require|/\S+/',
|
||||
'memo' => '/\S+/',
|
||||
'memo' => '/\S+/',
|
||||
], [
|
||||
'name.require' => '请输入项目名称',
|
||||
'account.require' => '请输入账号',
|
||||
'account.max' => '账号长度受限',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'name.require' => '请输入项目名称',
|
||||
'account.require' => '请输入账号',
|
||||
'account.max' => '账号长度受限',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'username.require' => '请输入用户昵称',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone.regex' => '手机号格式错误',
|
||||
'status.require' => '缺少重要参数',
|
||||
'status.in' => '非法参数',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone.regex' => '手机号格式错误',
|
||||
'status.require' => '缺少重要参数',
|
||||
'status.in' => '非法参数',
|
||||
'password.require' => '请输入密码',
|
||||
]);
|
||||
|
||||
if (!$validate->check($params)) {
|
||||
throw new \Exception($validate->getError(), 400);
|
||||
throw new Exception($validate->getError(), 400);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -111,7 +113,7 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function s2CreateDeviceGroup(array $params): void
|
||||
{
|
||||
@@ -119,7 +121,7 @@ class CreateCompanyController extends BaseController
|
||||
$respon = json_decode($respon, true);
|
||||
|
||||
if ($respon['code'] != 200) {
|
||||
throw new \Exception('设备分组添加错误', 210 . $respon['code']);
|
||||
throw new Exception('设备分组添加错误', 210 . $respon['code']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,14 +130,14 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function creatS2About(array $params): array
|
||||
{
|
||||
$department = $this->s2CreateDepartmentAndUser($params);
|
||||
|
||||
if (!$department || !isset($department['id']) || !isset($department['departmentId'])) {
|
||||
throw new \Exception('S2返参异常', 210402);
|
||||
throw new Exception('S2返参异常', 210402);
|
||||
}
|
||||
|
||||
// 设备创建分组
|
||||
@@ -152,7 +154,7 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ckbCreateCompany(array $params): void
|
||||
{
|
||||
@@ -160,7 +162,7 @@ class CreateCompanyController extends BaseController
|
||||
$result = CompanyModel::create($params);
|
||||
|
||||
if (!$result) {
|
||||
throw new \Exception('创建公司记录失败', 402);
|
||||
throw new Exception('创建公司记录失败', 402);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,17 +171,17 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function createFuncUsers(array $params): void
|
||||
{
|
||||
$seedCols = [
|
||||
['account' => $params['account'] . '_offline', 'username' => '处理离线专用', 'status' => 0, 'isAdmin' => 0, 'typeId' => -1],
|
||||
['account' => $params['account'] . '_delete' , 'username' => '处理删除专用', 'status' => 0, 'isAdmin' => 0, 'typeId' => -1],
|
||||
['account' => $params['account'] . '_offline', 'username' => '处理离线专用', 'status' => UsersModel::STATUS_STOP, 'isAdmin' => UsersModel::ADMIN_OTP, 'typeId' => UsersModel::NOT_USER],
|
||||
['account' => $params['account'] . '_delete', 'username' => '处理删除专用', 'status' => UsersModel::STATUS_STOP, 'isAdmin' => UsersModel::ADMIN_OTP, 'typeId' => UsersModel::NOT_USER],
|
||||
];
|
||||
|
||||
foreach ($seedCols as $seeds) {
|
||||
$this->s2CreateUser (array_merge($params, ArrHelper::getValue('account,username', $seeds)));
|
||||
$this->s2CreateUser(array_merge($params, ArrHelper::getValue('account,username', $seeds)));
|
||||
$this->ckbCreateUser(array_merge($params, $seeds));
|
||||
}
|
||||
}
|
||||
@@ -189,7 +191,7 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ckbCreateUser(array $params): void
|
||||
{
|
||||
@@ -201,14 +203,14 @@ class CreateCompanyController extends BaseController
|
||||
]);
|
||||
|
||||
if (!UsersModel::create($params)) {
|
||||
throw new \Exception('创建用户记录失败', 402);
|
||||
throw new Exception('创建用户记录失败', 402);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function createCkbAbout(array $params)
|
||||
{
|
||||
@@ -217,8 +219,8 @@ class CreateCompanyController extends BaseController
|
||||
|
||||
// 2. 存客宝创建操盘手总账号
|
||||
$this->ckbCreateUser(array_merge($params, [
|
||||
'isAdmin' => 1, // 主要账号默认1
|
||||
'typeId' => 1, // 类型:运营后台/操盘手传1、 门店传2
|
||||
'isAdmin' => UsersModel::ADMIN_STP, // 主要账号默认1
|
||||
'typeId' => UsersModel::MASTER_USER, // 类型:运营后台/操盘手传1、 门店传2
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -227,7 +229,7 @@ class CreateCompanyController extends BaseController
|
||||
*
|
||||
* @param array $where
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function checkCompanyNameOrAccountOrPhoneExists(array $where): void
|
||||
{
|
||||
@@ -236,26 +238,26 @@ class CreateCompanyController extends BaseController
|
||||
// 项目名称尽量不重名
|
||||
$exists = CompanyModel::where(compact('name'))->count() > 0;
|
||||
if ($exists) {
|
||||
throw new \Exception('项目名称已存在', 403);
|
||||
throw new Exception('项目名称已存在', 403);
|
||||
}
|
||||
|
||||
// 账号不重名
|
||||
$exists = UsersModel::where(compact('account'))->count() > 0;
|
||||
if ($exists) {
|
||||
throw new \Exception('用户账号已存在', 403);
|
||||
throw new Exception('用户账号已存在', 403);
|
||||
}
|
||||
|
||||
// 手机号不重名
|
||||
$exists = UsersModel::where(compact('phone'))->count() > 0;
|
||||
if ($exists) {
|
||||
throw new \Exception('手机号已存在', 403);
|
||||
throw new Exception('手机号已存在', 403);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新项目
|
||||
*
|
||||
* @return \think\response\Json
|
||||
* @return Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
@@ -273,7 +275,7 @@ class CreateCompanyController extends BaseController
|
||||
|
||||
Db::commit();
|
||||
return ResponseHelper::success();
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class DeleteCompanyController extends BaseController
|
||||
$validate = Validate::make([
|
||||
'id' => 'require|regex:/^[1-9]\d*$/',
|
||||
], [
|
||||
'id.regex' => '非法请求',
|
||||
'id.regex' => '非法请求',
|
||||
'id.require' => '非法请求',
|
||||
]);
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ class GetCompanyDetailForProfileController extends BaseController
|
||||
*/
|
||||
protected function getDeveiceWechats(int $companyId): array
|
||||
{
|
||||
$wechatId = DeviceWechatLoginModel::where('companyId', $companyId)->column('wechatId');
|
||||
$wechatIds = DeviceWechatLoginModel::where('companyId', $companyId)->column('wechatId');
|
||||
|
||||
return array_unique($wechatId);
|
||||
return array_unique($wechatIds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ class GetCompanyDetailForProfileController extends BaseController
|
||||
*/
|
||||
protected function getUsersCountByCompanyId(int $companyId): int
|
||||
{
|
||||
$where = array_merge(compact('companyId'), array('isAdmin' => 0));
|
||||
$where = array_merge(compact('companyId'), array('isAdmin' => UserModel::ADMIN_OTP));
|
||||
|
||||
return UserModel::where($where)->count();
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class GetCompanyDetailForProfileController extends BaseController
|
||||
'c.id', 'c.name', 'c.memo', 'c.companyId', 'c.createTime',
|
||||
'u.account', 'u.phone'
|
||||
])
|
||||
->leftJoin('users u', 'c.companyId = u.companyId and u.isAdmin = 1')
|
||||
->leftJoin('users u', 'c.companyId = u.companyId and u.isAdmin = ' . UserModel::ADMIN_STP)
|
||||
->find($id);
|
||||
|
||||
if (!$detail) {
|
||||
@@ -100,7 +100,7 @@ class GetCompanyDetailForProfileController extends BaseController
|
||||
try {
|
||||
$data = $this->getCompanyDetail($id);
|
||||
|
||||
$userCount = $this->getUsersCountByCompanyId($id);
|
||||
$userCount = $this->getUsersCountByCompanyId($id);
|
||||
$deviceCount = $this->getDeviceCountByCompanyId($id);
|
||||
$friendCount = $this->getFriendCountByCompanyId($id);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\superadmin\controller\company;
|
||||
|
||||
use app\common\model\Company as CompanyModel;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\superadmin\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
@@ -43,7 +44,7 @@ class GetCompanyDetailForUpdateController extends BaseController
|
||||
'c.id', 'c.name', 'c.status', 'c.memo', 'c.companyId',
|
||||
'u.account', 'u.username', 'u.phone', 'u.s2_accountId'
|
||||
])
|
||||
->leftJoin('users u', 'c.companyId = u.companyId and u.isAdmin = 1')
|
||||
->leftJoin('users u', 'c.companyId = u.companyId and u.isAdmin = ' . UserModel::ADMIN_STP)
|
||||
->find($id);
|
||||
|
||||
if (!$detail) {
|
||||
|
||||
@@ -23,7 +23,11 @@ class GetCompanyDevicesForProfileController extends Controller
|
||||
{
|
||||
$companyId = $this->request->param('companyId/d', 0);
|
||||
|
||||
$devices = DeviceModel::where(compact('companyId'))->field('id,memo,imei,phone,model,brand,alive,id deviceId')
|
||||
$devices = DeviceModel::alias('d')
|
||||
->field([
|
||||
'd.id', 'd.memo', 'd.imei', 'd.phone', 'd.model', 'd.brand', 'd.alive', 'd.id deviceId'
|
||||
])
|
||||
->where(compact('companyId'))
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
@@ -47,7 +51,10 @@ class GetCompanyDevicesForProfileController extends Controller
|
||||
// 获取最新登录记录id
|
||||
$latestIds = array_column($latestLogs, 'lastedId');
|
||||
|
||||
return DeviceWechatLoginModel::field('deviceId,wechatId,alive wAlive')
|
||||
return DeviceWechatLoginModel::alias('d')
|
||||
->field([
|
||||
'd.deviceId', 'd.wechatId', 'd.alive wAlive'
|
||||
])
|
||||
->whereIn('id', $latestIds)
|
||||
->select()
|
||||
->toArray();
|
||||
@@ -65,7 +72,10 @@ class GetCompanyDevicesForProfileController extends Controller
|
||||
$relations = $this->getDeviceWechatRelationsByDeviceIds($deviceIds);
|
||||
|
||||
// 统计微信好友数量
|
||||
$friendCounts = WechatFriendModel::alias('f')->field('ownerWechatId wechatId,count(*) friendCount')
|
||||
$friendCounts = WechatFriendModel::alias('f')
|
||||
->field([
|
||||
'f.ownerWechatId wechatId', 'count(*) friendCount'
|
||||
])
|
||||
->whereIn('ownerWechatId', array_column($relations, 'wechatId'))
|
||||
->group('ownerWechatId')
|
||||
->select()
|
||||
|
||||
@@ -57,9 +57,9 @@ class GetCompanyListController extends BaseController
|
||||
protected function getCompanyList(array $where): \think\Paginator
|
||||
{
|
||||
$query = CompanyModel::alias('c')
|
||||
->field(
|
||||
'id, name, status, companyId, memo, createTime'
|
||||
);
|
||||
->field([
|
||||
'c.id', 'c.name', 'c.status', 'c.companyId', 'c.memo', 'c.createTime'
|
||||
]);
|
||||
|
||||
foreach ($where as $key => $value) {
|
||||
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') {
|
||||
@@ -118,7 +118,7 @@ class GetCompanyListController extends BaseController
|
||||
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'list' => $this->makeReturnedResult($result),
|
||||
'list' => $this->makeReturnedResult($result),
|
||||
'total' => $result->total(),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -21,10 +21,16 @@ class GetCompanySubusersForProfileController extends Controller
|
||||
{
|
||||
$where = [
|
||||
'companyId' => $this->request->param('companyId/d', 0),
|
||||
'isAdmin' => 0
|
||||
'isAdmin' => UserModel::ADMIN_OTP
|
||||
];
|
||||
|
||||
return UserModel::field('id,account,phone,username,avatar,status,createTime,typeId')->where($where)->select()->toArray();
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,7 @@ class UpdateCompanyController extends BaseController
|
||||
protected function getUserDetailByCompanyId(): ?UsersModel
|
||||
{
|
||||
$where = [
|
||||
'isAdmin' => 1, // 必须保证 isAdmin 有且只有一个
|
||||
'isAdmin' => UsersModel::MASTER_USER, // 必须保证 isAdmin 有且只有一个
|
||||
'companyId' => $this->companyId,
|
||||
];
|
||||
|
||||
@@ -175,23 +175,23 @@ class UpdateCompanyController extends BaseController
|
||||
protected function dataValidate(array $params): self
|
||||
{
|
||||
$validate = Validate::make([
|
||||
'id' => 'require',
|
||||
'name' => 'require|max:50|/\S+/',
|
||||
'id' => 'require',
|
||||
'name' => 'require|max:50|/\S+/',
|
||||
'username' => 'require|max:20|/\S+/',
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/',
|
||||
'phone' => 'require|regex:/^1[3-9]\d{9}$/',
|
||||
'status' => 'require|in:0,1'
|
||||
'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/',
|
||||
'phone' => 'require|regex:/^1[3-9]\d{9}$/',
|
||||
'status' => 'require|in:0,1'
|
||||
], [
|
||||
'id.require' => '非法请求',
|
||||
'name.require' => '请输入项目名称',
|
||||
'id.require' => '非法请求',
|
||||
'name.require' => '请输入项目名称',
|
||||
'username.require' => '请输入用户昵称',
|
||||
'account.require' => '请输入账号',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'account.max' => '账号长度受限',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone.regex' => '手机号格式错误',
|
||||
'status.require' => '缺少重要参数',
|
||||
'status.in' => '非法参数',
|
||||
'account.require' => '请输入账号',
|
||||
'account.regex' => '账号只能用数字或者字母或者数字字母组合',
|
||||
'account.max' => '账号长度受限',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone.regex' => '手机号格式错误',
|
||||
'status.require' => '缺少重要参数',
|
||||
'status.in' => '非法参数',
|
||||
]);
|
||||
|
||||
if (!$validate->check($params)) {
|
||||
|
||||
@@ -52,7 +52,7 @@ class GetBasestatisticsController extends Controller
|
||||
{
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'companyCount' => $this->getCompanyCount(),
|
||||
'companyCount' => $this->getCompanyCount(),
|
||||
'adminCount' => $this->getAdminCount(),
|
||||
'customerCount' => $this->getDeviceCount(),
|
||||
]
|
||||
|
||||
@@ -85,7 +85,7 @@ class GetAddResultedDevicesController extends Controller
|
||||
[
|
||||
'accountId' => $accountId,
|
||||
'pageIndex' => 0,
|
||||
'pageSize' => 1
|
||||
'pageSize' => 1
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
@@ -61,9 +61,9 @@ class GetPoolListController extends BaseController
|
||||
protected function makeReturnedValue(\think\Paginator $list): \think\Paginator
|
||||
{
|
||||
$list->each(function ($item) {
|
||||
$item->gender = $this->formatGender($item->gender);
|
||||
$item->gender = $this->formatGender($item->gender);
|
||||
$item->addTime = $this->formatDate($item->addTime);
|
||||
$item->tags = $this->handlTags($item->tags);
|
||||
$item->tags = $this->handlTags($item->tags);
|
||||
});
|
||||
|
||||
return $list;
|
||||
@@ -78,15 +78,10 @@ class GetPoolListController extends BaseController
|
||||
{
|
||||
$query = TrafficPoolModel::alias('tp')
|
||||
->field([
|
||||
'ts.id',
|
||||
'tp.wechatId',
|
||||
'ts.createTime as addTime',
|
||||
'ts.fromd as source',
|
||||
'ts.id', 'ts.createTime as addTime', 'ts.fromd as source',
|
||||
'c.name as projectName',
|
||||
'wa.avatar',
|
||||
'wa.gender',
|
||||
'wa.nickname',
|
||||
'wa.region',
|
||||
'wa.avatar', 'wa.gender', 'wa.nickname', 'wa.region',
|
||||
'wt.tags'
|
||||
])
|
||||
->join('traffic_source ts', 'tp.identifier = ts.identifier', 'RIGHT')
|
||||
@@ -108,9 +103,9 @@ class GetPoolListController extends BaseController
|
||||
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'list' => $this->makeReturnedValue($list)->items(),
|
||||
'list' => $this->makeReturnedValue($list)->items(),
|
||||
'total' => $list->total(),
|
||||
'page' => $list->currentPage(),
|
||||
'page' => $list->currentPage(),
|
||||
'limit' => $list->listRows()
|
||||
]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user