Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function tarikDanaWallet(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'amount' => 'required',
- ]);
- if ($validator->fails()) {
- return response()->json([
- 'success' => false,
- 'messages' => 'Please fill in the blank !',
- 'data' => $validator->errors(),
- ], 403);
- }
- $getUser = Auth::User();
- if ($request->amount > $getUser->uang) {
- return response()->json([
- 'success' => false,
- 'messages' => 'Nominal Terlalu Besar !',
- 'data' => [],
- ], 403);
- }
- // $getUser->uang = $getUser->uang - $request->amount; // ketika verifiasi/done saja oleh cfo (roni)
- // $getUser->save();
- // get saldo akhir transaksi/withdraw terakhir
- $transaksiSaldoAkhir = TransaksiKeuangan::where('user_id', $getUser->_id)->where('tag', 'WITHDRAW WALLET')->orderBy('created_at', 'desc')->first();
- if ($transaksiSaldoAkhir) {
- $uangAkhir = $transaksiSaldoAkhir->saldo_akhir;
- } else {
- $uangAkhir = $getUser->uang;
- }
- // insert ke transaksi keuangan
- $HistoryBonusMitra = TransaksiKeuangan::create([
- 'user_id' => Auth::id(),
- 'tanggal_transaksi' => date('Y-m-d'),
- 'tipe' => "OUT",
- 'nominal' => (int) $request->amount,
- 'saldo_akhir' => (int) $uangAkhir - $request->amount,
- 'tag' => "WITHDRAW WALLET",
- 'keterangan' => "Penarikan Dompet Mitra",
- 'status' => "PENGAJUAN",
- ]);
- if ($HistoryBonusMitra) {
- // Mail::send(new \App\Mail\SendNotifications(Auth::User(), 'mitraWithDraw', $HistoryBonusMitra));
- }
- if (!empty($getUser)) {
- return response()->json([
- 'success' => true,
- 'messages' => 'Tarik Dana Berhasil !',
- 'data' => [
- 'id' => $getUser->_id,
- 'nama' => $getUser->name,
- 'nominal' => $getUser->uang,
- ],
- ], 200);
- } else {
- return response()->json([
- 'success' => false,
- 'messages' => 'User Not Found !',
- 'data' => null,
- ], 403);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement