芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/tblonline.org/app/Http/Controllers/WithdrawController.php
with('user') ->with('currency') ->where('type', 'Withdraw') ->orderBy("transactions.id", "desc"); return Datatables::eloquent($transactions) ->editColumn('user.name', function ($transaction) { return '
' . $transaction->user->name . '
' . $transaction->user->email; }) ->editColumn('amount', function ($transaction) { return decimalPlace($transaction->amount, currency($transaction->currency->name)); }) ->editColumn('status', function ($transaction) { return transaction_status($transaction->status); }) ->addColumn('action', function ($transaction) { return '
' . '
' . _lang('View') . '
' . csrf_field() . '
' . '
' . _lang('Delete') . '
' . '
'; }) ->setRowId(function ($transaction) { return "row_" . $transaction->id; }) ->rawColumns(['user.name', 'status', 'action']) ->make(true); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(Request $request) { if (!$request->ajax()) { return view('backend.withdraw.create'); } else { return view('backend.withdraw.modal.create'); } } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { @ini_set('max_execution_time', 0); @set_time_limit(0); $validator = Validator::make($request->all(), [ 'user_email' => 'required', 'currency_id' => 'required', 'amount' => 'required|numeric|min:1.00', ]); if ($validator->fails()) { if ($request->ajax()) { return response()->json(['result' => 'error', 'message' => $validator->errors()->all()]); } else { return back()->withErrors($validator)->withInput(); } } $user = User::where('email', $request->user_email)->where('user_type', 'customer')->first(); if (!$user) { return back()->with('error', _lang('User Account not found !'))->withInput(); } //Check Available Balance if (get_account_balance($request->currency_id, $user->id) < $request->amount) { if (!$request->ajax()) { return back()->with('error', _lang('Insufficient balance !'))->withInput(); } else { return response()->json(['result' => 'error', 'message' => _lang('Insufficient balance !')]); } } $transaction = new Transaction(); $transaction->user_id = $user->id; $transaction->currency_id = $request->input('currency_id'); $transaction->amount = $request->input('amount'); $transaction->dr_cr = 'dr'; $transaction->type = 'Withdraw'; $transaction->method = 'Manual'; $transaction->status = 2; $transaction->note = $request->input('note'); $transaction->created_user_id = auth()->id(); $transaction->branch_id = auth()->user()->branch_id; $transaction->save(); try { $transaction->user->notify(new WithdrawMoney($transaction)); } catch (\Exception $e) {} if (!$request->ajax()) { return back()->with('success', _lang('Withdraw made successfully')); } else { return response()->json(['result' => 'success', 'action' => 'store', 'message' => _lang('Withdraw made successfully'), 'data' => $transaction, 'table' => '#transactions_table']); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request, $id) { $transaction = Transaction::find($id); if (!$request->ajax()) { return view('backend.withdraw.view', compact('transaction', 'id')); } else { return view('backend.withdraw.modal.view', compact('transaction', 'id')); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $transaction = Transaction::find($id); $transaction->delete(); return redirect()->route('withdraw.index')->with('success', _lang('Deleted Successfully')); } }