// +---------------------------------------------------------------------- namespace App\Http\Controllers\Admin; use App\Models\UserModel; use App\Models\AdminRomModel; use App\Services\Common\AccountService; use App\Services\Common\AdminService; use App\Services\Common\AgentService; use App\Services\Common\BalanceLogService; use App\Services\Common\DriverService; use App\Services\Common\FinanceService; use App\Services\Common\MemberService; use App\Services\Common\MenuService; use App\Services\Common\OrderService; use App\Services\Common\UserService; use App\Services\RedisService; use App\utils\TimeUtils; /** * 系统主页控制器 * @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(); } /** * 后台主页 * @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:d*"); RedisService::keyDel("caches:adm*"); RedisService::keyDel("caches:inde*"); RedisService::keyDel("caches:goods*"); RedisService::keyDel("caches:advert*"); RedisService::keyDel("caches:counts*"); RedisService::keyDel("caches:articl*"); RedisService::keyDel("caches:qrcode*"); RedisService::keyDel("caches:memb*"); RedisService::keyDel("caches:conf*"); RedisService::keyDel("caches:order*"); RedisService::keyDel("caches:message*"); RedisService::keyDel("laravel_cache:model*"); return message(MESSAGE_OK, true); } /** * 获取首页数据 * @return array */ public function statistics() { $cacheKey = "caches:admin:indexData:" . $this->userId; $datas = RedisService::get($cacheKey); if ($datas) { return message(1010, true, $datas); } $datas = [ // 用户 'users' => [ 'count' => MemberService::make()->getRegisterCount(), // 总用户数 'count_by_day' => MemberService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册 'count_by_month' => MemberService::make()->getRegisterCount(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月注册 'count_by_year' => MemberService::make()->getRegisterCount(TimeUtils::beginYear(), TimeUtils::endYear()), // 今年 ], // 司机 'driver' => [ 'count' => DriverService::make()->getRegisterCount(), // 总数 'count_by_day' => DriverService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册 ], // 代理 'agent' => [ 'count' => AgentService::make()->getRegisterCount(), // 总数 'count_by_day' => AgentService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册 ], // 商城订单 'orders' => [ 'count' => OrderService::make()->getCountByTime(), // 总量 'count_by_day' => OrderService::make()->getCountByTime(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日 'count_by_month' => OrderService::make()->getCountByTime(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月 'count_by_year' => OrderService::make()->getCountByTime(TimeUtils::beginYear(), TimeUtils::endYear()), // 今年 ], // 营收 'finance' => [ 'total' => AccountService::make()->getTotalByTime(), // 总量 'income' => FinanceService::make()->getTotalByTime(), // 总收入 'income_by_day' => FinanceService::make()->getTotalByTime(TimeUtils::beginToday(), TimeUtils::endToday(),), // 今日 'income_by_month' => FinanceService::make()->getTotalByTime(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月 'income_by_year' => FinanceService::make()->getTotalByTime(TimeUtils::beginYear(), TimeUtils::endYear()), // 今年 ], ]; // 提现统计 $withdrawUser = BalanceLogService::make()->getCountByType(); $withdrawDriver = BalanceLogService::make()->getCountByType(2); $datas['withdraw'] = [ 'total_user' => BalanceLogService::make()->getTotalByStatus(1), // 总量 'total_user_wait' => BalanceLogService::make()->getTotalByStatus(1,1), // 待审核 'total_driver' => BalanceLogService::make()->getTotalByStatus(2), // 总量 'total_driver_wait' => BalanceLogService::make()->getTotalByStatus(2,1), // 待审核 'count_user' => $withdrawUser, // 已提现 'count_user_no' => max(0, $datas['users']['count'] - $withdrawUser), // 未提现 'count_driver' => $withdrawDriver, // 已提现 'count_driver_no' => max(0, $datas['driver']['count'] - $withdrawDriver), // 未提现 ]; RedisService::set($cacheKey, $datas, rand(5, 10)); return message(1010, true, $datas); } }