58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Component\Models\Client;
|
|
use App\Component\Models\ClientsGroup;
|
|
use App\Console\Commands\HRCCommand;
|
|
use App\Console\Commands\HRCCommandInterface;
|
|
|
|
class POSTClientGroup extends HRCCommand implements HRCCommandInterface {
|
|
protected $signature = 'postclientgroup';
|
|
|
|
public function command($input, $output = null) {
|
|
|
|
if (isset($input['task']) && isset($input['id'])) {
|
|
if ($input['task'] == 'update') {
|
|
$group = ClientsGroup::find($input['id']);
|
|
$group->name = $input['name'];
|
|
$group->save();
|
|
|
|
return [
|
|
'status' => 'success',
|
|
'group' => $group,
|
|
'message' => 'Группа обновлена',
|
|
];
|
|
}
|
|
|
|
if ($input['task'] == 'delete') {
|
|
$group = ClientsGroup::where('id', '=', $input['id'])->first();
|
|
if ($group->code == '0') {
|
|
return [
|
|
'status' => 'success',
|
|
'error_message' => 'Запрещено удаление группы по умолчанию',
|
|
];
|
|
} else {
|
|
$client_count = Client::where('group_id', '=', $group->code)->count();
|
|
if ($client_count !== 0) {
|
|
return [
|
|
'status' => 'success',
|
|
'error_message' => 'Разрешено удаление только пустых групп.',
|
|
];
|
|
} else {
|
|
$group->delete();
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Группа удалена',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
return [
|
|
'status' => 'success',
|
|
'error_message' => 'Проверьте введенные данные',
|
|
];
|
|
}
|
|
}
|
|
} |