批量更新
This commit is contained in:
parent
0ed654b5b8
commit
0bf9b77aed
@ -16,10 +16,32 @@ use app\model\AppsBabyhealthUsers;
|
|||||||
class DashboradController extends BaseController
|
class DashboradController extends BaseController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 统计宝贝数量
|
* dashborad总体输出
|
||||||
* @return Json
|
|
||||||
*/
|
*/
|
||||||
public function getBabyCounts()
|
public function getDashborad()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return json([
|
||||||
|
'code' => 200,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => [
|
||||||
|
'userCounts' => $this->getUserCounts(),
|
||||||
|
'babyCounts' => $this->getBabyCounts()
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} catch (DbException $e) {
|
||||||
|
return json([
|
||||||
|
'code' => 500,
|
||||||
|
'msg' => '获取失败:' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计宝贝数量
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getBabyCounts(): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// 总数
|
// 总数
|
||||||
@ -34,29 +56,29 @@ class DashboradController extends BaseController
|
|||||||
// 未知性别 (sex = 0)
|
// 未知性别 (sex = 0)
|
||||||
$unknownCount = AppsBabyhealthBabys::where('delete_time', null)->where('sex', 0)->count();
|
$unknownCount = AppsBabyhealthBabys::where('delete_time', null)->where('sex', 0)->count();
|
||||||
|
|
||||||
return json([
|
return [
|
||||||
'code' => 200,
|
|
||||||
'msg' => '统计成功',
|
|
||||||
'data' => [
|
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
'male' => $maleCount,
|
'male' => $maleCount,
|
||||||
'female' => $femaleCount,
|
'female' => $femaleCount,
|
||||||
'unknown' => $unknownCount
|
'unknown' => $unknownCount
|
||||||
]
|
];
|
||||||
]);
|
|
||||||
} catch (DbException $e) {
|
} catch (DbException $e) {
|
||||||
return json([
|
// 返回空数组而不是抛出异常,让外层处理
|
||||||
'code' => 500,
|
error_log('统计宝贝数量失败: ' . $e->getMessage());
|
||||||
'msg' => '统计失败:' . $e->getMessage()
|
return [
|
||||||
]);
|
'total' => 0,
|
||||||
|
'male' => 0,
|
||||||
|
'female' => 0,
|
||||||
|
'unknown' => 0
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计用户数量
|
* 统计用户数量
|
||||||
* @return Json
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getUserCounts()
|
private function getUserCounts(): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// 总数
|
// 总数
|
||||||
@ -65,27 +87,27 @@ class DashboradController extends BaseController
|
|||||||
// 父亲 (sex = 1)
|
// 父亲 (sex = 1)
|
||||||
$fatherCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 1)->count();
|
$fatherCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 1)->count();
|
||||||
|
|
||||||
// 母亲宝数 (sex = 2)
|
// 母亲 (sex = 2)
|
||||||
$motherCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 2)->count();
|
$motherCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 2)->count();
|
||||||
|
|
||||||
// 未知性别 (sex = 0)
|
// 未知性别 (sex = 0)
|
||||||
$unknownCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 0)->count();
|
$unknownCount = AppsBabyhealthUsers::where('delete_time', null)->where('sex', 0)->count();
|
||||||
|
|
||||||
return json([
|
return [
|
||||||
'code' => 200,
|
|
||||||
'msg' => '统计成功',
|
|
||||||
'data' => [
|
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
'father' => $fatherCount,
|
'father' => $fatherCount,
|
||||||
'mother' => $motherCount,
|
'mother' => $motherCount,
|
||||||
'unknown' => $unknownCount
|
'unknown' => $unknownCount
|
||||||
]
|
];
|
||||||
]);
|
|
||||||
} catch (DbException $e) {
|
} catch (DbException $e) {
|
||||||
return json([
|
// 返回空数组而不是抛出异常,让外层处理
|
||||||
'code' => 500,
|
error_log('统计用户数量失败: ' . $e->getMessage());
|
||||||
'msg' => '统计失败:' . $e->getMessage()
|
return [
|
||||||
]);
|
'total' => 0,
|
||||||
|
'father' => 0,
|
||||||
|
'mother' => 0,
|
||||||
|
'unknown' => 0
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ class LoginController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function login(): Json
|
public function login(): Json
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$data = $this->request->param();
|
$data = $this->request->param();
|
||||||
|
|
||||||
if (isset($data['email'])) {
|
if (isset($data['email'])) {
|
||||||
@ -72,10 +73,17 @@ class LoginController extends BaseController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新登录次数和IP,确保 login_count 不为 null
|
||||||
|
try {
|
||||||
|
$loginCount = isset($user['login_count']) && $user['login_count'] !== null ? (int)$user['login_count'] : 0;
|
||||||
AdminUser::where('id', $user['id'])->update([
|
AdminUser::where('id', $user['id'])->update([
|
||||||
'login_count' => $user['login_count'] + 1,
|
'login_count' => $loginCount + 1,
|
||||||
'last_login_ip' => $this->request->ip()
|
'last_login_ip' => $this->request->ip()
|
||||||
]);
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 更新登录信息失败不影响登录流程
|
||||||
|
error_log('更新登录信息失败: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$userInfo = [
|
$userInfo = [
|
||||||
'id' => $user['id'],
|
'id' => $user['id'],
|
||||||
@ -84,9 +92,24 @@ class LoginController extends BaseController
|
|||||||
'group_id' => $user['group_id']
|
'group_id' => $user['group_id']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
$token = $this->generateToken($userInfo);
|
$token = $this->generateToken($userInfo);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->logFail('登录管理', '登录', 'Token生成失败: ' . $e->getMessage());
|
||||||
|
return json([
|
||||||
|
'code' => 500,
|
||||||
|
'msg' => '登录失败,请稍后重试'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录日志,但不影响登录流程
|
||||||
|
try {
|
||||||
$this->logSuccess('登录管理', '登录', ['id' => $user['id']], $userInfo);
|
$this->logSuccess('登录管理', '登录', ['id' => $user['id']], $userInfo);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 日志记录失败不影响登录
|
||||||
|
error_log('登录日志记录失败: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
return json([
|
return json([
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'msg' => '登录成功',
|
'msg' => '登录成功',
|
||||||
@ -95,6 +118,19 @@ class LoginController extends BaseController
|
|||||||
'user' => $userInfo
|
'user' => $userInfo
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 捕获所有未预期的错误
|
||||||
|
error_log('登录失败: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine());
|
||||||
|
try {
|
||||||
|
$this->logFail('登录管理', '登录', $e->getMessage());
|
||||||
|
} catch (\Exception $logError) {
|
||||||
|
error_log('记录登录失败日志也失败: ' . $logError->getMessage());
|
||||||
|
}
|
||||||
|
return json([
|
||||||
|
'code' => 500,
|
||||||
|
'msg' => '登录失败,请稍后重试'
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
use think\facade\Route;
|
use think\facade\Route;
|
||||||
|
|
||||||
// 宝贝管理路由
|
// 宝贝管理路由
|
||||||
Route::group('baby', function() {
|
Route::group('babys', function() {
|
||||||
// 获取宝贝列表
|
// 获取宝贝列表
|
||||||
Route::get('list', 'app\admin\controller\BabyHealth\BabysController/getBabyList');
|
Route::get('list', 'app\admin\controller\BabyHealth\BabysController/getBabyList');
|
||||||
// 获取宝贝详情
|
// 获取宝贝详情
|
||||||
Route::get('detail/:id', 'app\admin\controller\BabyHealth\BabysController/getBabyDetail');
|
Route::get(':id', 'app\admin\controller\BabyHealth\BabysController/getBabyDetail');
|
||||||
// 创建宝贝
|
// 创建宝贝
|
||||||
Route::post('create', 'app\admin\controller\BabyHealth\BabysController/createBaby');
|
Route::post('create', 'app\admin\controller\BabyHealth\BabysController/createBaby');
|
||||||
// 更新宝贝
|
// 更新宝贝
|
||||||
@ -29,6 +29,6 @@ Route::group('babyhealthUser', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 统计路由
|
// 统计路由
|
||||||
Route::group('baby-dashboard', function() {
|
Route::group('babyhealthDashborad', function() {
|
||||||
Route::get('counts', 'app\admin\controller\BabyHealth\DashboardController/getBabyCounts');
|
Route::get('dashborad', 'app\admin\controller\BabyHealth\DashboradController/getDashborad');
|
||||||
});
|
});
|
||||||
@ -17,8 +17,10 @@ class AllowCrossDomain
|
|||||||
|
|
||||||
$allowedDomains = [
|
$allowedDomains = [
|
||||||
'http://localhost:3000',
|
'http://localhost:3000',
|
||||||
|
'http://localhost:5000',
|
||||||
'http://localhost:8000',
|
'http://localhost:8000',
|
||||||
'http://127.0.0.1:3000',
|
'http://127.0.0.1:3000',
|
||||||
|
'http://127.0.0.1:5000',
|
||||||
'http://127.0.0.1:8000',
|
'http://127.0.0.1:8000',
|
||||||
'http://localhost:5173',
|
'http://localhost:5173',
|
||||||
'http://backapi.yunzer.cn',
|
'http://backapi.yunzer.cn',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user