feat: update order status handling and timestamp on completion
This commit is contained in:
parent
5927fc4e56
commit
c162ccab04
@ -309,13 +309,15 @@ public function update(Order $order, array $data): Order
|
|||||||
DB::table('order_items')->insert($itemRows);
|
DB::table('order_items')->insert($itemRows);
|
||||||
|
|
||||||
$newPaymentType = $data['payment_type'] ?? $order->payment_type->value;
|
$newPaymentType = $data['payment_type'] ?? $order->payment_type->value;
|
||||||
|
$oldStatus = $order->status;
|
||||||
|
$newStatus = ($data['is_completed'] ?? false) ? OrderStatus::COMPLETED : OrderStatus::PENDING;
|
||||||
|
|
||||||
$order->update([
|
$order->update([
|
||||||
'customer_id' => $data['customer_id'] ?? null,
|
'customer_id' => $data['customer_id'] ?? null,
|
||||||
'marketing_id' => $data['marketing_id'] ?? null,
|
'marketing_id' => $data['marketing_id'] ?? null,
|
||||||
'channel' => $data['channel'] ?? $order->channel->value,
|
'channel' => $data['channel'] ?? $order->channel->value,
|
||||||
'price_type' => $priceType,
|
'price_type' => $priceType,
|
||||||
'status' => ($data['is_completed'] ?? false) ? OrderStatus::COMPLETED : OrderStatus::PENDING,
|
'status' => $newStatus,
|
||||||
'payment_type' => $newPaymentType,
|
'payment_type' => $newPaymentType,
|
||||||
'tiktok_order_id' => $data['tiktok_order_id'] ?? null,
|
'tiktok_order_id' => $data['tiktok_order_id'] ?? null,
|
||||||
'shopee_order_id' => $data['shopee_order_id'] ?? null,
|
'shopee_order_id' => $data['shopee_order_id'] ?? null,
|
||||||
@ -327,6 +329,17 @@ public function update(Order $order, array $data): Order
|
|||||||
'notes' => $data['notes'] ?? null,
|
'notes' => $data['notes'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($oldStatus !== OrderStatus::COMPLETED && $newStatus === OrderStatus::COMPLETED) {
|
||||||
|
$now = now();
|
||||||
|
DB::table('orders')
|
||||||
|
->where('id', $order->id)
|
||||||
|
->update([
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
]);
|
||||||
|
$order->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
$this->applyStock($data['items'], $stockType, -1);
|
$this->applyStock($data['items'], $stockType, -1);
|
||||||
|
|
||||||
if ($oldPaymentType === PaymentType::CASH && $newPaymentType !== PaymentType::CASH->value) {
|
if ($oldPaymentType === PaymentType::CASH && $newPaymentType !== PaymentType::CASH->value) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user