调整代码格式及使用常量去替换常用值

This commit is contained in:
柳清爽
2025-05-08 10:39:53 +08:00
parent b5939b36b3
commit 0426485177
31 changed files with 230 additions and 191 deletions

View File

@@ -12,6 +12,8 @@ class Administrator extends Model
{ {
use SoftDelete; use SoftDelete;
const MASTER_ID = 1;
// 设置数据表名 // 设置数据表名
protected $name = 'administrators'; protected $name = 'administrators';

View File

@@ -3,12 +3,15 @@
namespace app\common\model; namespace app\common\model;
use think\Model; use think\Model;
use think\model\concern\SoftDelete;
/** /**
* 设备任务配置模型类 * 设备任务配置模型类
*/ */
class DeviceTaskconf extends Model class DeviceTaskconf extends Model
{ {
use SoftDelete;
// 设置表名 // 设置表名
protected $name = 'device_taskconf'; protected $name = 'device_taskconf';
@@ -16,4 +19,5 @@ class DeviceTaskconf extends Model
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
protected $createTime = 'createTime'; protected $createTime = 'createTime';
protected $updateTime = 'updateTime'; protected $updateTime = 'updateTime';
protected $defaultSoftDelete = 0;
} }

View File

@@ -9,6 +9,9 @@ use think\Model;
*/ */
class Menu extends Model class Menu extends Model
{ {
const STATUS_ACTIVE = 1;
const TOP_LEVEL = 0;
// 设置数据表名 // 设置数据表名
protected $name = 'menus'; protected $name = 'menus';
} }

View File

@@ -9,6 +9,14 @@ class User extends Model
{ {
use SoftDelete; use SoftDelete;
const ADMIN_STP = 1;
const ADMIN_OTP = 0;
const NOT_USER = -1;
const MASTER_USER = 1; // 操盘手
const CUSTOMER_USER = 2; // 门店接待
const STATUS_STOP = 0; // 禁用状态
const STATUS_ACTIVE = 1; // 活动状态
/** /**
* 数据表名 * 数据表名
* @var string * @var string

View File

@@ -35,7 +35,7 @@ Route::group('v1/', function () {
// 获客场景相关 // 获客场景相关
Route::group('plan/scenes', function () { Route::group('plan/scenes', function () {
Route::get('', 'app\cunkebao\controller\Scene@index'); // 获取场景列表 Route::get('', 'app\cunkebao\controller\Scene@index'); // 获取场景列表
Route::post('create', 'app\cunkebao\controller\Plan@index'); // 获取场景列表 Route::post('create', 'app\cunkebao\controller\Plan@index'); // 获取场景列表
}); });
// 流量标签相关 // 流量标签相关

View File

@@ -85,7 +85,7 @@ class GetAddResultedDevicesController extends BaseController
[ [
'accountId' => $accountId, 'accountId' => $accountId,
'pageIndex' => 0, 'pageIndex' => 0,
'pageSize' => 1 'pageSize' => 1
], ],
true true
); );

View File

@@ -6,8 +6,10 @@ use app\common\model\Device as DeviceModel;
use app\common\model\DeviceTaskconf as DeviceTaskconfModel; use app\common\model\DeviceTaskconf as DeviceTaskconfModel;
use app\common\model\DeviceUser as DeviceUserModel; use app\common\model\DeviceUser as DeviceUserModel;
use app\common\model\DeviceWechatLogin; use app\common\model\DeviceWechatLogin;
use app\common\model\User as UserModel;
use app\common\model\WechatFriend; use app\common\model\WechatFriend;
use app\cunkebao\controller\BaseController; use app\cunkebao\controller\BaseController;
use Eison\Utils\Helper\ArrHelper;
use library\ResponseHelper; use library\ResponseHelper;
/** /**
@@ -24,8 +26,8 @@ class GetDeviceDetailV1Controller extends BaseController
protected function checkUserDevicePermission(int $deviceId): void protected function checkUserDevicePermission(int $deviceId): void
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'userId' => $this->getUserInfo('id'), 'userId' => $this->getUserInfo('id'),
'companyId' => $this->getUserInfo('companyId') 'companyId' => $this->getUserInfo('companyId')
]; ];
@@ -65,19 +67,20 @@ class GetDeviceDetailV1Controller extends BaseController
protected function getTaskConfig(int $deviceId): array protected function getTaskConfig(int $deviceId): array
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'companyId' => $this->getUserInfo('companyId'), 'companyId' => $this->getUserInfo('companyId'),
'deleteTime' => 0
]; ];
$conf = DeviceTaskconfModel::where($where)->field('autoAddFriend,autoReply,contentSync,aiChat')->find(); $conf = DeviceTaskconfModel::alias('c')
->field([
'c.autoAddFriend', 'c.autoReply', 'c.contentSync', 'c.aiChat'
])
->where($where)
->find();
return $conf ? $conf->toArray() : [ return $conf
'autoAddFriend' => 0, ? $conf->toArray()
'autoReply' => 0, : ArrHelper::getValue([], 'autoAddFriend,autoReply,contentSync,aiChat', 0);
'contentSync' => 0,
'aiChat' => 0
];
} }
/** /**
@@ -90,7 +93,7 @@ class GetDeviceDetailV1Controller extends BaseController
protected function getTotalFriend(int $deviceId): int protected function getTotalFriend(int $deviceId): int
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'companyId' => $this->getUserInfo('companyId'), 'companyId' => $this->getUserInfo('companyId'),
]; ];
@@ -125,7 +128,6 @@ class GetDeviceDetailV1Controller extends BaseController
->field([ ->field([
'd.id', 'd.imei', 'd.memo', 'd.alive', 'd.updateTime as lastUpdateTime', 'd.extra' 'd.id', 'd.imei', 'd.memo', 'd.alive', 'd.updateTime as lastUpdateTime', 'd.extra'
]) ])
->where('d.deleteTime', 0)
->find($id); ->find($id);
if (empty($device)) { if (empty($device)) {
@@ -155,7 +157,7 @@ class GetDeviceDetailV1Controller extends BaseController
try { try {
$id = $this->request->param('id/d'); $id = $this->request->param('id/d');
if ($this->getUserInfo('isAdmin') != 1) { if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
$this->checkUserDevicePermission($id); $this->checkUserDevicePermission($id);
} }

View File

@@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device;
use app\common\model\DeviceHandleLog; use app\common\model\DeviceHandleLog;
use app\common\model\DeviceUser as DeviceUserModel; use app\common\model\DeviceUser as DeviceUserModel;
use app\common\model\User as UserModel;
use app\cunkebao\controller\BaseController; use app\cunkebao\controller\BaseController;
use library\ResponseHelper; use library\ResponseHelper;
@@ -21,15 +22,15 @@ class GetDeviceHandleLogsV1Controller extends BaseController
protected function checkUserDevicePermission(int $deviceId): void protected function checkUserDevicePermission(int $deviceId): void
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'userId' => $this->getUserInfo('id'), 'userId' => $this->getUserInfo('id'),
'companyId' => $this->getUserInfo('companyId') 'companyId' => $this->getUserInfo('companyId')
]; ];
$hasPermission = DeviceUserModel::where($where)->count() > 0; $hasPermission = DeviceUserModel::where($where)->count() > 0;
if (!$hasPermission) { if (!$hasPermission) {
throw new \Exception('您没有权限查看该设备', '403'); throw new \Exception('您没有权限查看该设备', 403);
} }
} }
@@ -43,9 +44,7 @@ class GetDeviceHandleLogsV1Controller extends BaseController
{ {
return DeviceHandleLog::alias('l') return DeviceHandleLog::alias('l')
->field([ ->field([
'l.id', 'l.id', 'l.content', 'l.createTime',
'l.content',
'l.createTime',
'u.username' 'u.username'
]) ])
->leftJoin('users u', 'l.userId = u.id') ->leftJoin('users u', 'l.userId = u.id')
@@ -64,7 +63,7 @@ class GetDeviceHandleLogsV1Controller extends BaseController
try { try {
$deviceId = $this->request->param('id/d'); $deviceId = $this->request->param('id/d');
if ($this->getUserInfo('isAdmin') != 1) { if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
$this->checkUserDevicePermission($deviceId); $this->checkUserDevicePermission($deviceId);
} }

View File

@@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device;
use app\common\model\Device as DeviceModel; use app\common\model\Device as DeviceModel;
use app\common\model\DeviceUser as DeviceUserModel; use app\common\model\DeviceUser as DeviceUserModel;
use app\common\model\User as UserModel;
use app\common\model\WechatFriend; use app\common\model\WechatFriend;
use app\cunkebao\controller\BaseController; use app\cunkebao\controller\BaseController;
use library\ResponseHelper; use library\ResponseHelper;
@@ -34,7 +35,6 @@ class GetDeviceListV1Controller extends BaseController
} }
$where['d.companyId'] = $this->getUserInfo('companyId'); $where['d.companyId'] = $this->getUserInfo('companyId');
$where['d.deleteTime'] = 0;
return array_merge($params, $where); return array_merge($params, $where);
} }
@@ -72,7 +72,11 @@ class GetDeviceListV1Controller extends BaseController
protected function getDeviceList(array $where, int $page = 1, int $limit = 10): \think\Paginator protected function getDeviceList(array $where, int $page = 1, int $limit = 10): \think\Paginator
{ {
$query = DeviceModel::alias('d') $query = DeviceModel::alias('d')
->field(['d.id', 'd.imei', 'd.memo', 'l.wechatId', 'd.alive', 'wa.nickname', 'wa.alias', '0 totalFriend']) ->field([
'd.id', 'd.imei', 'd.memo', 'd.alive',
'l.wechatId',
'wa.nickname', 'wa.alias', '0 totalFriend'
])
->leftJoin('device_wechat_login l', 'd.id = l.deviceId') ->leftJoin('device_wechat_login l', 'd.id = l.deviceId')
->leftJoin('wechat_account wa', 'l.wechatId = wa.wechatId') ->leftJoin('wechat_account wa', 'l.wechatId = wa.wechatId')
->order('d.id desc'); ->order('d.id desc');
@@ -119,7 +123,7 @@ class GetDeviceListV1Controller extends BaseController
public function index() public function index()
{ {
try { try {
if ($this->getUserInfo('isAdmin') == 1) { if ($this->getUserInfo('isAdmin') == UserModel::ADMIN_STP) {
$where = $this->makeWhere(); $where = $this->makeWhere();
$result = $this->getDeviceList($where); $result = $this->getDeviceList($where);
} else { } else {
@@ -129,7 +133,7 @@ class GetDeviceListV1Controller extends BaseController
return ResponseHelper::success( return ResponseHelper::success(
[ [
'list' => $this->countFriend($result), 'list' => $this->countFriend($result),
'total' => $result->total(), 'total' => $result->total(),
] ]
); );

View File

@@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device;
use app\common\model\DeviceUser as DeviceUserModel; use app\common\model\DeviceUser as DeviceUserModel;
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel; use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
use app\common\model\User as UserModel;
use app\common\model\WechatAccount as WechatAccountModel; use app\common\model\WechatAccount as WechatAccountModel;
use app\common\model\WechatFriend; use app\common\model\WechatFriend;
use app\cunkebao\controller\BaseController; use app\cunkebao\controller\BaseController;
@@ -23,8 +24,8 @@ class GetRelatedAccountsV1Controller extends BaseController
protected function checkUserDevicePermission(int $deviceId): void protected function checkUserDevicePermission(int $deviceId): void
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'userId' => $this->getUserInfo('id'), 'userId' => $this->getUserInfo('id'),
'companyId' => $this->getUserInfo('companyId') 'companyId' => $this->getUserInfo('companyId')
]; ];
@@ -44,7 +45,7 @@ class GetRelatedAccountsV1Controller extends BaseController
protected function getDeviceWechatIds(int $deviceId): array protected function getDeviceWechatIds(int $deviceId): array
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'companyId' => $this->getUserInfo('companyId') 'companyId' => $this->getUserInfo('companyId')
]; ];
@@ -148,7 +149,7 @@ class GetRelatedAccountsV1Controller extends BaseController
try { try {
$deviceId = $this->request->param('id/d'); $deviceId = $this->request->param('id/d');
if ($this->getUserInfo('isAdmin') != 1) { if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
$this->checkUserDevicePermission($deviceId); $this->checkUserDevicePermission($deviceId);
} }
@@ -159,7 +160,7 @@ class GetRelatedAccountsV1Controller extends BaseController
[ [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'accounts' => $wechatAccounts, 'accounts' => $wechatAccounts,
'total' => count($wechatAccounts) 'total' => count($wechatAccounts)
] ]
); );
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -25,9 +25,8 @@ class PostAddDeviceV1Controller extends BaseController
{ {
if ($this->request->param('imei')) { if ($this->request->param('imei')) {
$where = [ $where = [
'imei' => $this->request->param('imei'), 'imei' => $this->request->param('imei'),
'companyId' => $this->getUserInfo('companyId'), 'companyId' => $this->getUserInfo('companyId'),
'deleteTime' => 0
]; ];
$exist = DeviceModel::where($where)->count() > 0; $exist = DeviceModel::where($where)->count() > 0;
@@ -72,9 +71,9 @@ class PostAddDeviceV1Controller extends BaseController
{ {
DeviceHandleLogModel::addLog( DeviceHandleLogModel::addLog(
[ [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'content' => '添加设备', 'content' => '添加设备',
'userId' => $this->getUserInfo('id'), 'userId' => $this->getUserInfo('id'),
'companyId' => $this->getUserInfo('companyId'), 'companyId' => $this->getUserInfo('companyId'),
] ]
); );

View File

@@ -6,6 +6,7 @@ use app\common\model\Device as DeviceModel;
use app\common\model\DeviceHandleLog as DeviceHandleLogModel; use app\common\model\DeviceHandleLog as DeviceHandleLogModel;
use app\common\model\DeviceTaskconf; use app\common\model\DeviceTaskconf;
use app\common\model\DeviceUser as DeviceUserModel; use app\common\model\DeviceUser as DeviceUserModel;
use app\common\model\User as UserModel;
use app\cunkebao\controller\BaseController; use app\cunkebao\controller\BaseController;
use library\ResponseHelper; use library\ResponseHelper;
use think\Db; use think\Db;
@@ -25,9 +26,8 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
protected function checkDeviceExists(int $deviceId) protected function checkDeviceExists(int $deviceId)
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'companyId' => $this->getUserInfo('companyId'), 'companyId' => $this->getUserInfo('companyId'),
'deleteTime' => 0
]; ];
$device = DeviceModel::find($where); $device = DeviceModel::find($where);
@@ -46,8 +46,8 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
protected function checkUserDevicePermission(int $deviceId): void protected function checkUserDevicePermission(int $deviceId): void
{ {
$where = [ $where = [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'userId' => $this->getUserInfo('id'), 'userId' => $this->getUserInfo('id'),
'companyId' => $this->getUserInfo('companyId') 'companyId' => $this->getUserInfo('companyId')
]; ];
@@ -81,9 +81,9 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
DeviceHandleLogModel::addLog( DeviceHandleLogModel::addLog(
[ [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
'content' => $content, 'content' => $content,
'userId' => $this->getUserInfo('id'), 'userId' => $this->getUserInfo('id'),
'companyId' => $this->getUserInfo('companyId'), 'companyId' => $this->getUserInfo('companyId'),
] ]
); );
@@ -119,7 +119,7 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
$this->checkDeviceExists($id); $this->checkDeviceExists($id);
if ($this->getUserInfo('isAdmin') != 1) { if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
$this->checkUserDevicePermission($id); $this->checkUserDevicePermission($id);
} }

View File

@@ -2,6 +2,7 @@
namespace app\superadmin\controller\Menu; namespace app\superadmin\controller\Menu;
use app\common\model\Administrator as AdministratorModel;
use app\common\model\Menu as MenuModel; use app\common\model\Menu as MenuModel;
use app\common\model\AdministratorPermissions as AdministratorPermissionsModel; use app\common\model\AdministratorPermissions as AdministratorPermissionsModel;
use app\superadmin\controller\BaseController; use app\superadmin\controller\BaseController;
@@ -69,7 +70,7 @@ class GetMenuTreeController extends BaseController
protected function getMenuTree(): array 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) : []; return $allMenus ? $this->buildMenuTree($allMenus) : [];
@@ -84,8 +85,8 @@ class GetMenuTreeController extends BaseController
protected function getTopMenusInPermissionIds(array $permissionIds): array protected function getTopMenusInPermissionIds(array $permissionIds): array
{ {
$where = [ $where = [
'parentId' => 0, 'parentId' => MenuModel::TOP_LEVEL,
'status' => 1, 'status' => MenuModel::STATUS_ACTIVE,
]; ];
return MenuModel::where($where)->whereIn('id', $permissionIds)->order('sort', 'asc')->select()->toArray(); 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 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() public function index()
{ {
if ($this->getAdminInfo('id') == 1) { if ($this->getAdminInfo('id') == AdministratorModel::MASTER_ID) {
$menuTree = $this->getMenuTree(); $menuTree = $this->getMenuTree();
} else { } else {
$menuTree = $this->getMenuTreeByPermissions( $menuTree = $this->getMenuTreeByPermissions(

View File

@@ -19,8 +19,8 @@ class GetTopLevelForPermissionController extends BaseController
protected function getTopLevelMenus(): array protected function getTopLevelMenus(): array
{ {
$where = [ $where = [
'parentId' => 0, 'parentId' => MenuModel::TOP_LEVEL,
'status' => 1 'status' => MenuModel::STATUS_NORMAL
]; ];
return MenuModel::where($where)->field('id, title')->order('sort', 'asc')->select()->toArray(); return MenuModel::where($where)->field('id, title')->order('sort', 'asc')->select()->toArray();

View File

@@ -41,15 +41,15 @@ class AddAdministratorController extends BaseController
protected function dataValidate(array $params): self protected function dataValidate(array $params): self
{ {
$validate = Validate::make([ $validate = Validate::make([
'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/', 'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/',
'username' => 'require|/\S+/', 'username' => 'require|/\S+/',
'password' => 'require|/\S+/', 'password' => 'require|/\S+/',
'permissionIds' => 'require|array', 'permissionIds' => 'require|array',
], [ ], [
'account.require' => '账号不能为空', 'account.require' => '账号不能为空',
'account.regex' => '账号只能用数字或者字母或者数字字母组合', 'account.regex' => '账号只能用数字或者字母或者数字字母组合',
'username.require' => '用户名不能为空', 'username.require' => '用户名不能为空',
'password.require' => '密码不能为空', 'password.require' => '密码不能为空',
'permissionIds.require' => '请至少分配一种权限', 'permissionIds.require' => '请至少分配一种权限',
]); ]);
@@ -67,7 +67,7 @@ class AddAdministratorController extends BaseController
*/ */
protected function checkPermission(): self protected function checkPermission(): self
{ {
if ($this->getAdminInfo('id') != 1) { if ($this->getAdminInfo('id') != AdministratorModel::MASTER_ID) {
throw new \Exception('您没有权限添加管理员', 403); throw new \Exception('您没有权限添加管理员', 403);
} }
@@ -95,7 +95,7 @@ class AddAdministratorController extends BaseController
]); ]);
} else { } else {
return AdministratorPermissionsModel::create([ return AdministratorPermissionsModel::create([
'adminId' => $adminId, 'adminId' => $adminId,
'permissions' => json_encode($permissionData), 'permissions' => json_encode($permissionData),
]); ]);
} }

