more optimization && add plan user count

This commit is contained in:
Tokumeikoi 2020-06-24 13:47:25 +08:00
parent ffd13fbc64
commit b5a9b3e68c
4 changed files with 19 additions and 4 deletions

View File

@ -16,8 +16,23 @@ class PlanController extends Controller
{
public function fetch(Request $request)
{
$counts = User::select(
DB::raw("plan_id"),
DB::raw("count(*) as count")
)
->where('plan_id', '!=', NULL)
->groupBy("plan_id")
->get();
$plans = Plan::orderBy('sort', 'ASC')->get();
foreach ($plans as $k => $v) {
$plans[$k]->count = 0;
foreach ($counts as $kk => $vv) {
if ($plans[$k]->id === $counts[$kk]->plan_id) $plans[$k]->count = $counts[$kk]->count;
}
}
return response([
'data' => Plan::orderBy('sort', 'ASC')->get()
'data' => $plans
]);
}

View File

@ -87,7 +87,7 @@ class TelegramController extends Controller
$commands = [
'/bind 订阅地址 - 绑定你的' . config('v2board.app_name', 'V2Board') . '账号',
'/traffic - 查询流量信息',
'/getLatestUrl - 获取最新的' . config('v2board.app_name', 'V2Board') . '网址'
'/getlatesturl - 获取最新的' . config('v2board.app_name', 'V2Board') . '网址'
];
$text = implode(PHP_EOL, $commands);
$telegramService->sendMessage($msg->chat_id, "你可以使用以下命令进行操作:\n\n$text", 'markdown');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long