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
@@ -524,6 +524,96 @@ class WalletController extends Controller
return response()->json($Withdraw);
}
public function depositRequest(Request $request)
{
$customer = auth('customer')->user();
if (!$customer) {
throw new UnprocessableEntityHttpException('کاربر یافت نشد.');
}
$request->validate([
'cash' => 'required|numeric|min:1000',
'receipt' => 'required|file|mimes:jpeg,jpg,png,webp,pdf|max:10240',
'tracked_number' => 'nullable|string|max:100',
'extra_note' => 'nullable|string|max:500',
], [
'cash.required' => 'مبلغ واریزی الزامی است.',
'cash.numeric' => 'مبلغ واریزی باید به صورت عددی باشد.',
'cash.min' => 'حداقل مبلغ واریزی معتبر نیست.',
'receipt.required' => 'بارگذاری تصویر فیش واریزی الزامی است.',
'receipt.file' => 'فایل فیش ارسالی نامعتبر است.',
'receipt.mimes' => 'فرمت فیش واریزی باید یکی از فرمت‌های jpg, png, webp یا pdf باشد.',
'receipt.max' => 'حجم فایل فیش واریزی نباید بیش از ۱۰ مگابایت باشد.',
]);
$uploaded = $request->file('receipt');
$now = verta();
$dirPath = 'receipts/' . $now->year . '/' . sprintf('%02d', $now->month);
$disk = \Illuminate\Support\Facades\Storage::disk('public');
if (! $disk->exists($dirPath)) {
$disk->makeDirectory($dirPath);
}
$ext = $uploaded->getClientOriginalExtension() ?: 'jpg';
$fileName = md5(time() . '_' . $uploaded->getClientOriginalName() . '_' . $customer->id) . '.' . $ext;
$stored = $disk->putFileAs($dirPath, $uploaded, $fileName);
if (! $stored) {
throw new UnprocessableEntityHttpException('خطا در ذخیره تصویر فیش واریزی.');
}
$relativePath = 'storage/' . $stored;
try {
\App\Models\File::create([
'original_name' => $uploaded->getClientOriginalName(),
'ext' => $ext,
'title' => 'فیش واریز ' . ($customer->name ?? ''),
'has_thumb' => false,
'size' => $uploaded->getSize(),
'src' => $relativePath,
'user_id' => $customer->id,
]);
} catch (\Throwable $e) {
report($e);
}
$nationalCode = trim((string) ($customer->n_code ?? ''));
$withdraw = Withdraw::create([
'customer_id' => $customer->id,
'cash' => (float) $request->cash,
'gold' => 0,
'type' => 1,
'sts' => 1,
'tracked_number' => $request->tracked_number ? trim((string) $request->tracked_number) : null,
'deposit_identifier' => $nationalCode ?: null,
'receipt' => $relativePath,
'extra_note' => $request->extra_note ? trim((string) $request->extra_note) : null,
'note' => 'درخواست واریز نقدی (فیش بانکی)',
'date_at' => now(),
]);
try {
$companyName = $this->Config('name_fa');
$amountFormatted = number_format((int) $request->cash);
$userName = $customer->name ?? 'مشتری';
$userMobile = $customer->mobile ?? '';
$message = "کاربر $userName با شماره موبایل $userMobile درخواست واریز مبلغ {$amountFormatted} ریال با شناسه واریز {$nationalCode} ثبت نمود. با تشکر، $companyName";
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
if (self::isSmsNotifEnabled('sms_notif_withdraw_admin')) {
$this->Send($admin->mobile, $message . ' ' . now()->format('H:i:s'));
}
});
} catch (\Throwable $e) {
report($e);
}
return response()->json([
'message' => 'درخواست واریز شما با موفقیت ثبت شد و پس از بررسی تایید خواهد شد.',
'withdraw' => $withdraw->loadMissing('customer'),
]);
}
private function formatDeliveryQuantity(float $value): string
{
$rounded = round($value, 3);