Uname: Linux peekpos.com 6.8.0-1060-aws #63~22.04.1-Ubuntu SMP Tue Jun 30 02:32:53 UTC 2026 x86_64
Software: Apache
PHP version: 8.3.25 [ PHP INFO ] PHP os: Linux
Server Ip: 47.130.192.226
Your Ip: 10.3.134.78
User: www (1001) | Group: www (1001)
Safe Mode: OFF
Disable Function:
passthru,putenv,chroot,chgrp,chown,shell_exec,popen,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv

name : PromocodeController.php
<?php

namespace App\Http\Controllers\addons\included;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Helpers\helper;
use App\Models\Promocode;
use App\Models\Order;
use Illuminate\Support\Facades\Validator;

class PromocodeController extends Controller
{
    public function index()
    {
        $getpromocode = Promocode::orderBy('reorder_id')->get();
        return view('admin.included.promocode.promocode', compact('getpromocode'));
    }
    public function add()
    {
        return view('admin.included.promocode.add');
    }
    public function store(Request $request)
    {
        $getpromocode = Promocode::where('offer_code', $request->offer_code)->get();
        if ($getpromocode->count() > 0) {
            return redirect('admin/promocode/add')->with('error', trans('messages.coupon_already_exist'));
        } else {
            $promocode = new Promocode;
            $promocode->offer_name = $request->offer_name;
            $promocode->offer_code = $request->offer_code;
            $promocode->offer_type = $request->offer_type;
            $promocode->offer_amount = helper::number_format($request->offer_amount);
            $promocode->min_amount = helper::number_format($request->min_amount);
            $promocode->start_date = $request->start_date;
            $promocode->expire_date = $request->expire_date;
            $promocode->usage_type = $request->usage_type;
            $promocode->usage_limit = $request->usage_type == 1 ? $request->usage_limit : '';
            $promocode->description = $request->description;
            $promocode->is_available = '1';
            $promocode->save();
            return redirect('admin/promocode')->with('success', trans('messages.success'));
        }
    }
    public function show(Request $request)
    {
        $getpromocode = Promocode::find($request->id);
        return view('admin.included.promocode.edit', compact('getpromocode'));
    }
    public function update(Request $request)
    {
        $promocode = Promocode::find($request->id);
        $promocode->offer_name = $request->offer_name;
        $promocode->offer_code = $request->offer_code;
        $promocode->offer_type = $request->offer_type;
        $promocode->offer_amount = helper::number_format($request->offer_amount);
        $promocode->min_amount = helper::number_format($request->min_amount);
        $promocode->start_date = $request->start_date;
        $promocode->expire_date = $request->expire_date;
        $promocode->usage_type = $request->usage_type;
        $promocode->usage_limit = $request->usage_type == 1 ? $request->usage_limit : '';
        $promocode->description = $request->description;
        $promocode->save();
        return redirect('admin/promocode')->with('success', trans('messages.success'));
    }
    public function status(Request $request)
    {
        $promocode = Promocode::where('id', $request->id)->update(['is_available' => $request->status]);
        if ($promocode) {
            return 1;
        } else {
            return 0;
        }
    }
    public function destroy(Request $request)
    {
        $delete = Promocode::where('id', $request->id)->delete();
        if ($delete) {
            return redirect('admin/promocode')->with('success', trans('messages.success'));
        } else {
            return redirect('admin/promocode')->with('error', trans('messages.wrong'));
        }
    }
    public function reorder_promocode(Request $request)
    {
        $getPromocode = Promocode::all();
        foreach ($getPromocode as $slider) {
            foreach ($request->order as $order) {

                $ct = Promocode::where('id', $order['id'])->first();
                $ct->reorder_id = $order['position'];
                $ct->save();
            }
        }
        return response()->json(['status' => 1, 'msg' => 'Update Successfully!!'], 200);
    }

    public function checkpromocode(Request $request)
    {
        if ($request->sub_total == "") {
            return response()->json(["status" => 0, "message" => trans('messages.subtotal_required')], 200);
        }
        if ($request->offer_code == "") {
            return response()->json(["status" => 0, "message" => trans('messages.promocode_required')], 200);
        }
        $checkoffercode = Promocode::where('offer_code', $request->offer_code)->where('is_available', 1)->first();
        if (!empty($checkoffercode)) {
            if ((date('Y-m-d') >= $checkoffercode->start_date) && (date('Y-m-d') <= $checkoffercode->expire_date)) {
                if ($request->sub_total > $checkoffercode->min_amount) {
                    $checkcount = Order::select('offer_code')->where('offer_code', $request->offer_code)->count();
                    if ($checkoffercode->usage_type == 1) {
                        if ($checkcount < 1) {
                            if ($checkoffercode->offer_type == 1) {
                                $offer_amount = $checkoffercode->offer_amount;
                            } else {
                                $offer_amount = $request->sub_total * $checkoffercode->offer_amount / 100;
                            }
                            $arr = array(
                                "offer_code" => $checkoffercode->offer_code,
                                "offer_amount" => $offer_amount,
                            );
                            session()->put('discount_data', $arr);
                            return response()->json(["status" => 1, "message" => trans('messages.success'), 'data' => $arr], 200);
                        } else {
                            return response()->json(["status" => 0, "message" => trans('messages.once_per_user')], 200);
                        }
                    } else {
                        if ($checkoffercode->offer_type == 1) {
                            $offer_amount = $checkoffercode->offer_amount;
                        } else {
                            $offer_amount = $request->sub_total * $checkoffercode->offer_amount / 100;
                        }
                        $arr = array(
                            "offer_code" => $checkoffercode->offer_code,
                            "offer_amount" => $offer_amount,
                        );
                        session()->put('discount_data', $arr);
                        return response()->json(["status" => 1, "message" => trans('messages.success'), 'data' => $arr], 200);
                    }
                } else {
                    return response()->json(["status" => 0, "message" => trans('messages.order_amount_greater_then') . ' : ' . helper::currency_format($checkoffercode->min_amount)], 200);
                }
            } else {
                return response()->json(["status" => 0, "message" => trans('messages.offer_expired')], 200);
            }
        } else {
            return response()->json(["status" => 0, "message" => trans('messages.invalid_promocode')], 200);
        }
    }
    public function removepromocode()
    {
        session()->forget('discount_data');
        return response()->json(['status' => 1, 'message' => trans('messages.promocode_removed')], 200);
    }
}
© 2026 GrazzMean