96 lines
2.9 KiB
PHP
96 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Component\Models\ExchangeActions;
|
|
use App\Component\Models\ExchangeDeleted;
|
|
use App\Component\Models\ExchangeItems;
|
|
use App\Component\Models\ExchangeOrders;
|
|
use App\Component\Models\ExchangeShifts;
|
|
use App\Component\Models\Report;
|
|
use App\Console\Commands\HRCCommand;
|
|
use App\Console\Commands\HRCCommandInterface;
|
|
|
|
class POSTDeleteData extends HRCCommand implements HRCCommandInterface {
|
|
protected $signature = 'postdeletedata';
|
|
|
|
public function command($input, $output = null) {
|
|
if ($input['value'] == 'delete_shift') {
|
|
if ($input['shift_id']) {
|
|
$exchange_shift = ExchangeShifts::where('id', $input['shift_id'])->first();
|
|
$exchange_orders = ExchangeOrders::where('shift_id', '=', $input['shift_id'])->get();
|
|
$exchange_items = ExchangeItems::where('shift_id', '=', $input['shift_id'])->get();
|
|
$exchange_actions = ExchangeActions::where('shift_id', '=', $input['shift_id'])->get();
|
|
$exchange_deleted = ExchangeDeleted::where('shift_id', '=', $input['shift_id'])->get();
|
|
if ($exchange_shift) {
|
|
$exchange_shift = ExchangeShifts::find($input['shift_id']);
|
|
$exchange_shift->delete();
|
|
}
|
|
if ($exchange_orders) {
|
|
$exchange_orders = ExchangeOrders::where('shift_id', '=', $input['shift_id'])->delete();
|
|
}
|
|
if ($exchange_items) {
|
|
$exchange_items = ExchangeItems::where('shift_id', '=', $input['shift_id'])->delete();
|
|
}
|
|
if ($exchange_actions) {
|
|
$exchange_actions = ExchangeActions::where('shift_id', '=', $input['shift_id'])->delete();
|
|
}
|
|
if ($exchange_deleted) {
|
|
$exchange_deleted = ExchangeDeleted::where('shift_id', '=', $input['shift_id'])->delete();
|
|
}
|
|
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);
|
|
}
|
|
$cache_dir = __DIR__ . "\\..\\..\\..\\Cache\\";
|
|
dirDel($cache_dir);
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Данные удалены',
|
|
];
|
|
|
|
} else {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Check input data',
|
|
];
|
|
}
|
|
} elseif ($input['value'] == 'delete_report') {
|
|
if ($input['report_id']) {
|
|
$report = Report::where('id', $input['report_id'])->first();
|
|
if ($report) {
|
|
$report = Report::where('id', $input['report_id'])->delete();
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Данные удалены',
|
|
];
|
|
} else {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Report not found',
|
|
];
|
|
}
|
|
} else {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Check input data',
|
|
];
|
|
}
|
|
} else {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Check input data',
|
|
];
|
|
}
|
|
}
|
|
} |