View File

@@ -66,12 +66,12 @@ class DeleteAdministratorController extends BaseController
} }
// 只有超级管理员(ID为1)可以删除管理员 // 只有超级管理员(ID为1)可以删除管理员
if ($this->getAdminInfo('id') != 1) { if ($this->getAdminInfo('id') != AdministratorModel::MASTER_ID) {
throw new \Exception('您没有权限删除管理员', 403); throw new \Exception('您没有权限删除管理员', 403);
} }
// 不能删除超级管理员账号 // 不能删除超级管理员账号
if ($adminId == 1) { if ($adminId == AdministratorModel::MASTER_ID) {
throw new \Exception('不能删除超级管理员账号', 403); throw new \Exception('不能删除超级管理员账号', 403);
} }
} }
@@ -88,7 +88,7 @@ class DeleteAdministratorController extends BaseController
$validate = Validate::make([ $validate = Validate::make([
'id' => 'require|regex:/^[1-9]\d*$/', 'id' => 'require|regex:/^[1-9]\d*$/',
], [ ], [
'id.regex' => '非法请求', 'id.regex' => '非法请求',
'id.require' => '非法请求', 'id.require' => '非法请求',
]); ]);

View File

@@ -22,9 +22,10 @@ class GetAdministratorDetailController extends BaseController
protected function getAdministrator(int $adminId): AdministratorModel protected function getAdministrator(int $adminId): AdministratorModel
{ {
$admin = AdministratorModel::alias('a') $admin = AdministratorModel::alias('a')
->field( ->field([
'a.id, a.account, a.username, a.status, a.authId, a.createTime createdAt, a.lastLoginTime lastLogin, p.permissions' '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') ->leftJoin('administrator_permissions p', 'a.id = p.adminId')
->where('a.id', $adminId) ->where('a.id', $adminId)
->find(); ->find();
@@ -94,10 +95,10 @@ class GetAdministratorDetailController extends BaseController
return ResponseHelper::success( return ResponseHelper::success(
array_merge($admin->toArray(), [ array_merge($admin->toArray(), [
'roleName' => $roleName, 'roleName' => $roleName,
'permissions' => $permissionIds, 'permissions' => $permissionIds,
'lastLogin' => $admin->lastLogin ? date('Y-m-d H:i', $admin->lastLogin) : '从未登录', 'lastLogin' => $admin->lastLogin ? date('Y-m-d H:i', $admin->lastLogin) : '从未登录',
'createdAt' => date('Y-m-d H:i', $admin->createdAt), 'createdAt' => date('Y-m-d H:i', $admin->createdAt),
]) ])
); );
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -40,9 +40,9 @@ class GetAdministratorListController extends Controller
protected function getAdministratorList(array $where): \think\Paginator protected function getAdministratorList(array $where): \think\Paginator
{ {
$query = AdministratorModel::alias('a') $query = AdministratorModel::alias('a')
->field( ->field([
'id, account, username, status, authId, createTime createdAt, lastLoginTime, lastLoginIp' 'a.id', 'a.account', 'a.username', 'a.status', 'a.authId', 'a.createTime createdAt', 'a.lastLoginTime', 'a.lastLoginIp'
); ]);
foreach ($where as $key => $value) { foreach ($where as $key => $value) {
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') { 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) { foreach ($list->items() as $item) {
$section = [ $section = [
'id' => $item->id, 'id' => $item->id,
'account' => $item->account, 'account' => $item->account,
'username' => $item->username, 'username' => $item->username,
'status' => $item->status, 'status' => $item->status,
'createdAt' => date('Y-m-d H:i:s', $item->createdAt), 'createdAt' => date('Y-m-d H:i:s', $item->createdAt),
'lastLogin' => !empty($item->lastLoginTime) ? date('Y-m-d H:i:s', $item->lastLoginTime) : '从未登录', 'lastLogin' => !empty($item->lastLoginTime) ? date('Y-m-d H:i:s', $item->lastLoginTime) : '从未登录',
'role' => $this->getRoleName($item->authId), 'role' => $this->getRoleName($item->authId),
'permissions' => $this->getPermissions($item->id), 'permissions' => $this->getPermissions($item->id),
]; ];
@@ -167,7 +167,7 @@ class GetAdministratorListController extends Controller
return ResponseHelper::success( return ResponseHelper::success(
[ [
'list' => $this->makeReturnedResult($result), 'list' => $this->makeReturnedResult($result),
'total' => $result->total(), 'total' => $result->total(),
] ]
); );

View File

@@ -48,16 +48,16 @@ class UpdateAdministratorController extends BaseController
protected function dataValidate(array $params): self protected function dataValidate(array $params): self
{ {
$validate = Validate::make([ $validate = Validate::make([
'id' => 'require|regex:/^[1-9]\d*$/', 'id' => 'require|regex:/^[1-9]\d*$/',
'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/', 'account' => 'require|regex:^[a-zA-Z0-9]+$|/\S+/',
'username' => 'require|/\S+/', 'username' => 'require|/\S+/',
'password' => '/\S+/', 'password' => '/\S+/',
'permissionIds' => 'array', 'permissionIds' => 'array',
], [ ], [
'id.require' => '缺少必要参数', 'id.require' => '缺少必要参数',
'account.require' => '账号不能为空', 'account.require' => '账号不能为空',
'account.regex' => '账号只能用数字或者字母或者数字字母组合', 'account.regex' => '账号只能用数字或者字母或者数字字母组合',
'username.require' => '用户名不能为空', 'username.require' => '用户名不能为空',
'permissionIds.array' => '请至少分配一种权限', 'permissionIds.array' => '请至少分配一种权限',
]); ]);
@@ -79,11 +79,11 @@ class UpdateAdministratorController extends BaseController
{ {
$currentAdminId = $this->getAdminInfo('id'); $currentAdminId = $this->getAdminInfo('id');
if ($currentAdminId != 1 && $currentAdminId != $adminId) { if ($currentAdminId != AdministratorModel::MASTER_ID && $currentAdminId != $adminId) {
throw new \Exception('您没有权限修改其他管理员', 403); throw new \Exception('您没有权限修改其他管理员', 403);
} }
if ($params['id'] != 1 && empty($params['permissionIds'])) { if ($params['id'] != AdministratorModel::MASTER_ID && empty($params['permissionIds'])) {
throw new \Exception('请至少分配一种权限', 403); throw new \Exception('请至少分配一种权限', 403);
} }
@@ -111,7 +111,7 @@ class UpdateAdministratorController extends BaseController
]); ]);
} else { } else {
return AdministratorPermissionsModel::create([ return AdministratorPermissionsModel::create([
'adminId' => $adminId, 'adminId' => $adminId,
'permissions' => json_encode($permissionData), 'permissions' => json_encode($permissionData),
]); ]);
} }
@@ -137,7 +137,7 @@ class UpdateAdministratorController extends BaseController
$this->udpateAdministrator($params); $this->udpateAdministrator($params);
// 如果当前是超级管理员(ID为1),并且修改的不是自己,则更新权限 // 如果当前是超级管理员(ID为1),并且修改的不是自己,则更新权限
if ($this->getAdminInfo('id') == 1 if ($this->getAdminInfo('id') == AdministratorModel::MASTER_ID
&& $this->getAdminInfo('id') != $adminId && $this->getAdminInfo('id') != $adminId
&& !empty($params['permissionIds']) && !empty($params['permissionIds'])
) { ) {

View File

@@ -7,6 +7,7 @@ use app\superadmin\controller\administrator\DeleteAdministratorController;
use library\ResponseHelper; use library\ResponseHelper;
use think\Controller; use think\Controller;
use think\Validate; use think\Validate;
use think\facade\Cookie;
class AuthLoginController extends Controller class AuthLoginController extends Controller
{ {
@@ -30,7 +31,7 @@ class AuthLoginController extends Controller
protected function dataValidate(array $params): self protected function dataValidate(array $params): self
{ {
$validate = Validate::make([ $validate = Validate::make([
'account' => 'require|/\S+/', 'account' => 'require|/\S+/',
'password' => 'require|/\S+/', 'password' => 'require|/\S+/',
]); ]);
@@ -96,11 +97,11 @@ class AuthLoginController extends Controller
{ {
// 获取当前环境 // 获取当前环境
$env = app()->env->get('APP_ENV', 'production'); $env = app()->env->get('APP_ENV', 'production');
// 获取请求的域名 // 获取请求的域名
$origin = $this->request->header('origin'); $origin = $this->request->header('origin');
$domain = ''; $domain = '';
if ($origin) { if ($origin) {
// 解析域名 // 解析域名
$parsedUrl = parse_url($origin); $parsedUrl = parse_url($origin);
@@ -112,7 +113,7 @@ class AuthLoginController extends Controller
// 生产环境使用顶级域名 // 生产环境使用顶级域名
$parts = explode('.', $parsedUrl['host']); $parts = explode('.', $parsedUrl['host']);
if (count($parts) > 1) { 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选项 // 设置cookie选项
$options = [ $options = [
'expire' => 86400, 'expire' => 86400,
'path' => '/', 'path' => '/',
'httponly' => true, 'httponly' => true,
'samesite' => 'None', // 允许跨域 'samesite' => 'None', // 允许跨域
'secure' => true // 仅 HTTPS 下有效 'secure' => true // 仅 HTTPS 下有效
]; ];
// 如果有域名,添加到选项 // 如果有域名,添加到选项
@@ -133,8 +134,8 @@ class AuthLoginController extends Controller
} }
// 设置cookies // 设置cookies
\think\facade\Cookie::set('admin_id', $admin->id, $options); Cookie::set('admin_id', $admin->id, $options);
\think\facade\Cookie::set('admin_token', $this->createToken($admin), $options); Cookie::set('admin_token', $this->createToken($admin), $options);
} }
/** /**
@@ -152,10 +153,10 @@ class AuthLoginController extends Controller
return ResponseHelper::success( return ResponseHelper::success(
[ [
'id' => $admin->id, 'id' => $admin->id,
'name' => $admin->username, 'name' => $admin->username,
'account' => $admin->account, 'account' => $admin->account,
'token' => cookie('admin_token') 'token' => Cookie::get('admin_token')
] ]
); );
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -7,10 +7,12 @@ use app\common\model\Company as CompanyModel;
use app\common\model\User as UsersModel; use app\common\model\User as UsersModel;
use app\superadmin\controller\BaseController; use app\superadmin\controller\BaseController;
use Eison\Utils\Helper\ArrHelper; use Eison\Utils\Helper\ArrHelper;
use Exception;
use library\ResponseHelper; use library\ResponseHelper;
use library\s2\CurlHandle; use library\s2\CurlHandle;
use think\Db; use think\Db;
use think\facade\Env; use think\facade\Env;
use think\response\Json;
use think\Validate; use think\Validate;
/** /**
@@ -23,7 +25,7 @@ class CreateCompanyController extends BaseController
* *
* @param array $params * @param array $params
* @return mixed|null * @return mixed|null
* @throws \Exception * @throws Exception
*/ */
protected function s2CreateUser(array $params): ?array protected function s2CreateUser(array $params): ?array
{ {
@@ -38,7 +40,7 @@ class CreateCompanyController extends BaseController
$result = json_decode($response, true); $result = json_decode($response, true);
if ($result['code'] != 200) { if ($result['code'] != 200) {
throw new \Exception($result['msg'], 210 . $result['code']); throw new Exception($result['msg'], 210 . $result['code']);
} }
return $result['data'] ?: null; return $result['data'] ?: null;
@@ -63,7 +65,7 @@ class CreateCompanyController extends BaseController
$result = json_decode($response, true); $result = json_decode($response, true);
if ($result['code'] != 200) { if ($result['code'] != 200) {
throw new \Exception($result['msg'], 210 . $result['code']); throw new Exception($result['msg'], 210 . $result['code']);
} }
return $result['data'] ?: null; return $result['data'] ?: null;
@@ -74,33 +76,33 @@ class CreateCompanyController extends BaseController
* *
* @param array $params * @param array $params
* @return $this * @return $this
* @throws \Exception * @throws Exception
*/ */
protected function dataValidate(array $params): self protected function dataValidate(array $params): self
{ {
$validate = Validate::make([ $validate = Validate::make([
'name' => 'require|max:50|/\S+/', 'name' => 'require|max:50|/\S+/',
'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/', 'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/',
'username' => 'require|max:20|/\S+/', 'username' => 'require|max:20|/\S+/',
'phone' => 'require|regex:/^1[3-9]\d{9}$/', 'phone' => 'require|regex:/^1[3-9]\d{9}$/',
'status' => 'require|in:0,1', 'status' => 'require|in:0,1',
'password' => 'require|/\S+/', 'password' => 'require|/\S+/',
'memo' => '/\S+/', 'memo' => '/\S+/',
], [ ], [
'name.require' => '请输入项目名称', 'name.require' => '请输入项目名称',
'account.require' => '请输入账号', 'account.require' => '请输入账号',
'account.max' => '账号长度受限', 'account.max' => '账号长度受限',
'account.regex' => '账号只能用数字或者字母或者数字字母组合', 'account.regex' => '账号只能用数字或者字母或者数字字母组合',
'username.require' => '请输入用户昵称', 'username.require' => '请输入用户昵称',
'phone.require' => '请输入手机号', 'phone.require' => '请输入手机号',
'phone.regex' => '手机号格式错误', 'phone.regex' => '手机号格式错误',
'status.require' => '缺少重要参数', 'status.require' => '缺少重要参数',
'status.in' => '非法参数', 'status.in' => '非法参数',
'password.require' => '请输入密码', 'password.require' => '请输入密码',
]); ]);
if (!$validate->check($params)) { if (!$validate->check($params)) {
throw new \Exception($validate->getError(), 400); throw new Exception($validate->getError(), 400);
} }
return $this; return $this;
@@ -111,7 +113,7 @@ class CreateCompanyController extends BaseController
* *
* @param array $params * @param array $params
* @return void * @return void
* @throws \Exception * @throws Exception
*/ */
protected function s2CreateDeviceGroup(array $params): void protected function s2CreateDeviceGroup(array $params): void
{ {
@@ -119,7 +121,7 @@ class CreateCompanyController extends BaseController
$respon = json_decode($respon, true); $respon = json_decode($respon, true);
if ($respon['code'] != 200) { 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 * @param array $params
* @return array * @return array
* @throws \Exception * @throws Exception
*/ */
protected function creatS2About(array $params): array protected function creatS2About(array $params): array
{ {
$department = $this->s2CreateDepartmentAndUser($params); $department = $this->s2CreateDepartmentAndUser($params);
if (!$department || !isset($department['id']) || !isset($department['departmentId'])) { 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 * @param array $params
* @return void * @return void
* @throws \Exception * @throws Exception
*/ */
protected function ckbCreateCompany(array $params): void protected function ckbCreateCompany(array $params): void
{ {
@@ -160,7 +162,7 @@ class CreateCompanyController extends BaseController
$result = CompanyModel::create($params); $result = CompanyModel::create($params);
if (!$result) { if (!$result) {
throw new \Exception('创建公司记录失败', 402); throw new Exception('创建公司记录失败', 402);
} }
} }
@@ -169,17 +171,17 @@ class CreateCompanyController extends BaseController
* *
* @param array $params * @param array $params
* @return void * @return void
* @throws \Exception * @throws Exception
*/ */
protected function createFuncUsers(array $params): void protected function createFuncUsers(array $params): void
{ {
$seedCols = [ $seedCols = [
['account' => $params['account'] . '_offline', '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' => 0, 'isAdmin' => 0, 'typeId' => -1], ['account' => $params['account'] . '_delete', 'username' => '处理删除专用', 'status' => UsersModel::STATUS_STOP, 'isAdmin' => UsersModel::ADMIN_OTP, 'typeId' => UsersModel::NOT_USER],
]; ];
foreach ($seedCols as $seeds) { 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)); $this->ckbCreateUser(array_merge($params, $seeds));
} }
} }
@@ -189,7 +191,7 @@ class CreateCompanyController extends BaseController
* *
* @param array $params * @param array $params
* @return void * @return void
* @throws \Exception * @throws Exception
*/ */
protected function ckbCreateUser(array $params): void protected function ckbCreateUser(array $params): void
{ {
@@ -201,14 +203,14 @@ class CreateCompanyController extends BaseController
]); ]);
if (!UsersModel::create($params)) { if (!UsersModel::create($params)) {
throw new \Exception('创建用户记录失败', 402); throw new Exception('创建用户记录失败', 402);
} }
} }
/** /**
* @param array $params * @param array $params
* @return void * @return void
* @throws \Exception * @throws Exception
*/ */
protected function createCkbAbout(array $params) protected function createCkbAbout(array $params)
{ {
@@ -217,8 +219,8 @@ class CreateCompanyController extends BaseController
// 2. 存客宝创建操盘手总账号 // 2. 存客宝创建操盘手总账号
$this->ckbCreateUser(array_merge($params, [ $this->ckbCreateUser(array_merge($params, [
'isAdmin' => 1, // 主要账号默认1 'isAdmin' => UsersModel::ADMIN_STP, // 主要账号默认1
'typeId' => 1, // 类型:运营后台/操盘手传1、 门店传2 'typeId' => UsersModel::MASTER_USER, // 类型:运营后台/操盘手传1、 门店传2
])); ]));
} }
@@ -227,7 +229,7 @@ class CreateCompanyController extends BaseController
* *
* @param array $where * @param array $where
* @return void * @return void
* @throws \Exception * @throws Exception
*/ */
protected function checkCompanyNameOrAccountOrPhoneExists(array $where): void protected function checkCompanyNameOrAccountOrPhoneExists(array $where): void
{ {
@@ -236,26 +238,26 @@ class CreateCompanyController extends BaseController
// 项目名称尽量不重名 // 项目名称尽量不重名
$exists = CompanyModel::where(compact('name'))->count() > 0; $exists = CompanyModel::where(compact('name'))->count() > 0;
if ($exists) { if ($exists) {
throw new \Exception('项目名称已存在', 403); throw new Exception('项目名称已存在', 403);
} }
// 账号不重名 // 账号不重名
$exists = UsersModel::where(compact('account'))->count() > 0; $exists = UsersModel::where(compact('account'))->count() > 0;
if ($exists) { if ($exists) {
throw new \Exception('用户账号已存在', 403); throw new Exception('用户账号已存在', 403);
} }
// 手机号不重名 // 手机号不重名
$exists = UsersModel::where(compact('phone'))->count() > 0; $exists = UsersModel::where(compact('phone'))->count() > 0;
if ($exists) { if ($exists) {
throw new \Exception('手机号已存在', 403); throw new Exception('手机号已存在', 403);
} }
} }
/** /**
* 创建新项目 * 创建新项目
* *
* @return \think\response\Json * @return Json
*/ */
public function index() public function index()
{ {
@@ -273,7 +275,7 @@ class CreateCompanyController extends BaseController
Db::commit(); Db::commit();
return ResponseHelper::success(); return ResponseHelper::success();
} catch (\Exception $e) { } catch (Exception $e) {
Db::rollback(); Db::rollback();
return ResponseHelper::error($e->getMessage(), $e->getCode()); return ResponseHelper::error($e->getMessage(), $e->getCode());
} }

View File

@@ -26,7 +26,7 @@ class DeleteCompanyController extends BaseController
$validate = Validate::make([ $validate = Validate::make([
'id' => 'require|regex:/^[1-9]\d*$/', 'id' => 'require|regex:/^[1-9]\d*$/',
], [ ], [
'id.regex' => '非法请求', 'id.regex' => '非法请求',
'id.require' => '非法请求', 'id.require' => '非法请求',
]); ]);

View File

@@ -23,9 +23,9 @@ class GetCompanyDetailForProfileController extends BaseController
*/ */
protected function getDeveiceWechats(int $companyId): array 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 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(); return UserModel::where($where)->count();
} }
@@ -79,7 +79,7 @@ class GetCompanyDetailForProfileController extends BaseController
'c.id', 'c.name', 'c.memo', 'c.companyId', 'c.createTime', 'c.id', 'c.name', 'c.memo', 'c.companyId', 'c.createTime',
'u.account', 'u.phone' '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); ->find($id);
if (!$detail) { if (!$detail) {
@@ -100,7 +100,7 @@ class GetCompanyDetailForProfileController extends BaseController
try { try {
$data = $this->getCompanyDetail($id); $data = $this->getCompanyDetail($id);
$userCount = $this->getUsersCountByCompanyId($id); $userCount = $this->getUsersCountByCompanyId($id);
$deviceCount = $this->getDeviceCountByCompanyId($id); $deviceCount = $this->getDeviceCountByCompanyId($id);
$friendCount = $this->getFriendCountByCompanyId($id); $friendCount = $this->getFriendCountByCompanyId($id);

View File

@@ -4,6 +4,7 @@ namespace app\superadmin\controller\company;
use app\common\model\Company as CompanyModel; use app\common\model\Company as CompanyModel;
use app\common\model\Device as DeviceModel; use app\common\model\Device as DeviceModel;
use app\common\model\User as UserModel;
use app\superadmin\controller\BaseController; use app\superadmin\controller\BaseController;
use library\ResponseHelper; use library\ResponseHelper;
@@ -43,7 +44,7 @@ class GetCompanyDetailForUpdateController extends BaseController
'c.id', 'c.name', 'c.status', 'c.memo', 'c.companyId', 'c.id', 'c.name', 'c.status', 'c.memo', 'c.companyId',
'u.account', 'u.username', 'u.phone', 'u.s2_accountId' '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); ->find($id);
if (!$detail) { if (!$detail) {

View File

@@ -23,7 +23,11 @@ class GetCompanyDevicesForProfileController extends Controller
{ {
$companyId = $this->request->param('companyId/d', 0); $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() ->select()
->toArray(); ->toArray();
@@ -47,7 +51,10 @@ class GetCompanyDevicesForProfileController extends Controller
// 获取最新登录记录id // 获取最新登录记录id
$latestIds = array_column($latestLogs, 'lastedId'); $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) ->whereIn('id', $latestIds)
->select() ->select()
->toArray(); ->toArray();
@@ -65,7 +72,10 @@ class GetCompanyDevicesForProfileController extends Controller
$relations = $this->getDeviceWechatRelationsByDeviceIds($deviceIds); $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')) ->whereIn('ownerWechatId', array_column($relations, 'wechatId'))
->group('ownerWechatId') ->group('ownerWechatId')
->select() ->select()

View File

@@ -57,9 +57,9 @@ class GetCompanyListController extends BaseController
protected function getCompanyList(array $where): \think\Paginator protected function getCompanyList(array $where): \think\Paginator
{ {
$query = CompanyModel::alias('c') $query = CompanyModel::alias('c')
->field( ->field([
'id, name, status, companyId, memo, createTime' 'c.id', 'c.name', 'c.status', 'c.companyId', 'c.memo', 'c.createTime'
); ]);
foreach ($where as $key => $value) { foreach ($where as $key => $value) {
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') { if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') {
@@ -118,7 +118,7 @@ class GetCompanyListController extends BaseController
return ResponseHelper::success( return ResponseHelper::success(
[ [
'list' => $this->makeReturnedResult($result), 'list' => $this->makeReturnedResult($result),
'total' => $result->total(), 'total' => $result->total(),
] ]
); );

View File

@@ -21,10 +21,16 @@ class GetCompanySubusersForProfileController extends Controller
{ {
$where = [ $where = [
'companyId' => $this->request->param('companyId/d', 0), '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();
} }
/** /**

View File

@@ -46,7 +46,7 @@ class UpdateCompanyController extends BaseController
protected function getUserDetailByCompanyId(): ?UsersModel protected function getUserDetailByCompanyId(): ?UsersModel
{ {
$where = [ $where = [
'isAdmin' => 1, // 必须保证 isAdmin 有且只有一个 'isAdmin' => UsersModel::MASTER_USER, // 必须保证 isAdmin 有且只有一个
'companyId' => $this->companyId, 'companyId' => $this->companyId,
]; ];
@@ -175,23 +175,23 @@ class UpdateCompanyController extends BaseController
protected function dataValidate(array $params): self protected function dataValidate(array $params): self
{ {
$validate = Validate::make([ $validate = Validate::make([
'id' => 'require', 'id' => 'require',
'name' => 'require|max:50|/\S+/', 'name' => 'require|max:50|/\S+/',
'username' => 'require|max:20|/\S+/', 'username' => 'require|max:20|/\S+/',
'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/', 'account' => 'require|regex:^[a-zA-Z0-9]+$|max:20|/\S+/',
'phone' => 'require|regex:/^1[3-9]\d{9}$/', 'phone' => 'require|regex:/^1[3-9]\d{9}$/',
'status' => 'require|in:0,1' 'status' => 'require|in:0,1'
], [ ], [
'id.require' => '非法请求', 'id.require' => '非法请求',
'name.require' => '请输入项目名称', 'name.require' => '请输入项目名称',
'username.require' => '请输入用户昵称', 'username.require' => '请输入用户昵称',
'account.require' => '请输入账号', 'account.require' => '请输入账号',
'account.regex' => '账号只能用数字或者字母或者数字字母组合', 'account.regex' => '账号只能用数字或者字母或者数字字母组合',
'account.max' => '账号长度受限', 'account.max' => '账号长度受限',
'phone.require' => '请输入手机号', 'phone.require' => '请输入手机号',
'phone.regex' => '手机号格式错误', 'phone.regex' => '手机号格式错误',
'status.require' => '缺少重要参数', 'status.require' => '缺少重要参数',
'status.in' => '非法参数', 'status.in' => '非法参数',
]); ]);
if (!$validate->check($params)) { if (!$validate->check($params)) {

View File

@@ -52,7 +52,7 @@ class GetBasestatisticsController extends Controller
{ {
return ResponseHelper::success( return ResponseHelper::success(
[ [
'companyCount' => $this->getCompanyCount(), 'companyCount' => $this->getCompanyCount(),
'adminCount' => $this->getAdminCount(), 'adminCount' => $this->getAdminCount(),
'customerCount' => $this->getDeviceCount(), 'customerCount' => $this->getDeviceCount(),
] ]

View File

@@ -85,7 +85,7 @@ class GetAddResultedDevicesController extends Controller
[ [
'accountId' => $accountId, 'accountId' => $accountId,
'pageIndex' => 0, 'pageIndex' => 0,
'pageSize' => 1 'pageSize' => 1
], ],
true true
); );

View File

@@ -61,9 +61,9 @@ class GetPoolListController extends BaseController
protected function makeReturnedValue(\think\Paginator $list): \think\Paginator protected function makeReturnedValue(\think\Paginator $list): \think\Paginator
{ {
$list->each(function ($item) { $list->each(function ($item) {
$item->gender = $this->formatGender($item->gender); $item->gender = $this->formatGender($item->gender);
$item->addTime = $this->formatDate($item->addTime); $item->addTime = $this->formatDate($item->addTime);
$item->tags = $this->handlTags($item->tags); $item->tags = $this->handlTags($item->tags);
}); });
return $list; return $list;
@@ -78,15 +78,10 @@ class GetPoolListController extends BaseController
{ {
$query = TrafficPoolModel::alias('tp') $query = TrafficPoolModel::alias('tp')
->field([ ->field([
'ts.id',
'tp.wechatId', 'tp.wechatId',
'ts.createTime as addTime', 'ts.id', 'ts.createTime as addTime', 'ts.fromd as source',
'ts.fromd as source',
'c.name as projectName', 'c.name as projectName',
'wa.avatar', 'wa.avatar', 'wa.gender', 'wa.nickname', 'wa.region',
'wa.gender',
'wa.nickname',
'wa.region',
'wt.tags' 'wt.tags'
]) ])
->join('traffic_source ts', 'tp.identifier = ts.identifier', 'RIGHT') ->join('traffic_source ts', 'tp.identifier = ts.identifier', 'RIGHT')
@@ -108,9 +103,9 @@ class GetPoolListController extends BaseController
return ResponseHelper::success( return ResponseHelper::success(
[ [
'list' => $this->makeReturnedValue($list)->items(), 'list' => $this->makeReturnedValue($list)->items(),
'total' => $list->total(), 'total' => $list->total(),
'page' => $list->currentPage(), 'page' => $list->currentPage(),
'limit' => $list->listRows() 'limit' => $list->listRows()
] ]
); );