/
home
/
pay
/
server_old
/
app
/
Http
/
Controllers
/
Customer
/
File Upload :
llllll
Current File: /home/pay/server_old/app/Http/Controllers/Customer/WalletController.php
<?php namespace App\Http\Controllers\Customer; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Models\Order; use App\Models\User; use App\Models\Withdraw; use App\Models\BankAccount; use App\Models\Price; 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 Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; class WalletController extends Controller { public function walletMe(){ $wallet = Wallet::select(['owner','id','gold','cash'])->where('owner',auth('customer')->id()) ->first(); $wallet['gold_sum'] =round(Wallet::where('owner', auth('customer')->id())->sum('gold'), 2); return response()->json($wallet); } public function priceData(Request $request){ $prise = Price::with('order'); TableEngine::create($prise, $request) ->initSearch(['price']) ->select(['*']) ->export($prise); return response()->json($prise); } public function transactionTable(Request $request){ $wallet = Wallet::where('owner',auth('customer')->id())->whereNull('fund_id') ->first(); if (is_null($wallet)){ $records = ['query'=>['total'=>0],'rows'=>[]]; }else{ $records = Transaction::with(['order'=>function($q){ return $q->select(['*',Order::$SELECT_STS_STR]); },'withdraw'=>function($q){ return $q->select(['*',Order::$SELECT_STS_STR]); }])->where('wallet',$wallet->id)->whereNull('fund_id'); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ '*',Transaction::$SELECT_CAJ,Transaction::$SELECT_TYPE_STR,Transaction::$SELECT_SAJ,Transaction::$SELECT_EAJ ])->export($records); } return response()->json($records); } public function withdraw(Request $request){ $customer = auth('customer')->user(); $data = $request->all(); if (!isset($data['card_id'])){ return response()->json(['message' => 'کارت انتخاب نشده'], 422); } if (BankAccount::where('id', $data['card_id'])->first()->sts != 2){ return response()->json(['message' => 'کارت انتخاب شده غیر فعال است یا ردشده'], 422); } $wallet_interface_fund = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type); $wallet = $wallet_interface_fund->wallet; if ($data['value'] < 0){ throw new UnprocessableEntityHttpException('مقدار برداشت باید مثبت باشد'); } if ($data['value'] > $wallet->cash){ throw new UnprocessableEntityHttpException('مقدار برداشت بیشتر از موجودی است'); } $Withdraw =Withdraw::create([ 'customer_id'=>auth('customer')->id(), "cash" => $data['value'], "bank_account_id" => $data['card_id'], 'sts'=>1 ]); $transaction = new TransactionInterface($wallet_interface_fund, $_inp = [ "cash" => $data['value'], 'expire_at'=>now(), 'withdraw_id'=>$Withdraw->id, 'active'=>true ], 4, false,false); //----------sms // User information $userMobile = $customer->mobile; // User's mobile number $userName = $customer->name; // User's name $withdrawAmount = $data['value']; // amount // Company name $companyName = config('company'); // Company name from configuration // Constructing the SMS message $message = "کاربر $userName با شماره موبایل $userMobile درخواست برداشت مبلغ " . number_format($withdrawAmount) . " ریال را دارد. با تشکر، $companyName"; // Getting admin mobile numbers and sending the SMS User::where('active', 1) ->where('send_sms', 1)->get()->each(function($admin) use ($message) { $this->Send($admin->mobile, $message); }); return response()->json(true); } }
Copyright ©2k19 -
Hexid
|
Tex7ure