v2board/app/Http/Controllers/Admin/StatController.php

128 lines
4.5 KiB
PHP
Raw Normal View History

2019-12-18 18:08:52 +08:00
<?php
namespace App\Http\Controllers\Admin;
2020-12-24 23:41:32 +08:00
use App\Models\ServerShadowsocks;
use App\Models\ServerTrojan;
use App\Services\ServerService;
2019-12-18 18:08:52 +08:00
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\ServerGroup;
2021-09-21 18:07:53 +08:00
use App\Models\ServerV2ray;
2019-12-18 18:08:52 +08:00
use App\Models\Plan;
use App\Models\User;
use App\Models\Ticket;
use App\Models\Order;
2020-12-24 23:41:32 +08:00
use App\Models\StatOrder;
use App\Models\StatServer;
2020-01-12 01:27:36 +08:00
use Illuminate\Support\Facades\Cache;
2020-12-24 23:41:32 +08:00
use Illuminate\Support\Facades\DB;
2019-12-18 18:08:52 +08:00
2019-12-23 18:46:37 +08:00
class StatController extends Controller
2019-12-18 18:08:52 +08:00
{
2020-01-11 13:36:52 +08:00
public function getOverride(Request $request)
{
2019-12-18 18:08:52 +08:00
return response([
'data' => [
2020-01-20 13:57:30 +08:00
'month_income' => Order::where('created_at', '>=', strtotime(date('Y-m-1')))
->where('created_at', '<', time())
2021-03-13 00:03:53 +08:00
->whereNotIn('status', [0, 2])
2020-01-20 13:57:30 +08:00
->sum('total_amount'),
'month_register_total' => User::where('created_at', '>=', strtotime(date('Y-m-1')))
->where('created_at', '<', time())
->count(),
2022-02-07 14:54:13 +08:00
'ticket_pending_total' => Ticket::where('status', 0)
2019-12-18 18:08:52 +08:00
->count(),
2022-02-07 14:54:13 +08:00
'commission_pending_total' => Order::where('commission_status', 0)
2019-12-18 18:14:26 +08:00
->where('invite_user_id', '!=', NULL)
2021-03-13 00:03:53 +08:00
->whereNotIn('status', [0, 2])
2020-05-26 15:46:44 +08:00
->where('commission_balance', '>', 0)
2019-12-18 18:08:52 +08:00
->count(),
2020-05-10 23:09:22 +08:00
'day_income' => Order::where('created_at', '>=', strtotime(date('Y-m-d')))
->where('created_at', '<', time())
2021-03-13 00:03:53 +08:00
->whereNotIn('status', [0, 2])
2020-05-10 23:09:22 +08:00
->sum('total_amount'),
'last_month_income' => Order::where('created_at', '>=', strtotime('-1 month', strtotime(date('Y-m-1'))))
->where('created_at', '<', strtotime(date('Y-m-1')))
2021-03-13 00:03:53 +08:00
->whereNotIn('status', [0, 2])
2020-05-10 23:09:22 +08:00
->sum('total_amount')
2019-12-18 18:08:52 +08:00
]
]);
}
2020-12-24 23:41:32 +08:00
public function getOrder(Request $request)
{
$statistics = StatOrder::where('record_type', 'd')
->limit(31)
2021-01-26 18:33:11 +08:00
->orderBy('record_at', 'DESC')
2020-12-24 23:41:32 +08:00
->get()
->toArray();
$result = [];
foreach ($statistics as $statistic) {
$date = date('m-d', $statistic['record_at']);
array_push($result, [
'type' => '收款金额',
'date' => $date,
'value' => $statistic['order_amount'] / 100
]);
array_push($result, [
'type' => '收款笔数',
'date' => $date,
'value' => $statistic['order_count']
]);
array_push($result, [
2022-03-11 01:12:49 +08:00
'type' => '佣金金额(已发放)',
2020-12-24 23:41:32 +08:00
'date' => $date,
'value' => $statistic['commission_amount'] / 100
]);
array_push($result, [
2022-03-11 01:12:49 +08:00
'type' => '佣金笔数(已发放)',
2020-12-24 23:41:32 +08:00
'date' => $date,
'value' => $statistic['commission_count']
]);
}
2021-02-01 18:04:03 +08:00
$result = array_reverse($result);
2020-12-24 23:41:32 +08:00
return response([
'data' => $result
]);
}
public function getServerLastRank()
{
$servers = [
'shadowsocks' => ServerShadowsocks::where('parent_id', null)->get()->toArray(),
2021-09-21 18:07:53 +08:00
'vmess' => ServerV2ray::where('parent_id', null)->get()->toArray(),
2020-12-24 23:41:32 +08:00
'trojan' => ServerTrojan::where('parent_id', null)->get()->toArray()
];
2022-03-10 11:04:09 +08:00
$startAt = strtotime('-1 day', strtotime(date('Y-m-d')));
$endAt = strtotime(date('Y-m-d'));
2021-09-21 18:11:14 +08:00
$statistics = StatServer::select([
2020-12-24 23:41:32 +08:00
'server_id',
'server_type',
'u',
2021-02-26 22:54:38 +08:00
'd',
DB::raw('(u+d) as total')
2020-12-24 23:41:32 +08:00
])
2022-03-10 11:04:09 +08:00
->where('record_at', '>=', $startAt)
->where('record_at', '<', $endAt)
2020-12-24 23:41:32 +08:00
->where('record_type', 'd')
->limit(10)
2021-02-26 22:54:38 +08:00
->orderBy('total', 'DESC')
2020-12-24 23:41:32 +08:00
->get()
->toArray();
foreach ($statistics as $k => $v) {
foreach ($servers[$v['server_type']] as $server) {
if ($server['id'] === $v['server_id']) {
$statistics[$k]['server_name'] = $server['name'];
}
}
2021-02-26 22:54:38 +08:00
$statistics[$k]['total'] = $statistics[$k]['total'] / 1073741824;
2020-12-24 23:41:32 +08:00
}
array_multisort(array_column($statistics, 'total'), SORT_DESC, $statistics);
return response([
'data' => $statistics
]);
}
2019-12-18 18:08:52 +08:00
}
2021-02-01 18:04:03 +08:00