v.1.7 update
This commit is contained in:
129
commands/GETOrder.php
Normal file
129
commands/GETOrder.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\ClientsAddress;
|
||||
use App\Component\Models\ClientsPhone;
|
||||
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 GETOrder extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getorder';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
|
||||
if (isset($input['task'])) {
|
||||
if ($input['task'] == 'single' && isset($input['order_id'])) {
|
||||
$order = Orders::where('id', '=', $input['order_id'])->first();
|
||||
|
||||
if (isset($order->client_id) && $order->client_id !== null && $order->client_id !== '') {
|
||||
$client = Client::where('user_code', '=', $order->client_id)->first();
|
||||
$client = $client->name;
|
||||
$client_phone = ClientsPhone::where('client_guid', '=', $order->client_id)->first();
|
||||
$client_phone = $client_phone->phone;
|
||||
$client_address = ClientsAddress::where('client_guid', '=', $order->client_id)->first();
|
||||
$client_address = $client_address->address;
|
||||
} else {
|
||||
$client = '';
|
||||
$client_phone = '';
|
||||
$client_address = '';
|
||||
}
|
||||
|
||||
$orderItems = OrderItems::where('order_id', '=', $order->id)->whereNull('modifier_id')->get();
|
||||
$modOut = array();
|
||||
if (isset($orderItems)) {
|
||||
foreach ($orderItems as $key => $item) {
|
||||
$itemName = Dishes::where('code', '=', $item->item_id)->first();
|
||||
$itemName = $itemName->name;
|
||||
$itemModifiers = OrderItems::where('order_id', '=', $order->id)->where('parent_id', '=', $item->id)->whereNotNull('modifier_id')->get();
|
||||
if (isset($itemModifiers)) {
|
||||
foreach ($itemModifiers as $key => $itemModifier) {
|
||||
$modifier = Modifier::where('id', '=', $itemModifier->modifier_id)->first();
|
||||
if ($modifier->dish_code == 0 && $modifier->unit_id == 0) {
|
||||
$modOut[] = array('' => , );
|
||||
}
|
||||
}
|
||||
}
|
||||
$output[] = array('id' => $item->id,
|
||||
'num' => $key + 1,
|
||||
'order_id' => $item->order_id,
|
||||
'item_id' => $item->item_id,
|
||||
'item_name' => $itemName,
|
||||
'item_count' => $item->item_count,
|
||||
'item_price' => $item->item_price,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$output = [];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ №' . $order->id,
|
||||
'order' => $order,
|
||||
'orderItems' => $output,
|
||||
'client_name' => $client,
|
||||
'client_phone' => $client_phone,
|
||||
'client_address' => $client_address,
|
||||
'totalCount' => $order->total_count,
|
||||
'totalPrice' => $order->total_price,
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'list') {
|
||||
$orders = Orders::all();
|
||||
foreach ($orders as $key => $order) {
|
||||
$client = Client::where('user_code', '=', $order->client_id)->first();
|
||||
$client_phone = ClientsPhone::where('client_guid', '=', $order->client_id)->first();
|
||||
$client_address = ClientsAddress::where('client_guid', '=', $order->client_id)->first();
|
||||
if (isset($client)) {
|
||||
$output[] = array('id' => $order->id, 'client_name' => $client->name, 'client_phone' => $client_phone->phone, 'client_address' => $client_address->address, 'total_count' => $order->total_count, 'total_price' => $order->total_price, 'is_send' => $order->is_send);
|
||||
} else {
|
||||
$output[] = array('id' => $order->id, 'client_name' => '', 'client_phone' => '', 'client_address' => '', 'total_count' => $order->total_count, 'total_price' => $order->total_price, 'is_send' => $order->is_send);
|
||||
}
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Список заказов',
|
||||
'orders' => $output,
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'clientsearch' && $input['search']) {
|
||||
$input['search'] = urldecode($input['search']);
|
||||
$phone = '+375 (' . substr($input['search'], 0, 2) . ') ' . substr($input['search'], 2, 3) . '-' . substr($input['search'], 5, 2) . '-' . substr($input['search'], 7, 2);
|
||||
$clients = ClientsPhone::where('phone', '=', $phone)->get();
|
||||
if (isset($clients)) {
|
||||
foreach ($clients as $key => $client) {
|
||||
$client_name = Client::where('user_code', '=', $client->client_guid)->first();
|
||||
$client_name = $client_name->name;
|
||||
$client_address = ClientsAddress::where('client_guid', '=', $client->client_guid)->first();
|
||||
$client_phone = $client->phone;
|
||||
$client_guid = $client->client_guid;
|
||||
$output[] = array('guid' => $client_guid, 'name' => $client_name, 'phone' => $client_phone, 'address' => $client_address->address);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($clients)) {
|
||||
$clients = [];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Список клиентов',
|
||||
'clients' => $output,
|
||||
];
|
||||
}
|
||||
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user