Advertisement
MyZik

Untitled

Jul 2nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. /**
  2.      * @param CallbackQuery $query
  3.      * @param Telegram $telegram
  4.      * @param Update $update
  5.      * @return \Longman\TelegramBot\Entities\ServerResponse
  6.      * @throws \Longman\TelegramBot\Exception\TelegramException
  7.      */
  8.     public function newOrder(CallbackQuery $query, Telegram $telegram, Update $update) {
  9.         $callback_data = $query->getData();
  10.         $message = $query->getMessage();
  11.         $user = $message->getFrom();
  12.         $user_id = $user->getId();
  13.         $chat_id = $message->getChat()->getId();
  14.         $text = $message->getText();
  15.  
  16.         if (strpos($callback_data, 'newOrder_') !== 0) {
  17.             return Request::emptyResponse();
  18.         }
  19.  
  20.         $current = substr($callback_data, strlen('newOrder_')); // ID услуги
  21.  
  22.         $conversation = new Conversation($user->getIsBot() ? $chat_id : $user_id, $chat_id, 'neworder');
  23.  
  24.         $notes = &$conversation->notes;
  25.         !is_array($notes) && $notes = [];
  26.  
  27.         $state = 0;
  28.         if (isset($notes['state'])) {
  29.             $state = $notes['state'];
  30.         }
  31.  
  32.         $text = $current;
  33.         $result = Request::emptyResponse();
  34.  
  35.         switch ($state) {
  36.             case 0:
  37.                 if ($text === '' || !is_numeric($text) || self::searchService($text) == false) {
  38.                     $notes['state'] = 0;
  39.                     $conversation->update();
  40.  
  41.                     $data['text'] = 'Укажите ID услуги';
  42.  
  43.                     if ($text !== '')
  44.                         $data['text'] = 'Пожалуйста, укажите ID услуги.';
  45.  
  46.                     $result = Request::sendMessage($data);
  47.                     break;
  48.                 }
  49.  
  50.                 $notes['order_id'] = $text;
  51.                 $text = '';
  52.  
  53.             case 1:
  54.                 if ($text === '' || !is_numeric($text)) {
  55.                     $notes['state'] = 1;
  56.                     $conversation->update();
  57.  
  58.                     $data['text'] = 'OrderID: ' . $notes['order_id'];
  59.  
  60.                     if ($text !== '')
  61.                         $data['text'] = 'Пожалуйста, укажите ID услуги.';
  62.  
  63.                     $result = Request::sendMessage($data);
  64.                     break;
  65.                 }
  66.  
  67.                 $notes['order_id '] = $text;
  68.                 $text             = '';
  69.  
  70.             // no break
  71.             case 2:
  72.                 $conversation->update();
  73.                 unset($notes['state']);
  74.  
  75.                 /**
  76.                  * Выводим уведомление
  77.                  */
  78.                 $data['text'] = '✅ Сообщение успешно отправлено! Мы свяжемся с Вами в ближайшее время.';
  79.  
  80.                 $data['reply_markup'] = Keyboard::remove();
  81.  
  82.                 $conversation->stop();
  83.                 $result =Request::sendMessage($data);
  84.                 break;
  85.         }
  86.  
  87.         return $result;
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement