Update api requests
This commit is contained in:
53
commands/CreateBarcode.php
Normal file
53
commands/CreateBarcode.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\ClientsBarcode;
|
||||
use App\Component\Models\ClientsGroup;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class CreateBarcode extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postcreatebarcode';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
|
||||
if (($input['start'] <= $input['end']) && (srtlen($input['start']) == srtlen($input['end']))) {
|
||||
for ($i = $input['start']; $i <= $input['end']; $i++) {
|
||||
$total = Client::where('name', '=', $i)->count();
|
||||
$client = new Client;
|
||||
if ($total >= 1) {
|
||||
$total = $total + 1;
|
||||
$client->name = '#' . $total . ' ' . urldecode($i);
|
||||
} else {
|
||||
$client->name = urldecode($i);
|
||||
}
|
||||
$client->user_code = strtoupper(md5(time() + $i));
|
||||
$client->group_id = $group['code'];
|
||||
$client->is_special_price = 0;
|
||||
|
||||
$barcode = new ClientsBarcode;
|
||||
$barcode->code_id = $i;
|
||||
$barcode->name = '';
|
||||
$barcode->client_guid = $client->user_code;
|
||||
$barcode->value = $i;
|
||||
$barcode->block = 0;
|
||||
$barcode->symptom_block = 0;
|
||||
|
||||
$barcode->save();
|
||||
$client->save();
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Штрих коды созданы',
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'message' => 'Проверьте правильность введенных данных',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user