This commit is contained in:
2026-08-02 16:47:19 +03:30
parent ef32046e85
commit ec0fd28efc
4 changed files with 113 additions and 31 deletions
+19 -6
View File
@@ -38,6 +38,9 @@ class ReferralGiftService
/**
* پاداش معرف/معرف‌شونده پس از اولین سفارش — فقط وقتی تنظیم referral_gift_on_first_order روشن است.
*
* توجه: has_page_earn_money فقط نمایش منوی «کسب درآمد» در اپ است؛ واریز پاداش را قطع نمی‌کند.
* اگر اولین سفارش قبلاً ثبت شده و پاداش نرفته باشد، با سفارش‌های بعدی هم (تا وقتی تکراری نباشد) جبران می‌شود.
*/
public function tryGiveOnFirstOrder(Customer $customer): void
{
@@ -45,12 +48,7 @@ class ReferralGiftService
return;
}
$config = app(ConfigService::class);
if ($config->getString('has_page_earn_money', 'false') !== 'true') {
return;
}
if (Order::where('customer_id', $customer->id)->count() !== 1) {
if (! Order::where('customer_id', $customer->id)->exists()) {
return;
}
@@ -60,6 +58,21 @@ class ReferralGiftService
$this->depositGifts($customer, $referrer, $referrerGiftAllowed, true);
}
/**
* واریز معوق/دستی پاداش (مثلاً جبران وقتی گیت اشتباه جلوی واریز را گرفته).
* Idempotent — اگر قبلاً «پاداش بابت معرفی» خورده باشد دوباره نمی‌زند.
*/
public function givePendingGifts(Customer $customer, bool $requireExistingOrder = false): void
{
if ($requireExistingOrder && ! Order::where('customer_id', $customer->id)->exists()) {
return;
}
$referrer = $customer->referrer();
$referrerGiftAllowed = $this->resolveReferrerGiftPermission($referrer);
$this->depositGifts($customer, $referrer, $referrerGiftAllowed, true);
}
public function resolveReferrerGiftPermission(?Customer $referrer): bool
{
if ($referrer === null) {