where('id', '=', $input['shift_id'])->get(); if (is_array($shifts) || is_object($shifts)) { foreach ($shifts as $shift) { $out = array('id' => $shift['id'], 'opened' => $shift['opened'], 'closed' => $shift['closed']); } } $orders = Orders::select('id', 'order', 'created_at')->where('created_at', '>', $out['opened'])->where('created_at', '<=', $out['closed'])->get(); $count_items = 0; if (is_array($orders) || is_object($orders)) { foreach ($orders as $order) { $order_id = $order['id']; $price = json_decode(base64_decode($order['order']), true)['price']; $items = json_decode(base64_decode($order['order']), true)['items']; $date = strtotime($order['created_at']); $newformat = date('Y-m-d H:i:s', $date); foreach ($items as $key => $item) { $out_item[$key] = array( 'id' => $item['id'], 'name' => $item['name'], 'count' => $item['count'], 'price' => $item['price'], 'full_price' => $item['full_price'], ); $count_items += 1; } $remoteOrder[] = array( 'id' => $order_id, 'items_count' => $count_items, 'items' => $out_item, 'date' => $newformat, 'price' => $price, ); unset($out_item); $count_items = 0; } } if (isset($remoteOrder)) { $total_count = 0; $total_price = 0; foreach ($orders as $order) { $total_count += 1; $total_price += json_decode(base64_decode($order['order']), true)['price']; } $total = array('total_count' => $total_count, 'total_price' => $total_price); return [ 'status' => 'success', 'message' => 'true', 'shift' => $out, 'orders' => $remoteOrder, 'total' => $total, ]; } else { return [ 'status' => 'success', 'message' => 'false', ]; } } if ((array_key_exists('start_date', $input)) === true) { $start_t = strtotime($input['start_date']) + 1; $end_t = strtotime($input['end_date']) - 1; $start = date('Y-m-d H:i:s', $start_t); $end = date('Y-m-d H:i:s', $end_t); $orders = Orders::select('id', 'order', 'created_at')->where('created_at', '>', $start)->where('created_at', '<=', $end)->get(); $count_items = 0; if (is_array($orders) || is_object($orders)) { foreach ($orders as $order) { $order_id = $order['id']; $price = json_decode(base64_decode($order['order']), true)['price']; $items = json_decode(base64_decode($order['order']), true)['items']; $date = strtotime($order['created_at']); $newformat = date('Y-m-d H:i:s', $date); foreach ($items as $key => $item) { $out_item[$key] = array( 'id' => $item['id'], 'name' => $item['name'], 'count' => $item['count'], 'price' => $item['price'], 'full_price' => $item['full_price'], ); $count_items += 1; } $remoteOrder[] = array( 'id' => $order_id, 'items_count' => $count_items, 'items' => $out_item, 'date' => $newformat, 'price' => $price, ); unset($out_item); $count_items = 0; } } if (isset($remoteOrder)) { $total_count = 0; $total_price = 0; if (is_array($orders) || is_object($orders)) { foreach ($orders as $order) { $total_count += 1; $total_price += json_decode(base64_decode($order['order']), true)['price']; } } $total = array('total_count' => $total_count, 'total_price' => $total_price); $report = new Report; $report->user_id = $input['admin_user_id']; $report->name = 'Отчет по внешним заказам'; $report->shift_id = 0; $report->start_date = $start; $report->end_date = $end; $report->report_type = 'out'; $report->save(); return [ 'status' => 'success', 'message' => 'true', 'orders' => $remoteOrder, 'total' => $total, ]; } else { return [ 'status' => 'success', 'message' => 'false', ]; } } } }