/
home
/
old_henza
/
server
/
app
/
Http
/
Controllers
/
Adm
/
File Upload :
llllll
Current File: /home/old_henza/server/app/Http/Controllers/Adm/WalletController.php
<?php namespace App\Http\Controllers\Adm; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Models\ConfigStatic; use App\Models\SingleCustomer; use App\Models\SingleCustomerOrders; 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 charge(Request $request){ $data = $request->all(); $deposit = false; if ($data['value'] >0 ){ $deposit = true; } $wallet = Wallet::where('owner',$data['customer_id'])->first(); if (is_null($wallet) && !$deposit){ throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست'); } if (!is_null($wallet) && $wallet->credit < abs($data['value']) && !$deposit){ throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست'); } $wallet_interface = new WalletInterface($data['customer_id'], 1); $transaction = new TransactionInterface($wallet_interface, $_inp = [ "value" => $data['value'], 'expire_at'=>now()->addYear(), 'active'=>true ], 2, $deposit); return response()->json(true); } public function changePercent(Request $request){ $data = $request->all(); SingleCustomer::query()->update(['percent'=>$data['percent']]); return response()->json(true); } public function index(Request $request){ $records = Transaction::with(['customer','order'=>function($q){ return $q->select(['id',SingleCustomerOrders::$SELECT_CAJ]); }]); TableEngine::create($records, $request->all()) ->initSearch(['order_id','customer.name']) ->select([ 'value','expire_at','note','customer_id','order_id','id','transaction_type' ])->export($records); return response()->json($records); } public function setConst(Request $request){ $data = $request->all(); foreach ($data as $key=>$item){ $config = ConfigStatic::firstOrNew(['key' => $key]); $config->val = $item; $config->save(); } return response()->json(true); } public function getConfig(){ $config = ConfigStatic::whereIn('key',['percent','expire'])->get(); return response()->json($config); } public function getConfigBirthday(){ $config = ConfigStatic::whereIn('key',['birthday_credit','birthday_expire'])->get(); return response()->json($config); } }
Copyright ©2k19 -
Hexid
|
Tex7ure