main
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Customer;
|
||||
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\CheckOrder;
|
||||
use App\Models\Order;
|
||||
use App\Models\Price;
|
||||
use App\Models\User;
|
||||
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) {
|
||||
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){
|
||||
throw new UnprocessableEntityHttpException('امکان سفارش برای شما غیرفعال است.');
|
||||
}
|
||||
$wallet = Wallet::where('owner',auth('customer')->id())->whereNull('fund_id')
|
||||
->first();
|
||||
$wallet_interface = new WalletInterface($data['customer_id'], 1);
|
||||
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);
|
||||
}
|
||||
public function table(Request $request){
|
||||
$records = Order::where('customer_id',auth('customer')->id())
|
||||
->where('type',1);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch([])
|
||||
->select([
|
||||
'*',Order::$SELECT_STS_STR
|
||||
])->export($records);
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user