IndexController.php 5.7 KB

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