增加dashborad统计
This commit is contained in:
parent
36fe5e2ab9
commit
399d61e2f2
91
app/admin/controller/BabyHealth/DashboradController.php
Normal file
91
app/admin/controller/BabyHealth/DashboradController.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller\BabyHealth;
|
||||
|
||||
use app\admin\BaseController;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Session;
|
||||
use think\response\Json;
|
||||
use think\db\exception\DbException;
|
||||
use app\model\AppsBabyhealthBabys;
|
||||
use app\model\AppsBabyhealthUsers;
|
||||
|
||||
class DashboradController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 统计宝贝数量
|
||||
* @return Json
|
||||
*/
|
||||
public function getBabyCounts()
|
||||
{
|
||||
try {
|
||||
// 总数
|
||||
$total = AppsBabyhealthBabys::where('delete_time', null)->count();
|
||||
|
||||
// 男宝宝数 (sex = 1)
|
||||
$maleCount = AppsBabyhealthBabys::where('delete_time', null)->where('sex', 1)->count();
|
||||
|
||||
// 女宝宝数 (sex = 2)
|
||||
$femaleCount = AppsBabyhealthBabys::where('delete_time', null)->where('sex', 2)->count();
|
||||
|
||||
// 未知性别 (sex = 0)
|
||||
$unknownCount = AppsBabyhealthBabys::where('delete_time', null)->where('sex', 0)->count();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '统计成功',
|
||||
'data' => [
|
||||
'total' => $total,
|
||||
'male' => $maleCount,
|
||||
'female' => $femaleCount,
|
||||
'unknown' => $unknownCount
|
||||
]
|
||||
]);
|
||||
} catch (DbException $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '统计失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计用户数量
|
||||
* @return Json
|
||||
*/
|
||||
public function getUserCounts()
|
||||
{
|
||||
try {
|
||||
// 总数
|
||||
$total = AppsBabyhealthUsers::where('delete_time', null)->count();
|
||||
|
||||
// 父亲 (sex = 1)
|
||||
$fatherCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 1)->count();
|
||||
|
||||
// 母亲宝数 (sex = 2)
|
||||
$motherCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 2)->count();
|
||||
|
||||
// 未知性别 (sex = 0)
|
||||
$unknownCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 0)->count();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '统计成功',
|
||||
'data' => [
|
||||
'total' => $total,
|
||||
'male' => $fatherCount,
|
||||
'female' => $motherCount,
|
||||
'unknown' => $unknownCount
|
||||
]
|
||||
]);
|
||||
} catch (DbException $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '统计失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,4 +16,8 @@ Route::get('babyhealthUser/list', 'app\\admin\\controller\\BabyHealth\\UserContr
|
||||
Route::get('babyhealthUser/:id', 'app\\admin\\controller\\BabyHealth\\UserController@getUserDetail');
|
||||
Route::post('babyhealthUser', 'app\\admin\\controller\\BabyHealth\\UserController@createUser');
|
||||
Route::post('babyhealthUser/:id', 'app\\admin\\controller\\BabyHealth\\UserController@updateUser');
|
||||
Route::delete('babyhealthUser/:id', 'app\\admin\\controller\\BabyHealth\\UserController@deleteUser');
|
||||
Route::delete('babyhealthUser/:id', 'app\\admin\\controller\\BabyHealth\\UserController@deleteUser');
|
||||
|
||||
// 统计路由
|
||||
Route::get('babyhealthDashborad/babys', 'app\\admin\\controller\\BabyHealth\\DashboradController@getBabyCounts');
|
||||
Route::get('babyhealthDashborad/users', 'app\\admin\\controller\\BabyHealth\\DashboradController@getUserCounts');
|
||||
Loading…
Reference in New Issue
Block a user