IndexController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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\MemberService;
  13. use App\Services\Common\MenuService;
  14. use App\Services\Common\UserService;
  15. use App\Services\RedisService;
  16. use App\utils\TimeUtils;
  17. /**
  18. * 系统主页控制器
  19. * @author laravel开发员
  20. * @since 2020/11/10
  21. * Class IndexController
  22. * @package App\Http\Controllers
  23. */
  24. class IndexController extends Backend
  25. {
  26. /**
  27. * 构造函数
  28. * @author laravel开发员
  29. * @since 2020/11/10
  30. * IndexController constructor.
  31. */
  32. public function __construct()
  33. {
  34. parent::__construct();
  35. }
  36. /**
  37. * 后台主页
  38. * @author laravel开发员
  39. * @since 2020/11/10
  40. */
  41. public function getMenuList()
  42. {
  43. $menuService = new MenuService();
  44. $menuList = $menuService->getPermissionList($this->userId);
  45. return $menuList;
  46. }
  47. /**
  48. * 获取个人信息
  49. * @return array
  50. * @since 2020/11/10
  51. * @author laravel开发员
  52. */
  53. public function getUserInfo()
  54. {
  55. $userService = new UserService();
  56. $result = $userService->getUserInfo($this->userId);
  57. return $result;
  58. }
  59. /**
  60. * 更新个人资料
  61. * @return mixed
  62. * @since 2020/11/11
  63. * @author laravel开发员
  64. */
  65. public function updateUserInfo()
  66. {
  67. $userService = new UserService();
  68. $result = $userService->updateUserInfo($this->userId);
  69. return $result;
  70. }
  71. /**
  72. * 更新密码
  73. * @return mixed
  74. * @since 2020/11/11
  75. * @author laravel开发员
  76. */
  77. public function updatePwd()
  78. {
  79. $userService = new UserService();
  80. $result = $userService->updatePwd($this->userId);
  81. return $result;
  82. }
  83. /**
  84. * 清除缓存
  85. * @return array
  86. */
  87. public function clearCache()
  88. {
  89. RedisService::keyDel("caches:adm*");
  90. RedisService::keyDel("caches:index*");
  91. RedisService::keyDel("caches:activity*");
  92. RedisService::keyDel("caches:advert*");
  93. RedisService::keyDel("caches:count*");
  94. RedisService::keyDel("caches:articles*");
  95. RedisService::keyDel("caches:member*");
  96. RedisService::keyDel("caches:config*");
  97. RedisService::keyDel(env('APP_NAME') . "_cache:*");
  98. return message(MESSAGE_OK, true);
  99. }
  100. /**
  101. * 获取首页数据
  102. * @return array
  103. */
  104. public function statistics()
  105. {
  106. // 获取当前用户的商户ID,如果为0则显示全部数据(管理员),否则只显示该商户的数据
  107. $storeId = $this->storeId;
  108. $datas = [
  109. // 会员(会员数据没有store_id区分,商户用户返回0,只有平台管理员可见)
  110. 'users' => [
  111. 'count' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(), // 总会员数
  112. 'count_by_day' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册
  113. 'count_by_month' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月注册
  114. 'count_by_active' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(0, 0, 1), // 正常会员
  115. ],
  116. // 活动
  117. 'activity' => [
  118. 'count' => \App\Models\ActivityModel::where('mark', 1)
  119. ->count(), // 总量
  120. ]
  121. ];
  122. return message(1010, true, $datas);
  123. }
  124. }