Пример #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']], 'Заказ оформлен');
 }
Пример #2
0
 /**
  * @param string $password
  *
  * @return Customer $this
  */
 public function doChangePassword($password)
 {
     Mailer::newPasswordChanged($this->customer, $password);
     $this->customer->credential->password = $this->hash($password);
     $this->customer->credential->save();
     return $this;
 }
Пример #3
0
 public function create()
 {
     Validation::prepareInput(['phone']);
     $validator = Validator::make(Input::all(), ['name' => 'required|min:3', 'phone' => 'required|min:10', 'email' => 'required|email', 'text' => 'required|min:10']);
     if ($validator->fails()) {
         return $this->responseError($validator, 'Исправьте ошибки в полях формы');
     }
     Mailer::feedbackMessage(['name' => Input::get('name'), 'phone' => Input::get('phone'), 'email' => Input::get('email'), 'text' => Input::get('text')]);
     return $this->responseSuccess();
 }
Пример #4
0
 public function fire()
 {
     $list = CustomerInvite::whereBonus(0)->with('customer')->get()->all();
     $this->line('Найдено безбонусных инвайтов: ' . count($list));
     foreach ($list as $item) {
         if ($item->customer && $item->customer->initExistsPaid()) {
             $this->line('Отправляем письмо по инвайту: ' . $item->id . ', customer = ' . $item->customer->name);
             Mailer::inviteIsPayment($item->customer, $item->owner);
             $item->bonus = 1;
             $item->save();
         }
     }
 }
Пример #5
0
 public function orderMessage()
 {
     $title = Input::get('title');
     Validation::prepareInput(['phone']);
     $phone = Input::get('phone');
     $validator = Validation::validator(['phone']);
     if ($validator->fails()) {
         return $this->responseError($validator, 'Некорректные данные');
     }
     $user = Customer::instance()->initByPhone($phone);
     if ($user) {
         Mailer::confirmOrderMessage($phone, $title);
         return $this->responseSuccess([], 'Спасибо! Подтверждение принято.');
     }
     return $this->responseError([], 'К сожалению, такой номер не зарегистрирован. ' . 'Пожалуйста, пройдите регистрацию на сайте dryharder.me прежде, ' . 'чем оставлять заказ');
 }
Пример #6
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()]);
     }
 }
Пример #7
0
 public function start($order_id, $customer_id)
 {
     if (!$this->isNotPaidOrder($customer_id, $order_id)) {
         return Response::json(['message' => 'Заказ находится в процессе оплаты'], 500);
     }
     $customer = Customer::instance()->initByExternalId($customer_id);
     if (!$customer) {
         return Response::json(['message' => 'Клиент не найден'], 500);
     }
     $autopayCard = PaymentCloud::getCustomerAutopayCard($customer_id);
     if (!$autopayCard) {
         return Response::json(['message' => 'Автоплатежи клиента выключены'], 500);
     }
     $key = 'users.agbis.sessions.customer' . $customer_id;
     $sessionId = $this->initSessionKey($customer, $customer->get()->credential->agbis_password, $key);
     if (!$sessionId) {
         return Response::json(['message' => 'Сессия клиента не найдена'], 500);
     }
     $api = new Api();
     $order = $api->getOrder($order_id, $sessionId);
     if (!$order) {
         return Response::json(['message' => 'Заказ клиента не найден'], 500);
     }
     if ($autopayCard->token == '') {
         return Response::json(['message' => 'Токен привязанной карты не найден'], 500);
     }
     OrderAutopay::unguard();
     $pay = OrderAutopay::create(['order_id' => $order_id, 'customer_id' => $customer_id, 'state' => 0]);
     $result = $api->payByToken($order_id, $autopayCard->token, $order['amount'], $order['doc_number'], $sessionId);
     $pay->comment = $result->message;
     $pay->save();
     if ($result->success) {
         $pay->state = 1;
         $pay->save();
         Mailer::succesAutoPay($customer, $order, $autopayCard);
         return Response::json(['amount' => $order['amount']]);
     }
     Mailer::errorAutoPay($customer, $order, $autopayCard);
     return Response::json(['message' => $result->message], 500);
 }
Пример #8
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' => 'отзыв сохранен']);
 }