IndexController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Http\Controllers;
  12. use App\Models\EnshrineOrdersModel;
  13. use App\Models\GongdengOrderModel;
  14. use App\Models\MemberModel;
  15. use App\Models\OrdersModel;
  16. use App\Models\UserModel;
  17. use App\Models\AdminRomModel;
  18. use App\Services\AdminService;
  19. use App\Services\MenuService;
  20. use App\Services\RedisService;
  21. use App\Services\UserService;
  22. /**
  23. * 系统主页控制器
  24. * @author wesmiler
  25. * @since 2020/11/10
  26. * Class IndexController
  27. * @package App\Http\Controllers
  28. */
  29. class IndexController extends Backend
  30. {
  31. /**
  32. * 构造函数
  33. * @author wesmiler
  34. * @since 2020/11/10
  35. * IndexController constructor.
  36. */
  37. public function __construct()
  38. {
  39. parent::__construct();
  40. }
  41. /**
  42. * 后台主页
  43. * @author wesmiler
  44. * @since 2020/11/10
  45. */
  46. public function getMenuList()
  47. {
  48. $menuService = new MenuService();
  49. $menuList = $menuService->getPermissionList($this->userId);
  50. return $menuList;
  51. }
  52. /**
  53. * 获取个人信息
  54. * @return array
  55. * @since 2020/11/10
  56. * @author wesmiler
  57. */
  58. public function getUserInfo()
  59. {
  60. $userService = new UserService();
  61. $result = $userService->getUserInfo($this->userId);
  62. return $result;
  63. }
  64. /**
  65. * 更新个人资料
  66. * @return mixed
  67. * @since 2020/11/11
  68. * @author wesmiler
  69. */
  70. public function updateUserInfo()
  71. {
  72. $userService = new UserService();
  73. $result = $userService->updateUserInfo($this->userId);
  74. return $result;
  75. }
  76. /**
  77. * 更新密码
  78. * @return mixed
  79. * @since 2020/11/11
  80. * @author wesmiler
  81. */
  82. public function updatePwd()
  83. {
  84. $userService = new UserService();
  85. $result = $userService->updatePwd($this->userId);
  86. return $result;
  87. }
  88. /**
  89. * 工作台统计数据
  90. * @return array
  91. */
  92. public function counts(){
  93. $data = [
  94. 'gdCount'=> GongdengOrderModel::where(['mark'=> 1,'status'=> 2])
  95. ->count('id'),
  96. 'shopCount'=> OrdersModel::where(['mark'=> 1])
  97. ->whereIn('status',[2,3,4])
  98. ->count('id'),
  99. 'memberCount'=> MemberModel::where(['mark'=> 1,'status'=> 1])
  100. ->where('create_time','>', strtotime(date('Y-m-d')))
  101. ->count('id')
  102. ];
  103. return message(MESSAGE_OK,true, $data);
  104. }
  105. /**
  106. * 数据分析统计
  107. * @return array
  108. */
  109. public function statistics(){
  110. $cacheKey = "caches:statistics:counts";
  111. $datas = RedisService::get($cacheKey);
  112. $datas = $datas? json_decode($datas, true) : [];
  113. if($datas){
  114. return message(MESSAGE_OK, true, $datas);
  115. }
  116. $datas = [
  117. 'gdCount'=> GongdengOrderModel::where(['mark'=> 1,'status'=> 2])
  118. ->count('id'),
  119. 'gdDayCount'=> GongdengOrderModel::where(['mark'=> 1,'status'=> 2])
  120. ->where('pay_at','>=', date('Y-m-d'))
  121. ->count('id'),
  122. 'shopCount'=> OrdersModel::where(['mark'=> 1])
  123. ->whereIn('status',[2,3,4])
  124. ->count('id'),
  125. 'shopDayCount'=> OrdersModel::where(['mark'=> 1])
  126. ->whereIn('status',[2,3,4])
  127. ->where('pay_at','>=', date('Y-m-d'))
  128. ->count('id'),
  129. 'memberCount'=> MemberModel::where(['mark'=> 1,'status'=> 1])
  130. ->count('id'),
  131. 'memberDayCount'=> MemberModel::where(['mark'=> 1,'status'=> 1])
  132. ->where('create_time','>=', strtotime(date('Y-m-d')))
  133. ->count('id'),
  134. 'enshrineCount'=> EnshrineOrdersModel::where(['mark'=> 1,'status'=> 2])
  135. ->sum('total'),
  136. 'enshrineDayCount'=> EnshrineOrdersModel::where(['mark'=> 1,'status'=> 2])
  137. ->where('pay_at','>=', date('Y-m-d'))
  138. ->sum('total'),
  139. ];
  140. RedisService::set($cacheKey, json_encode($datas, 256), rand(5, 10));
  141. return message(MESSAGE_OK,true, $datas);
  142. }
  143. public function statisticsTable(){
  144. $type = request()->get('type', 'trade');
  145. $dateType = request()->get('dateType', 0);
  146. $datas = [];
  147. switch($type){
  148. case 'trade': // 消费
  149. break;
  150. case 'gd': // 供灯交易量
  151. break;
  152. case 'member': // 用户注册
  153. break;
  154. case 'shop': // 商城交易量
  155. break;
  156. case 'enshrine': // 供奉订单交易额
  157. break;
  158. }
  159. return message(MESSAGE_OK,true, $datas);
  160. }
  161. /**
  162. * 清除缓存
  163. * @return array
  164. */
  165. public function clearCache(){
  166. RedisService::keyDel("caches:config:*");
  167. RedisService::keyDel("caches:index:*");
  168. RedisService::keyDel("caches:articles:*");
  169. RedisService::keyDel("caches:qrcodes:*");
  170. RedisService::keyDel("caches:statistics:*");
  171. return message(MESSAGE_OK, true);
  172. }
  173. }