API: v.1.4: Edit, remove clients
This commit is contained in:
@@ -39,6 +39,7 @@ class ClientFile extends HRCCommand implements HRCCommandInterface {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'filename' => $filename,
|
||||
'terminalKey' => $terminal['key'],
|
||||
];
|
||||
|
||||
} else {
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
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 {
|
||||
class GETClientGroup extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getclientgroup';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
@@ -21,35 +20,9 @@ class ClientGroup extends HRCCommand implements HRCCommandInterface {
|
||||
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,
|
||||
];
|
||||
}
|
||||
}
|
||||
28
commands/GETClientGroup.php
Normal file
28
commands/GETClientGroup.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\ClientsGroup;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETClientGroup 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']);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'groups' => $out,
|
||||
];
|
||||
}
|
||||
}
|
||||
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' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hrc-admin/hello-world",
|
||||
"version": "1.2",
|
||||
"version": "1.4",
|
||||
"require": {
|
||||
"horeca/admin-php-module-core": "dev-master"
|
||||
},
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddForeignKeyToClientsTable extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up() {
|
||||
|
||||
Schema::table('clients', function (Blueprint $table) {
|
||||
$table->string('user_code')->unique()->change();
|
||||
$table->foreign('user_code')->references('client_guid')->on('clients_phone');
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down() {
|
||||
Schema::table('clients', function (Blueprint $table) {
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,4 @@
|
||||
name=V1
|
||||
version=1.2
|
||||
[build]
|
||||
version=1.2
|
||||
version=1.3
|
||||
|
||||
Reference in New Issue
Block a user