Файловый менеджер - Редактировать - /home/clickysoft/public_html/charliapp-v2.clickysoft.net/app/Http/Controllers/Admin/PackageController.php
Назад
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Controllers\PayPalController; use App\Http\Requests\MassDestroyPackageRequest; use App\Http\Requests\StorePackageRequest; use App\Http\Requests\UpdatePackageRequest; use App\Models\Color; use App\Models\Package; use App\Models\PackageOption; use App\Models\PackagesOptions; use Gate; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response; use Yajra\DataTables\Facades\DataTables; class PackageController extends Controller { protected $paypalController; public $valueOptions = [1, 2, 3, 4, 5, 7, 8, 9]; public function __construct(PayPalController $paypalController) { $this->paypalController = $paypalController; } public function index(Request $request) { abort_if(Gate::denies('package_access'), Response::HTTP_FORBIDDEN, '403 Forbidden'); if ($request->ajax()) { $query = Package::with(['color'])->select(sprintf('%s.*', (new Package())->table)); $table = Datatables::of($query); $table->addColumn('placeholder', ' '); $table->addColumn('actions', ' '); $table->editColumn('actions', function ($row) { $viewGate = 'package_show'; $editGate = 'package_edit'; $deleteGate = 'package_delete'; $crudRoutePart = 'packages'; $tableName = 'packages'; return view('partials.datatablesActions', compact( 'viewGate', 'editGate', 'deleteGate', 'crudRoutePart', 'row', 'tableName' )); }); $table->editColumn('id', function ($row) { return $row->id; }); $table->editColumn('package_name', function ($row) { return $row->package_name; }); $table->editColumn('description', function ($row) { return $row->description; }); $table->addColumn('color_color', function ($row) { return $row->color ? '<span class="color-block"><span style="background-color: ' . $row->color->color_code . '"></span>' . $row->color->color . '</span>' : ''; })->escapeColumns('color_color'); $table->editColumn('price_monthly', function ($row) { return '$' . $row->price_monthly; }); $table->editColumn('yearly_discount', function ($row) { return $row->yearly_discount . '%'; }); $table->editColumn('price_yearly', function ($row) { return '$' . $row->price_yearly; }); $table->editColumn('status', function ($row) { return '<span id="recordSts' . $row->id . '"><i class="sts fa fa-' . ($row->status == 1 ? "check" : "times") . '"></i> ' . Package::STATUS_RADIO[$row->status] . '</span>'; }); $table->rawColumns(['actions', 'placeholder', 'color']); return $table->make(true); } $colors = Color::get(); return view('admin.packages.index', compact('colors')); } public function create() { abort_if(Gate::denies('package_create'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $colors = Color::select("id", "color", "color_code", "foreground_color")->get(); $packages_options = PackageOption::all(); $value_options = $this->valueOptions; return view('admin.packages.create', compact('colors', 'packages_options', 'value_options')); } public function create_paypal_product($package_name, $description) { return $this->paypalController->createProduct( $package_name, $description ); } public function create_paypal_plan($product_id, $package_name, $description, $price, $interval) { $paypalPlan = $this->paypalController->createPlan( $product_id, $package_name, $description, $price, $interval ); if (!$paypalPlan["success"]) { abort(403, $paypalPlan["message"]); } else { return $paypalPlan["paypalPlanId"]; } } public function store(StorePackageRequest $request) { if ((int)$request->input("price_monthly") <= 0) { return redirect()->back()->withInput()->with("warning_msg", "Monthly price must be greater than 0."); } if ((int)$request->input("price_yearly") <= 0) { return redirect()->back()->withInput()->with("warning_msg", "Yearly price must be greater than 0."); } $paypalProductId = null; $paypalMonthlyPlanId = null; $paypalYearlyPlanId = null; $paypalProduct = $this->create_paypal_product( $request->input("package_name"), $request->input("description") ); if ($paypalProduct["success"]) { $paypalProductId = $paypalProduct["paypalProductId"]; $paypalMonthlyPlanId = $this->create_paypal_plan( $paypalProductId, $request->input("package_name"), $request->input("description"), $request->input("price_monthly"), 'MONTH' ); $paypalYearlyPlanId = $this->create_paypal_plan( $paypalProductId, $request->input("package_name"), $request->input("description"), $request->input("price_yearly"), 'YEAR' ); } else { abort(403, $paypalProduct["message"]."Token: ".request()->get("paypalToken")." =-=-= PayPal Mode: ".config('paypal.mode')); } $packageData = $request->except('package_options', '_token'); $packageData["paypal_product_id"] = $paypalProductId; $packageData["paypal_monthly_plan_id"] = $paypalMonthlyPlanId; $packageData["paypal_yearly_plan_id"] = $paypalYearlyPlanId; $package = Package::create($packageData); $options = []; foreach ($request->package_options as $po) { $options[$po] = [ "option_limit" => $request->input("option_limit" . $po, null), "option_title" => $request->input("option_title" . $po, null), ]; } $package->options()->attach($options); return redirect()->route('admin.packages.index'); } public function edit(Package $package) { abort_if(Gate::denies('package_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $colors = Color::select("id", "color", "color_code", "foreground_color")->get(); $package->load('color'); $value_options = $this->valueOptions; $packageOptions = []; foreach ($package->options as $package_option) { $packageOptions[$package_option->id] = [ "option_limit" => $package_option->pivot->option_limit, "option_title" => $package_option->pivot->option_title ]; } $packages_options = PackageOption::all(); return view('admin.packages.edit', compact('colors', 'package', 'packages_options', 'packageOptions', 'value_options')); } public function update(UpdatePackageRequest $request, Package $package) { $packageData = $request->except('package_options', '_token'); if ((int)$request->input("price_monthly") <= 0) { return redirect()->back()->withInput()->with("warning_msg", "Mothly price must be greater than 0."); } if ((int)$request->input("price_yearly") <= 0) { return redirect()->back()->withInput()->with("warning_msg", "Yearly price must be greater than 0."); } $paypalProductId = $package->paypal_product_id; $paypalMonthlyPlanId = $package->paypal_monthly_plan_id; $paypalYearlyPlanId = $package->paypal_yearly_plan_id; if (((float)$request->input("price_monthly") > 0 || (float)$request->input("price_yearly") > 0) && empty($paypalProductId)) { $paypalProduct = $this->create_paypal_product( $request->input("package_name"), $request->input("description") ); if ($paypalProduct["success"]) { $paypalProductId = $paypalProduct["paypalProductId"]; } else { abort(403, $paypalProduct["message"]); } } if ((float)$request->input("price_monthly") > 0 && (float)$package->price_monthly != (float)$request->input("price_monthly")) { $paypalMonthlyPlanId = $this->create_paypal_plan( $paypalProductId, $request->input("package_name"), $request->input("description"), $request->input("price_monthly"), 'MONTH' ); } if ((float)$request->input("price_yearly") > 0 && (float)$package->price_yearly != (float)$request->input("price_yearly")) { $paypalYearlyPlanId = $this->create_paypal_plan( $paypalProductId, $request->input("package_name"), $request->input("description"), $request->input("price_yearly"), 'YEAR' ); } $packageData["paypal_product_id"] = $paypalProductId; $packageData["paypal_monthly_plan_id"] = $paypalMonthlyPlanId; $packageData["paypal_yearly_plan_id"] = $paypalYearlyPlanId; // } $package->update($packageData); $options = []; foreach ($request->package_options as $po) { $options[$po] = [ "option_limit" => $request->input("option_limit" . $po, null), "option_title" => $request->input("option_title" . $po, null), ]; } $package->options()->sync($options); return redirect()->route('admin.packages.index'); } public function show(Package $package) { abort_if(Gate::denies('package_show'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $package->load('color'); $packages_options = PackageOption::all(); $packageOptions = []; foreach ($package->options as $package_option) { $packageOptions[$package_option->id] = [ "option_limit" => $package_option->pivot->option_limit, "option_title" => $package_option->pivot->option_title ]; } return view('admin.packages.show', compact('package', 'packages_options', 'packageOptions')); } public function destroy(Package $package) { abort_if(Gate::denies('package_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden'); try { $package->delete(); } catch (\Illuminate\Database\QueryException $ex) { return redirect()->back()->withErrors("Record could not be deleted because selected resource is being used."); } return back(); } public function massDestroy(MassDestroyPackageRequest $request) { try { Package::whereIn('id', request('ids'))->delete(); } catch (\Illuminate\Database\QueryException $ex) { return redirect()->back()->withErrors("Record could not be deleted because selected resource is being used."); } return response(null, Response::HTTP_NO_CONTENT); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка