API v.1.5: Update, Delete clients

This commit is contained in:
miroman-afk
2021-06-04 13:46:11 +03:00
parent a290eb3a80
commit 7325d8946a
5 changed files with 111 additions and 7 deletions

View File

@@ -3,6 +3,9 @@
namespace App\Commands;
use App\Component\Models\Client;
use App\Component\Models\ClientsAddress;
use App\Component\Models\ClientsBarcode;
use App\Component\Models\ClientsEmail;
use App\Component\Models\ClientsGroup;
use App\Component\Models\ClientsPhone;
use App\Console\Commands\HRCCommand;
@@ -41,7 +44,19 @@ class Clients extends HRCCommand implements HRCCommandInterface {
foreach ($clients as $client) {
$phone = ClientsPhone::where('client_guid', '=', $client['user_code'])->first();
$out[] = array('id' => $client['id'], 'name' => $client['name'], 'phone' => $phone['phone']);
$email = ClientsEmail::where('client_guid', '=', $client['user_code'])->first();
$address = ClientsAddress::where('client_guid', '=', $client['user_code'])->first();
$barcode = ClientsBarcode::where('client_guid', '=', $client['user_code'])->first();
$group = ClientsGroup::where('code', '=', $client['group_id'])->first();
$out[] = array(
'id' => $client['id'],
'client_group' => $group['id'],
'name' => $client['name'],
'phone' => $phone['phone'],
'email' => $email['email'],
'address' => $address['address'],
'barcode' => $barcode['code_id'],
);
}
return [
'status' => 'success',

View File

@@ -59,11 +59,11 @@ class CreateClient extends HRCCommand implements HRCCommandInterface {
$clientBarcode->block = 0;
$clientBarcode->symptom_block = 0;
$clientBarcode->save();
$clientEmail->save();
$clientAddress->save();
$client->save();
$clientPhone->save();
$clientEmail->save();
$clientAddress->save();
$clientBarcode->save();
return [
'status' => 'success',

89
commands/POSTClient.php Normal file
View File

@@ -0,0 +1,89 @@
<?php
namespace App\Commands;
use App\Component\Models\Client;
use App\Component\Models\ClientsAddress;
use App\Component\Models\ClientsBarcode;
use App\Component\Models\ClientsEmail;
use App\Component\Models\ClientsGroup;
use App\Component\Models\ClientsPhone;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class POSTClient extends HRCCommand implements HRCCommandInterface {
protected $signature = 'postclient';
public function command($input, $output = null) {
if (isset($input['task']) && isset($input['id'])) {
if ($input['task'] == 'update') {
$client = Client::find($input['id']);
$client->name = urldecode($input['name']);
$client->unloaded = 0;
$clientGroup = ClientsGroup::where('id', $input['group_id'])->first();
$client->group_id = urldecode($clientGroup->code);
$clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
if ($input['phone'] !== '') {
if (substr($input['phone'], 0, 1) == '+') {
$phoneData = urldecode($input['phone']);
} else {
$phoneData = urldecode($input['phone']);
$clientPhone->phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2);
}
} else {
$clientPhone->phone = '';
}
$clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
$clientEmail->email = urldecode($input['email']);
$clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
$clientAddress->address = urldecode($input['address']);
$clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first();
$clientBarcode->code_id = urldecode($input['barcode']);
$client->save();
$clientGroup->save();
$clientPhone->save();
$clientEmail->save();
$clientAddress->save();
$clientBarcode->save();
return [
'status' => 'success',
'client' => $client,
'phone' => $clientPhone,
'email' => $clientEmail,
'address' => $clientAddress,
'barcode' => $clientBarcode,
'message' => 'Клиент обновлен',
];
}
if ($input['task'] == 'delete') {
$client = Client::where('id', '=', $input['id'])->first();
$clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
$clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
$clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
$clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first();
$clientPhone->delete();
$clientEmail->delete();
$clientAddress->delete();
$clientBarcode->delete();
$client->delete();
return [
'status' => 'success',
'message' => 'Клиент удален',
];
}
} else {
return [
'status' => 'success',
'error_message' => 'Проверьте введенные данные',
];
}
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "hrc-admin/hello-world",
"version": "1.4",
"version": "1.5",
"require": {
"horeca/admin-php-module-core": "dev-master"
},

View File

@@ -1,5 +1,5 @@
[info]
name=V1
version=1.2
version=1.5
[build]
version=1.3
version=1.5