| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Http\Controllers\Admin;
- use App\Services\Common\MemberService;
- use App\Services\Common\MenuService;
- use App\Services\Common\UserService;
- use App\Services\RedisService;
- use App\utils\TimeUtils;
- /**
- * 系统主页控制器
- * @author laravel开发员
- * @since 2020/11/10
- * Class IndexController
- * @package App\Http\Controllers
- */
- class IndexController extends Backend
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/10
- * IndexController constructor.
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 后台主页
- * @author laravel开发员
- * @since 2020/11/10
- */
- public function getMenuList()
- {
- $menuService = new MenuService();
- $menuList = $menuService->getPermissionList($this->userId);
- return $menuList;
- }
- /**
- * 获取个人信息
- * @return array
- * @since 2020/11/10
- * @author laravel开发员
- */
- public function getUserInfo()
- {
- $userService = new UserService();
- $result = $userService->getUserInfo($this->userId);
- return $result;
- }
- /**
- * 更新个人资料
- * @return mixed
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function updateUserInfo()
- {
- $userService = new UserService();
- $result = $userService->updateUserInfo($this->userId);
- return $result;
- }
- /**
- * 更新密码
- * @return mixed
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function updatePwd()
- {
- $userService = new UserService();
- $result = $userService->updatePwd($this->userId);
- return $result;
- }
- /**
- * 清除缓存
- * @return array
- */
- public function clearCache()
- {
- RedisService::keyDel("caches:adm*");
- RedisService::keyDel("caches:index*");
- RedisService::keyDel("caches:good*");
- RedisService::keyDel("caches:advert*");
- RedisService::keyDel("caches:accounts*");
- RedisService::keyDel("caches:count*");
- RedisService::keyDel("caches:account*");
- RedisService::keyDel("caches:articles*");
- RedisService::keyDel("caches:member*");
- RedisService::keyDel("caches:config*");
- RedisService::keyDel("caches:stores*");
- RedisService::keyDel("caches:order*");
- RedisService::keyDel(env('APP_NAME') . "_cache:*");
- //Cache::flush();
- return message(MESSAGE_OK, true);
- }
- /**
- * 获取首页数据
- * @return array
- */
- public function statistics()
- {
- // 获取当前用户的商户ID,如果为0则显示全部数据(管理员),否则只显示该商户的数据
- $storeId = $this->storeId;
- $datas = [
- // 会员(会员数据没有store_id区分,商户用户返回0,只有平台管理员可见)
- 'users' => [
- 'count' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(), // 总会员数
- 'count_by_day' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(TimeUtils::beginToday(), TimeUtils::endToday()), // 今日注册
- 'count_by_month' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(TimeUtils::beginMonth(), TimeUtils::endMonth()), // 本月注册
- 'count_by_active' => $storeId > 0 ? 0 : MemberService::make()->getRegisterCount(0, 0, 1), // 正常会员
- ],
- // 订单
- 'orders' => [
- 'count' => \App\Models\OrderModel::where('mark', 1)
- ->when($storeId > 0, function ($query) use ($storeId) {
- return $query->where('store_id', $storeId);
- })
- ->count(), // 总量
- 'count_by_day' => \App\Models\OrderModel::where('mark', 1)
- ->when($storeId > 0, function ($query) use ($storeId) {
- return $query->where('store_id', $storeId);
- })
- ->whereBetween('create_time', [strtotime(TimeUtils::beginToday()), strtotime(TimeUtils::endToday())])
- ->count(), // 今日
- 'count_by_month' => \App\Models\OrderModel::where('mark', 1)
- ->when($storeId > 0, function ($query) use ($storeId) {
- return $query->where('store_id', $storeId);
- })
- ->whereBetween('create_time', [strtotime(TimeUtils::beginMonth()), strtotime(TimeUtils::endMonth())])
- ->count(), // 本月
- 'amount_by_day' => \App\Models\OrderModel::where('mark', 1)
- ->when($storeId > 0, function ($query) use ($storeId) {
- return $query->where('store_id', $storeId);
- })
- ->whereBetween('create_time', [strtotime(TimeUtils::beginToday()), strtotime(TimeUtils::endToday())])
- ->sum('pay_total'), // 日营业额(实付金额)
- 'amount_by_month' => \App\Models\OrderModel::where('mark', 1)
- ->when($storeId > 0, function ($query) use ($storeId) {
- return $query->where('store_id', $storeId);
- })
- ->whereBetween('create_time', [strtotime(TimeUtils::beginMonth()), strtotime(TimeUtils::endMonth())])
- ->sum('pay_total'), // 月营业额(实付金额)
- ],
- // 营收
- 'balance' => [
- 'income_by_total' => \App\Models\OrderModel::where('mark', 1)
- ->when($storeId > 0, function ($query) use ($storeId) {
- return $query->where('store_id', $storeId);
- })
- ->sum('pay_total'), // 累计实付金额
- // 提现金额(balance_logs表没有store_id字段,商户用户返回0)
- 'withdraw_by_total' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
- ->where('type', 2)
- ->where('status', 2)
- ->sum('actual_money'), // 累计提现金额
- ],
- // 商家统计(商户用户不显示商家统计,返回0)
- 'stores' => [
- 'count' => $storeId > 0 ? 0 : \App\Models\StoreModel::where('mark', 1)->count(), // 总商家数
- 'count_by_pending' => $storeId > 0 ? 0 : \App\Models\StoreModel::where('mark', 1)->where('status', 2)->count(), // 待审核
- 'count_by_active' => $storeId > 0 ? 0 : \App\Models\StoreModel::where('mark', 1)->where('status', 1)->count(), // 营业中
- ],
- // 代理统计(agents表没有store_id字段,商户用户返回0)
- 'agents' => [
- 'count' => $storeId > 0 ? 0 : \App\Models\AgentModel::where('mark', 1)->count(), // 总代理数
- 'count_by_pending' => $storeId > 0 ? 0 : \App\Models\AgentModel::where('mark', 1)->where('status', 2)->count(), // 待审核
- 'count_by_active' => $storeId > 0 ? 0 : \App\Models\AgentModel::where('mark', 1)->where('status', 1)->count(), // 已审核
- ],
- // 提现申请统计(balance_logs表没有store_id字段,商户用户返回0)
- 'withdrawals' => [
- 'count_by_pending' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
- ->where('type', 2)
- ->where('status', 1)
- ->count(), // 待审核提现
- 'amount_by_pending' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
- ->where('type', 2)
- ->where('status', 1)
- ->sum('money'), // 待审核金额
- 'count_by_today' => $storeId > 0 ? 0 : \App\Models\BalanceLogModel::where('mark', 1)
- ->where('type', 2)
- ->whereBetween('create_time', [strtotime(TimeUtils::beginToday()), strtotime(TimeUtils::endToday())])
- ->count(), // 今日提现申请
- ],
- ];
- return message(1010, true, $datas);
- }
- }
|