v.2.22
Редактор карты зала Электронные заказы Отчет по удалениям
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,9 @@ class GETDiscountItems extends HRCCommand implements HRCCommandInterface {
|
||||
$discount = 0;
|
||||
}
|
||||
$dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first();
|
||||
if (!isset($dish)) {
|
||||
$dish = Dishes::where('legacy_code', $item['dish_code'])->where('is_history', 0)->first();
|
||||
}
|
||||
$items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,42 +18,43 @@ class GETOrder extends HRCCommand implements HRCCommandInterface {
|
||||
|
||||
if (isset($input['task'])) {
|
||||
if ($input['task'] == 'single' && isset($input['order_id'])) {
|
||||
$order = Orders::where('id', '=', $input['order_id'])->first();
|
||||
$order = Orders::where('id', intval($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;
|
||||
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();
|
||||
$orderItems = OrderItems::where('order_id', $order['id'])->whereNull('modifier_id')->get();
|
||||
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();
|
||||
$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' => '*');
|
||||
$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,
|
||||
$output[] = array('id' => $item['id'],
|
||||
'num' => $key + 1,
|
||||
'order_id' => $item->order_id,
|
||||
'item_id' => $item->item_id,
|
||||
'order_id' => $item['order_id'],
|
||||
'item_id' => $item['item_id'],
|
||||
'item_name' => $itemName,
|
||||
'item_count' => $item->item_count,
|
||||
'item_price' => $item->item_price,
|
||||
'item_count' => round($item['item_count'], 3),
|
||||
'item_price' => round($item['item_price'], 2),
|
||||
'is_real' => $is_real,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -62,27 +63,41 @@ class GETOrder extends HRCCommand implements HRCCommandInterface {
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ №' . $order->id,
|
||||
'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,
|
||||
'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();
|
||||
$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);
|
||||
$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);
|
||||
$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 [
|
||||
@@ -98,12 +113,16 @@ class GETOrder extends HRCCommand implements HRCCommandInterface {
|
||||
$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);
|
||||
$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']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,35 +78,6 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
return true;
|
||||
}
|
||||
|
||||
function dishName($data) {
|
||||
$dish_name = Dishes::where('code', $data)->where('is_history', 0)->first();
|
||||
if ($dish_name) {
|
||||
$dish_name = $dish_name['name'];
|
||||
} else {
|
||||
$dish_name = Dishes::where('code', $data)->where('is_history', 1)->first();
|
||||
if ($dish_name) {
|
||||
$dish_name = $dish_name['name'];
|
||||
} else {
|
||||
$dish_name = 'Связанный товар удален';
|
||||
}
|
||||
}
|
||||
return $dish_name;
|
||||
}
|
||||
|
||||
function staffName($data) {
|
||||
$staff_name = Staff::where('code', $data)->where('is_history', 0)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = Staff::where('code', $data)->where('is_history', 1)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = 'Связанный персонал не найден';
|
||||
}
|
||||
}
|
||||
return $staff_name;
|
||||
}
|
||||
|
||||
function data_decode($data) {
|
||||
$alph = [
|
||||
@@ -166,7 +137,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
foreach ($order as $key => $item) {
|
||||
$action_type = ActionTypes::where('type_id', $item['type_action'])->first();
|
||||
$action_name = $action_type['name'];
|
||||
$staff_name = staffName($item['who']);
|
||||
$staff_name = Staff::getName($item['who']);
|
||||
|
||||
if ($item['type_action'] == 1) {
|
||||
$action_name = 'Заказ создан';
|
||||
@@ -181,7 +152,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
} else {
|
||||
$unit_name = 'шт';
|
||||
}
|
||||
$dish = dishName($item['more']);
|
||||
$dish = Dishes::getName($item['more']);
|
||||
$action_name = $action_name . ': ' . $dish . ' в количестве ' . $item['value'] . ' ' . $unit_name;
|
||||
}
|
||||
|
||||
@@ -195,7 +166,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
$unit_name = 'шт';
|
||||
}
|
||||
|
||||
$dish = dishName($shiftOnlineDeletedItem['dishes_code']);
|
||||
$dish = Dishes::getName($shiftOnlineDeletedItem['dishes_code']);
|
||||
$action_name = $action_name . ': ' . $dish . ' в количестве ' . $item['value'] . ' ' . $unit_name;
|
||||
}
|
||||
|
||||
@@ -220,7 +191,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
}
|
||||
|
||||
if ($item['type_action'] == 22) {
|
||||
$dish = dishName($item['order_position']);
|
||||
$dish = Dishes::getName($item['order_position']);
|
||||
$action_name = 'Отменена позиции: ' . $dish . ' в количестве ' . $item['value'];
|
||||
}
|
||||
|
||||
@@ -263,13 +234,12 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
} else {
|
||||
$slice_order_items = json_decode(utf8_encode(base64_decode($item['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
}
|
||||
//$slice_order_items = json_decode(utf8_encode($item['more']), true, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
$slice_order_items = $slice_order_items['items'];
|
||||
$slice_order = $item['value'];
|
||||
foreach ($slice_order_items as $key => $slice_order_item) {
|
||||
$slice_items[] = array('id' => $key + 1, 'name' => $slice_order_item['name'], 'count' => $slice_order_item['count']);
|
||||
}
|
||||
$staff_name = staffName($item['who']);
|
||||
$staff_name = Staff::getName($item['who']);
|
||||
$sliced_order_items[] = array('order' => $slice_order, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'items' => $slice_items);
|
||||
$slice_trigger = 1;
|
||||
}
|
||||
@@ -282,16 +252,18 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
->where('type_action', 32)
|
||||
->get();
|
||||
foreach ($item_actions as $key => $item_action) {
|
||||
if ($item_action['more']) {
|
||||
if ($item_action['more'] != '') {
|
||||
$merge_items_before = $merge_items_after = $merge_items = $merge_order_item_before = $merge_order_item_after = $merged_items = [];
|
||||
if (json_validate($item['more'])) {
|
||||
if (json_validate($item_action['more'])) {
|
||||
$merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
} else {
|
||||
$merge_order_items = json_decode(utf8_encode(base64_decode($item_action['more'])), true, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
$merge_order_items = json_decode(base64_decode($item_action['more']), true);
|
||||
}
|
||||
|
||||
//$merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
$merge_order_items_before = $merge_order_items['before']['items'];
|
||||
$merge_order_items_after = $merge_order_items['after']['items'];
|
||||
|
||||
foreach ($merge_order_items_before as $key => $merge_order_item_before) {
|
||||
$merge_items_before[] = array('id' => $key + 1,
|
||||
'code' => $merge_order_item_before['id'],
|
||||
@@ -320,7 +292,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
'name' => $merged_item['name'],
|
||||
'count' => $merged_item['count']);
|
||||
}
|
||||
$staff_name = staffName($item['who']);
|
||||
$staff_name = Staff::getName($item['who']);
|
||||
$merged_order_items[] = array('order' => $merge_order, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'items' => $merge_items);
|
||||
$merge_trigger = 1;
|
||||
}
|
||||
@@ -332,7 +304,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
->where('type_action', 39)
|
||||
->get();
|
||||
foreach ($order_data as $key => $data) {
|
||||
$staff_name = staffName($data['who']);
|
||||
$staff_name = Staff::getName($data['who']);
|
||||
$moved_order_data[] = array('staff_name' => $staff_name, 'time' => date('d.m.Y H:i:s', strtotime($data['time'])), 'data' => data_decode($data['value']));
|
||||
$move_trigger = 1;
|
||||
}
|
||||
|
||||
51
commands/GETRoomMap.php
Normal file
51
commands/GETRoomMap.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Places;
|
||||
use App\Component\Models\Tables;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETRoomMap extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getroommap';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
if (isset($input['type'])) {
|
||||
$roommap = [];
|
||||
if ($input['type'] == 'places') {
|
||||
$places = Places::all();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'places' => $places,
|
||||
];
|
||||
}
|
||||
if ($input['type'] == 'place' && isset($input['id'])) {
|
||||
$place_name = Places::getName($input['id']);
|
||||
$tables = Tables::where('place_id', $input['id'])->get();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'place_id' => $input['id'],
|
||||
'place' => $place_name,
|
||||
'tables' => $tables,
|
||||
];
|
||||
}
|
||||
if ($input['type'] == 'full') {
|
||||
$places = Places::all();
|
||||
foreach ($places as $place) {
|
||||
$tables = Tables::where('place_id', $place['id'])->get();
|
||||
$roommap[] = array('place_id' => $place['id'], 'place_name' => $place['name'], 'tables' => $tables);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'roommap' => $roommap,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Ошибка данных запроса',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
101
commands/GETRoomMapFile.php
Normal file
101
commands/GETRoomMapFile.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Places;
|
||||
use App\Component\Models\Tables;
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class GETRoomMapFile extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getroommapfile';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
|
||||
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->first();
|
||||
$files = [];
|
||||
$dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\places\\";
|
||||
Http::post('https://portal.hrc.by/api/cloud/folder', [
|
||||
'code' => $terminal['key'],
|
||||
'folder' => 'places',
|
||||
'project_code' => 'hrc',
|
||||
'api' => '2.0',
|
||||
]);
|
||||
$response_files = Http::get('https://portal.hrc.by/api/cloud/list?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&folder=places');
|
||||
if (count($response_files->json()['files']) > 0) {
|
||||
foreach ($response_files->json()['files'] as $response) {
|
||||
$filename = $response['filename'];
|
||||
$basename = $response['basename'];
|
||||
$files[$response['timestamp']] = array('filename' => $filename, 'basename' => $basename);
|
||||
}
|
||||
if (count($files) == 0) {
|
||||
return ['status' => 'success',
|
||||
'message' => 'Файлы не найдены'
|
||||
];
|
||||
}
|
||||
$iMaxArrayIndex = max(array_keys($files));
|
||||
$basename = $files[$iMaxArrayIndex]['basename'];
|
||||
$download_files = Http::get('https://portal.hrc.by/api/cloud/download?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&path=/places/' . $basename);
|
||||
$file = base64_decode($download_files->json()['content']);
|
||||
if (!is_dir($dirname)) {
|
||||
mkdir($dirname, 0755, 'w+');
|
||||
}
|
||||
if (file_exists($dirname . $basename)) {
|
||||
unlink($dirname . $basename);
|
||||
}
|
||||
$handle = fopen($dirname . $basename, 'w+');
|
||||
fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM
|
||||
file_put_contents($dirname . $basename, $file);
|
||||
fclose($handle);
|
||||
foreach ($files as $file) {
|
||||
Http::delete('https://portal.hrc.by/api/cloud/file', [
|
||||
'code' => $terminal['key'],
|
||||
'name' => $file['basename'],
|
||||
'folder' => 'places',
|
||||
'project_code' => 'hrc',
|
||||
'api' => '2.0',
|
||||
]);
|
||||
}
|
||||
$places_file = $dirname . $basename;
|
||||
} else {
|
||||
return ['status' => 'success',
|
||||
'message' => 'Файлы не найдены'
|
||||
];
|
||||
}
|
||||
$objXmlDocument = simplexml_load_file($places_file);
|
||||
$objJsonDocument = json_encode($objXmlDocument);
|
||||
$xmlPlaces = json_decode($objJsonDocument, TRUE);
|
||||
|
||||
Schema::disableForeignKeyConstraints();
|
||||
DB::table('place_tables')->truncate();
|
||||
DB::table('places')->truncate();
|
||||
Schema::enableForeignKeyConstraints();
|
||||
|
||||
foreach ($xmlPlaces['Place'] as $xmlPlace) {
|
||||
$place_name = $xmlPlace['@attributes']['name'];
|
||||
$newPlace = new Places;
|
||||
$newPlace->name = $place_name;
|
||||
$newPlace->save();
|
||||
foreach ($xmlPlace['Table'] as $table) {
|
||||
$newTable = new Tables;
|
||||
$newTable->name = $table['@attributes']['text'];
|
||||
$newTable->table_id = intval($table['@attributes']['number']);
|
||||
$newTable->place_id = $newPlace['id'];
|
||||
$newTable->width = $table['@attributes']['width'];
|
||||
$newTable->height = $table['@attributes']['height'];
|
||||
$newTable->x = $table['@attributes']['y'];
|
||||
$newTable->y = $table['@attributes']['x'];
|
||||
$newTable->save();
|
||||
}
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'places' => $xmlPlaces
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -65,10 +65,10 @@ class POSTOrderItem extends HRCCommand implements HRCCommandInterface {
|
||||
$totalCount = 0;
|
||||
$totalPrice = 0;
|
||||
foreach ($orderItems as $key => $item) {
|
||||
$totalCount = $totalCount + $item->item_count;
|
||||
//$totalCount = $totalCount + $item->item_count;
|
||||
$totalPrice = $totalPrice + $item->item_count * $item->item_price;
|
||||
}
|
||||
$order->total_count = $totalCount;
|
||||
$order->total_count = count($orderItems);
|
||||
$order->total_price = $totalPrice;
|
||||
$order->save();
|
||||
return [
|
||||
|
||||
221
commands/POSTRoomMap.php
Normal file
221
commands/POSTRoomMap.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
|
||||
use App\Component\Models\Places;
|
||||
use App\Component\Models\Tables;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class POSTRoomMap extends HRCCommand implements HRCCommandInterface
|
||||
{
|
||||
protected $signature = 'postroommap';
|
||||
|
||||
public function command($input, $output = null)
|
||||
{
|
||||
|
||||
if (isset($input['type']) && $input['type'] == 'place') {
|
||||
if ($input['action'] == 'create' && isset($input['name'])) {
|
||||
$max_id = Places::max('id');
|
||||
$place = new Places;
|
||||
$place->id = $max_id + 1;
|
||||
$place->name = urldecode($input['name']);
|
||||
$place->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Зал успешно добавлен',
|
||||
'place' => $place
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['action'] == 'update' && isset($input['id']) && isset($input['name'])) {
|
||||
$place = Places::find($input['id']);
|
||||
$place->name = urldecode($input['name']);
|
||||
$place->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Зал успешно обновлен',
|
||||
'place' => $place
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['action'] == 'delete' && isset($input['id'])) {
|
||||
$place = Places::find($input['id']);
|
||||
$place->delete();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Зал успешно удален'
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['action'] == 'saveplaces' && isset($input['places'])) {
|
||||
DB::statement("SET foreign_key_checks=0");
|
||||
Tables::truncate();
|
||||
Places::truncate();
|
||||
DB::statement("SET foreign_key_checks=1");
|
||||
$input['places'] = json_decode(urldecode($input['places']), TRUE);
|
||||
|
||||
foreach ($input['places'] as $place_items) {
|
||||
$place_name = urldecode($place_items['place_name']);
|
||||
$newPlace = new Places;
|
||||
$newPlace->name = $place_name;
|
||||
$newPlace->save();
|
||||
foreach ($place_items['tables'] as $table_item) {
|
||||
$table_id = $table_item['table_id'];
|
||||
$table_place_id = $place_items['place_id'];
|
||||
$table_name = urldecode($table_item['name']);
|
||||
$table_width = $table_item['width'];
|
||||
$table_height = $table_item['height'];
|
||||
$table_x = $table_item['x'];
|
||||
$table_y = $table_item['y'];
|
||||
$newTable = new Tables;
|
||||
$newTable->name = $table_name;
|
||||
$newTable->table_id = $table_id;
|
||||
$newTable->place_id = $table_place_id;
|
||||
$newTable->width = $table_width;
|
||||
$newTable->height = $table_height;
|
||||
$newTable->x = $table_x;
|
||||
$newTable->y = $table_y;
|
||||
$newTable->save();
|
||||
}
|
||||
|
||||
}
|
||||
$places = Places::all();
|
||||
foreach ($places as $place) {
|
||||
$tables = Tables::where('place_id', $place['id'])->get();
|
||||
$roommap[] = array('place_id' => $place['id'], 'place_name' => $place['name'], 'tables' => $tables);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Карта успешно обновлена',
|
||||
'roommap' => $roommap,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Проверьте введенные данные',
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
if (isset($input['type']) && $input['type'] == 'table') {
|
||||
if ($input['action'] == 'create' &&
|
||||
isset($input['place_id']) &&
|
||||
isset($input['table_id']) &&
|
||||
isset($input['name']) &&
|
||||
isset($input['width']) &&
|
||||
isset($input['height']) &&
|
||||
isset($input['x']) &&
|
||||
isset($input['y'])) {
|
||||
$table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->where('name', $input['name'])->first();
|
||||
if (isset($table)) {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Стол уже существует',
|
||||
];
|
||||
}
|
||||
$table_id = $input['table_id'];
|
||||
$table_place_id = $input['place_id'];
|
||||
$table_name = urldecode($input['name']);
|
||||
$table_width = $input['width'];
|
||||
$table_height = $input['height'];
|
||||
$table_x = $input['x'];
|
||||
$table_y = $input['y'];
|
||||
$newTable = new Tables;
|
||||
$newTable->name = $table_name;
|
||||
$newTable->table_id = $table_id;
|
||||
$newTable->place_id = $table_place_id;
|
||||
$newTable->width = $table_width;
|
||||
$newTable->height = $table_height;
|
||||
$newTable->x = $table_x;
|
||||
$newTable->y = $table_y;
|
||||
$newTable->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Стол успешно добавлен',
|
||||
'table' => $newTable
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['action'] == 'update' &&
|
||||
isset($input['place_id']) &&
|
||||
isset($input['table_id']) &&
|
||||
isset($input['name']) &&
|
||||
isset($input['width']) &&
|
||||
isset($input['height']) &&
|
||||
isset($input['x']) &&
|
||||
isset($input['y'])) {
|
||||
$table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->first();
|
||||
$table_id = $input['table_id'];
|
||||
$table_place_id = $input['place_id'];
|
||||
$table_name = urldecode($input['name']);
|
||||
$table_width = $input['width'];
|
||||
$table_height = $input['height'];
|
||||
$table_x = $input['x'];
|
||||
$table_y = $input['y'];
|
||||
$table = Tables::find($table['id']);
|
||||
$table->name = $table_name;
|
||||
$table->table_id = $table_id;
|
||||
$table->place_id = $table_place_id;
|
||||
$table->width = $table_width;
|
||||
$table->height = $table_height;
|
||||
$table->x = $table_x;
|
||||
$table->y = $table_y;
|
||||
$table->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Стол успешно обновлен',
|
||||
'table' => $table
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['action'] == 'delete' &&
|
||||
isset($input['place_id']) &&
|
||||
isset($input['table_id'])) {
|
||||
$table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->first();
|
||||
$table = Tables::find($table['id']);
|
||||
$table->delete();
|
||||
}
|
||||
|
||||
if ($input['action'] == 'savetables' && isset($input['tables']) && isset($input['place_id'])) {
|
||||
$input['tables'] = json_decode(urldecode($input['tables']), TRUE);
|
||||
$tables = Tables::where('place_id', intval($input['place_id']))->get();
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$del_table = Tables::find($table['id']);
|
||||
$del_table->delete();
|
||||
}
|
||||
foreach ($input['tables'] as $item) {
|
||||
$table_id = $item['table_id'];
|
||||
$table_place_id = $item['place_id'];
|
||||
$table_name = urldecode($item['name']);
|
||||
$table_width = $item['width'];
|
||||
$table_height = $item['height'];
|
||||
$table_x = $item['x'];
|
||||
$table_y = $item['y'];
|
||||
$newTable = new Tables;
|
||||
$newTable->name = $table_name;
|
||||
$newTable->table_id = $table_id;
|
||||
$newTable->place_id = $table_place_id;
|
||||
$newTable->width = $table_width;
|
||||
$newTable->height = $table_height;
|
||||
$newTable->x = $table_x;
|
||||
$newTable->y = $table_y;
|
||||
$newTable->save();
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Зал успешно обновлен'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user