Files
admin-php-module/commands/CreateBarcode.php
2021-06-07 15:08:15 +03:00

54 lines
1.5 KiB
PHP

<?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;
$client->barcode_type = 1;
$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' => 'Проверьте правильность введенных данных',
];
}
}
}