fix title
This commit is contained in:
@@ -535,8 +535,8 @@ class PargarInboundWalletService
|
||||
{
|
||||
return match ($log->type) {
|
||||
PargarSyncService::TYPE_ORDER => 'سفارش ' . $log->order_id,
|
||||
PargarSyncService::TYPE_WALLET_GOLD => 'شارژ طلای کیف',
|
||||
PargarSyncService::TYPE_WALLET_CASH => 'سند ریالی کیف',
|
||||
PargarSyncService::TYPE_WALLET_GOLD => 'واریز/برداشت طلای کیف',
|
||||
PargarSyncService::TYPE_WALLET_CASH => 'واریز/برداشت ریالی کیف',
|
||||
default => (string) $log->type,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -204,11 +204,9 @@ class PargarSyncService
|
||||
}
|
||||
|
||||
$isDeposit = $signedAmount > 0;
|
||||
if ($kind === 'cash') {
|
||||
$desc = $isDeposit ? 'واریز ریالی — ارسال به پرگار' : 'برداشت ریالی — ارسال به پرگار';
|
||||
} else {
|
||||
$desc = $isDeposit ? 'شارژ طلای کیف اصلی — ارسال به پرگار' : 'برداشت طلای کیف اصلی — ارسال به پرگار';
|
||||
}
|
||||
$note = isset($meta['note']) ? trim((string) $meta['note']) : '';
|
||||
$docDesc = \App\Http\Controllers\Controller::accountingWalletDesc($isDeposit, $note !== '' ? $note : null);
|
||||
$desc = $docDesc . ' — ارسال به پرگار';
|
||||
|
||||
$absAmount = abs($signedAmount);
|
||||
// اگر هنوز مایگریشن widen اجرا نشده، مبلغ بزرگ را از همان اول در ستون نگذار
|
||||
|
||||
@@ -57,6 +57,10 @@ TXT;
|
||||
*/
|
||||
public function scheduleBroadcastIfEligible(): void
|
||||
{
|
||||
if (! $this->hasPriceChannelAccess()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->config->getBool('price_channel_enabled', false)) {
|
||||
return;
|
||||
}
|
||||
@@ -81,6 +85,10 @@ TXT;
|
||||
public function broadcastIfEligible(): void
|
||||
{
|
||||
try {
|
||||
if (! $this->hasPriceChannelAccess()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->config->getBool('price_channel_enabled', false)) {
|
||||
return;
|
||||
}
|
||||
@@ -202,6 +210,10 @@ TXT;
|
||||
public function broadcastAfterTemplateChange(): void
|
||||
{
|
||||
try {
|
||||
if (! $this->hasPriceChannelAccess()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->config->getBool('price_channel_enabled', false)) {
|
||||
return;
|
||||
}
|
||||
@@ -323,7 +335,7 @@ TXT;
|
||||
'selected' => $isSelected,
|
||||
'has_token' => $token !== '',
|
||||
'destinations' => $chatIds,
|
||||
'will_send' => $isSelected && $token !== '' && $chatIds !== [],
|
||||
'will_send' => $this->hasPriceChannelAccess() && $isSelected && $token !== '' && $chatIds !== [],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -333,6 +345,7 @@ TXT;
|
||||
$display = $trade !== null ? $this->computeDisplayPrices() : null;
|
||||
|
||||
return [
|
||||
'access' => $this->hasPriceChannelAccess(),
|
||||
'enabled' => $this->config->getBool('price_channel_enabled', false),
|
||||
'selected_messengers' => $selected,
|
||||
'min_seconds' => $this->config->getInt('price_channel_min_seconds', 120),
|
||||
@@ -850,6 +863,11 @@ TXT;
|
||||
}
|
||||
|
||||
/** @return array<int, string> */
|
||||
private function hasPriceChannelAccess(): bool
|
||||
{
|
||||
return $this->config->getBool('price_channel_access', false);
|
||||
}
|
||||
|
||||
private function parseList(string $raw): array
|
||||
{
|
||||
$parts = preg_split('/[,\n]+/', trim($raw)) ?: [];
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Order;
|
||||
use App\Models\Setting;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use App\Models\Withdraw;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
||||
use Rooyesh\Wallet\interfaces\WalletInterface;
|
||||
use Rooyesh\Wallet\models\Transaction;
|
||||
@@ -60,7 +61,7 @@ class ReferralGiftService
|
||||
|
||||
/**
|
||||
* واریز معوق/دستی پاداش (مثلاً جبران وقتی گیت اشتباه جلوی واریز را گرفته).
|
||||
* Idempotent — اگر قبلاً «پاداش بابت معرفی» خورده باشد دوباره نمیزند.
|
||||
* Idempotent — اگر قبلاً «پاداش معرفی» (یا عنوان قدیمی) خورده باشد دوباره نمیزند.
|
||||
*/
|
||||
public function givePendingGifts(Customer $customer, bool $requireExistingOrder = false): void
|
||||
{
|
||||
@@ -128,7 +129,7 @@ class ReferralGiftService
|
||||
{
|
||||
return TransactionsAdmin::where('customer_id', $invited->id)
|
||||
->where('customer_to_id', $referrer->id)
|
||||
->where('note', 'پاداش بابت معرفی')
|
||||
->whereIn('note', Controller::accountingReferralRewardDescAliases())
|
||||
->exists();
|
||||
}
|
||||
|
||||
@@ -139,6 +140,63 @@ class ReferralGiftService
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* وقتی price_provider=montzar و کلید referral_gift_buy_from_montzar روشن است،
|
||||
* قبل از واریز پاداش همان وزن از همکار خرید میشود.
|
||||
* خاموش بودن کلید = روال قبلی (واریز محلی بدون خرید همکار).
|
||||
* شکست خرید → واریز نمیشود (ثبتنام/سفارش خراب نمیشود؛ با givePendingGifts قابل جبران است).
|
||||
*/
|
||||
private function ensureMontzarCoverPurchase(
|
||||
float $grams,
|
||||
Customer $beneficiary,
|
||||
string $reason,
|
||||
ConfigService $config
|
||||
): bool {
|
||||
if (!$config->usesMontzarPricing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$config->getBool('referral_gift_buy_from_montzar', true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($grams <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$livePrice = (float) $config->Config('montzar_live_price');
|
||||
$data = [
|
||||
'amount' => $grams,
|
||||
'direction' => 1, // خرید پوشش از همکار
|
||||
'customer' => [
|
||||
'name' => trim($reason . ' - ' . (string) ($beneficiary->name ?? '')),
|
||||
],
|
||||
'total_price' => (int) round($livePrice * $grams),
|
||||
];
|
||||
|
||||
try {
|
||||
$parsed = app(MontzarService::class)->submitOrder($data);
|
||||
Log::info('Referral gift covered by Montzar buy', [
|
||||
'grams' => $grams,
|
||||
'reason' => $reason,
|
||||
'beneficiary_id' => $beneficiary->id,
|
||||
'provider_id' => $parsed['provider_id'] ?? null,
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
Log::error('Referral gift blocked: Montzar cover buy failed', [
|
||||
'grams' => $grams,
|
||||
'reason' => $reason,
|
||||
'beneficiary_id' => $beneficiary->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function giveReferrerGift(
|
||||
Customer $customer,
|
||||
Customer $referrer,
|
||||
@@ -147,6 +205,12 @@ class ReferralGiftService
|
||||
string $companyUrl,
|
||||
ConfigService $config
|
||||
): void {
|
||||
$rewardDesc = Controller::accountingReferralRewardDesc();
|
||||
|
||||
if (!$this->ensureMontzarCoverPurchase($giftForInviter, $referrer, $rewardDesc, $config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$withdraw = Withdraw::create([
|
||||
'user_id' => $customer->id,
|
||||
'customer_id' => $referrer->id,
|
||||
@@ -161,7 +225,7 @@ class ReferralGiftService
|
||||
'gold' => $giftForInviter,
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'title' => 'پاداش بابت معرفی',
|
||||
'title' => $rewardDesc,
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'start_at' => now(),
|
||||
], 8, true, false);
|
||||
@@ -174,7 +238,7 @@ class ReferralGiftService
|
||||
'wallet' => null,
|
||||
'transaction_id' => $transaction->id,
|
||||
'cash' => 0,
|
||||
'note' => 'پاداش بابت معرفی',
|
||||
'note' => $rewardDesc,
|
||||
'type' => 1,
|
||||
'gold' => $giftForInviter,
|
||||
'balance_cash' => 0,
|
||||
@@ -186,7 +250,7 @@ class ReferralGiftService
|
||||
app(TahesabController::class)->referrerGoldReward(
|
||||
$customer,
|
||||
$giftForInviter,
|
||||
'پاداش بابت معرفی'
|
||||
$rewardDesc
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
@@ -198,13 +262,28 @@ class ReferralGiftService
|
||||
app(\App\Http\Controllers\Admin\ZarinController::class)->referrerGoldReward(
|
||||
$customer,
|
||||
$giftForInviter,
|
||||
'پاداش بابت معرفی'
|
||||
$rewardDesc
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
app(PargarSyncService::class)->queueWalletDocument(
|
||||
$referrer,
|
||||
'gold',
|
||||
(float) $giftForInviter,
|
||||
[
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'note' => $rewardDesc,
|
||||
'source' => 'referral_gift',
|
||||
]
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
$currentGold = Controller::formatSmsGoldWeight((float) $walletInterface->wallet->refresh()->gold);
|
||||
$message = "سلام {$referrer->name} عزیز،\n\n{$giftForInviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} گرم.\n\nاطلاعات بیشتر: {$companyUrl}\n\nبا احترام،\n{$companyName}";
|
||||
Controller::Send($referrer->mobile, $message);
|
||||
@@ -217,6 +296,10 @@ class ReferralGiftService
|
||||
string $companyUrl,
|
||||
ConfigService $config
|
||||
): void {
|
||||
if (!$this->ensureMontzarCoverPurchase($giftForInvited, $customer, 'پاداش بابت ثبت نام', $config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$withdraw = Withdraw::create([
|
||||
'user_id' => $customer->id,
|
||||
'customer_id' => $customer->id,
|
||||
@@ -275,6 +358,21 @@ class ReferralGiftService
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
app(PargarSyncService::class)->queueWalletDocument(
|
||||
$customer,
|
||||
'gold',
|
||||
(float) $giftForInvited,
|
||||
[
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'note' => 'پاداش بابت ثبت نام',
|
||||
'source' => 'referral_register_gift',
|
||||
]
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
$currentGold = Controller::formatSmsGoldWeight((float) $walletInterface->wallet->refresh()->gold);
|
||||
$message = "سلام {$customer->name} عزیز،\n\n{$giftForInvited} گرم طلا بابت ثبت نام به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} گرم.\n\nاطلاعات بیشتر: {$companyUrl}\n\nبا احترام،\n{$companyName}";
|
||||
Controller::Send($customer->mobile, $message);
|
||||
|
||||
Reference in New Issue
Block a user