IndexController.php 8.8 KB

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