示例#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');
     }
 }
示例#2
0
 protected function getCustomer()
 {
     $api = new Api();
     Customer::instance()->closeIfNotMember();
     // ключ из запроса
     $keyRequest = Input::get('key');
     // наш ключ клиента
     $keyCustomer = Customer::instance()->key();
     // id сессии агбиса
     $keyAgbis = $api->key();
     // при наличии нашего ключа плюс ключа агбиса
     // это значит что мы держим вполне живую сессию
     if ($keyCustomer && $keyAgbis) {
         $customer = Customer::instance()->initByKey();
         Reporter::customerTouchKey($keyCustomer, $keyAgbis, $customer->get()->agbis_id);
         return $customer;
     }
     Reporter::customerEmptyKey($keyCustomer, $keyAgbis);
     // нет своего ключа но есть ключ агбис или ключ запроса (он же ключ агбис)
     // это значит что свой ключ мы еще не выдали по какой то причине
     // поэтому работаем по ключу агбиса (из запроса - приоритетнее)
     Reporter::customerTouchExternalKey($keyRequest, $keyAgbis);
     $keyAgbis = $keyRequest ? $keyRequest : $keyAgbis;
     if ($keyAgbis) {
         try {
             $user = $api->_cache_customer_info($keyAgbis);
             $api->memory((object) ['id' => $user['id'], 'key' => $keyAgbis]);
             // получили человека по агбису, найдем его у нас и создадим свою сессию
             $customer = Customer::instance()->initByExternalId($user['id']);
             if ($customer) {
                 $key = $customer->startSession();
                 Reporter::loginNewKey($customer->get()->agbis_id, $key);
                 return $customer;
             }
             // иначе это значит, что в нашей базе пользователя нет
             // придется его выбросить и пусть авторизуется заново
             Reporter::customerLostExternalKey($keyAgbis);
         } catch (ApiException $e) {
             Reporter::customerFailExternalKey($keyAgbis);
         }
     } else {
         Reporter::customerEmptyExternalKey();
     }
     Customer::instance()->destroySession();
     return null;
 }