public function show() { $customer = $this->getCustomer(); if (!$customer) { return $this->responseError(['Данные не доступны'], 'Требуется авторизация', 401); } $api = new Api(); try { $key = $api->key(); Reporter::aggregateExternalInfoStart($key, $api->id(), $customer->get()->id); $client = $api->_cache_customer_info($key); $client['key'] = $key; try { $promo = $api->PromoCodeUse($key); } catch (ApiException $e) { if ($e->isDataError()) { $promo = null; } else { throw $e; } } $client['promo'] = $promo; Reporter::aggregateExternalInfoEnd($customer->get()->id); $customer->updateExternalInfo($client); return $this->responseSuccess($client, 'Данные клиента'); } catch (ApiException $e) { $api->cleanup(); return $this->responseException($e, 'Не удалось получить данные', 'customer'); } }
/** * @param string $key * @param Api $api * @param Customer $customer * * @throws ApiException * @throws Exception */ public function update($key, $api, $customer) { $this->info('начинаем сбор информации о клиенте: ' . $customer->id . ' [' . $customer->agbis_id . ']'); Reporter::aggregateExternalInfoStart($key, $customer->agbis_id, $customer->id); $client = $api->ContrInfo($key); $this->line('... общая информация'); $client['key'] = $key; try { $promo = $api->PromoCodeUse($key); $this->line('... промокод'); } catch (ApiException $e) { if ($e->isDataError()) { $promo = null; } else { throw $e; } } $client['promo'] = $promo; $client['bonus'] = $api->Bonus($key)['bonus']; $this->line('... бонус'); $client['deposit'] = $api->Deposit($key)['deposit']; $this->line('... депозитный счет'); $client['orders'] = $api->Orders($key)['orders']; $this->line('... заказы'); $client['history'] = $api->OrdersHistory($key)['orders']; $this->line('... история заказов'); $client['tokens'] = $api->TokenPayList($key)['tokens']; $this->line('... токены платежей'); Reporter::aggregateExternalInfoEnd($customer->id); $component = \Dryharder\Components\Customer::instance()->initByExternalId($client['id']); $this->line('... обновляем информацию в нашей базе данных'); $component->updateExternalInfo($client); $this->info('закончили работу с клиентом'); }