IndexController.php 8.7 KB

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