feat: update sms units to kilogram transactions notes price source label and trading closed message

This commit is contained in:
2026-11-18 18:25:34 +03:30
parent 0004192cbc
commit 3ce2c48438
19 changed files with 382 additions and 49 deletions
+18 -4
View File
@@ -2,7 +2,9 @@
namespace App\Services;
use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Models\Product;
use App\Models\TransactionsAdmin;
use Throwable;
@@ -38,7 +40,7 @@ class AccountingLedgerService
'wallet' => null,
'transaction_id' => null,
'cash' => (int) round((float) ($order->total_price ?? 0)),
'note' => $this->tradeNote((int) ($order->direction ?? 0)),
'note' => $this->tradeNote((int) ($order->direction ?? 0), $order),
'type' => 1,
'gold' => (float) ($order->amount ?? 0),
'balance_cash' => 0,
@@ -51,9 +53,21 @@ class AccountingLedgerService
}
}
/** توضیح سند معامله — همسان با desc ته‌حساب تا گزارشات و حسابداری یکی دیده شوند. */
public function tradeNote(int $direction): string
/** توضیح سند معامله — بر اساس نام محصول سفارش */
public function tradeNote(int $direction, ?Order $order = null): string
{
return $direction === 1 ? 'خرید آبشده' : ($direction === 2 ? 'فروش آبشده' : 'معامله');
$productTitle = null;
if ($order) {
$productTitle = $order->product?->title;
if (! $productTitle && $order->product_id) {
$productTitle = Product::query()->whereKey($order->product_id)->value('title');
}
}
$productTitle = trim((string) $productTitle);
if ($productTitle === '') {
$productTitle = Controller::mainWalletProductLabel() ?: 'مس';
}
return $direction === 1 ? ('خرید ' . $productTitle) : ($direction === 2 ? ('فروش ' . $productTitle) : 'معامله');
}
}
+20 -2
View File
@@ -25,6 +25,7 @@ class ConfigService
'show_home_price_when_closed',
'show_gold_ounce_price',
'trading_hours_by_day',
'closed_message',
];
/**
@@ -634,12 +635,24 @@ class ConfigService
{
// تاریخچهٔ برچسب‌دار همین provider — سقف/کف بدون قاطی شدن با تیک منبع دیگر
$fromLog = $this->providerTodayQuoteExtremes();
if ($fromLog['max'] > 0 && $fromLog['min'] > 0) {
return ['up' => $fromLog['max'], 'down' => $fromLog['min']];
$logMax = $fromLog['max'];
$logMin = $fromLog['min'];
if ($logMax > 1_000_000_000) {
$logMax = (int) round($logMax / 1000);
$logMin = (int) round($logMin / 1000);
}
if ($logMax > 0 && $logMin > 0) {
return ['up' => $logMax, 'down' => $logMin];
}
$up = $this->getInt('up_price', 0);
$down = $this->getInt('down_price', 0);
if ($up > 1_000_000_000) {
$up = (int) round($up / 1000);
}
if ($down > 1_000_000_000) {
$down = (int) round($down / 1000);
}
$candle = PriceCandle::whereDate('date_at', now()->toDateString())->first();
$candleHigh = $candle ? (int) round((float) $candle->high) : 0;
@@ -1098,6 +1111,11 @@ class ConfigService
public function tradingClosedMessage(?Carbon $now = null): string
{
$custom = trim((string) $this->getString('closed_message', ''));
if ($custom !== '') {
return $custom;
}
$now = $now ?? Carbon::now();
$bounds = $this->effectiveTradingBounds($now);
+6 -6
View File
@@ -435,7 +435,7 @@ class GoldCreditService
$customer = Customer::find($request->customer_id);
$company = $cfg->get('name_fa', '');
$message = sprintf(
"درخواست اعتبار طلایی جدید\nمشتری: %s\nموبایل: %s\nمقدار: %s گرم\nمدت: %s ماه\n%s",
"درخواست اعتبار طلایی جدید\nمشتری: %s\nموبایل: %s\nمقدار: %s کیلوگرم\nمدت: %s ماه\n%s",
$customer->name ?? '-',
$customer->mobile ?? '-',
$request->requested_gold,
@@ -461,7 +461,7 @@ class GoldCreditService
$numbers = $installments->pluck('installment_number')->implode(',');
$company = $cfg->get('name_fa', '');
$message = sprintf(
"پرداخت قسط اعتبار طلایی\nمشتری: %s\nموبایل: %s\nاقساط: %s\nمبلغ: %s سوت\nطلا: %s گرم / ریال: %s\n%s",
"پرداخت قسط اعتبار طلایی\nمشتری: %s\nموبایل: %s\nاقساط: %s\nمبلغ: %s سوت\nطلا: %s کیلوگرم / ریال: %s\n%s",
$customer->name ?? '-',
$customer->mobile ?? '-',
$numbers,
@@ -564,7 +564,7 @@ class GoldCreditService
$grace = $this->resolvePenaltyConfig($installment->goldCredit)['grace_hours'];
$penalty = $this->resolvePenaltyConfig($installment->goldCredit);
$penaltyLabel = $penalty['type'] === 'gold'
? number_format($penalty['amount'], 4) . ' گرم طلا'
? number_format($penalty['amount'], 4) . ' کیلوگرم طلا'
: number_format((int) $penalty['amount']) . ' ریال';
$template = $cfg->get(
@@ -745,9 +745,9 @@ class GoldCreditService
{
$cfg = app(ConfigService::class);
$defaultInfo = "اعتبار طلایی بر اساس موجودی طلای شما در قلک اعطا می‌شود.\n"
. "• کاربران با موجودی ۵۰۰ سوت تا ۱ گرم: ۳ گرم اعتبار — بازپرداخت ماهانه ۲۵۰ سوت\n"
. "• کاربران با موجودی ۱ تا ۲ گرم: ۴ گرم اعتبار — بازپرداخت ماهانه ۳۳۳ سوت\n"
. "• کاربران با موجودی ۲ تا ۳ گرم: ۵ گرم اعتبار — بازپرداخت ماهانه ۴۱۷ سوت\n"
. "• کاربران با موجودی ۵۰۰ سوت تا ۱ کیلوگرم: ۳ کیلوگرم اعتبار — بازپرداخت ماهانه ۲۵۰ سوت\n"
. "• کاربران با موجودی ۱ تا ۲ کیلوگرم: ۴ کیلوگرم اعتبار — بازپرداخت ماهانه ۳۳۳ سوت\n"
. "• کاربران با موجودی ۲ تا ۳ کیلوگرم: ۵ کیلوگرم اعتبار — بازپرداخت ماهانه ۴۱۷ سوت\n"
. "بازپرداخت همه طرح‌ها ۱۲ ماهه است.";
$defaultSuccess = 'درخواست شما ثبت شد و در حال بررسی است. تا ۲۴ ساعت آینده با شما تماس گرفته می‌شود و توضیحات تکمیلی توسط کارشناس ارائه خواهد شد.';
+2 -2
View File
@@ -280,7 +280,7 @@ class MontzarReconcileService
{
$gold = 0.0;
$cash = 0.0;
$goldUnit = 'گرم';
$goldUnit = 'کیلوگرم';
$cashUnit = 'ریال';
foreach ($raw as $item) {
@@ -291,7 +291,7 @@ class MontzarReconcileService
$value = (float) ($item['value'] ?? 0);
if ($eng === 'gold' || ($item['name_fa'] ?? '') === 'طلا') {
$gold = $value;
$goldUnit = (string) ($item['unit'] ?? 'گرم');
$goldUnit = (string) ($item['unit'] ?? 'کیلوگرم');
}
if ($eng === 'cash' || ($item['name_fa'] ?? '') === 'ریال') {
$cash = $value;
@@ -38,8 +38,8 @@ class PriceChannelBroadcastService
%عنوان
📅 %تاریخ 🕐 %ساعت
🔴 خرید گرم: %گرم_خرید
🟢 فروش گرم: %گرم_فروش
🔴 خرید کیلوگرم: %کیلوگرم_خرید
🟢 فروش کیلوگرم: %کیلوگرم_فروش
🔴 خرید مثقال: %مثقال_خرید
🟢 فروش مثقال: %مثقال_فروش
@@ -461,6 +461,8 @@ TXT;
$message = $this->applyTemplatePlaceholders($template, [
'مثقال_فروش' => $prices['mesghal_sell'],
'مثقال_خرید' => $prices['mesghal_buy'],
'کیلوگرم_فروش' => $prices['gram_sell'],
'کیلوگرم_خرید' => $prices['gram_buy'],
'گرم_فروش' => $prices['gram_sell'],
'گرم_خرید' => $prices['gram_buy'],
'اسم_اپ' => $name,
@@ -698,7 +700,8 @@ TXT;
private function isGramUnit(Product $product): bool
{
return trim((string) ($product->unit ?? '')) === 'گرم';
$unit = trim((string) ($product->unit ?? ''));
return $unit === 'گرم' || $unit === 'کیلوگرم';
}
/** قیمت را به واحد نمایش (تقسیم بر ۱۰٬۰۰۰) با جداکننده‌ی هزارگان می‌برد */
+2 -2
View File
@@ -285,7 +285,7 @@ class ReferralGiftService
}
$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}";
$message = "سلام {$referrer->name} عزیز،\n\n{$giftForInviter} کیلوگرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} کیلوگرم.\n\nاطلاعات بیشتر: {$companyUrl}\n\nبا احترام،\n{$companyName}";
Controller::Send($referrer->mobile, $message);
}
@@ -374,7 +374,7 @@ class ReferralGiftService
}
$currentGold = Controller::formatSmsGoldWeight((float) $walletInterface->wallet->refresh()->gold);
$message = "سلام {$customer->name} عزیز،\n\n{$giftForInvited} گرم طلا بابت ثبت نام به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} گرم.\n\nاطلاعات بیشتر: {$companyUrl}\n\nبا احترام،\n{$companyName}";
$message = "سلام {$customer->name} عزیز،\n\n{$giftForInvited} کیلوگرم طلا بابت ثبت نام به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} کیلوگرم.\n\nاطلاعات بیشتر: {$companyUrl}\n\nبا احترام،\n{$companyName}";
Controller::Send($customer->mobile, $message);
}
}
@@ -28,12 +28,25 @@ class SmsGatewayService
];
}
/**
* اصلاح عبارت «گرم» به «کیلوگرم» در متن تمامی پیامک‌های بورس مس
*/
public static function normalizeSmsWeightUnit(string $message): string
{
return preg_replace(
'/(?<![\p{L}\p{N}]|کیلو|کیلو\x{200c})گرم(?=[ی\s\n\r:،.,!؟\(\)\[\]\/\-–—]|$)/u',
'کیلو$0',
$message
) ?? $message;
}
public function send(
string $to,
string $message,
?string $source = null,
bool $isAlert = false
): SmsSendResult {
$message = self::normalizeSmsWeightUnit($message);
$config = $this->buildProviderConfig();
$useSuperAdmin = $this->superAdminSms->enabled();
$billingOperational = SmsWalletService::isBillingOperational() || $useSuperAdmin;
+54
View File
@@ -162,6 +162,60 @@ class ZaarboxPriceService
));
}
/**
* عنوان نمایشی منبع قیمت زنده — استخراج پویا از ردیف مرجع در فید تابلو
*/
public function priceSourceTitle(): string
{
$feed = $this->cachedPriceList(false);
if (is_array($feed)) {
// ۱. بررسی ردیف تنظیم‌شده به عنوان مرجع قیمت (zaarbox_price_key)
$identifier = $this->priceIdentifier();
if ($identifier !== '') {
$row = $this->findFeedRow($feed, $identifier);
if (!empty($row['name'])) {
return $this->formatFeedRowSourceName((string) $row['name']);
}
}
// ۲. بررسی reading_method محصول اصلی کیف یا کاتد مس
$mainProduct = $this->config->mainProduct();
if ($mainProduct && !empty($mainProduct->reading_method)) {
$row = $this->findFeedRow($feed, (string) $mainProduct->reading_method);
if (!empty($row['name'])) {
return $this->formatFeedRowSourceName((string) $row['name']);
}
}
// ۳. جستجوی کلیدهای شناخته‌شده گواهی کاتد مس در فید
foreach (['ime_copper_cthd', '8c19e06a-446e-3d56-9cc0-750f7c6cd767'] as $key) {
$row = $this->findFeedRow($feed, $key);
if (!empty($row['name'])) {
return $this->formatFeedRowSourceName((string) $row['name']);
}
}
}
// ۴. انطباق با نوع فلز سیستم
$metalLabel = \App\Http\Controllers\Controller::mainWalletProductLabel();
if ($metalLabel && !in_array($metalLabel, ['طلا', 'آبشده'], true)) {
return 'گواهی سپرده ' . $metalLabel;
}
return 'گواهی سپرده کاتد';
}
private function formatFeedRowSourceName(string $rawName): string
{
$name = trim($rawName);
if (str_contains($name, 'گواهی سپرده') && str_contains($name, 'کاتد')) {
return 'گواهی سپرده کاتد';
}
return $name;
}
/**
* UUID سری نمودار: settings.chart_id؛ وگرنه پیش‌فرض گلد علی.
* GET https://price.zaarbox.ir/api/history/{id}