Exemple #1
0
 public function request()
 {
     $api = new Api();
     $data = [];
     if ($api->key()) {
         try {
             $data = $api->ContrInfo();
         } catch (\Exception $e) {
         }
     }
     $rules = ['address1' => 'required', 'address2' => 'required', 'orderText' => 'required', 'comment' => ''];
     // тип формы "новый клиент" (иначе - авторизованный)
     if (!$api->key()) {
         Validation::prepareInput(['phone']);
         $rules['phone'] = 'required|phone';
         $rules['email'] = 'required|email';
     }
     Input::merge(array_map('trim', Input::all()));
     $validator = \Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return $this->responseError($validator, $validator->errors()->first());
     }
     $fields = array_keys($rules);
     foreach ($fields as $key) {
         $data[$key] = Input::get($key);
     }
     Mailer::requestOrderMessage($data);
     OrderRequest::unguard();
     OrderRequest::create(['email' => $data['email'], 'phone' => Customer::instance()->phone($data['phone']), 'address1' => $data['address1'], 'address2' => $data['address2'], 'orderText' => $data['orderText'], 'comment' => $data['comment']]);
     return $this->responseSuccess(['email' => $data['email'], 'phone' => Customer::instance()->phone($data['phone']), 'address' => $data['address1']], 'Заказ оформлен');
 }
