Fix API: GETClienFile
This commit is contained in:
@@ -14,36 +14,21 @@ class ClientFile extends HRCCommand implements HRCCommandInterface {
|
||||
$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'] . "\\";
|
||||
$filename = str_replace(' ', '_', date("d.m.Y H.i.s")) . '.csv';
|
||||
$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 = '';
|
||||
foreach (glob($tmp_dirname . "*.tmp") as $tmp_filename) {
|
||||
$code .= file_get_contents($tmp_filename);
|
||||
file_put_contents($dirname . $filename, $code);
|
||||
unlink($tmp_filename);
|
||||
}
|
||||
|
||||
$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[mb_convert_encoding($arrLineCsv[0], 'CP1251') . ";" . $arrLineCsv[1]] = $arrLineCsv[1];
|
||||
}
|
||||
$arrUniqFinish = array_unique($arrUniqFinish);
|
||||
|
||||
@@ -54,46 +39,35 @@ class ClientFile extends HRCCommand implements HRCCommandInterface {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'filename' => $filename,
|
||||
'filedate' => $file,
|
||||
];
|
||||
|
||||
} else {
|
||||
|
||||
$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+');
|
||||
$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);
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'filename' => $filename,
|
||||
];
|
||||
}
|
||||
$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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,9 @@ class AddForeignKeyToClientsTable extends Migration {
|
||||
|
||||
Schema::table('clients', function (Blueprint $table) {
|
||||
$table->string('user_code')->unique()->change();
|
||||
|
||||
});
|
||||
Schema::table('clients_phone', function (Blueprint $table) {
|
||||
$table->foreign('client_guid')->references('user_code')->on('clients');
|
||||
$table->foreign('user_code')->references('client_guid')->on('clients_phone');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user