IndexController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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:good*");
  92. RedisService::keyDel("caches:advert*");
  93. RedisService::keyDel("caches:count*");
  94. RedisService::keyDel("caches:account*");
  95. RedisService::keyDel("caches:article*");
  96. RedisService::keyDel("caches:member*");
  97. RedisService::keyDel("caches:config*");
  98. RedisService::keyDel("caches:deposit*");
  99. RedisService::keyDel("caches:order*");
  100. RedisService::keyDel(env('APP_NAME') . "_cache:*");
  101. //Cache::flush();
  102. return message(MESSAGE_OK, true);
  103. }
  104. /**
  105. * 获取首页数据
  106. * @return array
  107. */
  108. public function statistics()
  109. {
  110. // 获取当前用户的商户ID,如果为0则显示全部数据(管理员),否则只显示该商户的数据
  111. $storeId = $this->storeId;
  112. $datas = [
  113. // 会员(会员数据没有store_id区分,商户用户返回0,只有平台管理员可见)
  114. 'users' => [
  115. 'count' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(), // 总会员数
  116. 'count_by_day' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册
  117. 'count_by_month' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月注册
  118. 'count_by_active' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(0, 0, 1), // 正常会员
  119. ],
  120. // 订单
  121. 'orders' => [
  122. 'count' => \App\Models\OrderModel::where('mark', 1)
  123. ->when($storeId > 0, function ($query) use ($storeId) {
  124. return $query->where('store_id', $storeId);
  125. })
  126. ->count(), // 总量
  127. 'count_by_day' => \App\Models\OrderModel::where('mark', 1)
  128. ->when($storeId > 0, function ($query) use ($storeId) {
  129. return $query->where('store_id', $storeId);
  130. })
  131. ->whereBetween('create_time', [strtotime(TimeUtils::beginToday()), strtotime(TimeUtils::endToday())])
  132. ->count(), // 今日
  133. 'count_by_month' => \App\Models\OrderModel::where('mark', 1)
  134. ->when($storeId > 0, function ($query) use ($storeId) {
  135. return $query->where('store_id', $storeId);
  136. })
  137. ->whereBetween('create_time', [strtotime(TimeUtils::beginMonth()), strtotime(TimeUtils::endMonth())])
  138. ->count(), // 本月
  139. 'amount_by_day' => \App\Models\OrderModel::where('mark', 1)
  140. ->when($storeId > 0, function ($query) use ($storeId) {
  141. return $query->where('store_id', $storeId);
  142. })
  143. ->whereBetween('create_time', [strtotime(TimeUtils::beginToday()), strtotime(TimeUtils::endToday())])
  144. ->sum('pay_total'), // 日营业额(实付金额)
  145. 'amount_by_month' => \App\Models\OrderModel::where('mark', 1)
  146. ->when($storeId > 0, function ($query) use ($storeId) {
  147. return $query->where('store_id', $storeId);
  148. })
  149. ->whereBetween('create_time', [strtotime(TimeUtils::beginMonth()), strtotime(TimeUtils::endMonth())])
  150. ->sum('pay_total'), // 月营业额(实付金额)
  151. ],
  152. // 营收
  153. 'balance' => [
  154. 'income_by_total' => \App\Models\OrderModel::where('mark', 1)
  155. ->when($storeId > 0, function ($query) use ($storeId) {
  156. return $query->where('store_id', $storeId);
  157. })
  158. ->sum('pay_total'), // 累计实付金额
  159. // 提现金额(balance_logs表没有store_id字段,商户用户返回0)
  160. 'withdraw_by_total' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
  161. ->where('type', 2)
  162. ->where('status', 2)
  163. ->sum('actual_money'), // 累计提现金额
  164. ],
  165. // 商家统计(商户用户不显示商家统计,返回0)
  166. 'stores' => [
  167. 'count' => $storeId > 0 ? 0 : \App\Models\StoreModel::where('mark', 1)->count(), // 总商家数
  168. 'count_by_pending' => $storeId > 0 ? 0 : \App\Models\StoreModel::where('mark', 1)->where('status', 2)->count(), // 待审核
  169. 'count_by_active' => $storeId > 0 ? 0 : \App\Models\StoreModel::where('mark', 1)->where('status', 1)->count(), // 营业中
  170. ],
  171. // 代理统计(agents表没有store_id字段,商户用户返回0)
  172. 'agents' => [
  173. 'count' => $storeId > 0 ? 0 : \App\Models\AgentModel::where('mark', 1)->count(), // 总代理数
  174. 'count_by_pending' => $storeId > 0 ? 0 : \App\Models\AgentModel::where('mark', 1)->where('status', 2)->count(), // 待审核
  175. 'count_by_active' => $storeId > 0 ? 0 : \App\Models\AgentModel::where('mark', 1)->where('status', 1)->count(), // 已审核
  176. ],
  177. // 提现申请统计(balance_logs表没有store_id字段,商户用户返回0)
  178. 'withdrawals' => [
  179. 'count_by_pending' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
  180. ->where('type', 2)
  181. ->where('status', 1)
  182. ->count(), // 待审核提现
  183. 'amount_by_pending' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
  184. ->where('type', 2)
  185. ->where('status', 1)
  186. ->sum('money'), // 待审核金额
  187. 'count_by_today' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
  188. ->where('type', 2)
  189. ->whereBetween('create_time', [strtotime(TimeUtils::beginToday()), strtotime(TimeUtils::endToday())])
  190. ->count(), // 今日提现申请
  191. ],
  192. ];
  193. return message(1010, true, $datas);
  194. }
  195. }