IndexController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Http\Controllers\Admin;
  12. use App\Services\Common\AccountService;
  13. use App\Services\Common\AnswerRanksService;
  14. use App\Services\Common\BalanceLogService;
  15. use App\Services\Common\DepositService;
  16. use App\Services\Common\GoodsService;
  17. use App\Services\Common\MemberService;
  18. use App\Services\Common\MenuService;
  19. use App\Services\Common\OrderService;
  20. use App\Services\Common\UserService;
  21. use App\Services\RedisService;
  22. use App\utils\TimeUtils;
  23. use Request;
  24. /**
  25. * 系统主页控制器
  26. * @author laravel开发员
  27. * @since 2020/11/10
  28. * Class IndexController
  29. * @package App\Http\Controllers
  30. */
  31. class IndexController extends Backend
  32. {
  33. /**
  34. * 构造函数
  35. * @author laravel开发员
  36. * @since 2020/11/10
  37. * IndexController constructor.
  38. */
  39. public function __construct()
  40. {
  41. parent::__construct();
  42. $this->service = MemberService::make();
  43. }
  44. /**
  45. * 后台主页
  46. * @author laravel开发员
  47. * @since 2020/11/10
  48. */
  49. public function getMenuList()
  50. {
  51. $menuService = new MenuService();
  52. $menuList = $menuService->getPermissionList($this->userId);
  53. return $menuList;
  54. }
  55. /**
  56. * 获取个人信息
  57. * @return array
  58. * @since 2020/11/10
  59. * @author laravel开发员
  60. */
  61. public function getUserInfo()
  62. {
  63. $userService = new UserService();
  64. $result = $userService->getUserInfo($this->userId);
  65. return $result;
  66. }
  67. /**
  68. * 更新个人资料
  69. * @return mixed
  70. * @since 2020/11/11
  71. * @author laravel开发员
  72. */
  73. public function updateUserInfo()
  74. {
  75. $userService = new UserService();
  76. $result = $userService->updateUserInfo($this->userId);
  77. return $result;
  78. }
  79. /**
  80. * 更新密码
  81. * @return mixed
  82. * @since 2020/11/11
  83. * @author laravel开发员
  84. */
  85. public function updatePwd()
  86. {
  87. $userService = new UserService();
  88. $result = $userService->updatePwd($this->userId);
  89. return $result;
  90. }
  91. /**
  92. * 清除缓存
  93. * @return array
  94. */
  95. public function clearCache()
  96. {
  97. RedisService::keyDel("caches:adm*");
  98. RedisService::keyDel("caches:index*");
  99. RedisService::keyDel("caches:count*");
  100. RedisService::keyDel("caches:account*");
  101. RedisService::keyDel("caches:article*");
  102. RedisService::keyDel("caches:member*");
  103. RedisService::keyDel("caches:config*");
  104. RedisService::keyDel("caches:mpQrcode*");
  105. RedisService::keyDel("caches:order*");
  106. RedisService::keyDel(env('APP_NAME').'_cache:*');
  107. return message(MESSAGE_OK, true);
  108. }
  109. public function statistics()
  110. {
  111. // 从请求中获取参数,提供默认值
  112. $type = request()->input('type', 'all'); // 默认为 'all'
  113. $start_time = request()->input('start_time'); // 可选,默认为 null
  114. $end_time = request()->input('end_time'); // 可选,默认为 null
  115. $accountLogService = AccountService::make();
  116. // 调用 countUsers 方法并获取数据
  117. $datas = [
  118. // 用户
  119. 'users' => [
  120. 'count' => $this->service->countUsers($type, $start_time, $end_time), // 总用户数
  121. 'count_by_day' => $this->service->countUsers('today', $start_time, $end_time), // 今日注册
  122. 'count_by_month' => $this->service->countUsers('month', $start_time, $end_time), // 本月注册
  123. ],
  124. // VIP
  125. 'vipPayments' => [
  126. 'all' => $accountLogService->getStatistics('all', 1, 1, $start_time, $end_time), // 所有
  127. 'today' => $accountLogService->getStatistics('today', 1, 1, $start_time, $end_time),
  128. 'month' => $accountLogService->getStatistics('month', 1, 1, $start_time, $end_time),
  129. ],
  130. // 视频
  131. 'videoPayments' => [
  132. 'all' => $accountLogService->getStatistics('all', 2, 1, $start_time, $end_time), // 所有
  133. 'today' => $accountLogService->getStatistics('today', 2, 1, $start_time, $end_time),
  134. 'month' => $accountLogService->getStatistics('month', 2, 1, $start_time, $end_time),
  135. ]
  136. ];
  137. return message(1010, true, $datas);
  138. }
  139. public function answerRanksStat()
  140. {
  141. $params = Request()->only(['dateType', 'start_time', 'end_time', 'page', 'limit']);
  142. $service = AnswerRanksService::make();
  143. $data = $service->getAnswerRanks($params);
  144. return response()->json([
  145. 'code' => 0,
  146. 'data' => $data
  147. ]);
  148. }
  149. }