From c96e5820fedfb0052a4504be475467ff7eb72c43 Mon Sep 17 00:00:00 2001 From: safavimohadeseh78 Date: Sun, 1 Nov 2026 13:44:48 +0330 Subject: [PATCH] feat(convert): text the customer when a convert request is approved or rejected The message goes out after the result is saved, and a send failure does not undo the approval or rejection. Co-authored-by: Cursor --- .../abshode-domain-lookup/learned-notes.md | 1 + app/Services/CopperConvertRequestService.php | 55 ++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/.cursor/skills/abshode-domain-lookup/learned-notes.md b/.cursor/skills/abshode-domain-lookup/learned-notes.md index 26e55b8..88b1510 100644 --- a/.cursor/skills/abshode-domain-lookup/learned-notes.md +++ b/.cursor/skills/abshode-domain-lookup/learned-notes.md @@ -3,6 +3,7 @@ فرمت هر خط: - YYYY-MM-DD | موضوع | مسیر فایل(ها) | نکتهٔ ۱ خطی +- 2026-11-01 | پیامک تبدیل | `CopperConvertRequestService::notifyCustomer` | بعد از تأیید یا رد، پیامک جدا به موبایل مشتری؛ خطا پیامک سفارش را برنمی‌گرداند - 2026-11-01 | درخواست تبدیل مس | `CopperConvertRequestService` + `copper_convert_requests` + `POST customer/copper-convert-request` + `admin/copper-convert-request/{id}/approve` | تأیید = فروش دارایی و خرید حلقه با quote_unit_price؛ مهاجرت `2026_11_01_000001` - 2026-10-28 | شایگان کالا/مشتری | `products.shayegan_item_number` + `ShayeganSyncService::registerCustomer` Account/Put + `ensureCustomerAccountNumber` | بانک 10001 و معین 12101 در settings؛ ItemNumber per-product - 2026-10-17 | لاگ ترافیک شایگان | `ShayeganClient::request` | `Log::info` با کلید `shayegan.http_request` / `shayegan.http_response`; رمز `***`; خاموش: setting `shayegan_log_traffic=0` diff --git a/app/Services/CopperConvertRequestService.php b/app/Services/CopperConvertRequestService.php index 4e26296..cb9b1b9 100644 --- a/app/Services/CopperConvertRequestService.php +++ b/app/Services/CopperConvertRequestService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Http\Controllers\Controller; use App\Http\Controllers\Single\SingleOrderController; use App\Models\CopperConvertRequest; use App\Models\Customer; @@ -83,7 +84,7 @@ class CopperConvertRequestService public function approve(int $id, int $adminId): CopperConvertRequest { - return DB::transaction(function () use ($id, $adminId) { + $row = DB::transaction(function () use ($id, $adminId) { $row = CopperConvertRequest::query()->lockForUpdate()->findOrFail($id); if ($row->status !== 'pending') { throw new UnprocessableEntityHttpException('این درخواست قبلاً تعیین‌تکلیف شده است.'); @@ -113,6 +114,10 @@ class CopperConvertRequestService return $row; }); + + $this->notifyCustomer($row, true); + + return $row; } public function reject(int $id, int $adminId): CopperConvertRequest @@ -124,10 +129,58 @@ class CopperConvertRequestService $row->status = 'rejected'; $row->admin_id = $adminId; $row->save(); + $this->notifyCustomer($row, false); return $row; } + private function notifyCustomer(CopperConvertRequest $row, bool $approved): void + { + try { + $customer = Customer::query()->find($row->customer_id); + $mobile = trim((string) ($customer?->mobile ?? '')); + if ($mobile === '') { + return; + } + + $company = trim((string) Controller::Config('name_fa')); + $source = $this->sourceLabel((string) $row->source); + $lines = [$company !== '' ? $company : 'درخواست تبدیل']; + if ($approved) { + $lines[] = 'درخواست تبدیل #'.$row->id.' تأیید شد.'; + $lines[] = 'دارایی '.$source.' به مقدار '.$row->consumed_amount.' '.$row->asset_unit.' فروخته شد.'; + if ((int) $row->wire15_rings > 0) { + $lines[] = 'حلقه ۱.۵: '.$row->wire15_rings; + } + if ((int) $row->wire25_rings > 0) { + $lines[] = 'حلقه ۲.۵: '.$row->wire25_rings; + } + } else { + $lines[] = 'درخواست تبدیل #'.$row->id.' رد شد.'; + $lines[] = 'دارایی '.$source.' شما بدون تغییر ماند.'; + } + + Controller::Send($mobile, implode("\n", $lines)); + } catch (\Throwable $e) { + report($e); + } + } + + private function sourceLabel(string $source): string + { + if ($source === 'katod') { + return 'کاتد'; + } + if ($source === 'maftoul') { + return 'مفتول'; + } + if ($source === 'shamsh') { + return 'شمش'; + } + + return $source; + } + private function placeLeg(Customer $customer, int $productId, int $direction, float $number, float $unitPrice, string $note): int { if ($productId < 1 || $number <= 0 || $unitPrice <= 0) {