/
home
/
pay
/
server
/
app
/
Http
/
Controllers
/
Admin
/
File Upload :
llllll
Current File: /home/pay/server/app/Http/Controllers/Admin/WalletController.php
<?php namespace App\Http\Controllers\Admin; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\Order; use App\Models\Price; use Illuminate\Support\Facades\DB; use App\Models\Withdraw; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Rooyesh\Wallet\interfaces\TransactionInterface; use Rooyesh\Wallet\interfaces\WalletInterface; use Rooyesh\Wallet\models\Transaction; use Rooyesh\Wallet\models\Wallet; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; class WalletController extends Controller { public function charge(Request $request){ $data = $request->all(); $customer = Customer::findOrFail($data['customer_id']); $deposit = false; if ($data['value'] >0 ){ $deposit = true; } $wallet = Wallet::where('owner',$data['customer_id'])->whereNull('fund_id')->first(); if (is_null($wallet) && !$deposit){ throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست'); } if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit){ throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست'); } $wallet_interface = new WalletInterface($data['customer_id'],$customer->type ); $orders = Order::where('customer_id',$data['customer_id'])->where('sts',1)->get(); $gold_block = 0; if (count($orders) > 0){ $value = $data['value']; foreach ($orders as $order){ if($value < $order->payment_remind){ $order->payment_amount += $value; $order->payment_remind -= $value; $order->save(); break; }else{ $value -= $order->payment_remind; $order->payment_amount = $order->total_price; $order->payment_remind = 0; $order->sts=2; $gold_block -= $order->amount; $order->save(); } } } $user = auth()->user(); $customer = Customer::findOrFail($data["customer_id"]); $Withdraw = Withdraw::create([ 'user_id' => $user->id, 'customer_id' => $customer->id, "cash" => $data['value'], 'sts' => 4, ]); new TransactionInterface($wallet_interface, $_inp = [ 'cash'=> $data['value'], 'expire_at'=>now(), 'withdraw_id' =>$Withdraw->id, 'active'=>true ], 3,false,true,$gold_block); $message ='کیف پول شما به مبلغ '.$data['value']. " ریال در تاریخ ".verta()->format('Y/n/j H:i:s')." شارژ شد "."\n" .$this->Config('name_fa'); $this->Send($customer->mobile,$message); return response()->json(true); } public function charge_gold(Request $request){ $data = $request->all(); $customer = Customer::findOrFail($data['customer_id']); $deposit = false; if ($data['value'] >0 ){ $deposit = true; } $wallet = Wallet::where('owner',$data['customer_id'])->whereNull('fund_id')->first(); if (is_null($wallet) && !$deposit){ throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست'); } if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit){ throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست'); } $wallet_interface = new WalletInterface($data['customer_id'],$customer->type ); $orders = Order::where('customer_id',$data['customer_id'])->where('sts',1)->get(); $gold_block = 0; if (count($orders) > 0){ $value = $data['value']; foreach ($orders as $order){ if($value < $order->payment_remind){ $order->payment_amount += $value; $order->payment_remind -= $value; $order->save(); break; }else{ $value -= $order->payment_remind; $order->payment_amount = $order->total_price; $order->payment_remind = 0; $order->sts=2; $gold_block -= $order->amount; $order->save(); } } } $user = auth()->user(); $customer = Customer::findOrFail($data["customer_id"]); $Withdraw = Withdraw::create([ 'user_id' => $user->id, 'customer_id' => $customer->id, "gold" => $data['value'], "note" => $data['note'], 'sts' => 4, ]); new TransactionInterface($wallet_interface, $_inp = [ 'cash'=>0, 'gold'=> $data['value'], 'expire_at'=>now(), "note" => $data['note'], 'withdraw_id' =>$Withdraw->id, 'active'=>true ], 7,true,true,$gold_block); $message ='کیف پول شما به اندازه '.$data['value']. " گرم در تاریخ ".verta()->format('Y/n/j H:i:s')." شارژ شد بابت"."\n" .$data['note'] .$this->Config('name_fa'); $this->Send($customer->mobile,$message); return response()->json(true); } public function index(Request $request){ $records = Transaction::with(['customer'])->whereNull('fund_id'); TableEngine::create($records, $request->all()) ->initSearch(['order_id','customer.name']) ->select([ '*',Transaction::$SELECT_CAJ,Transaction::$SELECT_TYPE_STR,Transaction::$SELECT_SAJ,Transaction::$SELECT_EAJ ])->export($records); return response()->json($records); } public function indexWallet(Request $request) { // محاسبهی مجموع gold و cash به ازای هر owner $records = Wallet::with('customer'); // ایجاد جدول با استفاده از TableEngine TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select(['*']) ->export($records); // محاسبهی قیمت آخرین قیمت و مجموع کلی مقادیر gold و cash $lastPrice = Price::latest()->first()->price; $walletQuery = Wallet::where('owner', '!=', 4); $sums = [ "gold" => round($walletQuery->sum('gold'), 2), "goldToCash" => round($walletQuery->sum('gold') * $lastPrice, 2), "cash" => round($walletQuery->sum('cash'), 2), "cashToGold" => round($walletQuery->sum('cash') / $lastPrice, 2), ]; // $sums = [ // "gold" => round(Wallet::whereNot('owner', 4)->sum('gold'), 2), // "goldToCash" => round(Wallet::sum('gold') * $lastPrice, 2), // "cash" => round(Wallet::sum('cash'), 2), // "cashToGold" => round(Wallet::sum('cash') / $lastPrice, 2), // "on" => $lastPrice, // ]; // افزودن sums به records $records['sums'] = $sums; return response()->json($records); } public function indexWithdraw(Request $request){ $records = Withdraw::with(['customer','bank_account']); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ '*',Withdraw::$SELECT_STS_STR,Withdraw::$SELECT_DAJ ])->export($records); return response()->json($records); } public function completeWithdraw(Request $request){ $data = $request->all(); $data['user_id'] = auth('user')->id(); $data['sts'] = 2; $data['date_at'] = now(); Withdraw::findOrFail($data['id'])->update($data); return response()->json(true); } }
Copyright ©2k19 -
Hexid
|
Tex7ure