feat: add deposit receipt upload and admin approval/rejection workflow with SMS

This commit is contained in:
2026-11-08 13:26:28 +03:30
parent 808c272e0c
commit 885e51a79b
6 changed files with 322 additions and 3 deletions
@@ -1535,4 +1535,167 @@ class WalletController extends Controller
);
}
public function approveDeposit(Request $request)
{
$request->validate([
'id' => 'required|integer|exists:withdraws,id',
'tracked_number' => 'nullable|string|max:100',
]);
$withdraw = Withdraw::with(['customer', 'Transaction'])->findOrFail($request->id);
if ((int) $withdraw->sts === 2) {
return response()->json(['message' => 'این تراکنش قبلاً تایید شده است.'], 422);
}
$customer = $withdraw->customer ?: Customer::find($withdraw->customer_id);
if (!$customer) {
return response()->json(['message' => 'مشتری مربوطه یافت نشد.'], 404);
}
$adminId = auth('user')->id() ?: auth()->id();
$amount = (float) $withdraw->cash;
DB::transaction(function () use ($withdraw, $customer, $adminId, $amount, $request) {
$withdraw->sts = 2; // واریز شد
$withdraw->user_id = $adminId;
if ($request->filled('tracked_number')) {
$withdraw->tracked_number = trim((string) $request->tracked_number);
}
if (empty($withdraw->date_at)) {
$withdraw->date_at = now();
}
$withdraw->save();
$hasExistingCredit = Transaction::where('withdraw_id', $withdraw->id)
->where('cash', '>', 0)
->exists();
if (!$hasExistingCredit && $amount > 0) {
$walletInterface = new WalletInterface((int) $customer->id, (int) $customer->type);
new TransactionInterface($walletInterface, [
'gold' => 0,
'cash' => $amount,
'expire_at' => now(),
'note' => $withdraw->note ?: 'واریز نقدی (فیش بانکی)',
'withdraw_id' => $withdraw->id,
'active' => true,
], 3, true, true);
$this->recordAccountingTransaction(
$customer,
$withdraw,
(int) $adminId,
$amount,
0,
$withdraw->note ?: 'واریز نقدی (فیش بانکی)'
);
if (app(ConfigService::class)->isTahesabAccounting()) {
try {
app(TahesabController::class)->wallet([
'customer_id' => $customer->id,
'value' => $amount,
'direction' => 0,
'withdraw_id' => $withdraw->id,
'note' => $withdraw->note ?: 'شارژ حساب (فیش بانکی)',
]);
} catch (\Throwable $e) { report($e); }
}
if (app(ConfigService::class)->isZarinAccounting()) {
try {
app(\App\Http\Controllers\Admin\ZarinController::class)->wallet([
'customer_id' => $customer->id,
'value' => $amount,
'direction' => 0,
'withdraw_id' => $withdraw->id,
'note' => $withdraw->note ?: 'شارژ حساب (فیش بانکی)',
]);
} catch (\Throwable $e) { report($e); }
}
if (app(ConfigService::class)->isShayeganAccounting()) {
try {
app(\App\Http\Controllers\Admin\ShayeganController::class)->wallet([
'customer_id' => $customer->id,
'value' => $amount,
'direction' => 0,
'withdraw_id' => $withdraw->id,
'note' => $withdraw->note ?: 'شارژ حساب (فیش بانکی)',
]);
} catch (\Throwable $e) { report($e); }
}
try {
app(PargarSyncService::class)->queueWalletDocument(
$customer,
'cash',
$amount,
[
'withdraw_id' => $withdraw->id,
'note' => $withdraw->note ?: 'واریز نقدی',
'source' => 'deposit_receipt',
]
);
} catch (\Throwable $e) { report($e); }
}
});
$this->broadcastCustomerWalletAssets($customer);
try {
$appName = app(ConfigService::class)->getString('name_fa', 'سامانه');
$amountFormatted = number_format((int) $amount);
$trackedInfo = $withdraw->tracked_number ? "\nکد پیگیری: {$withdraw->tracked_number}" : '';
$smsMsg = "مشتری گرامی {$customer->name}\nدرخواست واریز شما به مبلغ {$amountFormatted} ریال تایید و به موجودی کیف پول شما افزوده شد.{$trackedInfo}\n{$appName}";
Controller::SendMessage($customer->mobile, $smsMsg, true, 'sms');
} catch (\Throwable $e) {
report($e);
}
return response()->json([
'message' => 'درخواست واریز با موفقیت تایید و مبلغ به کیف پول مشتری واریز شد.',
'withdraw' => $withdraw->fresh(['customer', 'Transaction']),
]);
}
public function rejectDeposit(Request $request)
{
$request->validate([
'id' => 'required|integer|exists:withdraws,id',
'reject_reason' => 'nullable|string|max:500',
]);
$withdraw = Withdraw::with('customer')->findOrFail($request->id);
if ((int) $withdraw->sts === 2) {
return response()->json(['message' => 'این تراکنش قبلاً تایید شده و امکان رد آن وجود ندارد.'], 422);
}
$adminId = auth('user')->id() ?: auth()->id();
$withdraw->sts = 3; // رد شده
$withdraw->user_id = $adminId;
$withdraw->reject_reason = $request->reject_reason ? trim((string) $request->reject_reason) : null;
$withdraw->save();
$customer = $withdraw->customer ?: Customer::find($withdraw->customer_id);
if ($customer) {
try {
$appName = app(ConfigService::class)->getString('name_fa', 'سامانه');
$amountFormatted = number_format((int) $withdraw->cash);
$reasonText = $withdraw->reject_reason ? "\nعلت رد: {$withdraw->reject_reason}" : '';
$smsMsg = "مشتری گرامی {$customer->name}\nدرخواست واریز شما به مبلغ {$amountFormatted} ریال متأسفانه رد شد.{$reasonText}\n{$appName}";
Controller::SendMessage($customer->mobile, $smsMsg, true, 'sms');
} catch (\Throwable $e) {
report($e);
}
}
return response()->json([
'message' => 'درخواست واریز رد شد و پیامک به مشتری ارسال گردید.',
'withdraw' => $withdraw->fresh(['customer']),
]);
}
}