feat: update sms units to kilogram transactions notes price source label and trading closed message
This commit is contained in:
@@ -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