Compare commits
8 Commits
34c80e87ac
...
clean-main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e26bd229b | |||
| e695a80e36 | |||
| ece9e6e017 | |||
| c3d798689c | |||
| 2796ce7de7 | |||
| c05587474f | |||
| 8fda92ead5 | |||
| ae522c5640 |
@@ -46,7 +46,6 @@ class LawController extends Controller
|
||||
$validated['is_locked'] = $request->has('is_locked', false);
|
||||
|
||||
if ($request->hasFile('image') && $request->file('image')->isValid()) {
|
||||
dd($request->has('image'));
|
||||
$imageName = uniqid('image_', true) . '.' . $request->file('image')->getClientOriginalExtension();
|
||||
|
||||
$request->file('image')->move(public_path('images'), $imageName);
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\LegalOpinionCategory;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LegalOpinionCategoryController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = LegalOpinionCategory::query();
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$q = $request->q;
|
||||
$query->where('name', 'like', "%{$q}%");
|
||||
}
|
||||
|
||||
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
|
||||
$categories = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
return view('admin.legal-opinion-category.index', compact('categories'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.legal-opinion-category.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|unique:legal_opinion_categories,name',
|
||||
]);
|
||||
|
||||
LegalOpinionCategory::create($validated);
|
||||
|
||||
return redirect(route('legal-opinion-category.index'));
|
||||
}
|
||||
|
||||
public function edit(LegalOpinionCategory $legalOpinionCategory)
|
||||
{
|
||||
return view('admin.legal-opinion-category.update', compact('legalOpinionCategory'));
|
||||
}
|
||||
|
||||
public function show(LegalOpinionCategory $legalOpinionCategory)
|
||||
{
|
||||
return redirect(route('legal-opinion-category.edit', $legalOpinionCategory->id));
|
||||
}
|
||||
|
||||
public function update(Request $request, LegalOpinionCategory $legalOpinionCategory)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|unique:legal_opinion_categories,name,' . $legalOpinionCategory->id,
|
||||
]);
|
||||
|
||||
$legalOpinionCategory->update($validated);
|
||||
|
||||
return redirect(route('legal-opinion-category.edit', $legalOpinionCategory->id));
|
||||
}
|
||||
|
||||
public function destroy(LegalOpinionCategory $legalOpinionCategory)
|
||||
{
|
||||
$legalOpinionCategory->delete();
|
||||
|
||||
return redirect(route('legal-opinion-category.index'));
|
||||
}
|
||||
}
|
||||
126
app/Http/Controllers/Admin/LegalOpinionController.php
Normal file
126
app/Http/Controllers/Admin/LegalOpinionController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Art;
|
||||
use App\Models\LegalOpinion;
|
||||
use App\Models\LegalOpinionCategory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class LegalOpinionController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = LegalOpinion::with('category');
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$q = $request->q;
|
||||
$query->where(function ($qry) use ($q) {
|
||||
$qry->where('opinion_number', 'like', "%{$q}%")
|
||||
->orWhere('subject', 'like', "%{$q}%")
|
||||
->orWhere('full_text', 'like', "%{$q}%")
|
||||
->orWhere('issuing_authority', 'like', "%{$q}%");
|
||||
});
|
||||
}
|
||||
|
||||
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
|
||||
$legalOpinions = $query->latest()->paginate($perPage)->withQueryString();
|
||||
|
||||
return view('admin.legal-opinion.index', compact('legalOpinions'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$arts = Art::all();
|
||||
$categories = LegalOpinionCategory::all();
|
||||
|
||||
return view('admin.legal-opinion.create', compact('arts', 'categories'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'opinion_number' => [
|
||||
'required',
|
||||
Rule::unique('legal_opinions', 'opinion_number')->where('category_id', $request->input('category_id')),
|
||||
],
|
||||
'opinion_date' => 'nullable|date',
|
||||
'subject' => 'nullable|string|max:1000',
|
||||
'full_text' => 'required|string',
|
||||
'issuing_authority' => 'nullable|string',
|
||||
'category_id' => 'required|exists:legal_opinion_categories,id',
|
||||
'art_ids' => 'nullable|array',
|
||||
'art_ids.*' => 'exists:art,id',
|
||||
]);
|
||||
|
||||
$legalOpinion = LegalOpinion::create([
|
||||
'opinion_number' => $validated['opinion_number'],
|
||||
'opinion_date' => $validated['opinion_date'] ?? null,
|
||||
'subject' => $validated['subject'] ?? null,
|
||||
'full_text' => $validated['full_text'],
|
||||
'issuing_authority' => $validated['issuing_authority'] ?? null,
|
||||
'category_id' => $validated['category_id'],
|
||||
]);
|
||||
|
||||
if (!empty($validated['art_ids'])) {
|
||||
$legalOpinion->arts()->attach($validated['art_ids']);
|
||||
}
|
||||
|
||||
return redirect(route('legal-opinion.index'));
|
||||
}
|
||||
|
||||
public function edit(LegalOpinion $legalOpinion)
|
||||
{
|
||||
$arts = Art::all();
|
||||
$categories = LegalOpinionCategory::all();
|
||||
$selectedArtIds = $legalOpinion->arts->pluck('id')->toArray();
|
||||
|
||||
return view('admin.legal-opinion.update', compact('legalOpinion', 'arts', 'categories', 'selectedArtIds'));
|
||||
}
|
||||
|
||||
public function show(LegalOpinion $legalOpinion)
|
||||
{
|
||||
return redirect(route('legal-opinion.edit', $legalOpinion->id));
|
||||
}
|
||||
|
||||
public function update(Request $request, LegalOpinion $legalOpinion)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'opinion_number' => [
|
||||
'required',
|
||||
Rule::unique('legal_opinions', 'opinion_number')
|
||||
->where('category_id', $request->input('category_id'))
|
||||
->ignore($legalOpinion->id),
|
||||
],
|
||||
'opinion_date' => 'nullable|date',
|
||||
'subject' => 'nullable|string|max:1000',
|
||||
'full_text' => 'required|string',
|
||||
'issuing_authority' => 'nullable|string',
|
||||
'category_id' => 'required|exists:legal_opinion_categories,id',
|
||||
'art_ids' => 'nullable|array',
|
||||
'art_ids.*' => 'exists:art,id',
|
||||
]);
|
||||
|
||||
$legalOpinion->update([
|
||||
'opinion_number' => $validated['opinion_number'],
|
||||
'opinion_date' => $validated['opinion_date'] ?? null,
|
||||
'subject' => $validated['subject'] ?? null,
|
||||
'full_text' => $validated['full_text'],
|
||||
'issuing_authority' => $validated['issuing_authority'] ?? null,
|
||||
'category_id' => $validated['category_id'],
|
||||
]);
|
||||
|
||||
$legalOpinion->arts()->sync($validated['art_ids'] ?? []);
|
||||
|
||||
return redirect(route('legal-opinion.edit', $legalOpinion->id));
|
||||
}
|
||||
|
||||
public function destroy(LegalOpinion $legalOpinion)
|
||||
{
|
||||
$legalOpinion->delete();
|
||||
|
||||
return redirect(route('legal-opinion.index'));
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,13 @@ class ArtController extends Controller
|
||||
|
||||
public function index(GetApiRequest $request)
|
||||
{
|
||||
$book = Book::find($request->book_id);
|
||||
$law = Law::find($book?->law_id);
|
||||
|
||||
if ($this->isLockedForCurrentUser($law)) {
|
||||
return $this->failed([], ['title' => 'Subscription Required', 'message' => 'This content requires an active subscription.'], 403);
|
||||
}
|
||||
|
||||
$arts = Art::with(['chapter', 'part', 'volum', 'law', 'book', 'section', 'gate'])->where('book_id', $request->book_id)->orderBy('number')->get();
|
||||
|
||||
$arts = $arts->map(function ($art) {
|
||||
@@ -84,6 +91,10 @@ class ArtController extends Controller
|
||||
|
||||
$law = Law::find($art?->law_id);
|
||||
|
||||
if ($this->isLockedForCurrentUser($law)) {
|
||||
return $this->failed([], ['title' => 'Subscription Required', 'message' => 'This content requires an active subscription.'], 403);
|
||||
}
|
||||
|
||||
$art->is_like = $this->isLiked($art->id);
|
||||
$art->note = Note::select('id', 'note', 'color_code','created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get();
|
||||
$art->category = $law?->category?->name;
|
||||
@@ -152,16 +163,23 @@ class ArtController extends Controller
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function isLockedForCurrentUser(?Law $law): bool
|
||||
{
|
||||
return !auth()->user()->isSubscriber() && (bool) $law?->is_locked;
|
||||
}
|
||||
|
||||
public function likes()
|
||||
{
|
||||
$likes = LikeArt::query()->where('user_id', auth()->user()->id)
|
||||
->with('art')
|
||||
->with('art.law')
|
||||
->get()
|
||||
->map(function ($q) {
|
||||
$isLocked = $this->isLockedForCurrentUser($q->art?->law);
|
||||
|
||||
return [
|
||||
'id' => $q->art->id,
|
||||
'title' => $q->art->title,
|
||||
'text' => $q->art->text
|
||||
'text' => $isLocked ? null : $q->art->text
|
||||
];
|
||||
});
|
||||
|
||||
@@ -257,12 +275,13 @@ class ArtController extends Controller
|
||||
}
|
||||
|
||||
$law = Law::find($item->law_id);
|
||||
$isLocked = $this->isLockedForCurrentUser($law);
|
||||
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'title' => $item->title,
|
||||
'text' => $context,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'text' => $isLocked ? null : $context,
|
||||
'is_locked' => $isLocked,
|
||||
'type' => 'art',
|
||||
'route' => array_values($this->route($modelClass, $item)),
|
||||
'category' => optional($law->category)->name,
|
||||
@@ -466,11 +485,13 @@ class ArtController extends Controller
|
||||
$context = $text;
|
||||
}
|
||||
|
||||
$isLocked = $this->isLockedForCurrentUser($law);
|
||||
|
||||
return [
|
||||
'id' => $q->id,
|
||||
'title' => $q->title,
|
||||
'text' => $context,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : $law->is_locked,
|
||||
'text' => $isLocked ? null : $context,
|
||||
'is_locked' => $isLocked,
|
||||
'type' => 'art',
|
||||
'route' => $route,
|
||||
'category' => $law?->category?->name,
|
||||
|
||||
@@ -59,7 +59,10 @@ class AuthController extends Controller
|
||||
if ($response->successful()) {
|
||||
return $this->success([], 'موفق', 'کد ورود به شماره موبایل شما ارسال شد');
|
||||
} else {
|
||||
return $this->failed([], 'نا موفق', 'در ارسال کد به شماره شما مشکلی وجود دارد');
|
||||
return $this->failed([], [
|
||||
'title' => 'نا موفق',
|
||||
'message' => 'در ارسال کد به شماره شما مشکلی وجود دارد',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class BookController extends Controller
|
||||
$books = Book::where('volum_id', $validated['volum_id'])->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
$books->getCollection()->transform(function ($section) {
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== true ? true : Law::where('is_locked',$section['law_id'])->first()?->is_locked ?? false;
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $section['law_id'])->first()?->is_locked ?? false;
|
||||
|
||||
unset($section['law_id']);
|
||||
unset($section['volum_id']);
|
||||
|
||||
@@ -24,7 +24,7 @@ class ChapterController extends Controller
|
||||
|
||||
$chapters->getCollection()->transform(function ($section) {
|
||||
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $section['law_id'])->first()?->is_locked;
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $section['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($section['law_id']);
|
||||
unset($section['section_id']);
|
||||
|
||||
@@ -83,13 +83,14 @@ class FolderController extends Controller
|
||||
} else {
|
||||
$shortText = $text;
|
||||
}
|
||||
$isLocked = !auth()->user()->isSubscriber() && (bool) $art->law?->is_locked;
|
||||
|
||||
return [
|
||||
'id' => $art->id,
|
||||
'title' => $art->title,
|
||||
'text' => $shortText,
|
||||
'text' => $isLocked ? null : $shortText,
|
||||
'number' => $art->number,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $art->law->id)->first()?->is_locked,
|
||||
'is_locked' => $isLocked,
|
||||
'chapter' => $art->chapter != null ? [
|
||||
'id' => $art->chapter->id,
|
||||
'title' => $art->chapter->title,
|
||||
|
||||
@@ -23,7 +23,7 @@ class GateController extends Controller
|
||||
|
||||
$gates->getCollection()->transform(function ($gate) {
|
||||
unset($gate['book_id']);
|
||||
$gate['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $gate['law_id'])->first()?->is_locked;
|
||||
$gate['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $gate['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($gate['law_id']);
|
||||
|
||||
|
||||
@@ -3,40 +3,27 @@
|
||||
namespace App\Http\Controllers\api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
// 1. IMPORT THE JOB WE CREATED
|
||||
use App\Jobs\CheckBazaarSubscription;
|
||||
|
||||
// These are your existing imports
|
||||
use App\Models\Law;
|
||||
use App\Models\Notification;
|
||||
use App\Models\RecentArt;
|
||||
use App\Models\UserSubscriber;
|
||||
use App\Services\AppMarketPurchaseVerifier;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function __construct(private AppMarketPurchaseVerifier $marketVerifier)
|
||||
{
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
// 2. DISPATCH THE JOB AT THE VERY BEGINNING
|
||||
// ===================================================================
|
||||
// Find the user's latest subscription that has a purchase token
|
||||
$latestSubscription = $user->userSubscribers()->whereNotNull('purchase_token')->latest()->first();
|
||||
|
||||
// If such a subscription exists, create a new job and hand it to the queue
|
||||
// if ($latestSubscription) {
|
||||
// CheckBazaarSubscription::dispatch($latestSubscription);
|
||||
// }
|
||||
// ===================================================================
|
||||
// Your API now continues immediately without waiting for the check to finish.
|
||||
|
||||
|
||||
// --- ALL THE REST OF YOUR CODE REMAINS EXACTLY THE SAME ---
|
||||
$this->refreshMarketSubscriptionAfterResponse($user);
|
||||
|
||||
$recent = RecentArt::query()->where('user_id', $user->id)->get()->map(function ($q) {
|
||||
return [
|
||||
@@ -81,8 +68,6 @@ class HomeController extends Controller
|
||||
];
|
||||
});
|
||||
|
||||
$current_plan = null;
|
||||
|
||||
$freeSubscription = $user->userSubscribers()
|
||||
->whereHas('subscribe', function ($query) {
|
||||
$query->where('is_free', true);
|
||||
@@ -90,11 +75,9 @@ class HomeController extends Controller
|
||||
->where('expired_at', '>=', now())
|
||||
->first();
|
||||
|
||||
$expiredAt = null;
|
||||
$current_plan = null;
|
||||
|
||||
if ($freeSubscription) {
|
||||
$expiredAt = $freeSubscription->expired_at;
|
||||
$current_plan = [
|
||||
'id' => $freeSubscription->id,
|
||||
'name' => $freeSubscription->subscribe->name,
|
||||
@@ -104,18 +87,22 @@ class HomeController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
$latestSubscription = $user->userSubscribers()->latest()->first();
|
||||
$latestSubscription = $user->userSubscribers()
|
||||
->where('expired_at', '>=', now())
|
||||
->latest('expired_at')
|
||||
->first();
|
||||
|
||||
$expiredDays = UserSubscriber::query()->where('user_id', $user->id)->where('expired_at', '>=', now())->get()->sum(function ($subscriber) {return $subscriber->expired_at->diffInDays(now());});
|
||||
|
||||
$purchase_token = $latestSubscription?->purchase_token;
|
||||
$current_plan = [
|
||||
'id' => $latestSubscription->id,
|
||||
'name' => $latestSubscription->subscribe->name ?? 'Subscription',
|
||||
'price' => $latestSubscription->subscribe->price ?? 100,
|
||||
'expired_day' => $expiredDays,
|
||||
'is_free' => false
|
||||
];
|
||||
if ($latestSubscription) {
|
||||
$current_plan = [
|
||||
'id' => $latestSubscription->id,
|
||||
'name' => $latestSubscription->subscribe->name ?? 'Subscription',
|
||||
'price' => $latestSubscription->subscribe->price ?? 100,
|
||||
'expired_day' => $expiredDays,
|
||||
'is_free' => (bool) $latestSubscription->is_free
|
||||
];
|
||||
}
|
||||
|
||||
$unread_notifications_count = Notification::unreadForUser($user->id)->count();
|
||||
|
||||
@@ -128,4 +115,55 @@ class HomeController extends Controller
|
||||
'unread_notifications_count' => $unread_notifications_count,
|
||||
]);
|
||||
}
|
||||
|
||||
private function refreshMarketSubscriptionAfterResponse($user): void
|
||||
{
|
||||
$cacheKey = "home-market-refresh-user-{$user->id}";
|
||||
$this->refreshMarketSubscription($user);
|
||||
|
||||
if (!Cache::add($cacheKey, true, now()->addHours(24))) {
|
||||
return;
|
||||
}
|
||||
|
||||
app()->terminating(function () use ($user) {
|
||||
$this->refreshMarketSubscription($user);
|
||||
});
|
||||
}
|
||||
|
||||
private function refreshMarketSubscription($user): void
|
||||
{
|
||||
$bazaarSubscription = $user->userSubscribers()
|
||||
->whereNotNull('purchase_token')
|
||||
->whereNotNull('subscription_id')
|
||||
->where(function ($query) {
|
||||
$query->where('market_provider', 'bazaar')
|
||||
->orWhereNull('market_provider');
|
||||
})
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($bazaarSubscription && $this->shouldRefreshMarketSubscription($bazaarSubscription) && $this->marketVerifier->refreshBazaarSubscriber($bazaarSubscription)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$myketSubscription = $user->userSubscribers()
|
||||
->where('market_provider', 'myket')
|
||||
->whereNotNull('purchase_token')
|
||||
->whereNotNull('product_id')
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($myketSubscription && $this->shouldRefreshMarketSubscription($myketSubscription)) {
|
||||
$this->marketVerifier->refreshMyketSubscriber($myketSubscription);
|
||||
}
|
||||
}
|
||||
|
||||
private function shouldRefreshMarketSubscription(UserSubscriber $subscriber): bool
|
||||
{
|
||||
if ($subscriber->expired_at && $subscriber->expired_at->lessThanOrEqualTo(now())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !$subscriber->last_verified_at || $subscriber->last_verified_at->lessThan(now()->subHours(12));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ class PartController extends Controller
|
||||
|
||||
$parts->getCollection()->transform(function ($part) {
|
||||
unset($part['book_id']);
|
||||
$gate['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $part['law_id'])->first()?->is_locked;
|
||||
$part['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $part['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($gate['law_id']);
|
||||
unset($part['law_id']);
|
||||
|
||||
return $gate;
|
||||
return $part;
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class SectionController extends Controller
|
||||
|
||||
$section->getCollection()->transform(function ($section) {
|
||||
unset($section['book_id']);
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked',$section['law_id'])->first()?->is_locked;
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $section['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($section['law_id']);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Models\SubscribePlan;
|
||||
use App\Models\UserSubscriber;
|
||||
use App\Services\AppMarketPurchaseVerifier;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -17,6 +18,10 @@ class SubscribePlanController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function __construct(private AppMarketPurchaseVerifier $marketVerifier)
|
||||
{
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$subscribePlans = SubscribePlan::query()->where('is_active', true)->get()->map(function ($q) {
|
||||
@@ -104,8 +109,6 @@ class SubscribePlanController extends Controller
|
||||
|
||||
public function subscribe_new(Request $request)
|
||||
{
|
||||
$package_name_bazzar = 'com.razzaghi.lawbook.android';
|
||||
|
||||
$request->validate([
|
||||
'subscribe_plan_id' => 'required|exists:subscribe_plans,id',
|
||||
'subscription_id' => 'nullable',
|
||||
@@ -149,23 +152,13 @@ class SubscribePlanController extends Controller
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid subscription details.']);
|
||||
}
|
||||
|
||||
$url = "https://pardakht.cafebazaar.ir/devapi/v2/api/applications/$package_name_bazzar/subscriptions/$subscription_id/purchases/$purchase_token";
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
try {
|
||||
$response = $client->get($url, [
|
||||
'headers' => [
|
||||
'CAFEBAZAAR-PISHKHAN-API-SECRET' => 'eyJhbGciOiJIUzI1NiIsImtpZCI6ImFuY2llbnQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJuYXNoZXItcGlzaGtoYW4tYXBpIiwiaWF0IjoxNzQwMjQ3NTMzLCJleHAiOjQ4OTM4NDc1MzMsImFwaV9hZ2VudF9pZCI6MzQ2NX0.UCrr3IHxCqn77ckxfnaubrsyCfrhPm18gJgyg1qNqwA',
|
||||
]
|
||||
]);
|
||||
$bazaarExpiredAt = $this->marketVerifier->verifyBazaarSubscription($subscription_id, $purchase_token);
|
||||
|
||||
$data = json_decode($response->getBody(), true);
|
||||
if (!isset($data['validUntilTimestampMsec']) || $data['validUntilTimestampMsec'] < now()->timestamp * 1000) {
|
||||
if (!$bazaarExpiredAt) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid or expired subscription.']);
|
||||
}
|
||||
|
||||
$bazaarExpiredAt = Carbon::createFromTimestampMs($data['validUntilTimestampMsec']);
|
||||
|
||||
$expiredAt = $activeSubscription ? $activeSubscription->expired_at->addDays($subscribePlan->expired_day) : $bazaarExpiredAt;
|
||||
$user->userSubscribers()->whereHas('subscribe', function ($query) {
|
||||
$query->where('is_free', true);
|
||||
@@ -177,6 +170,8 @@ class SubscribePlanController extends Controller
|
||||
'expired_at' => $expiredAt,
|
||||
'subscription_id' => $subscription_id,
|
||||
'purchase_token' => $purchase_token,
|
||||
'market_provider' => 'bazaar',
|
||||
'last_verified_at' => now(),
|
||||
'is_free' => false
|
||||
]);
|
||||
|
||||
@@ -187,6 +182,69 @@ class SubscribePlanController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function subscribeMyket(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'subscribe_plan_id' => 'required|exists:subscribe_plans,id',
|
||||
'sku_id' => 'required|string',
|
||||
'token' => 'required_without_all:tokenId,token_id,purchase_token|string',
|
||||
'tokenId' => 'required_without_all:token,token_id,purchase_token|string',
|
||||
'token_id' => 'required_without_all:token,tokenId,purchase_token|string',
|
||||
'purchase_token' => 'required_without_all:token,tokenId,token_id|string',
|
||||
]);
|
||||
|
||||
$subscribePlan = SubscribePlan::findOrFail($request->subscribe_plan_id);
|
||||
$user = auth()->user();
|
||||
$token = $request->input('token')
|
||||
?? $request->input('tokenId')
|
||||
?? $request->input('token_id')
|
||||
?? $request->input('purchase_token');
|
||||
|
||||
if ($subscribePlan->is_free) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid subscription details.']);
|
||||
}
|
||||
|
||||
try {
|
||||
$purchase = $this->marketVerifier->verifyMyketProduct($request->sku_id, $token);
|
||||
|
||||
if (!$purchase) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid or failed Myket purchase.']);
|
||||
}
|
||||
|
||||
$expiredAt = $purchase['purchased_at']->copy()->addDays($subscribePlan->expired_day);
|
||||
|
||||
if ($expiredAt->lessThan(now())) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid or expired subscription.']);
|
||||
}
|
||||
|
||||
$user->userSubscribers()->whereHas('subscribe', function ($query) {
|
||||
$query->where('is_free', true);
|
||||
})->update(['expired_at' => now()]);
|
||||
|
||||
$user->userSubscribers()->updateOrCreate(
|
||||
[
|
||||
'market_provider' => 'myket',
|
||||
'purchase_token' => $token,
|
||||
],
|
||||
[
|
||||
'subscribe_plan_id' => $subscribePlan->id,
|
||||
'expired_at' => $expiredAt,
|
||||
'subscription_id' => $request->sku_id,
|
||||
'product_id' => $request->sku_id,
|
||||
'purchased_at' => $purchase['purchased_at'],
|
||||
'last_verified_at' => now(),
|
||||
'is_free' => false,
|
||||
]
|
||||
);
|
||||
|
||||
return $this->success(null, 'Subscribe Plan', 'Myket subscription successfully activated.');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in Myket subscription', ['Error' => $e->getMessage()]);
|
||||
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Failed to verify Myket subscription.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function paymentCallback(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -35,7 +35,7 @@ class VolumController extends Controller
|
||||
|
||||
$volumes->getCollection()->transform(function ($volume) {
|
||||
$volume['has_book'] = Book::where('volum_id', $volume->id)->exists();
|
||||
$volume['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $volume['law_id'])->first()?->is_locked;
|
||||
$volume['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $volume['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($volume['law_id']);
|
||||
|
||||
@@ -79,7 +79,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
$paginationData = [
|
||||
@@ -117,7 +117,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -151,7 +151,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -184,7 +184,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -218,7 +218,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -252,7 +252,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -286,7 +286,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -321,7 +321,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -355,7 +355,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -399,7 +399,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => 'volume',
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
return $this->success($data, 'Success');
|
||||
@@ -423,7 +423,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => 'art',
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked
|
||||
];
|
||||
}
|
||||
return $this->success($data, 'Success');
|
||||
@@ -570,7 +570,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => 'laws',
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->id)->first()?->is_locked,
|
||||
'image' => $item?->image,
|
||||
'law' => $item?->title,
|
||||
'count_art' => $item->arts->count(),
|
||||
@@ -724,7 +724,7 @@ class VolumController extends Controller
|
||||
'number' => $item->number,
|
||||
'type' => $type,
|
||||
'route' => $this->route($item, $item),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
'law' => $law?->title,
|
||||
'image' => $law?->image,
|
||||
'count_art' => $law?->arts?->count() ?? 0,
|
||||
|
||||
@@ -53,6 +53,11 @@ class Art extends Model
|
||||
return $this->belongsToMany(JudicialPrecedent::class, 'art_judicial_precedent');
|
||||
}
|
||||
|
||||
public function legalOpinions()
|
||||
{
|
||||
return $this->belongsToMany(LegalOpinion::class, 'art_legal_opinion');
|
||||
}
|
||||
|
||||
public static function search($searchTerm)
|
||||
{
|
||||
return self::where('title', 'LIKE', "%{$searchTerm}%")
|
||||
|
||||
32
app/Models/LegalOpinion.php
Normal file
32
app/Models/LegalOpinion.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LegalOpinion extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'opinion_number',
|
||||
'opinion_date',
|
||||
'subject',
|
||||
'full_text',
|
||||
'issuing_authority',
|
||||
'category_id',
|
||||
];
|
||||
|
||||
protected $hidden = ['created_at', 'updated_at'];
|
||||
|
||||
public function arts()
|
||||
{
|
||||
return $this->belongsToMany(Art::class, 'art_legal_opinion');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(LegalOpinionCategory::class, 'category_id');
|
||||
}
|
||||
}
|
||||
18
app/Models/LegalOpinionCategory.php
Normal file
18
app/Models/LegalOpinionCategory.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LegalOpinionCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name'];
|
||||
|
||||
public function legalOpinions()
|
||||
{
|
||||
return $this->hasMany(LegalOpinion::class, 'category_id');
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,10 @@ class UserSubscriber extends Model
|
||||
'expired_at',
|
||||
'subscription_id',
|
||||
'purchase_token',
|
||||
'market_provider',
|
||||
'product_id',
|
||||
'purchased_at',
|
||||
'last_verified_at',
|
||||
'is_free'
|
||||
];
|
||||
|
||||
@@ -35,5 +39,7 @@ class UserSubscriber extends Model
|
||||
|
||||
protected $casts = [
|
||||
'expired_at' => 'datetime',
|
||||
'purchased_at' => 'datetime',
|
||||
'last_verified_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
118
app/Services/AppMarketPurchaseVerifier.php
Normal file
118
app/Services/AppMarketPurchaseVerifier.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\UserSubscriber;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AppMarketPurchaseVerifier
|
||||
{
|
||||
public function verifyBazaarSubscription(string $subscriptionId, string $purchaseToken): ?Carbon
|
||||
{
|
||||
$packageName = config('services.app_markets.package_name');
|
||||
$url = "https://pardakht.cafebazaar.ir/devapi/v2/api/applications/{$packageName}/subscriptions/{$subscriptionId}/purchases/{$purchaseToken}";
|
||||
|
||||
$response = Http::timeout(3)->connectTimeout(2)->withHeaders([
|
||||
'CAFEBAZAAR-PISHKHAN-API-SECRET' => config('services.app_markets.bazaar_secret'),
|
||||
])->get($url);
|
||||
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::error('Failed to verify Bazaar subscription', [
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body(),
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$validUntil = $response->json('validUntilTimestampMsec');
|
||||
|
||||
if (!$validUntil || $validUntil < now()->timestamp * 1000) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::createFromTimestampMs($validUntil);
|
||||
}
|
||||
|
||||
public function refreshBazaarSubscriber(UserSubscriber $subscriber): bool
|
||||
{
|
||||
if (!$subscriber->subscription_id || !$subscriber->purchase_token) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$expiredAt = $this->verifyBazaarSubscription($subscriber->subscription_id, $subscriber->purchase_token);
|
||||
|
||||
if (!$expiredAt) {
|
||||
$subscriber->update(['expired_at' => now()]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$subscriber->update([
|
||||
'expired_at' => $expiredAt,
|
||||
'last_verified_at' => now(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function verifyMyketProduct(string $skuId, string $token): ?array
|
||||
{
|
||||
$packageName = config('services.app_markets.package_name');
|
||||
$url = "https://developer.myket.ir/api/partners/applications/{$packageName}/purchases/products/{$skuId}/verify";
|
||||
|
||||
$response = Http::timeout(3)->connectTimeout(2)->withHeaders([
|
||||
'X-Access-Token' => config('services.app_markets.myket_access_token'),
|
||||
])->post($url, [
|
||||
'tokenId' => $token,
|
||||
]);
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::error('Failed to verify Myket purchase', [
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body(),
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
if (($data['purchaseState'] ?? null) !== 0 || empty($data['purchaseTime'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => $data,
|
||||
'purchased_at' => Carbon::createFromTimestampMs($data['purchaseTime']),
|
||||
];
|
||||
}
|
||||
|
||||
public function refreshMyketSubscriber(UserSubscriber $subscriber): bool
|
||||
{
|
||||
if (!$subscriber->product_id || !$subscriber->purchase_token || !$subscriber->subscribe) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$purchase = $this->verifyMyketProduct($subscriber->product_id, $subscriber->purchase_token);
|
||||
|
||||
if (!$purchase) {
|
||||
$subscriber->update(['expired_at' => now()]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$expiredAt = $purchase['purchased_at']->copy()->addDays($subscriber->subscribe->expired_day);
|
||||
|
||||
$subscriber->update([
|
||||
'purchased_at' => $purchase['purchased_at'],
|
||||
'expired_at' => $expiredAt,
|
||||
'last_verified_at' => now(),
|
||||
]);
|
||||
|
||||
return $expiredAt->greaterThanOrEqualTo(now());
|
||||
}
|
||||
}
|
||||
@@ -31,4 +31,11 @@ return [
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
'app_markets' => [
|
||||
'package_name' => env('APP_MARKET_PACKAGE_NAME', 'com.razzaghi.lawbook.android'),
|
||||
'myket_access_token' => env('MYKET_ACCESS_TOKEN', 'd9f9207b-72c9-438e-9ff1-0b44e24b2612'),
|
||||
'myket_public_key' => env('MYKET_PUBLIC_KEY', 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCg3ZcL+tvifbjvSbo1ZKbG0Zw7PwVEtkiP9yCwpn6J9pxs53ZO5dqWDc2u8pewPPFxXbi/sUrbdpuia+l2raSO+8ncp5loA8r/dCRww/qjtWmcXhqGEZWfb9dsh8VduNVjBBva1EcePL63L3PbLgnj+ty/gLd03o+H+yOJbFc/dwIDAQAB'),
|
||||
'bazaar_secret' => env('BAZAAR_API_SECRET', 'eyJhbGciOiJIUzI1NiIsImtpZCI6ImFuY2llbnQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJuYXNoZXItcGlzaGtoYW4tYXBpIiwiaWF0IjoxNzQwMjQ3NTMzLCJleHAiOjQ4OTM4NDc1MzMsImFwaV9hZ2VudF9pZCI6MzQ2NX0.UCrr3IHxCqn77ckxfnaubrsyCfrhPm18gJgyg1qNqwA'),
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('legal_opinion_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique()->comment('نام دستهبندی');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('legal_opinion_categories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('legal_opinions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('opinion_number')->comment('شماره نظریه');
|
||||
$table->date('opinion_date')->nullable()->comment('تاریخ نظریه');
|
||||
$table->string('subject', 1000)->nullable()->comment('موضوع استعلام یا نظریه');
|
||||
$table->longText('full_text')->comment('متن کامل نظریه و استعلام');
|
||||
$table->string('issuing_authority')->nullable()->comment('مرجع صدور');
|
||||
$table->foreignId('category_id')->constrained('legal_opinion_categories')->onDelete('cascade')->comment('شناسه دستهبندی');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['opinion_number', 'category_id'], 'unique_opinion_category');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('legal_opinions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('art_legal_opinion', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('art_id')->constrained('art')->onDelete('cascade');
|
||||
$table->foreignId('legal_opinion_id')->constrained('legal_opinions')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['art_id', 'legal_opinion_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('art_legal_opinion');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('user_subscribers', function (Blueprint $table) {
|
||||
$table->string('market_provider')->nullable()->after('purchase_token');
|
||||
$table->string('product_id')->nullable()->after('market_provider');
|
||||
$table->timestamp('purchased_at')->nullable()->after('product_id');
|
||||
$table->timestamp('last_verified_at')->nullable()->after('purchased_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('user_subscribers', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'market_provider',
|
||||
'1',
|
||||
'purchased_at',
|
||||
'last_verified_at',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
@extends('admin.layouts.app')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
@include('admin.layouts.errors')
|
||||
<div class="col-lg-8">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">افزودن دستهبندی نظریه حقوقی</h4>
|
||||
<div>
|
||||
<form action="{{ route('legal-opinion-category.store') }}" method="post">
|
||||
@csrf
|
||||
<div class="mb-4">
|
||||
<label for="name">نام دستهبندی</label>
|
||||
<input class="form-control" name="name" type="text" placeholder="نام دستهبندی" required>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" type="submit">ذخیره</button>
|
||||
<a href="{{ route('legal-opinion-category.index') }}" class="btn btn-secondary">بازگشت</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
44
resources/views/admin/legal-opinion-category/index.blade.php
Normal file
44
resources/views/admin/legal-opinion-category/index.blade.php
Normal file
@@ -0,0 +1,44 @@
|
||||
@extends('admin.layouts.app')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@include('admin.partial.list-filter', ['filterRoute' => 'legal-opinion-category.index'])
|
||||
<div id="datatable_wrapper" class="dataTables_wrapper dt-bootstrap4 no-footer">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<table id="datatable" class="table table-bordered dt-responsive nowrap dataTable no-footer dtr-inline" style="border-collapse: collapse; border-spacing: 0px; width: 100%;" role="grid" aria-describedby="datatable_info">
|
||||
<thead>
|
||||
<tr role="row">
|
||||
<th>نام دستهبندی</th>
|
||||
<th>عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($categories as $category)
|
||||
<tr>
|
||||
<td>{{ $category->name }}</td>
|
||||
<td>
|
||||
<form action="{{ route('legal-opinion-category.destroy', $category->id) }}" method="POST" style="display: inline;">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger waves-effect waves-light" onclick="return confirm('آیا مطمئنید که میخواهید این دستهبندی را حذف کنید؟')">حذف</button>
|
||||
</form>
|
||||
<a href="{{ route('legal-opinion-category.edit', $category->id) }}" type="button" class="btn btn-primary waves-effect waves-light">ویرایش</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center mt-3">
|
||||
{{ $categories->withQueryString()->links() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,26 @@
|
||||
@extends('admin.layouts.app')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
@include('admin.layouts.errors')
|
||||
<div class="col-lg-8">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">ویرایش دستهبندی نظریه حقوقی</h4>
|
||||
<div>
|
||||
<form action="{{ route('legal-opinion-category.update', $legalOpinionCategory->id) }}" method="post">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="mb-4">
|
||||
<label for="name">نام دستهبندی</label>
|
||||
<input class="form-control" name="name" type="text" value="{{ $legalOpinionCategory->name }}" placeholder="نام دستهبندی" required>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" type="submit">بروزرسانی</button>
|
||||
<a href="{{ route('legal-opinion-category.index') }}" class="btn btn-secondary">بازگشت</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
65
resources/views/admin/legal-opinion/create.blade.php
Normal file
65
resources/views/admin/legal-opinion/create.blade.php
Normal file
@@ -0,0 +1,65 @@
|
||||
@extends('admin.layouts.app')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
@include('admin.layouts.errors')
|
||||
<div class="col-lg-8">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">افزودن نظریه حقوقی</h4>
|
||||
<div>
|
||||
<form action="{{ route('legal-opinion.store') }}" method="post">
|
||||
@csrf
|
||||
<div class="mb-4">
|
||||
<label for="opinion_number">شماره نظریه</label>
|
||||
<input class="form-control" name="opinion_number" type="text" placeholder="شماره نظریه" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="opinion_date">تاریخ نظریه</label>
|
||||
<input class="form-control" name="opinion_date" type="date">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="subject">موضوع استعلام یا نظریه</label>
|
||||
<input class="form-control" name="subject" type="text" placeholder="موضوع استعلام یا نظریه">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="full_text">متن کامل نظریه و استعلام</label>
|
||||
<textarea class="form-control" name="full_text" id="full_text" cols="30" rows="10" required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="issuing_authority">مرجع صدور</label>
|
||||
<input class="form-control" name="issuing_authority" type="text" placeholder="مرجع صدور">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="category_id">دستهبندی</label>
|
||||
<select class="form-control" name="category_id" id="category_id" required>
|
||||
<option value="">انتخاب دستهبندی</option>
|
||||
@foreach ($categories as $category)
|
||||
<option value="{{ $category->id }}">{{ $category->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="art_ids">مواد مرتبط</label>
|
||||
<select class="form-control" name="art_ids[]" id="art_ids" multiple size="10">
|
||||
@foreach ($arts as $art)
|
||||
<option value="{{ $art->id }}">{{ $art->title }} - شماره {{ $art->number }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<small class="form-text text-muted">برای انتخاب چند ماده، کلید Ctrl (یا Cmd در Mac) را نگه دارید</small>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" type="submit">ذخیره</button>
|
||||
<a href="{{ route('legal-opinion.index') }}" class="btn btn-secondary">بازگشت</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
52
resources/views/admin/legal-opinion/index.blade.php
Normal file
52
resources/views/admin/legal-opinion/index.blade.php
Normal file
@@ -0,0 +1,52 @@
|
||||
@extends('admin.layouts.app')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@include('admin.partial.list-filter', ['filterRoute' => 'legal-opinion.index'])
|
||||
<div id="datatable_wrapper" class="dataTables_wrapper dt-bootstrap4 no-footer">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<table id="datatable" class="table table-bordered dt-responsive nowrap dataTable no-footer dtr-inline" style="border-collapse: collapse; border-spacing: 0px; width: 100%;" role="grid" aria-describedby="datatable_info">
|
||||
<thead>
|
||||
<tr role="row">
|
||||
<th>شماره نظریه</th>
|
||||
<th>تاریخ نظریه</th>
|
||||
<th>موضوع</th>
|
||||
<th>دستهبندی</th>
|
||||
<th>مرجع صدور</th>
|
||||
<th>عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($legalOpinions as $opinion)
|
||||
<tr>
|
||||
<td>{{ $opinion->opinion_number }}</td>
|
||||
<td>{{ $opinion->opinion_date }}</td>
|
||||
<td>{{ $opinion->subject }}</td>
|
||||
<td>{{ $opinion->category?->name }}</td>
|
||||
<td>{{ $opinion->issuing_authority }}</td>
|
||||
<td>
|
||||
<form action="{{ route('legal-opinion.destroy', $opinion->id) }}" method="POST" style="display: inline;">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger waves-effect waves-light" onclick="return confirm('آیا مطمئنید که میخواهید این نظریه را حذف کنید؟')">حذف</button>
|
||||
</form>
|
||||
<a href="{{ route('legal-opinion.edit', $opinion->id) }}" type="button" class="btn btn-primary waves-effect waves-light">ویرایش</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center mt-3">
|
||||
{{ $legalOpinions->withQueryString()->links() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
66
resources/views/admin/legal-opinion/update.blade.php
Normal file
66
resources/views/admin/legal-opinion/update.blade.php
Normal file
@@ -0,0 +1,66 @@
|
||||
@extends('admin.layouts.app')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
@include('admin.layouts.errors')
|
||||
<div class="col-lg-8">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">ویرایش نظریه حقوقی</h4>
|
||||
<div>
|
||||
<form action="{{ route('legal-opinion.update', $legalOpinion->id) }}" method="post">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="mb-4">
|
||||
<label for="opinion_number">شماره نظریه</label>
|
||||
<input class="form-control" name="opinion_number" type="text" value="{{ $legalOpinion->opinion_number }}" placeholder="شماره نظریه" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="opinion_date">تاریخ نظریه</label>
|
||||
<input class="form-control" name="opinion_date" type="date" value="{{ $legalOpinion->opinion_date }}">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="subject">موضوع استعلام یا نظریه</label>
|
||||
<input class="form-control" name="subject" type="text" value="{{ $legalOpinion->subject }}" placeholder="موضوع استعلام یا نظریه">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="full_text">متن کامل نظریه و استعلام</label>
|
||||
<textarea class="form-control" name="full_text" id="full_text" cols="30" rows="10" required>{{ $legalOpinion->full_text }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="issuing_authority">مرجع صدور</label>
|
||||
<input class="form-control" name="issuing_authority" type="text" value="{{ $legalOpinion->issuing_authority }}" placeholder="مرجع صدور">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="category_id">دستهبندی</label>
|
||||
<select class="form-control" name="category_id" id="category_id" required>
|
||||
<option value="">انتخاب دستهبندی</option>
|
||||
@foreach ($categories as $category)
|
||||
<option value="{{ $category->id }}" {{ $legalOpinion->category_id == $category->id ? 'selected' : '' }}>{{ $category->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="art_ids">مواد مرتبط</label>
|
||||
<select class="form-control" name="art_ids[]" id="art_ids" multiple size="10">
|
||||
@foreach ($arts as $art)
|
||||
<option value="{{ $art->id }}" {{ in_array($art->id, $selectedArtIds) ? 'selected' : '' }}>{{ $art->title }} - شماره {{ $art->number }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<small class="form-text text-muted">برای انتخاب چند ماده، کلید Ctrl (یا Cmd در Mac) را نگه دارید</small>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" type="submit">بروزرسانی</button>
|
||||
<a href="{{ route('legal-opinion.index') }}" class="btn btn-secondary">بازگشت</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -220,6 +220,28 @@
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="javascript:%20void(0);" class="has-arrow waves-effect">
|
||||
<i class="mdi mdi-file-document-outline"></i>
|
||||
<span>نظریههای حقوقی</span>
|
||||
</a>
|
||||
<ul class="sub-menu" aria-expanded="false">
|
||||
<li><a href="{{ route('legal-opinion.index') }}">لیست نظریهها</a></li>
|
||||
<li><a href="{{ route('legal-opinion.create') }}">افزودن نظریه جدید</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="javascript:%20void(0);" class="has-arrow waves-effect">
|
||||
<i class="mdi mdi-format-list-bulleted"></i>
|
||||
<span>دستهبندی نظریهها</span>
|
||||
</a>
|
||||
<ul class="sub-menu" aria-expanded="false">
|
||||
<li><a href="{{ route('legal-opinion-category.index') }}">لیست دستهبندیها</a></li>
|
||||
<li><a href="{{ route('legal-opinion-category.create') }}">افزودن دستهبندی جدید</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="javascript:%20void(0);" class="has-arrow waves-effect">
|
||||
<i class="mdi mdi-account-circle-outline"></i>
|
||||
|
||||
@@ -57,6 +57,7 @@ Route::prefix('v1')->middleware('auth:sanctum')->group(function () {
|
||||
Route::get('subscribe-plans', [SubscribePlanController::class, 'index']);
|
||||
Route::post('subscribe-plan-user', [SubscribePlanController::class, 'subscribe']);
|
||||
Route::post('subscribe-plan-user-new', [SubscribePlanController::class, 'subscribe_new']);
|
||||
Route::post('subscribe-plan-user-myket', [SubscribePlanController::class, 'subscribeMyket']);
|
||||
Route::get('subscribe-plan-current', [SubscribePlanController::class, 'current']);
|
||||
Route::post('pay',[PayController::class, 'pay']);
|
||||
|
||||
@@ -69,4 +70,3 @@ Route::prefix('v1')->middleware('auth:sanctum')->group(function () {
|
||||
|
||||
Route::post('suggestions',[SuggestionController::class,'index']);
|
||||
});
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ use App\Http\Controllers\Admin\HomeController;
|
||||
use App\Http\Controllers\Admin\JudicialPrecedentController;
|
||||
use App\Http\Controllers\Admin\JudicialPrecedentCategoryController;
|
||||
use App\Http\Controllers\Admin\LawController;
|
||||
use App\Http\Controllers\Admin\LegalOpinionController;
|
||||
use App\Http\Controllers\Admin\LegalOpinionCategoryController;
|
||||
use App\Http\Controllers\Admin\NotificationController;
|
||||
use App\Http\Controllers\Admin\PartController;
|
||||
use App\Http\Controllers\Admin\SectionController;
|
||||
@@ -43,6 +45,7 @@ Route::middleware(['auth',config('jetstream.auth_session')])->group(function ()
|
||||
Route::resource('notifications', NotificationController::class);
|
||||
Route::resource('judicial-precedent', JudicialPrecedentController::class);
|
||||
Route::resource('judicial-precedent-category', JudicialPrecedentCategoryController::class);
|
||||
Route::resource('legal-opinion', LegalOpinionController::class);
|
||||
Route::resource('legal-opinion-category', LegalOpinionCategoryController::class);
|
||||
Route::get('suggestions',[SuggestionController::class,'index'])->name('suggestions.index');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user