IndexController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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\Models\UserModel;
  13. use App\Models\AdminRomModel;
  14. use App\Services\Common\AccountService;
  15. use App\Services\Common\AdminService;
  16. use App\Services\Common\AgentService;
  17. use App\Services\Common\BalanceLogService;
  18. use App\Services\Common\DriverService;
  19. use App\Services\Common\FinanceService;
  20. use App\Services\Common\MemberService;
  21. use App\Services\Common\MenuService;
  22. use App\Services\Common\OrderService;
  23. use App\Services\Common\UserService;
  24. use App\Services\RedisService;
  25. use App\utils\TimeUtils;
  26. /**
  27. * 系统主页控制器
  28. * @author laravel开发员
  29. * @since 2020/11/10
  30. * Class IndexController
  31. * @package App\Http\Controllers
  32. */
  33. class IndexController extends Backend
  34. {
  35. /**
  36. * 构造函数
  37. * @author laravel开发员
  38. * @since 2020/11/10
  39. * IndexController constructor.
  40. */
  41. public function __construct()
  42. {
  43. parent::__construct();
  44. }
  45. /**
  46. * 后台主页
  47. * @author laravel开发员
  48. * @since 2020/11/10
  49. */
  50. public function getMenuList()
  51. {
  52. $menuService = new MenuService();
  53. $menuList = $menuService->getPermissionList($this->userId);
  54. return $menuList;
  55. }
  56. /**
  57. * 获取个人信息
  58. * @return array
  59. * @since 2020/11/10
  60. * @author laravel开发员
  61. */
  62. public function getUserInfo()
  63. {
  64. $userService = new UserService();
  65. $result = $userService->getUserInfo($this->userId);
  66. return $result;
  67. }
  68. /**
  69. * 更新个人资料
  70. * @return mixed
  71. * @since 2020/11/11
  72. * @author laravel开发员
  73. */
  74. public function updateUserInfo()
  75. {
  76. $userService = new UserService();
  77. $result = $userService->updateUserInfo($this->userId);
  78. return $result;
  79. }
  80. /**
  81. * 更新密码
  82. * @return mixed
  83. * @since 2020/11/11
  84. * @author laravel开发员
  85. */
  86. public function updatePwd()
  87. {
  88. $userService = new UserService();
  89. $result = $userService->updatePwd($this->userId);
  90. return $result;
  91. }
  92. /**
  93. * 清除缓存
  94. * @return array
  95. */
  96. public function clearCache()
  97. {
  98. RedisService::keyDel("caches:d*");
  99. RedisService::keyDel("caches:adm*");
  100. RedisService::keyDel("caches:inde*");
  101. RedisService::keyDel("caches:goods*");
  102. RedisService::keyDel("caches:advert*");
  103. RedisService::keyDel("caches:counts*");
  104. RedisService::keyDel("caches:articl*");
  105. RedisService::keyDel("caches:qrcode*");
  106. RedisService::keyDel("caches:memb*");
  107. RedisService::keyDel("caches:conf*");
  108. RedisService::keyDel("caches:order*");
  109. RedisService::keyDel("caches:message*");
  110. RedisService::keyDel("laravel_cache:model*");
  111. return message(MESSAGE_OK, true);
  112. }
  113. /**
  114. * 获取首页数据
  115. * @return array
  116. */
  117. public function statistics()
  118. {
  119. $cacheKey = "caches:admin:indexData:" . $this->userId;
  120. $datas = RedisService::get($cacheKey);
  121. if ($datas) {
  122. return message(1010, true, $datas);
  123. }
  124. $datas = [
  125. // 用户
  126. 'users' => [
  127. 'count' => MemberService::make()->getRegisterCount(), // 总用户数
  128. 'count_by_day' => MemberService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册
  129. 'count_by_month' => MemberService::make()->getRegisterCount(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月注册
  130. 'count_by_year' => MemberService::make()->getRegisterCount(TimeUtils::beginYear(), TimeUtils::endYear()), // 今年
  131. ],
  132. // 司机
  133. 'driver' => [
  134. 'count' => DriverService::make()->getRegisterCount(), // 总数
  135. 'count_by_day' => DriverService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册
  136. ],
  137. // 代理
  138. 'agent' => [
  139. 'count' => AgentService::make()->getRegisterCount(), // 总数
  140. 'count_by_day' => AgentService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册
  141. ],
  142. // 商城订单
  143. 'orders' => [
  144. 'count' => OrderService::make()->getCountByTime(), // 总量
  145. 'count_by_day' => OrderService::make()->getCountByTime(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日
  146. 'count_by_month' => OrderService::make()->getCountByTime(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月
  147. 'count_by_year' => OrderService::make()->getCountByTime(TimeUtils::beginYear(), TimeUtils::endYear()), // 今年
  148. ],
  149. // 营收
  150. 'finance' => [
  151. 'total' => AccountService::make()->getTotalByTime(), // 总量
  152. 'income' => FinanceService::make()->getTotalByTime(), // 总收入
  153. 'income_by_day' => FinanceService::make()->getTotalByTime(TimeUtils::beginToday(), TimeUtils::endToday(),), // 今日
  154. 'income_by_month' => FinanceService::make()->getTotalByTime(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月
  155. 'income_by_year' => FinanceService::make()->getTotalByTime(TimeUtils::beginYear(), TimeUtils::endYear()), // 今年
  156. ],
  157. ];
  158. // 提现统计
  159. $withdrawUser = BalanceLogService::make()->getCountByType();
  160. $withdrawDriver = BalanceLogService::make()->getCountByType(2);
  161. $datas['withdraw'] = [
  162. 'total_user' => BalanceLogService::make()->getTotalByStatus(1), // 总量
  163. 'total_user_wait' => BalanceLogService::make()->getTotalByStatus(1,1), // 待审核
  164. 'total_driver' => BalanceLogService::make()->getTotalByStatus(2), // 总量
  165. 'total_driver_wait' => BalanceLogService::make()->getTotalByStatus(2,1), // 待审核
  166. 'count_user' => $withdrawUser, // 已提现
  167. 'count_user_no' => max(0, $datas['users']['count'] - $withdrawUser), // 未提现
  168. 'count_driver' => $withdrawDriver, // 已提现
  169. 'count_driver_no' => max(0, $datas['driver']['count'] - $withdrawDriver), // 未提现
  170. ];
  171. RedisService::set($cacheKey, $datas, rand(5, 10));
  172. return message(1010, true, $datas);
  173. }
  174. }