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
+36
View File
@@ -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');
+43
View File
@@ -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);