IndexController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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:good*");
  100. RedisService::keyDel("caches:advert*");
  101. RedisService::keyDel("caches:count*");
  102. RedisService::keyDel("caches:account*");
  103. RedisService::keyDel("caches:article*");
  104. RedisService::keyDel("caches:member*");
  105. RedisService::keyDel("caches:config*");
  106. RedisService::keyDel("caches:deposit*");
  107. RedisService::keyDel("caches:order*");
  108. RedisService::keyDel("laravel_cache:model*");
  109. //Cache::flush();
  110. return message(MESSAGE_OK, true);
  111. }
  112. public function statistics()
  113. {
  114. // 从请求中获取参数,提供默认值
  115. $type = request()->input('type', 'all'); // 默认为 'all'
  116. $start_time = request()->input('start_time'); // 可选,默认为 null
  117. $end_time = request()->input('end_time'); // 可选,默认为 null
  118. $accountLogService = AccountService::make();
  119. // 调用 countUsers 方法并获取数据
  120. $datas = [
  121. // 用户
  122. 'users' => [
  123. 'count' => $this->service->countUsers($type, $start_time, $end_time), // 总用户数
  124. 'count_by_day' => $this->service->countUsers('today', $start_time, $end_time), // 今日注册
  125. 'count_by_month' => $this->service->countUsers('month', $start_time, $end_time), // 本月注册
  126. ],
  127. // VIP
  128. 'vipPayments' => [
  129. 'all' => $accountLogService->getStatistics('all', 1, 1, $start_time, $end_time), // 所有
  130. 'today' => $accountLogService->getStatistics('today', 1, 1, $start_time, $end_time),
  131. 'month' => $accountLogService->getStatistics('month', 1, 1, $start_time, $end_time),
  132. ],
  133. // 视频
  134. 'videoPayments' => [
  135. 'all' => $accountLogService->getStatistics('all', 2, 1, $start_time, $end_time), // 所有
  136. 'today' => $accountLogService->getStatistics('today', 2, 1, $start_time, $end_time),
  137. 'month' => $accountLogService->getStatistics('month', 2, 1, $start_time, $end_time),
  138. ]
  139. ];
  140. return message(1010, true, $datas);
  141. }
  142. public function answerRanksStat()
  143. {
  144. $params = Request()->only(['dateType', 'start_time', 'end_time', 'page', 'limit']);
  145. $service = AnswerRanksService::make();
  146. $data = $service->getAnswerRanks($params);
  147. return response()->json([
  148. 'code' => 0,
  149. 'data' => $data
  150. ]);
  151. }
  152. }