95 lines
3.4 KiB
PHP
95 lines
3.4 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\ClientsBonus;
|
|
use App\Component\Models\ClientsEmail;
|
|
use App\Component\Models\ClientsGroup;
|
|
use App\Component\Models\ClientsPhone;
|
|
use App\Component\Models\ClientsPresale;
|
|
use App\Console\Commands\HRCCommand;
|
|
use App\Console\Commands\HRCCommandInterface;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class GETCompanyClients extends HRCCommand implements HRCCommandInterface
|
|
{
|
|
protected $signature = 'getcompanyclients';
|
|
|
|
public function command($input, $output = null)
|
|
{
|
|
$dt = Carbon::createFromTimestamp($input['last_update'])->subHours(3);
|
|
$last_update = $dt->format('Y-m-d H:i:s');
|
|
$clients = Client::select('id', 'name', 'user_code', 'group_id', 'last_change', 'updated_at')
|
|
->where('updated_at', '>', $last_update)
|
|
->get();
|
|
if (count($clients) < 1) {
|
|
return [
|
|
'status' => 'success',
|
|
'clients' => [],
|
|
'groups' => [],
|
|
];
|
|
}
|
|
foreach ($clients as $client) {
|
|
$email_address = Client::getEmail($client['user_code']);
|
|
$phone_number = Client::getPhone($client['user_code']);
|
|
$email[] = array(
|
|
'email' => $email_address
|
|
);
|
|
$phone[] = array(
|
|
'phone' => $phone_number
|
|
);
|
|
$badge[] = array(
|
|
'name' => 'Test',
|
|
'code' => 1
|
|
);
|
|
$bonus_dishes[] = array(
|
|
'code' => ''
|
|
);
|
|
if (ClientsBonus::getBonus($client['user_code']) > 0) {
|
|
$bonus_info[] = array(
|
|
'amount' => ClientsBonus::getBonus($client['user_code']),
|
|
'dishes' => $bonus_dishes
|
|
);
|
|
} else {
|
|
$bonus_info = array(
|
|
'amount' => ClientsBonus::getBonus($client['user_code']),
|
|
'dishes' => []
|
|
);
|
|
}
|
|
$group_info = ClientsGroup::where('code', $client['group_id'])->first();
|
|
$clients_info[] = array(
|
|
'id' => $client['id'],
|
|
'name' => $client['name'],
|
|
'guid' => $client['user_code'],
|
|
'presale' => ClientsPresale::getPresale($client['user_code']),
|
|
'bonuses' => $bonus_info,
|
|
'barcode' => Client::getBarcode($client['user_code']),
|
|
'group_id' => ClientsGroup::getID($client['group_id']),
|
|
'emails' => $email,
|
|
'phones' => $phone,
|
|
'badges' => []
|
|
);
|
|
$groups[] = $group_info['code'];
|
|
$email = $phone = $badge = $bonus_dishes = $bonus_info = [];
|
|
}
|
|
$groups_guides = array_values(array_unique($groups));
|
|
foreach ($groups_guides as $group) {
|
|
$group_info = ClientsGroup::where('code', $group)->first();
|
|
$groups_info[] = array(
|
|
'id' => $group_info['id'],
|
|
'name' => $group_info['name'],
|
|
'guid' => $group_info['code'],
|
|
);
|
|
}
|
|
|
|
return [
|
|
'status' => 'success',
|
|
'clients' => $clients_info,
|
|
'groups' => $groups_info,
|
|
];
|
|
}
|
|
} |