This commit is contained in:
miroman-afk
2022-06-16 12:50:50 +03:00
parent cb33be6001
commit 415b291785
11 changed files with 198 additions and 60 deletions

View 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,
];
}
}

View File

@@ -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;
}

View File

@@ -1,6 +1,6 @@
{
"name": "hrc-admin/hello-world",
"version": "2.16",
"version": "2.17",
"require": {
"horeca/admin-php-module-core": "dev-master"
},

View File

@@ -10,20 +10,20 @@ class DeleteSettingsFrontendFolder extends Migration {
* @return void
*/
public function up() {
// function dirDel($dir) {
// $d = opendir($dir);
// while (($entry = readdir($d)) !== false) {
// if ($entry != "." && $entry != "..") {
// if (is_dir($dir . "/" . $entry)) {
// dirDel($dir . "/" . $entry);
// } else {
// unlink($dir . "/" . $entry);
// }
// }
// }
// closedir($d);
// rmdir($dir);
// }
function dirDel($dir) {
$d = opendir($dir);
while (($entry = readdir($d)) !== false) {
if ($entry != "." && $entry != "..") {
if (is_dir($dir . "/" . $entry)) {
dirDel($dir . "/" . $entry);
} else {
unlink($dir . "/" . $entry);
}
}
}
closedir($d);
rmdir($dir);
}
if (file_exists(CORE_PATH . '/../Settings/web/')) {
dirDel(CORE_PATH . '/../Settings/web/');
} else {

View File

@@ -0,0 +1,25 @@
<?php
namespace Database\Component\Seeders;
use App\Component\Models\Settings;
use Illuminate\Database\Seeder;
class Add1cMenuUploadSetting extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run() {
$check_setting = Settings::where('name', 'Триггер загрузки меню 1с (НЕ ИЗМЕНЯТЬ!)')->where('code', 12)->first();
if (!$check_setting) {
$setting = new Settings;
$setting->name = 'Триггер загрузки меню 1с (НЕ ИЗМЕНЯТЬ!)';
$setting->value = '0';
$setting->code = 12;
$setting->is_common = 1;
$setting->save();
}
}
}

View File

@@ -6,4 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class Dishes extends Model {
protected $table = 'dishes';
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
}

View File

@@ -6,4 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class Folders extends Model {
protected $table = 'folders';
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
}

View File

@@ -6,4 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class Units extends Model {
protected $table = 'units';
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
}

View File

@@ -6,4 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class UnitsList extends Model {
protected $table = 'units_list';
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
}

View File

@@ -1,5 +1,5 @@
[info]
name=V1
version=2.16
version=2.17
[build]
version=2.16
version=2.17