Update api requests
This commit is contained in:
34
commands/Bot.php
Normal file
34
commands/Bot.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\Folders;
|
||||
use App\Component\Models\Orders;
|
||||
use App\Component\Models\Settings;
|
||||
use App\Component\Models\Tasks;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class Bot extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getbot';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$settings = Settings::where('code', '=', 5)->where('value', '=', 1)->get();
|
||||
if (isset($settings['0']['value'])) {
|
||||
$dishes = Dishes::where('is_bot_export', '=', 0)->update(['is_bot_export' => 1]);
|
||||
$folders = Folders::where('is_bot_export', '=', 0)->update(['is_bot_export' => 1]);
|
||||
}
|
||||
$ordersinfo = Tasks::where('method', '=', 'orderinfo')->get();
|
||||
$delete_params = ['closed', 'deleted'];
|
||||
foreach ($ordersinfo as $more) {
|
||||
$order = Orders::where('id', '=', $more['more'])->whereIn('status', $delete_params)->get();
|
||||
foreach ($order as $value) {
|
||||
$delete = Tasks::where('method', '=', 'orderinfo')->where('more', '=', $value['id'])->delete();
|
||||
}
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
];
|
||||
}
|
||||
}
|
||||
99
commands/ClientFile.php
Normal file
99
commands/ClientFile.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class ClientFile extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getclientfile';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->where('work_code', '=', 1)->first();
|
||||
$tmp_dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\tmp\\" . $terminal['key'] . "\\";
|
||||
$dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\";
|
||||
$code = '';
|
||||
if (isset($input['complete'])) {
|
||||
foreach (glob($tmp_dirname . "*.tmp") as $filename) {
|
||||
$code .= file_get_contents($filename);
|
||||
}
|
||||
$filename = str_replace(' ', '_', date("d.m.Y H.i.s")) . '.csv';
|
||||
file_put_contents($dirname . $filename, $code);
|
||||
$files = glob($tmp_dirname . "*");
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
$files = glob($dirname . "*.*");
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($a) < filemtime($b);
|
||||
});
|
||||
foreach ($files as $plk2) {
|
||||
$file_array[] = str_replace($dirname, '', $plk2);
|
||||
}
|
||||
if (array_key_exists(0, $file_array)) {
|
||||
$file = date("d.m.Y H:i:s", filemtime($dirname . $file_array['0']));
|
||||
} else {
|
||||
$file = '';
|
||||
}
|
||||
$baseCSV = file($dirname . $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
foreach ($baseCSV as $itemBaseCSV) {
|
||||
$arrLineCsv = explode(";", $itemBaseCSV);
|
||||
$arrUniqFinish[$arrLineCsv[0] . ";" . $arrLineCsv[1]] = $arrLineCsv[1];
|
||||
}
|
||||
$arrUniqFinish = array_unique($arrUniqFinish);
|
||||
|
||||
foreach ($arrUniqFinish as $keyArr => $valueArr) {
|
||||
$finishSavedCsv[] = $keyArr;
|
||||
}
|
||||
file_put_contents($dirname . $filename, implode("\n", $finishSavedCsv));
|
||||
return [
|
||||
'status' => 'success',
|
||||
'filename' => $filename,
|
||||
'filedate' => $file,
|
||||
];
|
||||
}
|
||||
$clientsCount = Client::count();
|
||||
$urlThread = $input['th'];
|
||||
$mainThreads = 4;
|
||||
$countPerThread = ceil($clientsCount / $mainThreads);
|
||||
$offset = ($urlThread - 1) * $countPerThread;
|
||||
$clients = Client::with('clientPhone:client_guid,phone')->skip($offset)->take($countPerThread)->get();
|
||||
|
||||
if (!is_dir($tmp_dirname)) {
|
||||
mkdir($tmp_dirname, 0755, 'w+');
|
||||
}
|
||||
$filename = str_replace(' ', '_', date("d.m.Y H.i.s")) . '_' . $urlThread . '.tmp';
|
||||
$handle = fopen($tmp_dirname . $filename, 'w+');
|
||||
fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM
|
||||
$filename = str_replace('_', ' ', $filename);
|
||||
foreach ($clients as $row) {
|
||||
if (($row['clientPhone']->phone !== '') && ($row['clientPhone']->phone !== '+375 ( ) - -')) {
|
||||
$row = array($row['name'], $row['clientPhone']->phone);
|
||||
fputcsv($handle, $row, ';');
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
$files = glob($tmp_dirname . "*.*");
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($a) < filemtime($b);
|
||||
});
|
||||
foreach ($files as $plk2) {
|
||||
$file_array[] = str_replace($tmp_dirname, '', $plk2);
|
||||
}
|
||||
if (array_key_exists(0, $file_array)) {
|
||||
$file = date("d.m.Y H:i:s", filemtime($tmp_dirname . $file_array['0']));
|
||||
} else {
|
||||
$file = '';
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'filename' => $filename,
|
||||
'filedate' => $file,
|
||||
];
|
||||
}
|
||||
}
|
||||
55
commands/ClientGroup.php
Normal file
55
commands/ClientGroup.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\ClientsGroup;
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class ClientGroup extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getclientgroup';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
if (ClientsGroup::where('code', '0')->count() == 0) {
|
||||
$group = new ClientsGroup;
|
||||
$group->code = '0';
|
||||
$group->name = 'Без группы';
|
||||
$group->save();
|
||||
}
|
||||
$client_groups = ClientsGroup::orderBy('code')->get();
|
||||
foreach ($client_groups as $client_group) {
|
||||
$out[] = array('id' => $client_group['id'], 'name' => $client_group['name']);
|
||||
}
|
||||
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->where('work_code', '=', 1)->first();
|
||||
$dir = __DIR__ . "/../../../Exchange/" . $terminal['key'] . "/";
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, 'w+');
|
||||
}
|
||||
|
||||
$files = glob($dir . "*.*");
|
||||
if (count($files) > 0) {
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($a) < filemtime($b);
|
||||
});
|
||||
|
||||
foreach ($files as $plk2) {
|
||||
$file_array[] = str_replace($dir, '', $plk2);
|
||||
}
|
||||
$filename = $file_array['0'];
|
||||
$file = date("d.m.Y H:i:s", filemtime(__DIR__ . "/../../../Exchange/" . $terminal['key'] . "/" . $file_array['0']));
|
||||
} else {
|
||||
$file_array = '';
|
||||
$filename = '';
|
||||
$file = '';
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'groups' => $out,
|
||||
'terminalKey' => $terminal['key'],
|
||||
'files' => $files,
|
||||
'filename' => $filename,
|
||||
'filedate' => $file,
|
||||
];
|
||||
}
|
||||
}
|
||||
56
commands/Clients.php
Normal file
56
commands/Clients.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\ClientsGroup;
|
||||
use App\Component\Models\ClientsPhone;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class Clients extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getclients';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
if (ClientsGroup::where('code', '0')->count() == 0) {
|
||||
$group = new ClientsGroup([
|
||||
'code' => '0',
|
||||
'name' => 'Без группы',
|
||||
]);
|
||||
$group->save();
|
||||
}
|
||||
$countPerPage = 25;
|
||||
$offset = ($input['page'] - 1) * $countPerPage;
|
||||
if ($input['group_id'] == 0) {
|
||||
$group = ClientsGroup::where('code', '=', $input['group_id'])->first();
|
||||
} else {
|
||||
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
|
||||
}
|
||||
$clients = Client::where('group_id', '=', $group['code'])->skip($offset)->take($countPerPage)->get();
|
||||
$total = Client::where('group_id', '=', $group['code'])->count();
|
||||
if ($total == NULL) {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'clients' => array(),
|
||||
'total' => 0,
|
||||
'size' => $countPerPage,
|
||||
'pages' => 1,
|
||||
'currentGroup' => $group['id'],
|
||||
];
|
||||
} else {
|
||||
|
||||
foreach ($clients as $client) {
|
||||
$phone = ClientsPhone::where('client_guid', '=', $client['user_code'])->first();
|
||||
$out[] = array('id' => $client['id'], 'name' => $client['name'], 'phone' => $phone['phone']);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'clients' => $out,
|
||||
'total' => $total,
|
||||
'size' => $countPerPage,
|
||||
'pages' => ceil($total / $countPerPage),
|
||||
'currentGroup' => $group['id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
53
commands/CreateBarcode.php
Normal file
53
commands/CreateBarcode.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\ClientsBarcode;
|
||||
use App\Component\Models\ClientsGroup;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class CreateBarcode extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postcreatebarcode';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
|
||||
if (($input['start'] <= $input['end']) && (srtlen($input['start']) == srtlen($input['end']))) {
|
||||
for ($i = $input['start']; $i <= $input['end']; $i++) {
|
||||
$total = Client::where('name', '=', $i)->count();
|
||||
$client = new Client;
|
||||
if ($total >= 1) {
|
||||
$total = $total + 1;
|
||||
$client->name = '#' . $total . ' ' . urldecode($i);
|
||||
} else {
|
||||
$client->name = urldecode($i);
|
||||
}
|
||||
$client->user_code = strtoupper(md5(time() + $i));
|
||||
$client->group_id = $group['code'];
|
||||
$client->is_special_price = 0;
|
||||
|
||||
$barcode = new ClientsBarcode;
|
||||
$barcode->code_id = $i;
|
||||
$barcode->name = '';
|
||||
$barcode->client_guid = $client->user_code;
|
||||
$barcode->value = $i;
|
||||
$barcode->block = 0;
|
||||
$barcode->symptom_block = 0;
|
||||
|
||||
$barcode->save();
|
||||
$client->save();
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Штрих коды созданы',
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'message' => 'Проверьте правильность введенных данных',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
73
commands/CreateClient.php
Normal file
73
commands/CreateClient.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\ClientsAddress;
|
||||
use App\Component\Models\ClientsBarcode;
|
||||
use App\Component\Models\ClientsEmail;
|
||||
use App\Component\Models\ClientsGroup;
|
||||
use App\Component\Models\ClientsPhone;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class CreateClient extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postcreateclient';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
|
||||
$total = Client::where('name', '=', $input['name'])->count();
|
||||
if ($input['is_special_price'] == 'true') {
|
||||
$specialPrice = 1;
|
||||
} else {
|
||||
$specialPrice = 0;
|
||||
}
|
||||
$client = new Client;
|
||||
if ($total >= 1) {
|
||||
$total = $total + 1;
|
||||
$client->name = '#' . $total . ' ' . urldecode($input['name']);
|
||||
} else {
|
||||
$client->name = urldecode($input['name']);
|
||||
}
|
||||
$client->user_code = strtoupper(md5(time()));
|
||||
$client->group_id = $group['code'];
|
||||
$client->is_special_price = $specialPrice;
|
||||
|
||||
$clientEmail = new ClientsEmail;
|
||||
$clientEmail->email = urldecode($input['email']);
|
||||
$clientEmail->client_guid = $client->user_code;
|
||||
|
||||
$clientAddress = new ClientsAddress;
|
||||
$clientAddress->address = urldecode($input['address']);
|
||||
$clientAddress->client_guid = $client->user_code;
|
||||
|
||||
$clientPhone = new ClientsPhone;
|
||||
if ($input['phone'] !== '') {
|
||||
$phoneData = urldecode($input['phone']);
|
||||
$phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2);
|
||||
} else {
|
||||
$phone = '';
|
||||
}
|
||||
$clientPhone->phone = $phone;
|
||||
$clientPhone->client_guid = $client->user_code;
|
||||
|
||||
$clientBarcode = new ClientsBarcode;
|
||||
$clientBarcode->code_id = urldecode($input['barcode']);
|
||||
$clientBarcode->name = '';
|
||||
$clientBarcode->client_guid = $client->user_code;
|
||||
$clientBarcode->value = urldecode($input['barcode']);
|
||||
$clientBarcode->block = 0;
|
||||
$clientBarcode->symptom_block = 0;
|
||||
|
||||
$clientBarcode->save();
|
||||
$clientEmail->save();
|
||||
$clientAddress->save();
|
||||
$client->save();
|
||||
$clientPhone->save();
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Клиент создан',
|
||||
];
|
||||
}
|
||||
}
|
||||
35
commands/Equipment.php
Normal file
35
commands/Equipment.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Printer;
|
||||
use App\Component\Models\PrinterSettings;
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class Equipment extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getequipment';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$terminals = Terminal::select('work_code', 'work_group')
|
||||
->where('key', '=', $input['terminal'])
|
||||
->get();
|
||||
foreach ($terminals as $terminal) {
|
||||
$terminal_data = array('work_code' => $terminal['work_code'], 'work_group' => $terminal['work_group']);
|
||||
}
|
||||
$printer_groups = Printer::select('code', 'name')
|
||||
->where('is_history', '=', 0)
|
||||
->get();
|
||||
$printers = PrinterSettings::select('name', 'id', 'ip', 'com_port', 'type', 'speed', 'printer_group', 'template', 'size', 'driver', 'codepage', 'more')
|
||||
->where('workgroup', '=', $terminal_data['work_group'])
|
||||
->where('workcode', '=', $terminal_data['work_code'])
|
||||
->get();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'terminal_data' => $terminal_data,
|
||||
'printer_groups' => $printer_groups,
|
||||
'printers' => $printers,
|
||||
];
|
||||
}
|
||||
}
|
||||
22
commands/Fiscals.php
Normal file
22
commands/Fiscals.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class Fiscals extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postfiscals';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$terminals = Terminal::select('work_code', 'work_group')->where('key', '=', $input['terminal'])->get();
|
||||
foreach ($terminals as $terminal) {
|
||||
$out = array('work_code' => $terminal['work_code'], 'work_group' => $terminal['work_group']);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'terminal_data' => $out,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
use App\Models\User;
|
||||
|
||||
class HelloWorld extends HRCCommand implements HRCCommandInterface
|
||||
{
|
||||
protected $signature = 'gethello';
|
||||
|
||||
public function command($input, $output = null)
|
||||
{
|
||||
$users = User::all();
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'users' => $users
|
||||
];
|
||||
}
|
||||
}
|
||||
87
commands/Import.php
Normal file
87
commands/Import.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class Import extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getimport';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$HRCPortalURL = 'https://portal.hrc.by/';
|
||||
$folder = 'backup';
|
||||
$terminals = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->where('work_code', '=', 1)->get();
|
||||
$end_date = date('m/d/Y H:i:s', strtotime($input['end_date']) + 86399);
|
||||
$start_date = date('m/d/Y H:i:s', strtotime($input['start_date']));
|
||||
foreach ($terminals as $terminal) {
|
||||
$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'];
|
||||
foreach ($responses as $key => $response) {
|
||||
if (array_key_exists('filename', $response)) {
|
||||
$fulldate = date_parse_from_format('d-m-Y-H-i-s', $response['filename']);
|
||||
$fulldate = mktime($fulldate['hour'], $fulldate['minute'], $fulldate['second'], $fulldate['month'], $fulldate['day'], $fulldate['year']);
|
||||
if ($fulldate >= strtotime($start_date) && $fulldate <= strtotime($end_date)) {
|
||||
$out[] = date('d-m-Y-H-i-s', $fulldate);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($out)) {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'shifts not found',
|
||||
];
|
||||
} else {
|
||||
foreach ($out as $filename) {
|
||||
$path = '/backup/' . $filename . '.xml';
|
||||
$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'];
|
||||
$params = array('code' => $terminal['key'], 'name' => $filename . '.xml', 'folder' => 'exchange', 'content' => $file, 'project_code' => 'hrc', 'api' => '2.0');
|
||||
$upload = curl_init();
|
||||
curl_setopt_array($upload, array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_URL => $HRCPortalURL . 'api/cloud/upload',
|
||||
CURLOPT_SSL_VERIFYHOST => 0,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $params,
|
||||
));
|
||||
$upload_response = curl_exec($upload);
|
||||
curl_close($upload);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'start_date' => strtotime($start_date),
|
||||
'end_date' => strtotime($end_date),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
138
commands/OutOrders.php
Normal file
138
commands/OutOrders.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Orders;
|
||||
use App\Component\Models\Report;
|
||||
use App\Component\Models\Shifts;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class OutOrders extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getoutorders';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
if ((array_key_exists('shift_id', $input)) === true) {
|
||||
$shifts = Shifts::select('id', 'opened', 'closed')->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',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
71
commands/Printers.php
Normal file
71
commands/Printers.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Printer;
|
||||
use App\Component\Models\PrinterSettings;
|
||||
use App\Component\Models\Tasks;
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class Printers extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postprinters';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$terminals = Terminal::select('id', 'work_code', 'work_group')->where('key', '=', $input['terminal'])->get();
|
||||
foreach ($terminals as $terminal) {
|
||||
$terminal_data = array('id' => $terminal['id'], 'work_code' => $terminal['work_code'], 'work_group' => $terminal['work_group']);
|
||||
}
|
||||
$first_printer_data = PrinterSettings::where('id', '=', $input['id'])->get();
|
||||
foreach ($first_printer_data as $old_printer_data) {
|
||||
}
|
||||
$printer_name = Printer::where('code', '=', $input['group'])->get();
|
||||
foreach ($printer_name as $group_name) {
|
||||
}
|
||||
if ($input['group'] == 0) {
|
||||
$group_name['name'] = $input['name'];
|
||||
}
|
||||
if ($input['type'] == 'COM') {
|
||||
$task[] = "UPDATE main.printers SET `name`='" . urldecode($group_name['name']) . "', `IP`=NULL, `port`=NULL, `COMport`='" . $input['com_port'] . "', `type`='" . $input['type'] . "', `size`=" . $input['size'] . ", `speed`=" . $input['speed'] . ", `driver`=NULL, `workcode`=" . $terminal_data['work_code'] . ", `workgroup`=" . $terminal_data['work_group'] . ",`printer_group`=" . $input['group'] . ", `template`='" . $input['template'] . "', `more`='" . urldecode($input['more']) . "' WHERE `name`='" . $old_printer_data['name'] . "' AND `workcode`=" . $terminal_data['work_code'] . " AND `workgroup`=" . $terminal_data['work_group'] . ";";
|
||||
$task = base64_encode(json_encode(array('queries' => $task), TRUE));
|
||||
$add_task = new Tasks;
|
||||
$add_task->terminal_id = $terminal_data['id'];
|
||||
$add_task->next_at = date("Y-m-d H:i:s");
|
||||
$add_task->method = 'runquery';
|
||||
$add_task->period = 0;
|
||||
$add_task->is_cycle = 0;
|
||||
$add_task->more = $task;
|
||||
$add_task->save();
|
||||
}
|
||||
if ($input['type'] == 'LAN') {
|
||||
$task[] = "UPDATE main.printers SET `name`='" . urldecode($group_name['name']) . "', `IP`='" . $input['ip_address'] . "', `port`=9100, `COMport`=NULL, `type`='" . $input['type'] . "', `size`=" . $input['size'] . ", `speed`=NULL, `driver`=NULL, `workcode`=" . $terminal_data['work_code'] . ", `workgroup`=" . $terminal_data['work_group'] . ",`printer_group`=" . $input['group'] . ", `template`='" . $input['template'] . "', `more`='" . urldecode($input['more']) . "' WHERE `name`='" . $old_printer_data['name'] . "' AND `workcode`=" . $terminal_data['work_code'] . " AND `workgroup`=" . $terminal_data['work_group'] . ";";
|
||||
$task = base64_encode(json_encode(array('queries' => $task)));
|
||||
$add_task = new Tasks;
|
||||
$add_task->terminal_id = $terminal_data['id'];
|
||||
$add_task->next_at = date("Y-m-d H:i:s");
|
||||
$add_task->method = 'runquery';
|
||||
$add_task->period = 0;
|
||||
$add_task->is_cycle = 0;
|
||||
$add_task->more = $task;
|
||||
$add_task->save();
|
||||
}
|
||||
if ($input['type'] == 'Windows') {
|
||||
$task[] = "UPDATE main.printers SET `name`='" . urldecode($group_name['name']) . "', `IP`=NULL, `port`=NULL, `COMport`=NULL, `type`='" . $input['type'] . "', `size`=" . $input['size'] . ", `speed`=NULL, `driver`='" . urldecode($input['driver']) . "', `workcode`=" . $terminal_data['work_code'] . ", `workgroup`=" . $terminal_data['work_group'] . ",`printer_group`=" . $input['group'] . ", `template`='" . $input['template'] . "', `more`='" . urldecode($input['more']) . "' WHERE `name`='" . $old_printer_data['name'] . "' AND `workcode`=" . $terminal_data['work_code'] . " AND `workgroup`=" . $terminal_data['work_group'] . ";";
|
||||
$task = base64_encode(json_encode(array('queries' => $task)));
|
||||
$add_task = new Tasks;
|
||||
$add_task->terminal_id = $terminal_data['id'];
|
||||
$add_task->next_at = date("Y-m-d H:i:s");
|
||||
$add_task->method = 'runquery';
|
||||
$add_task->period = 0;
|
||||
$add_task->is_cycle = 0;
|
||||
$add_task->more = $task;
|
||||
$add_task->save();
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'input' => $input,
|
||||
'task' => $task,
|
||||
];
|
||||
}
|
||||
}
|
||||
70
commands/TopDishes.php
Normal file
70
commands/TopDishes.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\OnlineItems;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class TopDishes extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'gettopdishes';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
|
||||
$info = OnlineItems::where('menu_code', '>', 0)->get()->unique('menu_code');
|
||||
$count = OnlineItems::where('menu_code', '>', 0)->count();
|
||||
if ($count > 0) {
|
||||
foreach ($info as $key => $value) {
|
||||
$out[] = $value;
|
||||
}
|
||||
foreach ($out as $key => $item) {
|
||||
$dishInfo = Dishes::select('name')
|
||||
->where('code', '=', $item['menu_code'])
|
||||
->where('legacy_code', '=', $item['dish_code'])
|
||||
->where('is_history', '=', 0)
|
||||
->get();
|
||||
$onlineDishInfo = OnlineItems::select('real_price', 'sale_price', 'special_price')
|
||||
->where('menu_code', '=', $item['menu_code'])
|
||||
->where('dish_code', '=', $item['dish_code'])
|
||||
->get();
|
||||
$dishName = $dishInfo[0]->name;
|
||||
$dishCount = OnlineItems::where('menu_code', '=', $item['menu_code'])->sum('count');
|
||||
$dishSum = $onlineDishInfo[0]->real_price * $dishCount;
|
||||
if ($dishSum > 0) {
|
||||
$dishTotalCost = round(($onlineDishInfo[0]->special_price * $dishCount), 2);
|
||||
$dishPercent = round((100 - ((($dishSum - $dishTotalCost) * 100) / $dishSum)), 2);
|
||||
$dishProfit = $dishSum - $dishTotalCost;
|
||||
} else {
|
||||
$dishTotalCost = 0;
|
||||
$dishPercent = 0;
|
||||
$dishProfit = 0;
|
||||
}
|
||||
$dishes[] = array('name' => $dishName, 'count' => $dishCount, 'sum' => $dishSum, 'totalCost' => $dishTotalCost, 'percentProffit' => $dishPercent, 'proffit' => $dishProfit);
|
||||
}
|
||||
for ($i = 0; $i < count($dishes); $i++) {
|
||||
$sortkey[$i] = $dishes[$i]['count'];
|
||||
}
|
||||
arsort($sortkey);
|
||||
foreach ($sortkey as $key => $key) {
|
||||
$sorted[] = $dishes[$key];
|
||||
}
|
||||
$sorted = array_slice($sorted, 0, 10);
|
||||
return [
|
||||
'status' => 'success',
|
||||
'dishes' => $sorted,
|
||||
// 'info' => $info,
|
||||
// 'test' => $dishes,
|
||||
// 'count' => $dishCount,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'dishes' => [],
|
||||
// 'info' => $info,
|
||||
// 'test' => $dishes,
|
||||
// 'count' => $dishCount,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user