// +---------------------------------------------------------------------- namespace App\Http\Controllers\Admin; use App\Services\Common\AccountService; use App\Services\Common\AnswerRanksService; use App\Services\Common\ExamAccessLogsService; use App\Services\Common\MemberService; use App\Services\Common\MenuService; use App\Services\Common\UserService; use App\Services\RedisService; use Request; /** * 系统主页控制器 * @author laravel开发员 * @since 2020/11/10 * Class IndexController * @package App\Http\Controllers */ class IndexController extends Backend { /** * 构造函数 * @author laravel开发员 * @since 2020/11/10 * IndexController constructor. */ public function __construct() { parent::__construct(); $this->service = MemberService::make(); } /** * 后台主页 * @author laravel开发员 * @since 2020/11/10 */ public function getMenuList() { $menuService = new MenuService(); $menuList = $menuService->getPermissionList($this->userId); return $menuList; } /** * 获取个人信息 * @return array * @since 2020/11/10 * @author laravel开发员 */ public function getUserInfo() { $userService = new UserService(); $result = $userService->getUserInfo($this->userId); return $result; } /** * 更新个人资料 * @return mixed * @since 2020/11/11 * @author laravel开发员 */ public function updateUserInfo() { $userService = new UserService(); $result = $userService->updateUserInfo($this->userId); return $result; } /** * 更新密码 * @return mixed * @since 2020/11/11 * @author laravel开发员 */ public function updatePwd() { $userService = new UserService(); $result = $userService->updatePwd($this->userId); return $result; } /** * 清除缓存 * @return array */ public function clearCache() { RedisService::keyDel("caches:adm*"); RedisService::keyDel("caches:index*"); RedisService::keyDel("caches:count*"); RedisService::keyDel("caches:account*"); RedisService::keyDel("caches:article*"); RedisService::keyDel("caches:member*"); RedisService::keyDel("caches:videos*"); RedisService::keyDel("caches:config*"); RedisService::keyDel("caches:paper*"); RedisService::keyDel("caches:exam*"); RedisService::keyDel("caches:mpQrcode*"); RedisService::keyDel("caches:order*"); RedisService::keyDel(env('APP_NAME').'_cache:*'); return message(MESSAGE_OK, true); } public function statistics() { // 从请求中获取参数,提供默认值 $type = request()->input('type', 'all'); // 默认为 'all' $start_time = request()->input('start_time'); // 可选,默认为 null $end_time = request()->input('end_time'); // 可选,默认为 null $accountLogService = AccountService::make(); // 调用 countUsers 方法并获取数据 $datas = [ // 用户 'users' => [ 'count' => $this->service->countUsers($type, $start_time, $end_time), // 总用户数 'count_by_day' => $this->service->countUsers('today', $start_time, $end_time), // 今日注册 'count_by_month' => $this->service->countUsers('month', $start_time, $end_time), // 本月注册 ], // VIP 'vipPayments' => [ 'all' => $accountLogService->getStatistics('all', 1, 1, $start_time, $end_time), // 所有 'today' => $accountLogService->getStatistics('today', 1, 1, $start_time, $end_time), 'month' => $accountLogService->getStatistics('month', 1, 1, $start_time, $end_time), ], // 视频 'videoPayments' => [ 'all' => $accountLogService->getStatistics('all', 2, 1, $start_time, $end_time), // 所有 'today' => $accountLogService->getStatistics('today', 2, 1, $start_time, $end_time), 'month' => $accountLogService->getStatistics('month', 2, 1, $start_time, $end_time), ] ]; return message(1010, true, $datas); } public function answerRanksStat() { $params = Request()->only(['dateType', 'start_time', 'end_time', 'page', 'limit']); $service = AnswerRanksService::make(); $data = $service->getAnswerRanks($params); return response()->json([ 'code' => 0, 'data' => $data ]); } public function examAccessStats() { $params = Request()->only(['dateType', 'start_time', 'end_time', 'page', 'limit']); $service = ExamAccessLogsService::make(); $data = $service->examAccessStats($params); return response()->json([ 'code' => 0, 'data' => $data ]); } }