/
home
/
pay
/
server_old
/
app
/
Http
/
Controllers
/
Customer
/
File Upload :
llllll
Current File: /home/pay/server_old/app/Http/Controllers/Customer/FundController.php
<?php namespace App\Http\Controllers\Customer; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Http\Controllers\SuperController; use App\Models\Fund; 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 FundController extends SuperController { public function __construct(Request $request) { $model = Fund::class; $this->with=['wallet']; $select = ['*']; $search=['name']; $request->request->add(['customer_id'=>auth('customer')->id()]); $query = Fund::with($this->with)->where('customer_id',auth('customer')->id()); parent::__construct($model, $this->with, $select, null,$query,$search); } public function deposit(Request $request){ $data = $request->all(); $wallet_interface = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type,null); $wallet = $wallet_interface->wallet; if($wallet->gold < $data['value']){ throw new UnprocessableEntityHttpException('موجودی کمتر از مقدار وارد شده است'); } $transaction = new TransactionInterface($wallet_interface, $_inp = [ "gold" => $data['value'], "fund_id"=>$data["fund_id"], 'expire_at'=>now(), 'active'=>true ], 6, false); $wallet_interface_fund = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type,$data["fund_id"]); $transaction = new TransactionInterface($wallet_interface_fund, $_inp = [ "gold" => $data['value'], "fund_id"=>$data["fund_id"], 'expire_at'=>now(), 'active'=>true ], 5, true); return response()->json(true); } public function withdraw(Request $request){ $data = $request->all(); $wallet_interface_fund = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type,$data["fund_id"]); $wallet = $wallet_interface_fund->wallet; if($wallet->gold < $data['value']){ throw new UnprocessableEntityHttpException('موجودی کمتر از مقدار وارد شده است'); } $transaction = new TransactionInterface($wallet_interface_fund, $_inp = [ "gold" => $data['value'], "fund_id"=>$data["fund_id"], 'expire_at'=>now(), 'active'=>true ], 6, false); $wallet_interface = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type); $transaction = new TransactionInterface($wallet_interface, $_inp = [ "gold" => $data['value'], "fund_id"=>$data["fund_id"], 'expire_at'=>now(), 'active'=>true ], 5, true); return response()->json(true); } public function show($id){ $query = Fund::with($this->with)->findOrFail($id); return response()->json($query); } public function destroy($id){ $wallet_interface_fund = Wallet::where('owner',auth('customer')->id())->where('fund_id',$id)->first(); if (!is_null($wallet_interface_fund)){ if ($wallet_interface_fund->gold > 0){ throw new UnprocessableEntityHttpException('به علت داشتن موجودی امکان حذف صندوق وجود ندارد'); } } Fund::destroy($id); return response()->json(true); } public function transactionTable(Request $request){ $records = Transaction::where('wallet',$request->wallet_id); TableEngine::create($records, $request->all()) ->initSearch([]) ->select([ '*',Transaction::$SELECT_CAJ,Transaction::$SELECT_TYPE_STR ])->export($records); return response()->json($records); } }
Copyright ©2k19 -
Hexid
|
Tex7ure