feat: update sms units to kilogram transactions notes price source label and trading closed message
This commit is contained in:
@@ -659,7 +659,7 @@ class CustomerController extends SuperController
|
||||
// if ($referrer) {
|
||||
// if (Customer::where('referral_to_id', $referrer->referral_id)->get()->count()<=$referrer->add_user_limit) {
|
||||
// $referrerWallet = Wallet::where('owner',$customer->referral->id)->first();
|
||||
// $message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_invite} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName";
|
||||
// $message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_invite} کیلوگرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} کیلوگرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName";
|
||||
// $this->Send($referrer->mobile, $message);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -57,12 +57,14 @@ class SettingsController extends Controller
|
||||
}
|
||||
|
||||
$clientFeatureKeys = SuperAdminProgramSettingsOverlay::CLIENT_FEATURE_KEYS;
|
||||
$tradingHoursKeys = ConfigService::TRADING_HOURS_CLIENT_KEYS;
|
||||
|
||||
$local = Setting::query()
|
||||
->select(Setting::adminSelectColumns())
|
||||
->where(function ($query) use ($clientFeatureKeys) {
|
||||
->where(function ($query) use ($clientFeatureKeys, $tradingHoursKeys) {
|
||||
$query->where('show_to_user', 1)
|
||||
->orWhereIn('key', $clientFeatureKeys);
|
||||
->orWhereIn('key', $clientFeatureKeys)
|
||||
->orWhereIn('key', $tradingHoursKeys);
|
||||
})
|
||||
->orderBy('key')
|
||||
->get();
|
||||
@@ -185,6 +187,14 @@ class SettingsController extends Controller
|
||||
if (Setting::hasTypeColumn()) {
|
||||
$setting->type = $request->type ?? '';
|
||||
}
|
||||
if ($request->has('show_to_user') && Setting::hasShowToUserColumn()) {
|
||||
$setting->show_to_user = filter_var($request->show_to_user, FILTER_VALIDATE_BOOLEAN) ? 1 : 0;
|
||||
} elseif ($isNew && in_array($key, ConfigService::TRADING_HOURS_CLIENT_KEYS, true) && Setting::hasShowToUserColumn()) {
|
||||
$setting->show_to_user = 1;
|
||||
}
|
||||
if ($request->has('menu') && Setting::hasSettingsColumn('menu')) {
|
||||
$setting->menu = (string) $request->menu;
|
||||
}
|
||||
$setting->save();
|
||||
|
||||
if (
|
||||
|
||||
@@ -195,7 +195,12 @@ class AuthController extends Controller
|
||||
if (isset($data['referral_id'])) {
|
||||
$data['referral_to_id'] = $data['referral_id'];
|
||||
}
|
||||
$data['name'] = $data['fname'] . ' ' . $data['lname'];
|
||||
$fname = trim((string) ($data['fname'] ?? ''));
|
||||
$lname = trim((string) ($data['lname'] ?? ''));
|
||||
if (preg_match('/[a-zA-Z]/', $fname) || preg_match('/[a-zA-Z]/', $lname)) {
|
||||
throw new UnprocessableEntityHttpException('نام و نام خانوادگی باید فقط به زبان فارسی باشد.');
|
||||
}
|
||||
$data['name'] = trim($fname . ' ' . $lname);
|
||||
// فقط ورود به اپ — نه اجازهٔ معامله؛ معامله با is_legal جداست
|
||||
$data['active'] = $cfg->getBool('auto_active_customer', false);
|
||||
$data['is_legal'] = (int) ($data['is_legal'] ?? 0);
|
||||
|
||||
@@ -67,7 +67,17 @@ class Controller extends BaseController
|
||||
return number_format(abs((float) $value), 0, '.', ',');
|
||||
}
|
||||
|
||||
/** وزن طلا در پیامک — تا ۳ رقم اعشار، بدون گرد کردن به صفر برای زیر ۱ گرم */
|
||||
/** اصلاح عبارت «گرم» به «کیلوگرم» در متن تمامی پیامکهای پروژه */
|
||||
public static function normalizeSmsWeightUnit(string $message): string
|
||||
{
|
||||
return preg_replace(
|
||||
'/(?<![\p{L}\p{N}]|کیلو|کیلو\x{200c})گرم(?=[ی\s\n\r:،.,!؟\(\)\[\]\/\-–—]|$)/u',
|
||||
'کیلو$0',
|
||||
$message
|
||||
) ?? $message;
|
||||
}
|
||||
|
||||
/** وزن طلا در پیامک — تا ۳ رقم اعشار، بدون گرد کردن به صفر برای زیر ۱ کیلوگرم */
|
||||
public static function formatSmsGoldWeight(float|int|string $value): string
|
||||
{
|
||||
$formatted = rtrim(rtrim(number_format(abs((float) $value), 3, '.', ''), '0'), '.');
|
||||
@@ -141,6 +151,7 @@ class Controller extends BaseController
|
||||
|
||||
public static function SendMessage($to, $msg ,$is_send = false,$force_method ='null')
|
||||
{
|
||||
$msg = self::normalizeSmsWeightUnit((string) $msg);
|
||||
$credentials = [
|
||||
"telegram" => [
|
||||
"token" => self::Config('telegram_bot_token')
|
||||
|
||||
@@ -21,7 +21,7 @@ class FinanceController extends Controller
|
||||
*/
|
||||
public function fall(Request $request)
|
||||
{
|
||||
$transactions_admins = TransactionsAdmin::with(['withdraw', 'order', 'user', 'customerTo', 'customer']);
|
||||
$transactions_admins = TransactionsAdmin::with(['withdraw', 'order.product', 'user', 'customerTo', 'customer']);
|
||||
TableEngine::create($transactions_admins, $request)
|
||||
->initSearch(['price'])
|
||||
->select(['*'])
|
||||
@@ -68,7 +68,7 @@ class FinanceController extends Controller
|
||||
->from('wallets');
|
||||
})->get(['id','name','mobile']);
|
||||
|
||||
$transactions_admins = TransactionsAdmin::with(['withdraw','order',"user",'customerTo','customer'])->get();
|
||||
$transactions_admins = TransactionsAdmin::with(['withdraw','order.product',"user",'customerTo','customer'])->get();
|
||||
|
||||
return view('app', compact(
|
||||
'GT_all_customers',
|
||||
|
||||
@@ -956,7 +956,7 @@ class SingleOrderController extends Controller
|
||||
$goldBalanceLabel = self::formatSmsGoldWeight($goldBalance);
|
||||
$customerMessage = "$companyName\n$transactionType {$subjectTitle}\nکیلوگرم: {$amountLabel}\n" .
|
||||
"مبلغ کل: " . number_format($totalPrice) . "\n\n" .
|
||||
"موجودی {$balanceLabel}: {$goldBalanceLabel}\n" .
|
||||
"موجودی {$balanceLabel}: {$goldBalanceLabel} کیلوگرم\n" .
|
||||
"مانده ریالی: " . number_format($cashBalance) . "\n" .
|
||||
self::publicSiteUrl(request());
|
||||
|
||||
@@ -1231,7 +1231,7 @@ class SingleOrderController extends Controller
|
||||
$message .= "کیلوگرم: $weightLabel\n";
|
||||
$message .= "قیمت کیلوگرم: " . number_format($pricePerGram) . "\n";
|
||||
$message .= "مبلغ کل: " . number_format($totalAmount) . "\n\n";
|
||||
$message .= "موجودی طلایی: $goldBalance\n";
|
||||
$message .= "موجودی طلایی: $goldBalance کیلوگرم\n";
|
||||
$message .= "مانده ریالی: " . number_format($remainingBalance) . "\n";
|
||||
$message .= "$companyurl" . "\n";
|
||||
$this->Send($customer->mobile, $message);
|
||||
@@ -1606,7 +1606,7 @@ class SingleOrderController extends Controller
|
||||
'is_percent' => false,
|
||||
'raw' => $settingsAmt,
|
||||
'per_unit' => $settingsAmt,
|
||||
'detail' => number_format($settingsAmt) . ' ریال / گرم',
|
||||
'detail' => number_format($settingsAmt) . ' ریال / کیلوگرم',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1625,8 +1625,8 @@ class SingleOrderController extends Controller
|
||||
? (rtrim(rtrim(number_format($raw, 4, '.', ''), '0'), '.') . '%')
|
||||
: (number_format($raw) . ' ریال');
|
||||
$detail = $isPercent
|
||||
? ($rawLabel . ' از ' . number_format($base) . ' ≈ ' . number_format($productAmt) . ' ریال / گرم')
|
||||
: (number_format($productAmt) . ' ریال / گرم');
|
||||
? ($rawLabel . ' از ' . number_format($base) . ' ≈ ' . number_format($productAmt) . ' ریال / کیلوگرم')
|
||||
: (number_format($productAmt) . ' ریال / کیلوگرم');
|
||||
|
||||
$lines[] = [
|
||||
'kind' => 'product_spread',
|
||||
@@ -1660,7 +1660,7 @@ class SingleOrderController extends Controller
|
||||
'is_percent' => false,
|
||||
'raw' => $specialAmt,
|
||||
'per_unit' => $specialAmt,
|
||||
'detail' => number_format($specialAmt) . ' ریال / گرم',
|
||||
'detail' => number_format($specialAmt) . ' ریال / کیلوگرم',
|
||||
'package_id' => $specialRule['package_id'] ?? null,
|
||||
];
|
||||
}
|
||||
@@ -1671,13 +1671,13 @@ class SingleOrderController extends Controller
|
||||
|
||||
if ($hasSpecial && ($hasApp || $hasProduct)) {
|
||||
$source = 'app+product+special';
|
||||
$label = 'اختلاف پایه/محصول + قیمت ویژه مشتری = ' . number_format($amount) . ' ریال / گرم';
|
||||
$label = 'اختلاف پایه/محصول + قیمت ویژه مشتری = ' . number_format($amount) . ' ریال / کیلوگرم';
|
||||
} elseif ($hasSpecial) {
|
||||
$source = 'special';
|
||||
$label = ($lines[array_key_last($lines)]['label'] ?? 'قیمت ویژه مشتری') . ' = ' . number_format($amount) . ' ریال';
|
||||
} elseif ($hasApp && $hasProduct) {
|
||||
$source = 'app+product';
|
||||
$label = 'قیمت صفحه اصلی اپلیکیشن + تب اختلاف محصول = ' . number_format($amount) . ' ریال / گرم';
|
||||
$label = 'قیمت صفحه اصلی اپلیکیشن + تب اختلاف محصول = ' . number_format($amount) . ' ریال / کیلوگرم';
|
||||
} elseif ($hasApp) {
|
||||
$source = 'settings';
|
||||
$label = ($lines[0]['label'] ?? 'اختلاف پایه اپ') . ' = ' . number_format($amount) . ' ریال';
|
||||
@@ -1789,9 +1789,9 @@ class SingleOrderController extends Controller
|
||||
$receiptLines[] = array_merge($line, [
|
||||
'amount_units' => $amount,
|
||||
'total' => $total,
|
||||
'line_text' => ($line['detail'] ?? number_format($perUnit) . ' ریال / گرم')
|
||||
'line_text' => ($line['detail'] ?? number_format($perUnit) . ' ریال / کیلوگرم')
|
||||
. ($amount > 0
|
||||
? (' × ' . $amountLabel . ' گرم = ' . number_format($total) . ' ریال')
|
||||
? (' × ' . $amountLabel . ' کیلوگرم = ' . number_format($total) . ' ریال')
|
||||
: ''),
|
||||
]);
|
||||
}
|
||||
@@ -1807,10 +1807,10 @@ class SingleOrderController extends Controller
|
||||
'per_unit' => $data['fee'],
|
||||
'amount_units' => $amount,
|
||||
'total' => $feeTotal,
|
||||
'detail' => number_format($data['fee']) . ' ریال / گرم',
|
||||
'line_text' => number_format($data['fee']) . ' ریال / گرم × '
|
||||
'detail' => number_format($data['fee']) . ' ریال / کیلوگرم',
|
||||
'line_text' => number_format($data['fee']) . ' ریال / کیلوگرم × '
|
||||
. rtrim(rtrim(number_format($amount, 4, '.', ''), '0'), '.')
|
||||
. ' گرم = ' . number_format($feeTotal) . ' ریال',
|
||||
. ' کیلوگرم = ' . number_format($feeTotal) . ' ریال',
|
||||
];
|
||||
$spreadTotal = $feeTotal;
|
||||
}
|
||||
@@ -1823,7 +1823,7 @@ class SingleOrderController extends Controller
|
||||
$feeAsset = (string) ($data['fee_asset'] ?? 'rial');
|
||||
$fromMetal = $feeAsset === 'gold';
|
||||
$assetLabel = $fromMetal ? 'از فلز/مقدار' : 'از ریال';
|
||||
$goldLabel = rtrim(rtrim(number_format($scGold, 4, '.', ''), '0'), '.') . ' گرم';
|
||||
$goldLabel = rtrim(rtrim(number_format($scGold, 4, '.', ''), '0'), '.') . ' کیلوگرم';
|
||||
$detailParts = [];
|
||||
if ($scPct > 0) {
|
||||
$detailParts[] = rtrim(rtrim(number_format($scPct, 4, '.', ''), '0'), '.') . '%';
|
||||
@@ -1833,7 +1833,7 @@ class SingleOrderController extends Controller
|
||||
} elseif ($scRial > 0 && $priceOriginal > 0) {
|
||||
$goldEquiv = $scRial / $priceOriginal;
|
||||
$detailParts[] = number_format($scRial) . ' ریال ≈ '
|
||||
. rtrim(rtrim(number_format($goldEquiv, 4, '.', ''), '0'), '.') . ' گرم';
|
||||
. rtrim(rtrim(number_format($goldEquiv, 4, '.', ''), '0'), '.') . ' کیلوگرم';
|
||||
} else {
|
||||
$detailParts[] = number_format($scRial) . ' ریال';
|
||||
}
|
||||
@@ -2167,7 +2167,7 @@ class SingleOrderController extends Controller
|
||||
$reason = 'رد شده توسط همکار';
|
||||
}
|
||||
|
||||
$message = "سفارش {$dir} کاربر {$name} ({$mobile}) به مقدار {$amount} گرم در اپ ثبت شد ولی از سمت همکار رد شد. علت: {$reason}";
|
||||
$message = "سفارش {$dir} کاربر {$name} ({$mobile}) به مقدار {$amount} کیلوگرم در اپ ثبت شد ولی از سمت همکار رد شد. علت: {$reason}";
|
||||
if ($company !== '') {
|
||||
$message .= " — {$company}";
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class RequestsController extends Controller
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
$data['direction'] = 2;
|
||||
$data['description'] = "فروش {$data['amount']} گرم طلا برای $montifyCompanyName توسط کاربر {$myCustomer->name} با شماره موبایل {$myCustomer->mobile}";
|
||||
$data['description'] = "فروش {$data['amount']} کیلوگرم طلا برای $montifyCompanyName توسط کاربر {$myCustomer->name} با شماره موبایل {$myCustomer->mobile}";
|
||||
$data['order'] = $order = Order::create($data);
|
||||
new TransactionInterface($wallet_interface, [
|
||||
"gold" => $data['amount'],
|
||||
@@ -160,7 +160,7 @@ class RequestsController extends Controller
|
||||
}elseif ($data['method'] == 'gold') {
|
||||
$amountLabel = self::formatSmsGoldWeight($data['amount']);
|
||||
$message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType طلا به مقدار " .
|
||||
"{$amountLabel} گرم به مبلغ " . number_format($data['total_price']) .
|
||||
"{$amountLabel} کیلوگرم به مبلغ " . number_format($data['total_price']) .
|
||||
" ریال کرد. با تشکر، $companyName";
|
||||
}
|
||||
User::where('send_sms', 1)->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) {
|
||||
@@ -172,12 +172,12 @@ class RequestsController extends Controller
|
||||
// $this->SendTelegram($admin->telegram, $message);
|
||||
// });
|
||||
// $messageold = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType طلا به مقدار " .
|
||||
// "{$data['amount']} گرم به مبلغ " . number_format($data['total_price']) .
|
||||
// "{$data['amount']} کیلوگرم به مبلغ " . number_format($data['total_price']) .
|
||||
// " ریال کرد. با تشکر، $companyName";
|
||||
// $azOrTa = $data['direction'] == 1 ? 'از' : 'به';
|
||||
// $messageExam = "
|
||||
// {$transactionType} قلک طلا $azOrTa شما
|
||||
// {$data['amount']} گرم
|
||||
// {$data['amount']} کیلوگرم
|
||||
// در مظنه
|
||||
// " . number_format($data['price_original']) . " ریال";
|
||||
//
|
||||
@@ -207,13 +207,13 @@ class RequestsController extends Controller
|
||||
"\nموجودی طلایی: {$goldBalance}\n" .
|
||||
"مانده ریالی: " . number_format($cashBalance) . "\n" . self::publicSiteUrl(request());
|
||||
}elseif ($data['method'] == 'gold') {
|
||||
$customerMessage = "$companyName\nبرداشت طلایی \nگرم: {$data['amount']}\nقیمت گرم: " . number_format($pricePerGram) .
|
||||
$customerMessage = "$companyName\nبرداشت طلایی \nکیلوگرم: {$data['amount']}\nقیمت کیلوگرم: " . number_format($pricePerGram) .
|
||||
"\nمبلغ کل: " . number_format($data['total_price']) . "\nموجودی طلایی: {$goldBalance}\n" .
|
||||
"مانده ریالی: " . number_format($cashBalance) . "\n" . self::publicSiteUrl(request());
|
||||
}
|
||||
|
||||
|
||||
// $customerMessage = "$companyName\n$transactionType آبشده\nگرم: {$data['amount']}\nقیمت گرم: " . number_format($pricePerGram) .
|
||||
// $customerMessage = "$companyName\n$transactionType آبشده\nکیلوگرم: {$data['amount']}\nقیمت کیلوگرم: " . number_format($pricePerGram) .
|
||||
// "\nمبلغ کل: " . number_format($data['total_price']) . "\n\nموجودی طلایی: {$wallet->gold}\n" .
|
||||
// "مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url');
|
||||
|
||||
@@ -224,7 +224,7 @@ class RequestsController extends Controller
|
||||
try {
|
||||
$title = ($data['method'] ?? '') === 'gold' ? 'برداشت طلایی' : 'برداشت ریالی';
|
||||
$body = ($data['method'] ?? '') === 'gold'
|
||||
? 'گرم: ' . ($data['amount'] ?? '') . "\nمبلغ کل: " . number_format((float) ($data['total_price'] ?? 0)) . ' ریال'
|
||||
? 'کیلوگرم: ' . ($data['amount'] ?? '') . "\nمبلغ کل: " . number_format((float) ($data['total_price'] ?? 0)) . ' ریال'
|
||||
: 'مبلغ: ' . number_format((float) ($data['amount'] ?? 0)) . ' ریال';
|
||||
app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer(
|
||||
(int) $customer->id,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\ZaarboxPriceService;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
@@ -25,6 +26,41 @@ class PriceSyncLog extends Model
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'source_label',
|
||||
];
|
||||
|
||||
public function getSourceLabelAttribute(): string
|
||||
{
|
||||
$source = (string) ($this->source ?? '');
|
||||
|
||||
if ($source === 'zaarbox' || $source === 'store') {
|
||||
try {
|
||||
return app(ZaarboxPriceService::class)->priceSourceTitle();
|
||||
} catch (\Throwable) {
|
||||
return 'گواهی سپرده کاتد';
|
||||
}
|
||||
}
|
||||
|
||||
if ($source === 'montzar') {
|
||||
return 'تابلو montzar';
|
||||
}
|
||||
|
||||
if ($source === 'main_product') {
|
||||
return 'محصول اصلی';
|
||||
}
|
||||
|
||||
if ($source === 'legacy') {
|
||||
return 'فید قدیمی';
|
||||
}
|
||||
|
||||
if ($source === 'database_last') {
|
||||
return 'آخرین قیمت DB';
|
||||
}
|
||||
|
||||
return $source !== '' ? $source : 'گواهی سپرده کاتد';
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(PriceSyncLogItem::class, 'log_id');
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
|
||||
class TransactionsAdmin extends Model
|
||||
{
|
||||
@@ -30,6 +32,47 @@ class TransactionsAdmin extends Model
|
||||
// 3=>'رد شده',
|
||||
// ];
|
||||
|
||||
public function getNoteAttribute($value): ?string
|
||||
{
|
||||
$order = null;
|
||||
if ($this->relationLoaded('order')) {
|
||||
$order = $this->order;
|
||||
} elseif ($this->order_id) {
|
||||
$order = $this->order()->with('product')->first();
|
||||
}
|
||||
|
||||
if ($order) {
|
||||
$productTitle = null;
|
||||
if ($order->relationLoaded('product') && $order->product) {
|
||||
$productTitle = $order->product->title;
|
||||
} elseif ($order->product_id) {
|
||||
$productTitle = Product::query()->whereKey($order->product_id)->value('title');
|
||||
}
|
||||
|
||||
$productTitle = trim((string) $productTitle);
|
||||
if ($productTitle === '') {
|
||||
$productTitle = Controller::mainWalletProductLabel() ?: 'مس';
|
||||
}
|
||||
|
||||
$direction = (int) ($order->direction ?? 0);
|
||||
if ($direction === 1) {
|
||||
return 'خرید ' . $productTitle;
|
||||
} elseif ($direction === 2) {
|
||||
return 'فروش ' . $productTitle;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
if (str_contains($value, 'آبشده') || str_contains($value, 'طلای آبشده')) {
|
||||
$defaultTitle = Controller::mainWalletProductLabel() ?: 'مس';
|
||||
|
||||
return str_replace(['طلای آبشده', 'آبشده'], $defaultTitle, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
|
||||
@@ -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) : 'معامله');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 = 'درخواست شما ثبت شد و در حال بررسی است. تا ۲۴ ساعت آینده با شما تماس گرفته میشود و توضیحات تکمیلی توسط کارشناس ارائه خواهد شد.';
|
||||
|
||||
|
||||
@@ -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 === 'کیلوگرم';
|
||||
}
|
||||
|
||||
/** قیمت را به واحد نمایش (تقسیم بر ۱۰٬۰۰۰) با جداکنندهی هزارگان میبرد */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* بروزرسانی متون پیامکها و تنظیمات پیامکی: اصلاح «گرم» به «کیلوگرم»
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (Schema::hasTable('settings')) {
|
||||
$rows = DB::table('settings')
|
||||
->where(function ($q) {
|
||||
$q->where('key', 'like', '%sms%')
|
||||
->orWhere('key', 'like', '%notif%')
|
||||
->orWhere('key', 'like', '%message%');
|
||||
})
|
||||
->where('value', 'like', '%گرم%')
|
||||
->get();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$val = (string) ($row->value ?? '');
|
||||
$updated = preg_replace(
|
||||
'/(?<![\p{L}\p{N}]|کیلو|کیلو\x{200c})گرم(?=[ی\s\n\r:،.,!؟\(\)\[\]\/\-–—]|$)/u',
|
||||
'کیلو$0',
|
||||
$val
|
||||
);
|
||||
if ($updated !== null && $updated !== $val) {
|
||||
DB::table('settings')->where('id', $row->id)->update([
|
||||
'value' => $updated,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Schema::hasTable('automations')) {
|
||||
$autos = DB::table('automations')->where('message', 'like', '%گرم%')->get();
|
||||
foreach ($autos as $auto) {
|
||||
$msg = (string) ($auto->message ?? '');
|
||||
$updated = preg_replace(
|
||||
'/(?<![\p{L}\p{N}]|کیلو|کیلو\x{200c})گرم(?=[ی\s\n\r:،.,!؟\(\)\[\]\/\-–—]|$)/u',
|
||||
'کیلو$0',
|
||||
$msg
|
||||
);
|
||||
if ($updated !== null && $updated !== $msg) {
|
||||
DB::table('automations')->where('id', $auto->id)->update([
|
||||
'message' => $updated,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
};
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('transactions_admins')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Update rows with order_id that have a specific product
|
||||
if (Schema::hasTable('orders') && Schema::hasTable('products')) {
|
||||
try {
|
||||
$trades = DB::table('transactions_admins')
|
||||
->join('orders', 'transactions_admins.order_id', '=', 'orders.id')
|
||||
->join('products', 'orders.product_id', '=', 'products.id')
|
||||
->select(
|
||||
'transactions_admins.id as tx_id',
|
||||
'orders.direction',
|
||||
'products.title as product_title'
|
||||
)
|
||||
->get();
|
||||
|
||||
foreach ($trades as $trade) {
|
||||
$title = trim((string) $trade->product_title);
|
||||
if ($title === '') {
|
||||
continue;
|
||||
}
|
||||
$prefix = (int) $trade->direction === 2 ? 'فروش ' : 'خرید ';
|
||||
DB::table('transactions_admins')
|
||||
->where('id', $trade->tx_id)
|
||||
->update(['note' => $prefix . $title]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Update remaining 'خرید آبشده' and 'فروش آبشده' to 'مس'
|
||||
try {
|
||||
DB::table('transactions_admins')
|
||||
->where('note', 'like', '%آبشده%')
|
||||
->orWhere('note', 'like', '%طلای آبشده%')
|
||||
->get()
|
||||
->each(function ($row) {
|
||||
$newNote = str_replace(['طلای آبشده', 'آبشده'], 'مس', $row->note);
|
||||
DB::table('transactions_admins')
|
||||
->where('id', $row->id)
|
||||
->update(['note' => $newNote]);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user