Exemple #2
0
 public function fire()
 {
     $api = new Api();
     $list = $api->PriceList();
     $listGroup1 = [];
     $listGroup2 = [];
     $listGroup3 = [];
     foreach ($list as &$item) {
         foreach ($item as &$val) {
             $val = trim(urldecode($val));
         }
         if ($item->group_p && !in_array($item->group_p, $listGroup1)) {
             $listGroup1[] = $item->group_p;
         }
         if ($item->group_c && !in_array($item->group_c, $listGroup2)) {
             $listGroup2[] = $item->group_c;
         }
         if ($item->top_parent && !in_array($item->top_parent, $listGroup3)) {
             $listGroup3[] = $item->top_parent;
         }
     }
     foreach ($list as $item) {
         $title = ServiceTitle::whereAgbisId($item->id)->first();
         if (!$title) {
             $title = new ServiceTitle();
         }
         $title->agbis_id = $item->id;
         $title->code = $item->code;
         $title->name = $item->name;
         $lang = !empty($title->lang) ? json_decode($title->lang) : (object) [];
         $lang->ru = $item->name;
         $title->lang = json_encode($lang, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
         $title->save();
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     try {
         $api = new Api();
         $customers = Customer::all();
         foreach ($customers as $customer) {
             $customerId = $customer->agbis_id;
             $card = PaymentCloud::getCustomerAutopayCard($customerId);
             if ($card) {
                 $phone = '+7' . $customer->phone;
                 $password = $customer->credential->agbis_password;
                 $user = $api->Login_con($phone, $password);
                 $key = $user->key;
                 $orders = $api->Orders($key)['orders'];
                 foreach ($orders as $order) {
                     if ($this->isNotPaidOrder($customerId, $order['id'])) {
                         if ($api->IsGoodOrder($order['id'], $customerId)) {
                             $api->payByToken($order['id'], $card->token, $order['amount'], $order['doc_number'], $key);
                         }
                     }
                 }
             }
         }
     } catch (ApiException $e) {
     }
 }
 /**
  * @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('закончили работу с клиентом');
 }
Exemple #5
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;
 }
 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');
     }
 }
 public function parseOrderService($id, $sid = null)
 {
     $api = new Api();
     $clothes = $api->FullService($id, $sid);
     $result = [];
     foreach ($clothes as $item) {
         $description = ['name' => $item->service, 'service' => $item->service, 'dirty_name' => $item->dirty_name, 'status_name' => $item->status_name, 'price' => $item->price, 'amount' => $item->price, 'nurseries_name' => $item->nurseries_name, 'group_tov' => $item->group_tov, 'qnt' => $item->qty];
         $properties = [];
         foreach ($item->addons as $addon) {
             if (is_numeric($addon->aos_value) && strlen($addon->aos_value) > 0 && $addon->aos_value == 0) {
                 continue;
             } elseif (is_numeric($addon->aos_value) && $addon->aos_value == 1) {
                 $properties[] = ['title' => $addon->descr, 'value' => null];
             } elseif (!empty($addon->aos_value)) {
                 $properties[] = ['title' => $addon->descr, 'value' => $addon->aos_value];
             }
             $description['properties'] = $properties;
         }
         $result[] = $description;
     }
     return $result;
 }
Exemple #8
0
 /**
  * @param Customer $customer
  * @param $password
  * @param $key
  *
  * @return array
  */
 public function initSessionKey(Customer $customer, $password, $key)
 {
     $api = new Api();
     $user = $api->Login_con('+7' . $customer->get()->phone, $password);
     $sessionId = $user->key;
     Cache::put($key, $sessionId, 500);
     $this->log('get new session', ['customer' => $customer->get()->id, 'session' => $sessionId]);
     return $sessionId;
 }
 /**
  * проверяет, что заказ присутствует в системе Агбис
  */
 private function checkOrder()
 {
     $params = $this->parameters();
     try {
         $api = new Api();
         $api->IsGoodOrder((int) $params['order_id'], (int) $params['customer_id']);
         Reporter::payOrderFound($params['customer_id'], $params['order_id']);
     } catch (ApiException $e) {
         Reporter::payOrderLost($params['customer_id'], $params['order_id']);
         if ($e->getCode() == 400) {
             return $this->responseError('Ошибка оплаты заказа', 200);
         }
         return $this->responseError('Ошибка оплаты заказа', 200);
     }
     return true;
 }
Exemple #10
0
 private function parsePayTarget($target, $id)
 {
     $api = new Api();
     $id = (int) $id;
     if ($id <= 0) {
         return null;
     }
     // оплата заказа
     if ($target == 'order') {
         return $id;
     }
     // оплата подписки
     if ($target == 'subscription') {
         $customer_id = Customer::instance()->initByExternalId($api->id())->get()->id;
         $subscription_id = $id;
         Reporter::subscriptionPaymentRequest($customer_id, $subscription_id);
         $subscription = Subscription::whereCustomerId($customer_id)->find($subscription_id);
         if (!$subscription) {
             $list = $api->Certificate();
             // ищем эту подписку в агбисе
             foreach ($list as $item) {
                 if ($item->id == $subscription_id) {
                     Reporter::subscriptionFound($customer_id, $subscription_id, $item);
                     // создаем подписку в нашей базе
                     Subscription::unguard();
                     $subscription = Subscription::create(['id' => $item->id, 'name' => $item->name, 'description' => $item->comments, 'price' => $item->price, 'customer_id' => $customer_id, 'order_id' => 0]);
                     Reporter::subscriptionCreated($customer_id, $subscription_id);
                 }
             }
         }
         if (!$subscription) {
             Reporter::subscriptionNotFound($customer_id, $subscription_id);
             return null;
         }
         // если заказ уже был создан, отдаем его для оплаты
         if ($subscription->order_id > 0) {
             return $subscription->order_id;
         }
         // создадим заказа в агбисе
         $order_id = $api->CreatePayCertificate($subscription->id);
         if ($order_id > 0) {
             Reporter::subscriptionOrderCreated($customer_id, $subscription_id, $order_id);
             // отдадим для оплаты
             $subscription->order_id = $order_id;
             $subscription->save();
             return $subscription->order_id;
         }
     }
     return null;
 }
Exemple #11
0
 /**
  * поиск адресов по промо-коду
  */
 public function promo()
 {
     $promo = Input::get('promo');
     if (!$promo) {
         return $this->responseSuccess([], 'нет значения для поиска адресов');
     }
     $api = new Api();
     try {
         $list = $api->PromoCode($promo);
     } catch (ApiException $e) {
         return $this->responseSuccess([], $e->getMessage());
     }
     if (!$list) {
         return $this->responseSuccess([], 'адреса не найдены');
     }
     return $this->responseSuccess(['addresses' => $list], 'найдены адреса');
 }
 /**
  * проверяет, что заказ присутствует в системе Агбис
  */
 private function checkOrder()
 {
     if ($this->params['order_id'] > '') {
         try {
             $api = new Api();
             $api->IsGoodOrder($this->params['order_id'], $this->params['customer_id']);
             Reporter::payOrderFound($this->params['customer_id'], $this->params['order_id']);
         } catch (ApiException $e) {
             Reporter::payOrderLost($this->params['customer_id'], $this->params['order_id']);
             if ($e->getCode() == 400) {
                 $this->responseError(10);
             }
             $this->responseError(13);
         }
     }
 }