示例#1
0
 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('закончили работу с клиентом');
 }
示例#3
0
 /**
  * сборная информация по наличию промокода
  *
  * @param $user
  *
  * @return array
  */
 private function promoInfo($user)
 {
     try {
         $api = new Api();
         $promo = $api->PromoCodeUse();
     } catch (ApiException $e) {
     }
     $info = ['promo' => !empty($promo['promo']), 'address' => @$promo['address'], 'discountText' => trans('main.no discount')];
     if ($info['promo']) {
         if ($promo['discount'] > 0) {
             $info['discountText'] = $promo['discount'] . ' (' . trans('main.corporate tariff') . ')';
         } else {
             $info['discountText'] = trans('main.no discount') . ' (' . trans('main.corporate tariff') . ')';
         }
     }
     if (!empty($user['discount'])) {
         $info['discountText'] = $user['discount'];
     }
     return $info;
 }