Example #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']], 'Заказ оформлен');
 }
 /**
  * @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('закончили работу с клиентом');
 }
Example #3
0
 public function reviewOrder()
 {
     $data = Input::only(['stars', 'text', 'order']);
     $api = new Api();
     $user = $api->ContrInfo();
     if (Input::get('request') && Input::get('request') !== 'false') {
         $request = OrderRequest::find($data['order']);
         $order = ['id' => 0, 'doc_number' => $request->getHumanId()];
         $data['order'] = 0;
     } else {
         $order = $api->getOrder($data['order']);
     }
     $data['email'] = $user['email'];
     $data['phone'] = $user['phone'];
     $data['name'] = $user['name'];
     $data['doc_number'] = $order['doc_number'];
     Mailer::orderReview($data);
     OrderReview::unguard();
     $review = OrderReview::create(['customer_id' => Customer::instance()->initByExternalId($user['id'])->get()->id, 'text' => $data['text'], 'stars' => $data['stars'], 'doc_number' => $order['doc_number'], 'order_id' => $order['id']]);
     return Response::json(['data' => $review, 'message' => 'отзыв сохранен']);
 }