v.2.18
This commit is contained in:
81
commands/GETImportMenu.php
Normal file
81
commands/GETImportMenu.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETImportMenu extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getimportmenu';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$HRCPortalURL = 'https://portal.hrc.by/';
|
||||
$folder = 'menu';
|
||||
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->first();
|
||||
$url = $HRCPortalURL . 'api/cloud/list?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&folder=' . $folder;
|
||||
$search = curl_init();
|
||||
|
||||
curl_setopt_array($search, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
));
|
||||
$search_response = curl_exec($search);
|
||||
curl_close($search);
|
||||
$responses = json_decode($search_response, TRUE)['files'];
|
||||
|
||||
/*{"status":"success","message":[{"size":"61671","mimetype":"application\/xml","timestamp":1655321649,"type":"file","path":"menu\/Menu_1_1.xml","dirname":"menu","basename":"Menu_1_1.xml","extension":"xml","filename":"Menu_1_1"}]}*/
|
||||
|
||||
foreach ($responses as $key => $response) {
|
||||
$filename = $response['basename'];
|
||||
//$path = '/backup/' . $filename . '.xml';
|
||||
$path = '/menu/' . $filename;
|
||||
$download_url = $HRCPortalURL . 'api/cloud/download?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&path=' . $path;
|
||||
$download = curl_init();
|
||||
|
||||
curl_setopt_array($download, array(
|
||||
CURLOPT_URL => $download_url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
));
|
||||
$download_response = curl_exec($download);
|
||||
curl_close($download);
|
||||
$file = json_decode($download_response, TRUE)['content'];
|
||||
}
|
||||
$dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\menu\\";
|
||||
if (!is_dir($dirname)) {
|
||||
mkdir($dirname, 0755, 'w+');
|
||||
}
|
||||
if (file_exists($dirname . $filename)) {
|
||||
unlink($dirname . $filename);
|
||||
}
|
||||
$handle = fopen($dirname . $filename, 'w+');
|
||||
fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM
|
||||
file_put_contents($dirname . $filename, base64_decode($file));
|
||||
fclose($handle);
|
||||
$menu_file = $dirname . $filename;
|
||||
$objXmlDocument = simplexml_load_file($menu_file);
|
||||
$objJsonDocument = json_encode($objXmlDocument);
|
||||
$xmlmenu = json_decode($objJsonDocument, TRUE);
|
||||
$test = $xmlmenu['GeneralSettings']['@attributes'];
|
||||
/* $check_setting = Settings::where('code', 12)->first();
|
||||
$check_setting = $check_setting['value'] + 0;
|
||||
if ($check_setting == 0) {
|
||||
|
||||
}*/
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => $test,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,36 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
$merge_trigger = 0;
|
||||
$move_trigger = 0;
|
||||
|
||||
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 = [
|
||||
"А", "Б", "В", "Г", "Д",
|
||||
@@ -84,8 +114,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 = Staff::where('code', $item['who'])->first();
|
||||
$staff_name = $staff['name'];
|
||||
$staff_name = staffName($item['who']);
|
||||
|
||||
if ($item['type_action'] == 1) {
|
||||
$action_name = 'Заказ создан';
|
||||
@@ -95,18 +124,27 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
$shiftOnlineItem = ShiftOnlineItems::where('order_code', $item['order_code'])->where('dish_code', $item['more'])->first();
|
||||
$unitsList = UnitsList::where('id', $shiftOnlineItem['units_code'])->first();
|
||||
$units = Units::where('id', $unitsList['unit_id'])->first();
|
||||
$unit_name = $units['name'];
|
||||
$dish = Dishes::where('code', $item['more'])->first();
|
||||
$action_name = $action_name . ': ' . $dish['name'] . ' в количестве ' . $item['value'] . ' ' . $unit_name;
|
||||
if ($units) {
|
||||
$unit_name = $units['name'];
|
||||
} else {
|
||||
$unit_name = 'шт';
|
||||
}
|
||||
$dish = dishName($item['more']);
|
||||
$action_name = $action_name . ': ' . $dish . ' в количестве ' . $item['value'] . ' ' . $unit_name;
|
||||
}
|
||||
|
||||
if ($item['type_action'] == 5) {
|
||||
$shiftOnlineDeletedItem = ShiftOnlineDeleted::where('order_code', $item['order_code'])->where('item_id', $item['order_position'])->first();
|
||||
$unitsList = UnitsList::where('id', $shiftOnlineDeletedItem['units_id'])->first();
|
||||
$units = Units::where('id', $unitsList['unit_id'])->first();
|
||||
$unit_name = $units['name'];
|
||||
$dish = Dishes::where('code', $shiftOnlineDeletedItem['dishes_code'])->first();
|
||||
$action_name = $action_name . ': ' . $dish['name'] . ' в количестве ' . $item['value'] . ' ' . $unit_name;
|
||||
if ($units) {
|
||||
$unit_name = $units['name'];
|
||||
} else {
|
||||
$unit_name = 'шт';
|
||||
}
|
||||
|
||||
$dish = dishName($shiftOnlineDeletedItem['dishes_code']);
|
||||
$action_name = $action_name . ': ' . $dish . ' в количестве ' . $item['value'] . ' ' . $unit_name;
|
||||
}
|
||||
|
||||
if ($item['type_action'] == 11) {
|
||||
@@ -130,8 +168,8 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
}
|
||||
|
||||
if ($item['type_action'] == 22) {
|
||||
$dish = Dishes::where('code', $item['order_position'])->first();
|
||||
$action_name = 'Отменена позиции: ' . $dish['name'] . ' в количестве ' . $item['value'];
|
||||
$dish = dishName($item['order_position']);
|
||||
$action_name = 'Отменена позиции: ' . $dish . ' в количестве ' . $item['value'];
|
||||
}
|
||||
|
||||
if ($item['type_action'] == 24) {
|
||||
@@ -174,17 +212,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
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 = Staff::where('code', $item['who'])->where('is_history', 0)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = Staff::where('code', $item['who'])->where('is_history', 1)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = 'Связанный персонал не найден';
|
||||
}
|
||||
}
|
||||
$staff_name = staffName($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;
|
||||
}
|
||||
@@ -230,17 +258,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
'name' => $merged_item['name'],
|
||||
'count' => $merged_item['count']);
|
||||
}
|
||||
$staff_name = Staff::where('code', $item['who'])->where('is_history', 0)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = Staff::where('code', $item['who'])->where('is_history', 1)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = 'Связанный персонал не найден';
|
||||
}
|
||||
}
|
||||
$staff_name = staffName($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;
|
||||
}
|
||||
@@ -252,17 +270,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface {
|
||||
->where('type_action', 39)
|
||||
->get();
|
||||
foreach ($order_data as $key => $data) {
|
||||
$staff_name = Staff::where('code', $data['who'])->where('is_history', 0)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = Staff::where('code', $data['who'])->where('is_history', 1)->first();
|
||||
if ($staff_name) {
|
||||
$staff_name = $staff_name['name'];
|
||||
} else {
|
||||
$staff_name = 'Связанный персонал не найден';
|
||||
}
|
||||
}
|
||||
$staff_name = staffName($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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user