119 lines
3.6 KiB
PHP
119 lines
3.6 KiB
PHP
<?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 POSTCreateClient extends HRCCommand implements HRCCommandInterface {
|
|
protected $signature = 'postcreateclient';
|
|
|
|
public function command($input, $output = null) {
|
|
if (isset($input['group_id'])) {
|
|
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
|
|
} else {
|
|
$group['code'] = 0;
|
|
}
|
|
|
|
if (!isset($input['email'])) {
|
|
$input['email'] = '';
|
|
}
|
|
|
|
if (!isset($input['address'])) {
|
|
$input['address'] = '';
|
|
}
|
|
|
|
$total = Client::where('name', '=', $input['name'])->count();
|
|
if (isset($input['client_guid'])) {
|
|
$check_guid = Client::where('user_code', $input['client_guid'])->count();
|
|
if ($check_guid > 0) {
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Клиент уже существует'
|
|
];
|
|
}
|
|
}
|
|
$client_code = Client::max('code') + 1;
|
|
if (isset($input['is_special_price']) && $input['is_special_price'] == 'true') {
|
|
$specialPrice = 1;
|
|
} else {
|
|
$specialPrice = 0;
|
|
}
|
|
if (isset($input['is_employee']) && $input['is_employee'] == 'true') {
|
|
$employee = 1;
|
|
} else {
|
|
$employee = 0;
|
|
}
|
|
$client = new Client;
|
|
if ($total >= 1) {
|
|
$total = $total + 1;
|
|
$client->name = '#' . $total . ' ' . urldecode($input['name']);
|
|
} else {
|
|
$client->name = urldecode($input['name']);
|
|
}
|
|
if (!isset($input['client_guid'])) {
|
|
$client->user_code = strtoupper(md5(time()));
|
|
} else {
|
|
$client->user_code = $input['client_guid'];
|
|
}
|
|
|
|
$client->code = $client_code;
|
|
$client->group_id = $group['code'];
|
|
$client->is_special_price = $specialPrice;
|
|
$client->is_employee = $employee;
|
|
$client->last_change = date("Ymd");
|
|
$clientEmail = new ClientsEmail;
|
|
$clientEmail->email = urldecode($input['email']);
|
|
$clientEmail->client_guid = $client->user_code;
|
|
|
|
$clientAddress = new ClientsAddress;
|
|
$clientAddress->address = urldecode($input['address']);
|
|
$clientAddress->client_guid = $client->user_code;
|
|
|
|
$clientPhone = new ClientsPhone;
|
|
if ($input['phone'] !== '' && isset($input['phone'])) {
|
|
$phoneData = urldecode($input['phone']);
|
|
$phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2);
|
|
} else {
|
|
$phone = '';
|
|
}
|
|
$clientPhone->phone = $phone;
|
|
$clientPhone->client_guid = $client->user_code;
|
|
|
|
if (isset($input['barcode']) && $input['barcode'] > 0) {
|
|
$client->barcode_type = 2;
|
|
$clientBarcode = new ClientsBarcode;
|
|
$clientBarcode->code_id = urldecode($input['barcode']);
|
|
$clientBarcode->name = '';
|
|
$clientBarcode->client_guid = $client->user_code;
|
|
$clientBarcode->value = urldecode($input['barcode']);
|
|
$clientBarcode->block = 0;
|
|
$clientBarcode->symptom_block = 0;
|
|
$client->barcode_start = urldecode($input['barcode']);
|
|
$client->barcode_end = urldecode($input['barcode']);
|
|
$client->save();
|
|
$clientPhone->save();
|
|
$clientEmail->save();
|
|
$clientAddress->save();
|
|
$clientBarcode->save();
|
|
} else {
|
|
$client->barcode_type = 1;
|
|
$client->save();
|
|
$clientPhone->save();
|
|
$clientEmail->save();
|
|
$clientAddress->save();
|
|
}
|
|
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Клиент создан',
|
|
'client' => $client,
|
|
];
|
|
}
|
|
} |