IndexController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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\BalanceLogService;
  13. use App\Services\Common\DepositService;
  14. use App\Services\Common\GoodsService;
  15. use App\Services\Common\MemberService;
  16. use App\Services\Common\MenuService;
  17. use App\Services\Common\OrderService;
  18. use App\Services\Common\UserService;
  19. use App\Services\RedisService;
  20. use App\utils\TimeUtils;
  21. /**
  22. * 系统主页控制器
  23. * @author laravel开发员
  24. * @since 2020/11/10
  25. * Class IndexController
  26. * @package App\Http\Controllers
  27. */
  28. class IndexController extends Backend
  29. {
  30. /**
  31. * 构造函数
  32. * @author laravel开发员
  33. * @since 2020/11/10
  34. * IndexController constructor.
  35. */
  36. public function __construct()
  37. {
  38. parent::__construct();
  39. }
  40. /**
  41. * 后台主页
  42. * @author laravel开发员
  43. * @since 2020/11/10
  44. */
  45. public function getMenuList()
  46. {
  47. $menuService = new MenuService();
  48. $menuList = $menuService->getPermissionList($this->userId);
  49. return $menuList;
  50. }
  51. /**
  52. * 获取个人信息
  53. * @return array
  54. * @since 2020/11/10
  55. * @author laravel开发员
  56. */
  57. public function getUserInfo()
  58. {
  59. $userService = new UserService();
  60. $result = $userService->getUserInfo($this->userId);
  61. return $result;
  62. }
  63. /**
  64. * 更新个人资料
  65. * @return mixed
  66. * @since 2020/11/11
  67. * @author laravel开发员
  68. */
  69. public function updateUserInfo()
  70. {
  71. $userService = new UserService();
  72. $result = $userService->updateUserInfo($this->userId);
  73. return $result;
  74. }
  75. /**
  76. * 更新密码
  77. * @return mixed
  78. * @since 2020/11/11
  79. * @author laravel开发员
  80. */
  81. public function updatePwd()
  82. {
  83. $userService = new UserService();
  84. $result = $userService->updatePwd($this->userId);
  85. return $result;
  86. }
  87. /**
  88. * 清除缓存
  89. * @return array
  90. */
  91. public function clearCache()
  92. {
  93. RedisService::keyDel("caches:adm*");
  94. RedisService::keyDel("caches:index*");
  95. RedisService::keyDel("caches:good*");
  96. RedisService::keyDel("caches:advert*");
  97. RedisService::keyDel("caches:count*");
  98. RedisService::keyDel("caches:account*");
  99. RedisService::keyDel("caches:article*");
  100. RedisService::keyDel("caches:member*");
  101. RedisService::keyDel("caches:config*");
  102. RedisService::keyDel("caches:deposit*");
  103. RedisService::keyDel("caches:order*");
  104. RedisService::keyDel(env('APP_NAME')."_cache:*");
  105. //Cache::flush();
  106. return message(MESSAGE_OK, true);
  107. }
  108. /**
  109. * 获取首页数据
  110. * @return array
  111. */
  112. public function statistics()
  113. {
  114. $datas = [
  115. // 用户
  116. 'users' => [
  117. 'count' => MemberService::make()->getRegisterCount(), // 总用户数
  118. 'count_by_day' => MemberService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册
  119. 'count_by_month' => MemberService::make()->getRegisterCount(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月注册
  120. 'count_by_confirm' => MemberService::make()->getRegisterCount(0,0,2), // 待审核
  121. ],
  122. 'goods'=>[
  123. 'count_by_all'=> GoodsService::make()->getCounts(0),
  124. 'count_by_up'=> GoodsService::make()->getCounts(1),
  125. 'count_by_success'=> GoodsService::make()->getCounts(2),
  126. ],
  127. // 订单
  128. 'orders' => [
  129. 'count' => OrderService::make()->getCountByTime(), // 总量
  130. 'count_by_day' => OrderService::make()->getCountByTime(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日
  131. 'count_by_month' => OrderService::make()->getCountByTime(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月
  132. 'amount_by_day' => OrderService::make()->getTotalByTime(TimeUtils::beginToday(), TimeUtils::endToday()), // 日营业额
  133. 'amount_by_month' => OrderService::make()->getTotalByTime(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 月营业额
  134. ],
  135. 'deposit'=>[
  136. 'total'=> DepositService::make()->getTotal(0),
  137. 'withdraw'=> DepositService::make()->getTotal(1),
  138. ],
  139. // 营收
  140. 'balance' => [
  141. 'income_by_total'=> OrderService::make()->getTotalByTime(),
  142. 'withdraw_by_total'=> BalanceLogService::make()->getTotal(),
  143. ],
  144. ];
  145. return message(1010, true, $datas);
  146. }
  147. }