diff --git a/.cursor/skills/abshode-domain-lookup/learned-notes.md b/.cursor/skills/abshode-domain-lookup/learned-notes.md index 7b83ba4..519c7ce 100644 --- a/.cursor/skills/abshode-domain-lookup/learned-notes.md +++ b/.cursor/skills/abshode-domain-lookup/learned-notes.md @@ -8,4 +8,5 @@ - 2026-09-08 | widen مبلغ گیفت‌کارت | `migrations/2026_09_08_000001_widen_giftcard_amount_columns.php` + `deploy_safe_schema.sql` | `amount`/`total` → DECIMAL(20,4) تا مبالغ ≥۱۰۰ میلیون ریال جا شود - 2026-09-08 | لیست گیفت کاربر | `GiftCardController::mine` + `GET customer/giftcard/mine` + `GiftCardCodes::giftcard` | available=اختصاصی+عمومی تک‌کد use_once=0؛ history از assigned_to - 2026-09-09 | «کد قابل استفاده» خالی در اپ | `routes/customer.php` + `GiftCardController::mine` | مسیر `GET customer/giftcard/mine` هنوز کامیت/دیپلوی نشده؛ سرور واقعی ۴۰۴ می‌دهد (use و me → ۴۰۱) پس لیست همیشه خالی است +- 2026-09-09 | کارت هدیه فلزی | `GiftCardController::useGiftCard` | unit=2 دیگر «در دست ساخت» نیست؛ شارژ gold کیف اصلی + سینک ته‌حساب/زرین/پرگار؛ used_count فقط بعد از موفقیت - 2026-09-09 | رمز ادمین ≠ لاگین اپ | `Customer::setPasswordAttribute` + `AuthController` + `updateAdmin` | قبل از هش/لاگین ارقام فارسی→انگلیسی؛ jwt hash=false؛ آنلاین فقط password غیرخالی بفرست diff --git a/app/Http/Controllers/Admin/GiftCardController.php b/app/Http/Controllers/Admin/GiftCardController.php index 6b44415..eb4da98 100644 --- a/app/Http/Controllers/Admin/GiftCardController.php +++ b/app/Http/Controllers/Admin/GiftCardController.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use Rooyesh\Wallet\interfaces\TransactionInterface; use Rooyesh\Wallet\interfaces\WalletInterface; use App\Services\ConfigService; +use App\Services\PargarSyncService; class GiftCardController extends Controller @@ -88,20 +89,17 @@ class GiftCardController extends Controller $redeem = $request->code; $giftcode = GiftCardCodes::where('code', $redeem)->first(); - $gift = GiftCard::find($giftcode->giftcard_id); - if(!$giftcode){ return response()->json(['message' => 'کد هدیه یافت نشد!'], 404); } - //gift order update $gift = GiftCard::find($giftcode->giftcard_id); + if(!$gift){ + return response()->json(['message' => 'کد هدیه یافت نشد!'], 404); + } - if($gift->used_count+1 === $gift->count){ - $gift->sts = 2; - }elseif($gift->expiry_date <= now()){ + if($gift->expiry_date && $gift->expiry_date <= now()){ $gift->sts = 3; - $giftcode->sts = 3; $giftcode->save(); $gift->save(); @@ -109,19 +107,18 @@ class GiftCardController extends Controller return response()->json(['message' => 'کد هدیه منقضی شده است!'], 400); } - $gift->used_count += 1; - $gift->save(); - - if($giftcode->sts != 1){ + if((int) $giftcode->sts !== 1){ return response()->json(['message' => 'کد هدیه قبلا استفاده شده است!'], 400); } + if((int) $gift->count > 0 && (int) $gift->used_count >= (int) $gift->count){ + return response()->json(['message' => 'کد هدیه قبلا استفاده شده است!'], 400); + } + $unit = (int) $giftcode->unit; + $message = null; - - //tranaction - if($giftcode->unit === 1){ - + if($unit === 1){ //add IRR to user wallet $Withdraw = Withdraw::create([ 'customer_id' => auth('customer')->id(), @@ -148,7 +145,7 @@ class GiftCardController extends Controller ], 3, false, true); try { - app(\App\Services\PargarSyncService::class)->queueWalletDocument( + app(PargarSyncService::class)->queueWalletDocument( $user, 'cash', (float) $giftcode->amount, @@ -163,28 +160,130 @@ class GiftCardController extends Controller } } - //set text for sms to customer - $amount = number_format($giftcode->amount); + $amount = number_format((float) $giftcode->amount); $message = "$user->name عزیز کیف پول شما به مقدار $amount ریال به واسطه کارت هدیه از طرف $gift->name شارژ شد. - قلک طلا"; + ".$this->Config('name_fa'); - }elseif ($giftcode->unit === 2){ - //add Gold to user wallet - return response()->json(['message'=> 'در دست ساخت👷🏻🚧'], 400); + }elseif ($unit === 2){ + // شارژ کیف فلزی (طلا / مس — فیلد gold کیف اصلی) + $goldAmount = (float) $giftcode->amount; + if ($goldAmount <= 0) { + return response()->json(['message' => 'مقدار کارت هدیه نامعتبر است!'], 400); + } + + $configService = app(ConfigService::class); + $representative = $configService->mainWalletRepresentativeProduct(); + + $Withdraw = Withdraw::create([ + 'customer_id' => $user->id, + 'gold' => $goldAmount, + 'note' => 'کارت هدیه', + 'sts' => 6, + 'tracked_number' => $giftcode->id, + ]); + + $wallet_interface = new WalletInterface($user->id, $user->type); + new TransactionInterface($wallet_interface, [ + 'cash' => 0, + 'gold' => $goldAmount, + 'expire_at' => now(), + 'note' => 'کارت هدیه', + 'withdraw_id' => $Withdraw->id, + 'product_id' => $representative?->id, + 'active' => true, + ], 7, true, false); + + $syncPayload = [ + 'customer_id' => $user->id, + 'value' => $goldAmount, + 'direction' => 1, + 'withdraw_id' => $Withdraw->id, + 'note' => 'کارت هدیه', + ]; + if ($representative) { + $syncPayload['product_id'] = $representative->id; + $syncPayload['product'] = [ + 'id' => $representative->id, + 'title' => $representative->title, + 'group_type' => $representative->group_type, + 'metal_id' => $representative->metal_id, + 'amount' => $representative->amount, + 'unit' => $representative->unit, + 'trade_by_quantity' => $representative->trade_by_quantity, + ]; + } + + if ($configService->isTahesabAccounting()) { + try { + app(TahesabController::class)->walletGold($syncPayload); + } catch (\Throwable $e) { + report($e); + } + } + + if ($configService->isZarinAccounting()) { + try { + app(ZarinController::class)->walletGold($syncPayload); + } catch (\Throwable $e) { + report($e); + } + } + + try { + app(PargarSyncService::class)->queueWalletDocument( + $user, + 'gold', + $goldAmount, + [ + 'withdraw_id' => $Withdraw->id, + 'note' => 'کارت هدیه', + 'product_id' => $representative?->id, + 'source' => 'gift_card', + ] + ); + } catch (\Throwable $e) { + report($e); + } + + $weightUnit = self::tradeWeightUnit(); + $metalLabel = self::mainWalletMetalLabel(); + $formattedGold = self::formatSmsGoldWeight($goldAmount); + $message = "$user->name عزیز + کیف $metalLabel شما به مقدار $formattedGold $weightUnit + به واسطه کارت هدیه از طرف $gift->name شارژ شد. + ".$this->Config('name_fa'); + + try { + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $user->id, + 'واریز کارت هدیه', + "کیف $metalLabel شما به اندازه $formattedGold $weightUnit شارژ شد.", + 'success' + ); + } catch (\Throwable $e) { + report($e); + } + + } else { + return response()->json(['message' => 'نوع کارت هدیه پشتیبانی نمی‌شود.'], 400); } + if((int) $gift->used_count + 1 >= (int) $gift->count){ + $gift->sts = 2; + } + $gift->used_count = (int) $gift->used_count + 1; + $gift->save(); - - - //gift code update $giftcode->assigned_to = $user->id; $giftcode->sts = 2; $giftcode->used_at = now(); $giftcode->save(); - $this->Send($user->mobile, $message); + if ($message) { + $this->Send($user->mobile, $message); + } return response()->json([ 'message' => 'کد هدیه با موفقیت استفاده شد!',