v.1.7 update
This commit is contained in:
107
commands/POSTOrder.php
Normal file
107
commands/POSTOrder.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\OrderItems;
|
||||
use App\Component\Models\Orders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class POSTOrder extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postorder';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
|
||||
if (isset($input['task'])) {
|
||||
if ($input['task'] == 'create') {
|
||||
$order = new Orders;
|
||||
$order->staff_id = 1;
|
||||
$order->is_send = 0;
|
||||
$order->save();
|
||||
$order = Orders::where('id', '=', $order->id)->first();
|
||||
$orderItems = OrderItems::where('order_id', '=', $order->id)->get();
|
||||
if (!isset($orderItems)) {
|
||||
$orderItems = [];
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'order' => $order,
|
||||
'orderItems' => $orderItems,
|
||||
'message' => 'Заказ создан',
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'delete' && isset($input['id'])) {
|
||||
$order = Orders::where('id', '=', $input['id'])->first();
|
||||
if ($order->total_count > 0) {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Разрешено удаление только пустых заказов.',
|
||||
];
|
||||
} else {
|
||||
$order->delete();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ удален',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($input['task'] == 'update' && isset($input['order_id'])) {
|
||||
$order = Orders::find($input['order_id']);
|
||||
if (isset($input['item']) && $input['item'] == 'add') {
|
||||
$orderItem = new OrderItems;
|
||||
$orderItem->order_id = $input['order_id'];
|
||||
$orderItem->item_id = $input['item_id'];
|
||||
$orderItem->item_count = $input['item_count'];
|
||||
$item_price = Dishes::where('code', '=', $input['item_id'])->first();
|
||||
$orderItem->item_price = $item_price->cosht;
|
||||
$orderItem->staff_id = 1;
|
||||
$orderItem->save();
|
||||
}
|
||||
if (isset($input['client_id'])) {
|
||||
if ($input['client_id'] !== null) {
|
||||
$order->client_id = $input['client_id'];
|
||||
} else {
|
||||
$order->client_id = null;
|
||||
}
|
||||
|
||||
}
|
||||
if (isset($input['item_count'])) {
|
||||
$order->total_count = $order->total_count + $input['item_count'];
|
||||
$order->total_price = $order->total_price + ($item_price->cosht * $input['item_count']);
|
||||
}
|
||||
|
||||
$order->is_send = 0;
|
||||
$order->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ обновлен',
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'complete' && isset($input['id'])) {
|
||||
$order = Orders::find($input['id']);
|
||||
$order->is_send = 1;
|
||||
if (isset($input['client_id'])) {
|
||||
$order->client_id = $input['client_id'];
|
||||
}
|
||||
$order->is_delivery = $input['is_delivery'];
|
||||
$order->is_pickup = $input['is_pickup'];
|
||||
$order->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ отправлен',
|
||||
];
|
||||
}
|
||||
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user