/
home
/
pay
/
server
/
app
/
Http
/
Controllers
/
Single
/
File Upload :
llllll
Current File: /home/pay/server/app/Http/Controllers/Single/SingleOrderController.php
<?php namespace App\Http\Controllers\Single; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\Order; use App\Models\Price; use App\Models\User; use App\Models\Cnt; use App\Mail\YourMailableClass; use Illuminate\Support\Facades\Mail; use App\Models\Withdraw; use Illuminate\Http\Request; use Rooyesh\Wallet\interfaces\TransactionInterface; use Rooyesh\Wallet\interfaces\WalletInterface; use Rooyesh\Wallet\models\Transaction; use Rooyesh\Wallet\models\Wallet; use App\Models\TransactionsAdmin; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; class SingleOrderController extends Controller { public function store(Request $request) { // $response = Http::withHeaders([ // 'sicrtToket' => 'cl@SX^4&^p$i0kKiI7QG36%l', // ])->post('https://liman.gold/server/webHookFirsTime', ['sss'])->json(); // throw new UnprocessableEntityHttpException('به دلیل نوسانات سفارشات بسته میباشد.'); $data = $request->all(); if(auth('customer')->id() == 4) { // $payload = [ // 'direction' => $data['direction'], // 'price' => $data['price'], // 'method' => 'liman', // 'pay_at' => now(), // 'amount' => (int) $data['amount'], // 'customer_id' => 23, // 'product_id' => 2, // 'total_price_origina'=> $data['total_price'], // 'description' => $data['description'], //// 'cash' => $data['payment_amount'], // ]; // $response = Http::withHeaders([ // 'sicrtToket' => 'cl@SX^4&^p$i0kKiI7QG36%l', // ])->get('https://liman.gold/server/webHookFirsTime', $payload)->json(); } if(Cnt::where('key', 'liman_closed')->first()['value'] == "true"){ throw new UnprocessableEntityHttpException(' سفارشات بسته میباشد.'); } if ($this->Config('do_send_liman') == "true"){ $liman_diff = Cnt::where('key', 'liman_diff')->value('value'); $liman_price = Cnt::where('key', 'liman_price')->value('value'); $mazaneh = ($data['direction'] == 1) ? Cnt::where('key', 'liman_truly_buy_mazaneh')->value('value'):Cnt::where('key', 'liman_truly_sell_mazaneh')->value('value'); $response = Http::withToken(Cnt::where('key', 'liman')->first()['value'])->post("https://liman.gold/server/customer/order", [ "mazaneh" => ((int)$mazaneh), 'amount' => $data['amount'], 'description' =>$this->Config('name_fa')." - ". auth('customer')->user()->name, 'direction' => $data['direction'] , 'product_id' => 2 //2 ])->json(); if(isset($response['message']) && $response['message'] == 'no authorised'){ $cnt = new Cnt(); $cnt->liman_login(); $response = Http::withToken(Cnt::where('key', 'liman')->first()['value'])//$this->Config('liman_token')) ->post("https://liman.gold/server/customer/order", [ "mazaneh" => ((int)$mazaneh), 'amount' => $data['amount'], 'description' =>$this->Config('name_fa')." - ". auth('customer')->user()->name, 'direction' => $data['direction'] , 'product_id' => 2 //2 ])->body(); } if(!isset($response[1]) && !isset($response[1]['id'])){ throw new UnprocessableEntityHttpException('سفارشات توسط ارائه دهنده بسته شده است.'); } } $data['total_price_liman'] = ($data['direction'] == 1) ? ($liman_price+$liman_diff) : ($liman_price-$liman_diff) ; $data['provider_id'] = $response['1']['id']; $transactionType = $data['direction'] == 1 ? "خرید" : "فروش"; if (auth('customer')->id()) { $data['customer_id'] = auth('customer')->id(); $latestPrice = Price::latest()->first(); $data['price'] = $latestPrice->price; $data['price_id'] = $latestPrice->id; $data['difference'] = config('fee.cash'); $data['service_charge_percentage'] = config('fee.service_charge_percentage'); $data['pay_at'] = (new \DateTime())->format('Y-m-d H:i:s'); } else if (auth('user')->id()) { $data['service_charge_percentage'] = 0; } $data['sts'] = 2; $data['type'] = 2; $data['payment_sts'] = 4; $data['price_original'] = $data['price']; $data['total_price_original'] = $data['amount'] * ($data['price_original'] ?? 0); $data['payment_remind'] = 0; $data['fee'] = $data['difference']; $data['total_fee'] = $data['amount'] * $data['difference']; // if(auth('customer')->id() == 4) { // return [$data,'ss']; // } $myCustomer = Customer::where('id', $data['customer_id'])->first(); $wallet_interface = new WalletInterface($data['customer_id'], 2); $wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first(); $response = []; if ($data['direction'] == 1) { $response['buy'] = $this->processBuyTransaction($data, $wallet, $wallet_interface,$myCustomer); } else if ($data['direction'] == 2) { $response['sell'] = $this->processSellTransaction($data, $wallet, $wallet_interface,$myCustomer); } $response['reward'] = $this->give_order_reward($data, $wallet, $wallet_interface); $response['Notifications'] = $this->sendTransactionNotifications($data, $transactionType); return response()->json([$response, $data]); } private function processBuyTransaction(&$data, $wallet, $wallet_interface,$myCustomer) { $response = []; $data['price'] += $data['difference']; $data['total_price'] = $data['amount'] * $data['price']; $data['payment_amount'] = $data['total_price']; $data['service_charge'] = $data['service_charge_percentage'] * $data['amount']; $data['service_charge_price'] = $data['service_charge'] * $data['price_original']; $data['amount'] -= $data['service_charge']; if ($wallet->cash < $data['payment_amount']) { throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است'); } $data['order'] = $order = Order::create($data); new TransactionInterface($wallet_interface, [ "cash" => $data['payment_amount'], "gold" => $data['amount'], 'expire_at' => now(), 'active' => true, 'order_id' => $order->id, 'start_at' => now(), ], 1, true, false); $response['1'] = 2; //send to liman if ($this->Config('do_send_liman') == "true") { // // $payload = [ // 'direction' => $data['direction'], // 'price' => ($data['price']*4.331802), // 'method' => 'liman', // 'pay_at' => now(), // 'amount' => (float) $data['amount'], // 'customer_id' => 23, // 'product_id' => 2, // 'total_price_origina'=> $data['total_price'], // 'description' =>$myCustomer->name, //// 'cash' => $data['payment_amount'], // ]; // try { // $response = Http::withHeaders([ // 'sicrtToket' => 'cl@SX^4&^p$i0kKiI7QG36%l', // ])->get('https://liman.gold/server/api/gholak', $payload)->json(); // }catch (\Exception $e){} } return $response; } private function processSellTransaction(&$data, $wallet, $wallet_interface,$myCustomer) { // if ($data['amount'] < 0.06){ // throw new UnprocessableEntityHttpException('کمترین مقدار مجاز برای فروش 60 سوت است.'); // // } $data['price'] -= $data['difference']; $data['total_price'] = $data['amount'] * $data['price']; $data['payment_amount'] = $data['total_price']; $data['service_charge'] = $data['service_charge_percentage'] * $data['amount']; $data['service_charge_price'] = $data['service_charge'] * $data['price_original']; $data['total_price'] = $data['amount'] * $data['price'] -$data['service_charge_price']; $data['payment_amount'] = $data['total_price']; $data['payment_amount'] -= $data['service_charge_price']; if ($wallet->gold < $data['amount']) { throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است'); } $data['order'] = $order = Order::create($data); new TransactionInterface($wallet_interface, [ "gold" => $data['amount'], "cash" => $data['total_price'], 'expire_at' => now(), 'active' => true, 'order_id' => $order->id ], 2, false, true); // send to liman 1buy 2 sell if ($this->Config('do_send_liman') == "true") { // // $payload = [ // 'direction' => $data['direction'], // 'price' => ($data['price']*4.331802), // 'method' => 'liman', // 'pay_at' => now(), // 'amount' => (float) $data['amount'], // 'customer_id' => 23, // 'product_id' => 2, // 'total_price_origina'=> $data['total_price'], // 'description' =>$myCustomer->name, //// 'cash' => $data['payment_amount'], // ]; // try { // $response = Http::withHeaders([ // 'sicrtToket' => 'cl@SX^4&^p$i0kKiI7QG36%l', // ])->get('https://liman.gold/server/api/gholak', $payload)->json(); // }catch (\Exception $e){} } } //$payload = [ //'direction' => $data['direction'], // خرید (1) یا فروش (2) //'price' => $data['price'], // قیمت //'method' => 'liman', // متد //'pay_at' => now(), // تاریخ و زمان پرداخت //'amount' => $data['amount'], // مقدار //'customer_id' => $data['customer_id'], // شناسه مشتری //'product_id' => $data['product_id'], // شناسه محصول //'total_price_original' => $data['total_price'], // کل قیمت اصلی //'description' => $data['description'], // توضیحات //]; //if ($this->Config('do_send_liman') == "true") { //$payload = [ //'amount' => "$order->amount", //'description' => auth('customer')->user()->name, //'ref_id' => $order->id, //'direction' => 2, //'product_id' => 2 //]; //$response = Http::withToken('cl@SX^4&^p$i0kKiI7QG36%l') //->post("https://liman.gold/server/api/apiOrderGholak", $payload)->json(); //$order->total_price_liman = $response["payment_amount"]; //$order->save(); //} private function give_order_reward(&$data, $wallet, $wallet_interface) { $data['aCustomers'] = []; $i = 0; $data['aCustomers'][$i] = Customer::findOrFail($data['customer_id']); while ($data['aCustomers'][$i+1] = Customer::where('referral_id', $data['aCustomers'][$i]->referral_to_id)->first()) { if ($data['aCustomers'][$i+1]->profit_amount_by_lvl) { $levels = $data['aCustomers'][$i+1]->profit_amount_by_lvl; foreach ($levels as $level){ if ((int)$level['level']==$i+1){ $data['mobin2004']=[$level,$level['level'],(int)$level['level']]; // [$level[1],$data['aCustomers'][$i+1]]; if ($this->Config('has_page_earn_money') == true){ $gift_for_invite = ($data['order']['service_charge'] * (int)$level["present"]) /100 ; $profit_receiver = $data['aCustomers'][$i+1]->id; $profit_sender = $data['aCustomers'][0]->id; $Withdraw = Withdraw::create([ 'user_id' => $profit_sender, 'customer_id' => $profit_receiver, "cash" => 0, "gold" => $gift_for_invite, 'sts' => 9, ]); $wallet_interface = new WalletInterface($profit_receiver, 2); new TransactionInterface($wallet_interface, $_inp = [ "cash" => 0, "gold"=> $gift_for_invite, 'expire_at'=>now(), 'active'=>true, 'withdraw_id' =>$Withdraw->id, 'start_at'=>now(), ], 9, true,false); $transaction = Transaction::where('customer_id', $profit_receiver)->latest()->first(); TransactionsAdmin::create([ 'customer_id' => $profit_sender, 'customer_to_id' =>$profit_receiver, 'user_id' => $profit_sender, 'order_id' => $data['order']['id'], 'wallet' => null, // یا مقدار مناسب دیگری 'transaction_id' => $transaction->id , 'cash' => 0, 'note' => ' سود بابت سفارش', 'type' => 1, // یا مقدار مناسب دیگری 'gold' => $gift_for_invite, 'balance_cash' => 0, // یا مقدار مناسب دیگری 'balance_gold' => $gift_for_invite, // مقدار صحیح برای `balance_gold` 'withdraw_id' => $Withdraw->id, ]); } } } } if ($i == 100) break;$i++; // برای جلوگیری از حلقه بینهایت } return $data; } private function sendTransactionNotifications(array $data, string $transactionType) { $customer = Customer::findOrFail($data['customer_id']); $companyName = $this->Config('name_fa'); $message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType طلا به مقدار " . "{$data['amount']} گرم به مبلغ " . number_format($data['total_price']) . " ریال کرد. با تشکر، $companyName"; User::where('send_sms', 1)->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) { $this->send($admin->mobile, $message); }); // User::whereNotNull('telegram')->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) { // $this->SendTelegram($admin->telegram, $message); // }); $messageold = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType طلا به مقدار " . "{$data['amount']} گرم به مبلغ " . number_format($data['total_price']) . " ریال کرد. با تشکر، $companyName"; $azOrTa = $data['direction'] == 1 ? 'از' : 'به'; $messageExam = " {$transactionType} قلک طلا $azOrTa شما {$data['amount']} گرم در مظنه " . number_format($data['price_original']) . " ریال"; // User::whereNotNull('telegram')->get()->each(function ($admin) use ($messageExam) { // $this->SendTelegram($admin->telegram, $messageExam); // }); User::where('send_sms', 1)->get()->each(function ($admin) use ($messageExam) { $this->send($admin->mobile, $messageExam); }); $wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first(); $pricePerGram = $data['total_price'] / $data['amount']; $customerMessage = "$companyName\n$transactionType آبشده\nگرم: {$data['amount']}\nقیمت گرم: " . number_format($pricePerGram) . "\nمبلغ کل: " . number_format($data['total_price']) . "\n\nموجودی طلایی: {$wallet->gold}\n" . "مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url'); // ارسال SMS به مشتری $this->send($customer->mobile, $customerMessage); } public function storeBackUp(Request $request) { $data = $request->all(); if (auth('customer')->id()) {// متد در پنل کاربر $data['customer_id'] = auth('customer')->id(); $data['price'] = Price::orderBy('id', 'desc')->first()->price; } elseif (auth('user')->user()) {// متد در پنل ادمین $data['customer_id'] = $request->customer_id; $data['price'] = $request->price; } $data['sts'] = 2; $data['type'] = 2; $data['payment_sts'] = 4; $data['price_original'] = $data['price']; $add_sell_price = config('add_sell_price.single'); $wallet_interface = new WalletInterface($data['customer_id'], 2); $wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first(); $data['total_price_original'] = $data['amount'] * $data['price_original']; $data['payment_remind'] = 0; $data['fee'] = $add_sell_price; $data['total_fee'] = $data['amount'] * $data['fee']; if ($data['direction'] == 1) { $data['price'] += $add_sell_price; $data['total_price'] = $data['amount'] * $data['price']; $data['payment_amount'] = $data['total_price']; if ($wallet->cash < $data['total_price']) { throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است'); } $order = Order::create($data);//buy new TransactionInterface($wallet_interface, $_inp = [ "cash" => $data['total_price'], "gold" => $data['amount'], 'expire_at' => now(), 'active' => true, 'order_id' => $order->id, 'start_at' => now(), ], 1, true, false); } else {//sell $data['price'] -= $add_sell_price; $data['total_price'] = $data['amount'] * $data['price']; $data['payment_amount'] = $data['total_price']; if ($wallet->gold < $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); } //----------------------------------------------------------------------------sms // Determine transaction type $transactionType = ($data['direction'] == 1) ? "خرید" : "فروش"; // User information $customer = Customer::where("id", $data['customer_id'])->firstOrFail(); $userMobile = $customer->mobile; // User's mobile number $userName = $customer->name; // User's name $chargedAmount = $data['total_price']; // Total price in Rial $chargedAmountGold = $data['amount']; // Amount of gold // Company name $companyName = $this->Config('name_fa'); // Company name from configuration // Constructing the SMS message $message = "کاربر $userName با شماره موبایل $userMobile اقدام به $transactionType طلا به مقدار " . $chargedAmountGold . " گرم به مبلغ " . number_format($chargedAmount) . " ریال کرد. با تشکر، $companyName"; // Getting admin mobile numbers and sending the SMS User::where('active', 1)->get()->each(function ($admin) use ($message) { $this->Send($admin->mobile, $message); }); $Walet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first(); $companyName = $this->Config('name_fa'); $companyurl = $this->Config('app_url'); $weight = $data['amount']; $totalAmount = $data['total_price']; $pricePerGram = $totalAmount / $weight; $goldBalance = $Walet->gold; $remainingBalance = $Walet->cash; $message = "$companyName\n"; $message .= "خرید آبشده\n"; $message .= "گرم: $weight\n"; $message .= "قیمت گرم: " . number_format($pricePerGram) . "\n"; $message .= "مبلغ کل: " . number_format($totalAmount) . "\n\n"; $message .= "موجودی طلایی: $goldBalance\n"; $message .= "مانده ریالی: " . number_format($remainingBalance) . "\n"; $message .= "$companyurl" . "\n"; $this->Send($customer->mobile, $message); return response()->json($order); } public function table(Request $request) { $records = Order::where('customer_id', auth('customer')->id()) ->where('type', 2); TableEngine::create($records, $request->all()) ->initSearch([]) ->select([ '*', Order::$SELECT_STS_STR ])->export($records); return response()->json($records); } }
Copyright ©2k19 -
Hexid
|
Tex7ure