public function applicationsAction()
 {
     $date = new DateTime("now");
     if ($this->request->isPost() and $this->request->isAjax()) {
         $start_from = $this->request->getPost('start_from', 'int');
         $type = $this->request->getPost('type', 'int');
         if ($type == 1) {
             $apps = Application::find(array('conditions' => 'confirmed = 0 and term >= ?1', 'order' => 'term DESC', 'limit' => '5', 'offset' => $start_from, 'bind' => array(1 => $date->format('Y.m.d'))));
         } else {
             if ($type == 2) {
                 $apps = Application::find(array('conditions' => 'confirmed = 1 and term >= ?1', 'order' => 'term DESC', 'limit' => '5', 'offset' => $start_from, 'bind' => array(1 => $date->format('Y.m.d'))));
             } else {
                 if ($type == 3) {
                     $apps = Application::find(array('conditions' => 'confirmed = 1 and term < ?1', 'order' => 'term DESC', 'limit' => '5', 'offset' => $start_from, 'bind' => array(1 => $date->format('Y.m.d'))));
                 } else {
                     $apps = array();
                 }
             }
         }
         $services = array();
         $users = array();
         foreach ($apps as $key => $app) {
             $str = "";
             $a_ss = ApplicationService::find(array('conditions' => 'application_id = ?1', 'bind' => array(1 => $app->id)));
             foreach ($a_ss as $a_s) {
                 $service = Service::findFirst(array('conditions' => 'id = ?1', 'bind' => array(1 => $a_s->service_id)));
                 $str .= $service->name . ', ';
             }
             $services[$key] = substr($str, 0, -2) . '.';
             $car = Car::findFirst(array('conditions' => 'number = ?1', 'bind' => array(1 => $app->car)));
             $users[$key] = User::findFirst(array('conditions' => 'id = ?1', 'bind' => array(1 => $car->owner)));
         }
         if (count($apps) > 0) {
             $view = clone $this->view;
             $view->start();
             $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
             $view->setParamToView('apps', $apps);
             $view->setParamToView('type', $type);
             $view->setParamToView('services', $services);
             $view->setParamToView('users', $users);
             $view->render('admin', 'applications');
             $view->finish();
             $content = $view->getContent();
             $this->view->disable();
             $status = 200;
             $description = 'OK';
             $headers = array();
             $contentType = 'application/json';
             $content = json_encode($content);
             $response = new \Phalcon\Http\Response();
             $response->setStatusCode($status, $description);
             $response->setContentType($contentType, 'UTF-8');
             $response->setContent($content);
             foreach ($headers as $key => $value) {
                 $response->setHeader($key, $value);
             }
             return $response;
         } else {
             return 0;
         }
     }
 }
Beispiel #2
0
 public static function hasDone($uid)
 {
     $car = Car::findFirst("uid={$uid}");
     if (!$car) {
         return false;
     }
     $advises = Advise::getAdvisesByUid($uid, Advise::STATUS_UNDO, 'car');
     return $advises ? false : true;
 }
 public function viewAction($id = null)
 {
     if (!is_null($id) and is_numeric($id)) {
         $car = Car::findFirst("id = " . $id);
         if (!$car) {
             return $this->dispatcher->forward(["controller" => "index", "action" => "index"]);
         }
         $this->view->car = $car;
     } else {
         return $this->dispatcher->forward(["controller" => "index", "action" => "index"]);
     }
 }
 public function applyAction()
 {
     if ($this->request->isPost()) {
         $user = $this->getAuth();
         $new_car = $this->request->getPost('new_car');
         if ($new_car == 0) {
             $car = Car::findFirst(array('conditions' => 'number = ?1', 'bind' => array(1 => $this->request->getPost('choose-car'))));
         } else {
             $car = new Car();
             $car->number = $this->request->getPost('number');
             $car->brand = $this->request->getPost('brand');
             $car->model = $this->request->getPost('model');
             $car->owner = $user['user_id'];
             if (!$car->save()) {
                 message($this, "d", "Данные об автомобиле указаны неверно");
                 return $this->response->redirect("applyForService");
             }
         }
         if ($car) {
             $date = $this->request->getPost('date');
             $time = $this->request->getPost('time');
             $apps = Application::find(array('conditions' => 'term = ?1', 'bind' => array(1 => $date)));
             if ($date) {
                 if ($time) {
                     if (count($apps) < 4 * 20) {
                         $services = $this->request->getPost('services');
                         if (count($services) > 0) {
                             $app = new Application();
                             $app->car = $car->number;
                             $app->term = $date . ' ' . $time;
                             $app->confirmed = 0;
                             $app->manager = NULL;
                             if ($app->save()) {
                                 foreach ($services as $service) {
                                     $as = new ApplicationService();
                                     $as->application_id = $app->id;
                                     $as->service_id = $service;
                                     if (!$as->save()) {
                                         message($this, "d", "Ошибка при сохранении выбранной услуги");
                                         return $this->response->redirect("applyForService");
                                     }
                                 }
                                 //todo! Обработка поля с доп. информацией
                                 message($this, "s", "Заявка отправлена. В ближайшее время наш менеджер свяжется с Вами для ее подтверждения");
                                 return $this->response->redirect("cabinet");
                             } else {
                                 message($this, "d", "Ошибка при сохранении заявки");
                                 foreach ($app->getMessages() as $message) {
                                     message($this, "d", "Ошибка: " . $message->getMessage() . " в поле " . $message->getField() . ". Тип: " . $message->getType());
                                 }
                                 return $this->response->redirect("applyForService");
                             }
                         } else {
                             message($this, "d", "Минимум одна услуга должна быть выбрана");
                             return $this->response->redirect("applyForService");
                         }
                     } else {
                         message($this, "d", "Выбранная дата занята. Пожалуйста, выберите другой день");
                         return $this->response->redirect("applyForService");
                     }
                 } else {
                     message($this, "d", "Время не выбрано!");
                     return $this->response->redirect("applyForService");
                 }
             } else {
                 message($this, "d", "Дата не выбрана!");
                 return $this->response->redirect("applyForService");
             }
         } else {
             message($this, "d", "Автомобиль не найден");
             return $this->response->redirect("applyForService");
         }
     }
 }
Beispiel #5
0
 public static function advise($uid, $foid, $adviseType, $reason, $loan = false)
 {
     $isLoanSketch = false;
     switch ($adviseType) {
         case 'loansketch':
             $status = \App\LoanStatus::getStatusSketch();
             $oid = User::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
         case 'visit':
             $status = \App\LoanStatus::getStatusCarAssess();
             $oid = Visit::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
         case 'car':
             $status = \App\LoanStatus::getStatusVisit();
             $oid = Car::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
         case 'face':
             $status = \App\LoanStatus::getStatusChecked();
             $oid = Face::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
     }
     if (empty($oid)) {
         return false;
     }
     if ($isLoanSketch) {
         $model = LoanSketch::findFirst("uid={$uid}");
         $model->status = $status;
         $model->update();
     }
     Advise::add($uid, $oid, $foid, $adviseType, $reason);
     return true;
 }