fix trigger bug 2
This commit is contained in:
@@ -126,13 +126,17 @@ class ConditionalOrderController extends Controller
|
|||||||
|
|
||||||
if (! empty($data['expires_at'])) {
|
if (! empty($data['expires_at'])) {
|
||||||
try {
|
try {
|
||||||
$expires = \Illuminate\Support\Carbon::parse($data['expires_at']);
|
$expires = \Illuminate\Support\Carbon::parse(
|
||||||
|
$data['expires_at'],
|
||||||
|
config('app.timezone')
|
||||||
|
)->timezone(config('app.timezone'));
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
throw new UnprocessableEntityHttpException('زمان اعتبار تاریخ معتبری نیست.');
|
throw new UnprocessableEntityHttpException('زمان اعتبار تاریخ معتبری نیست.');
|
||||||
}
|
}
|
||||||
if ($expires->lte(now())) {
|
if ($expires->lte(now())) {
|
||||||
throw new UnprocessableEntityHttpException('زمان اعتبار باید بعد از الان باشد.');
|
throw new UnprocessableEntityHttpException('زمان اعتبار باید بعد از تایم فعلی باشد.');
|
||||||
}
|
}
|
||||||
|
// Wall-clock in app TZ; column is DATETIME (not TIMESTAMP) to avoid double TZ shift.
|
||||||
$data['expires_at'] = $expires->format('Y-m-d H:i:s');
|
$data['expires_at'] = $expires->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,13 +149,17 @@ class ConditionalOrderController extends Controller
|
|||||||
|
|
||||||
if (! empty($data['expires_at'])) {
|
if (! empty($data['expires_at'])) {
|
||||||
try {
|
try {
|
||||||
$expires = \Illuminate\Support\Carbon::parse($data['expires_at']);
|
$expires = \Illuminate\Support\Carbon::parse(
|
||||||
|
$data['expires_at'],
|
||||||
|
config('app.timezone')
|
||||||
|
)->timezone(config('app.timezone'));
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
throw new UnprocessableEntityHttpException('زمان اعتبار تاریخ معتبری نیست.');
|
throw new UnprocessableEntityHttpException('زمان اعتبار تاریخ معتبری نیست.');
|
||||||
}
|
}
|
||||||
if ($expires->lte(now())) {
|
if ($expires->lte(now())) {
|
||||||
throw new UnprocessableEntityHttpException('زمان اعتبار باید بعد از الان باشد.');
|
throw new UnprocessableEntityHttpException('زمان اعتبار باید بعد از تایم فعلی باشد.');
|
||||||
}
|
}
|
||||||
|
// Wall-clock in app TZ; column is DATETIME (not TIMESTAMP) to avoid double TZ shift.
|
||||||
$data['expires_at'] = $expires->format('Y-m-d H:i:s');
|
$data['expires_at'] = $expires->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,10 +205,12 @@ class ConditionalOrderService
|
|||||||
|
|
||||||
public function expirePendingPastDue(): int
|
public function expirePendingPastDue(): int
|
||||||
{
|
{
|
||||||
|
$now = now()->timezone(config('app.timezone'))->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
return ConditionalOrder::query()
|
return ConditionalOrder::query()
|
||||||
->where('status', ConditionalOrder::STATUS_PENDING)
|
->where('status', ConditionalOrder::STATUS_PENDING)
|
||||||
->whereNotNull('expires_at')
|
->whereNotNull('expires_at')
|
||||||
->where('expires_at', '<', now())
|
->where('expires_at', '<', $now)
|
||||||
->update([
|
->update([
|
||||||
'status' => ConditionalOrder::STATUS_EXPIRED,
|
'status' => ConditionalOrder::STATUS_EXPIRED,
|
||||||
'is_active' => false,
|
'is_active' => false,
|
||||||
|
|||||||
@@ -16,7 +16,11 @@ class ConditionalOrderValidation
|
|||||||
'in' => ':attribute انتخابشده نامعتبر است.',
|
'in' => ':attribute انتخابشده نامعتبر است.',
|
||||||
'boolean' => ':attribute باید صحیح یا غلط باشد.',
|
'boolean' => ':attribute باید صحیح یا غلط باشد.',
|
||||||
'date' => ':attribute تاریخ معتبری نیست.',
|
'date' => ':attribute تاریخ معتبری نیست.',
|
||||||
'after' => ':attribute باید بعد از الان باشد.',
|
'after' => 'زمان اعتبار باید بعد از تایم فعلی باشد.',
|
||||||
|
'after_or_equal' => 'زمان اعتبار باید بعد از تایم فعلی باشد.',
|
||||||
|
'expires_at.date' => 'زمان اعتبار تاریخ معتبری نیست.',
|
||||||
|
'expires_at.after' => 'زمان اعتبار باید بعد از تایم فعلی باشد.',
|
||||||
|
'expires_at.after_or_equal' => 'زمان اعتبار باید بعد از تایم فعلی باشد.',
|
||||||
'exists' => ':attribute انتخابشده معتبر نیست.',
|
'exists' => ':attribute انتخابشده معتبر نیست.',
|
||||||
'string' => ':attribute باید متن باشد.',
|
'string' => ':attribute باید متن باشد.',
|
||||||
'nullable' => '',
|
'nullable' => '',
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ return new class extends Migration
|
|||||||
$table->unsignedBigInteger('trigger_price');
|
$table->unsignedBigInteger('trigger_price');
|
||||||
$table->decimal('amount', 16, 4)->nullable();
|
$table->decimal('amount', 16, 4)->nullable();
|
||||||
$table->decimal('number', 16, 4)->nullable();
|
$table->decimal('number', 16, 4)->nullable();
|
||||||
$table->timestamp('expires_at')->nullable()->index();
|
$table->dateTime('expires_at')->nullable()->index();
|
||||||
$table->text('description')->nullable();
|
$table->text('description')->nullable();
|
||||||
$table->boolean('is_active')->default(true);
|
$table->boolean('is_active')->default(true);
|
||||||
$table->string('status', 16)->default('pending')->index(); // pending|executed|failed|expired
|
$table->string('status', 16)->default('pending')->index(); // pending|executed|failed|expired
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TIMESTAMP + app Asia/Tehran + MySQL session TZ caused double conversion:
|
||||||
|
* user 17:05 Tehran was stored ~3.5h earlier and expired immediately.
|
||||||
|
* DATETIME keeps the wall-clock the user/admin picked.
|
||||||
|
*/
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (! Schema::hasTable('conditional_orders')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::statement('ALTER TABLE `conditional_orders` MODIFY COLUMN `expires_at` DATETIME NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if (! Schema::hasTable('conditional_orders')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::statement('ALTER TABLE `conditional_orders` MODIFY COLUMN `expires_at` TIMESTAMP NULL');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user