超管后台 - 获取基础统计信息
This commit is contained in:
@@ -7,6 +7,11 @@ Route::post('auth/login', 'app\superadmin\controller\auth\AuthLoginController@in
|
||||
|
||||
// 需要登录认证的路由组
|
||||
Route::group('', function () {
|
||||
// 仪表盘概述
|
||||
Route::group('dashboard', function () {
|
||||
Route::get('base', 'app\superadmin\controller\dashboard\GetBasestatisticsController@index');
|
||||
});
|
||||
|
||||
// 菜单管理相关路由
|
||||
Route::group('menu', function () {
|
||||
Route::get('tree', 'app\superadmin\controller\MenuController@getMenuTree');
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\controller;
|
||||
|
||||
use app\library\s2\CurlHandle;
|
||||
use app\superadmin\model\Company as companyModel;
|
||||
use app\superadmin\model\Users;
|
||||
use GuzzleHttp\Client;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\facade\Config;
|
||||
use think\facade\Request;
|
||||
use think\facade\Session;
|
||||
|
||||
/**
|
||||
* 公司控制器
|
||||
*/
|
||||
class CompanyController extends Controller
|
||||
{
|
||||
/**
|
||||
* 删除项目
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 405, 'msg' => '请求方法不允许']);
|
||||
}
|
||||
|
||||
$id = $this->request->post('id/d', 0);
|
||||
if (empty($id)) {
|
||||
return json(['code' => 400, 'msg' => '请指定要删除的项目']);
|
||||
}
|
||||
|
||||
// 查询项目
|
||||
$company = companyModel::get($id);
|
||||
if (!$company) {
|
||||
return json(['code' => 404, 'msg' => '项目不存在']);
|
||||
}
|
||||
|
||||
// 检查是否有关联的子账号
|
||||
$userCount = Users::where('companyId', $id)
|
||||
->where('deleteTime', 0)
|
||||
->count();
|
||||
if ($userCount > 0) {
|
||||
return json(['code' => 400, 'msg' => '该项目下还有关联的子账号,无法删除']);
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
if ($company->delete()) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '删除成功'
|
||||
]);
|
||||
}
|
||||
|
||||
return json(['code' => 500, 'msg' => '删除失败']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace app\superadmin\controller\dashboard;
|
||||
|
||||
use app\common\model\Administrator as AdministratorModel;
|
||||
use app\common\model\Company as CompanyModel;
|
||||
use think\Controller;
|
||||
|
||||
/**
|
||||
* 仪表盘控制器
|
||||
*/
|
||||
class GetBasestatisticsController extends Controller
|
||||
{
|
||||
/**
|
||||
* 项目总数
|
||||
*
|
||||
* @return CompanyModel
|
||||
*/
|
||||
protected function getCompanyCount(): int
|
||||
{
|
||||
return CompanyModel::count('*');
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员数量
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getAdminCount(): int
|
||||
{
|
||||
return AdministratorModel::count('*');
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户总数
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getCustomerCount(): int
|
||||
{
|
||||
return $this->getCompanyCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基础统计信息
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'companyCount' => $this->getCompanyCount(),
|
||||
'adminCount' => $this->getAdminCount(),
|
||||
'customerCount' => $this->getCustomerCount(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user