v2board/app/Http/Controllers/User/PlanController.php

35 lines
964 B
PHP
Raw Normal View History

2019-10-29 15:33:36 +08:00
<?php
2020-01-29 16:08:50 +08:00
namespace App\Http\Controllers\User;
2019-10-29 15:33:36 +08:00
use App\Http\Controllers\Controller;
2022-04-19 04:10:02 +08:00
use App\Models\User;
2020-01-29 16:08:50 +08:00
use Illuminate\Http\Request;
2019-10-29 15:33:36 +08:00
use App\Models\Plan;
class PlanController extends Controller
{
2020-01-11 13:36:52 +08:00
public function fetch(Request $request)
{
2022-04-19 04:10:02 +08:00
$user = User::find($request->session()->get('id'));
2020-01-03 21:04:44 +08:00
if ($request->input('id')) {
2022-04-19 04:10:02 +08:00
$plan = Plan::where('id', $request->input('id'))->first();
2020-01-03 21:04:44 +08:00
if (!$plan) {
2021-06-12 00:56:39 +08:00
abort(500, __('Subscription plan does not exist'));
2020-01-03 21:04:44 +08:00
}
2022-04-19 04:10:02 +08:00
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
abort(500, __('Subscription plan does not exist'));
}
2020-01-03 21:04:44 +08:00
return response([
'data' => $plan
]);
2019-10-29 15:33:36 +08:00
}
2020-01-03 21:04:44 +08:00
$plan = Plan::where('show', 1)
2020-04-21 00:22:05 +08:00
->orderBy('sort', 'ASC')
2020-01-03 21:04:44 +08:00
->get();
2019-10-29 15:33:36 +08:00
return response([
'data' => $plan
]);
}
}