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(); if (isset($orderItems)) { foreach ($orderItems as $key => $item) { $itemName = Dishes::getName($item['item_id']); $is_real = Dishes::isReal($item['item_id']); $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('code', $itemModifier['modifier_id'])->first(); if ($modifier['dish_code'] == 0 && $modifier['unit_id'] == 0) { $modOut[] = array('id' => $modifier['code'], 'name' => $modifier['name'], 'price' => '*'); } } } $output[] = array('id' => $item['id'], 'num' => $key + 1, 'order_id' => $item['order_id'], 'item_id' => $item['item_id'], 'item_name' => $itemName, 'item_count' => round($item['item_count'], 3), 'item_price' => round($item['item_price'], 2), 'is_real' => $is_real, ); } } 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' => round($order['total_price'], 2), ]; } 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' => 'Проверьте введенные данные', ]; } } }