From e0c4897111b1e06952d7907992011093aeccf54c Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Fri, 10 Jul 2026 00:11:08 +0330 Subject: [PATCH] fix bug --- .../Controllers/Customer/OrderController.php | 102 ++---------------- 1 file changed, 8 insertions(+), 94 deletions(-) diff --git a/app/Http/Controllers/Customer/OrderController.php b/app/Http/Controllers/Customer/OrderController.php index a0d70b9..ba094e3 100644 --- a/app/Http/Controllers/Customer/OrderController.php +++ b/app/Http/Controllers/Customer/OrderController.php @@ -4,115 +4,29 @@ namespace App\Http\Controllers\Customer; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; -use App\Jobs\CheckOrder; +use App\Http\Controllers\Single\SingleOrderController; use App\Models\Customer; use App\Models\Order; use App\Models\Price; use App\Models\Setting; -use App\Models\User; -use App\Services\ConfigService; -use Carbon\Carbon; use Illuminate\Http\Request; -use Rooyesh\Wallet\interfaces\TransactionInterface; -use Rooyesh\Wallet\interfaces\WalletInterface; -use Rooyesh\Wallet\models\Wallet; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; class OrderController extends Controller { - public function store(Request $request){ - $user= auth()->user(); - if ($user->is_legal == 0 or $user->id==4) { + public function store(Request $request) + { + $user = auth()->user(); + if ($user->is_legal == 0 || $user->id == 4) { return response()->json(['massage' => 'لطفا ابتدا فرآیند احراز هویت خود را تکمیل کنید'], 422); - } - -// if () - $data = $request->all(); - $data['customer_id'] = auth('customer')->id(); - $data['sts'] = 2; - $data['payment_sts'] = 4; - $PriceMain = Price::orderBy('id','desc')->first(); - $data['price'] = $PriceMain->price; - $add_sell_price = config('add_sell_price.major'); - $customer = auth('customer')->user(); - - if (!auth('customer')->user()->trade_active){ + if (!auth('customer')->user()->trade_active) { throw new UnprocessableEntityHttpException('امکان سفارش برای شما غیرفعال است.'); } - app(ConfigService::class)->assertTradingOpen(); - $wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type); - $wallet = $wallet_interface->wallet; - if ($data['direction'] == 1){ -// $order = Order::where('customer_id',auth('customer')->id())->where('sts',1)->first(); -// if (!is_null($order)){ -// throw new UnprocessableEntityHttpException('شما یک سفارش باز دارید,ابتدا نسبت به تسویه آن اقدام نمایید و مجددا تلاش کنید'); -// } - $gold_block = 0; - $data['price_original'] = $data['price']; - $data['total_price_original'] = $data['amount']* $data['price_original']; - $data['price'] += $add_sell_price; - $data['total_price'] = $data['amount']* $data['price']; - $data['payment_remind'] = 0; - $data['payment_amount'] = $data['total_price']; - $data['fee'] = $add_sell_price; - $data['total_fee'] = $data['amount']* $data['fee']; - if ($wallet->cash < $data['total_price']){ - if ($data['amount'] > $customer->gram){ - throw new UnprocessableEntityHttpException('مقدار وارد شده بیش از سقف اعتبار شماست'); - } - $data['sts'] = 1; - $data['payment_remind'] = $data['total_price']; - $data['payment_amount'] = 0; - $gold_block = $data['amount']; - } - $data['price_id'] = $PriceMain->id; - $order = Order::create($data); - new TransactionInterface($wallet_interface, $_inp = [ - "cash" => $data['total_price'], - "gold"=> $data['amount'], - 'expire_at'=>now(), - 'active'=>true, - 'order_id'=>$order->id, - 'start_at'=>now(), - 'end_at'=>now()->addDay() - ], 1, true,false,$gold_block); - if ($data['sts'] == 1){ - CheckOrder::dispatch($order->id)->onConnection('database')->delay(now()->addMinutes(5)); - } - $message = auth('customer')->user()->name." عزیز" ."\n" - .'در تاریخ '.verta()->format('Y/n/j H:i:s')." کیف طلایی شما "."\n" - .$data['amount']." گرم شارژ شد"."\n" - ."با تشکر".$this->Config('name_fa'); - }else{ - $data['price_original'] = $data['price']; - $data['total_price_original'] = $data['amount']* $data['price_original']; - $data['price'] -= $add_sell_price; - $data['total_price'] = $data['amount']* $data['price']; - $data['payment_remind'] = 0; - $data['payment_amount'] = $data['total_price']; - $data['fee'] = $add_sell_price; - $data['total_fee'] = $data['amount']* $data['fee']; - if (($wallet->gold - $wallet->gold_block) < $data['amount']){ - throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است'); - } - $order = Order::create($data); - new TransactionInterface($wallet_interface, $_inp = [ - "gold" => $data['amount'], - "cash" => $data['total_price'], - 'expire_at'=>now(), - 'active'=>true, - 'order_id'=>$order->id - ], 2, false,true); - $message = auth('customer')->user()->name." عزیز" ."\n" - .'در تاریخ '.verta()->format('Y/n/j H:i:s')." کیف طلایی شما "."\n" - .$data['amount']." گرم کم شد"."\n" - ."با تشکر".$this->Config('name_fa'); - } - $this->Send(auth('customer')->user()->mobile,$message); - return response()->json($order); + // مسیر واحد سفارش — abshode_id / product_id و کیف محصول جدا + return app(SingleOrderController::class)->store($request); } public function profit_gold()