Exemplo n.º 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']], 'Заказ оформлен');
 }
Exemplo n.º 2
0
 public function index()
 {
     if (!$this->isAcceptedJson()) {
         return \View::make('man::request.index');
     }
     $list = OrderRequest::whereRaw('`created_at` >= DATE_SUB(NOW(), INTERVAL 1 MONTH)')->orderBy('id', 'desc')->get();
     return $list;
 }
Exemplo n.º 3
0
 private function notifyOrderInfo(NotifyOrder $notify)
 {
     $this->log('consume notify', $notify->getAttributes());
     $customerId = $notify->customer_id;
     $orderId = $notify->order_id;
     $customer = Customer::instance()->initByExternalId($customerId);
     if (!$customer) {
         $this->log('Customer is not initialized', ['customer_id' => $customerId]);
         return;
     }
     if (!$customer->get()->email) {
         $this->log('Email is empty', ['customer_id' => $customerId]);
         $notify->sent = 1;
         $notify->save();
         return;
     }
     $password = $customer->get()->credential->agbis_password;
     if (!$password) {
         $this->log('Customer password is not exists', ['customer_id' => $customerId]);
         return;
     }
     if (isset($this->keys[$customerId])) {
         $key = $this->keys[$customerId];
     } else {
         try {
             $user = $this->api->Login_con('+7' . $customer->get()->phone, $password);
         } catch (ApiException $e) {
             $this->log($e->getMessage(), [$customerId]);
             $notify->sent = 1;
             $notify->save();
             return;
         }
         $this->keys[$customerId] = $user->key;
         $key = $user->key;
     }
     $order = $this->api->getOrder($orderId, $key);
     $services = (new OrderServiceComponent())->parseOrderService($orderId, $key);
     $email = $customer->get()->email;
     $name = $customer->get()->name;
     $this->log('ready data send', ['services' => count($services)]);
     try {
         $attach = self::createClothesFile($order, $services, $name);
         Mailer::notifyNewOrder($order, $services, $email, $name, $attach);
         $notify->sent = 1;
         $notify->save();
         OrderRequest::markAsCompleted($customer->get()->phone, $orderId);
     } catch (\Exception $e) {
         $this->log('send mail error', ['email' => $customer->get()->email, 'id' => $customer->get()->id, 'message' => $e->getMessage()]);
     }
 }
Exemplo n.º 4
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' => 'отзыв сохранен']);
 }