fix trigger bug
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\Customer;
|
||||
use App\Models\Product;
|
||||
use App\Services\ConditionalOrderService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Support\ConditionalOrderValidation;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
@@ -128,12 +129,16 @@ class ConditionalOrderController extends Controller
|
||||
'trigger_price' => ($partial ? 'sometimes|' : '') . 'required|numeric|min:1',
|
||||
'amount' => 'nullable|numeric|min:0',
|
||||
'number' => 'nullable|numeric|min:0',
|
||||
'expires_at' => 'nullable|date|after:now',
|
||||
'expires_at' => 'nullable|date',
|
||||
'description' => 'nullable|string|max:2000',
|
||||
'is_active' => 'sometimes|boolean',
|
||||
];
|
||||
|
||||
$data = $request->validate($rules);
|
||||
$data = $request->validate(
|
||||
$rules,
|
||||
ConditionalOrderValidation::messages(),
|
||||
ConditionalOrderValidation::attributes()
|
||||
);
|
||||
|
||||
$amount = isset($data['amount']) ? (float) $data['amount'] : null;
|
||||
$number = isset($data['number']) ? (float) $data['number'] : null;
|
||||
@@ -142,6 +147,18 @@ class ConditionalOrderController extends Controller
|
||||
throw new UnprocessableEntityHttpException('مقدار گرم یا تعداد را وارد کنید.');
|
||||
}
|
||||
|
||||
if (! empty($data['expires_at'])) {
|
||||
try {
|
||||
$expires = \Illuminate\Support\Carbon::parse($data['expires_at']);
|
||||
} catch (\Throwable $e) {
|
||||
throw new UnprocessableEntityHttpException('زمان اعتبار تاریخ معتبری نیست.');
|
||||
}
|
||||
if ($expires->lte(now())) {
|
||||
throw new UnprocessableEntityHttpException('زمان اعتبار باید بعد از الان باشد.');
|
||||
}
|
||||
$data['expires_at'] = $expires->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
$productId = (int) ($data['product_id'] ?? $request->input('product_id') ?? 0);
|
||||
$product = $productId > 0 ? Product::find($productId) : null;
|
||||
if ($product && $amount !== null && $amount > 0 && ($number === null || $number <= 0)) {
|
||||
|
||||
Reference in New Issue
Block a user