v.2.2 Update
Top dishes block update
This commit is contained in:
58
commands/POSTClientGroup.php
Normal file
58
commands/POSTClientGroup.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user