/** * Finds the TimePriceTicket model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TimePriceTicket the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TimePriceTicket::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionAddPeople() { $session = Yii::$app->session; $name = $_REQUEST["name"]; $surname = $_REQUEST["surname"]; $father_name = $_REQUEST["father_name"]; $date_birthday = strtotime($_REQUEST["date_birthday"]); $phone = $_REQUEST["phone"]; $type_ticket = 0; $id_programm = 0; if ($_REQUEST["type_adult"] != "") { $type_adult = $_REQUEST["type_adult"]; } $order_id = $session["order_id"]; $order = Order::findOne($order_id); if (!$order->getIsSufficiency(true)) { $result["status"] = "error"; $result["msg"] = "Недостаточно мест"; return json_encode($result); } $now_date = date("N", $order->date); if ($now_date <= 5) { $type_day = 1; } else { $type_day = 2; } if (($order->count_hours == 11 or $order->count_hours == 12) and $now_date == 1) { $now_day = date("d.m.Y", $order->date); $dateString = 'first Monday of ' . date("Y", $order->date) . '-' . date("m", $order->date); if (!strtotime($dateString)) { throw new \Exception('"' . $dateString . '" is not a valid strtotime'); } $startDay = new \DateTime($dateString); //if ($startDay->format('j') > 2) { // $startDay->modify('- 7 days'); //} $mDays = array(); while ($startDay->format('Y-m') <= date("Y", $order->date) . '-' . str_pad(date("m", $order->date), 2, 0, STR_PAD_LEFT)) { $mDays[] = clone $startDay; $startDay->modify('+ 7 days'); } if ($now_day == $mDays[1]->format("d.m.Y")) { if ($order->count_hours == 11) { $order->count_hours = 17; } else { if ($order->count_hours == 12) { $order->count_hours = 18; } } } if ($now_day == $mDays[3]->format("d.m.Y")) { if ($order->count_hours == 11) { $order->count_hours = 17; } else { if ($order->count_hours == 12) { $order->count_hours = 18; } } } } $old = $this->getyeardiff($date_birthday, $order_id); if ($order->type_ticket == 6) { $kids = Kids::find()->where("LOWER(`name`)='" . mb_strtolower($name) . "' AND LOWER(`surname`) = '" . mb_strtolower($surname) . "' AND \n\t\t\t\t\tLOWER(`father_name`) = '" . mb_strtolower($father_name) . "' AND `birthday` = " . $date_birthday)->all(); $type_people = 2; if (count($kids) != 0) { $id_people = $kids[0]->id; } else { $kids = new Kids(); $kids->name = $name; $kids->surname = $surname; $kids->father_name = $father_name; $kids->birthday = $date_birthday; $kids->phone = $phone; $kids->save(); $id_people = $kids->id; } $id_programm = $order->id_programm; $id_time = $order->count_hours; $price = PriceProgramms::findOne(["id_programm" => $id_programm, "id_time" => $id_time]); $result["price"] = $price->price; if (isset($_REQUEST["pitanie"])) { if ($_REQUEST["pitanie"] == "true") { $type_day = TypeDayProgramms::findOne($id_time); $pitanie = DopPrice::find()->where(["name" => "pitanie"])->all(); $result["price"] += $pitanie[0]->price * $type_day->value; } } if ($old <= 7) { $result["old"] = $old; } } else { if ($order->type_ticket == 3) { $TypeTicket = TypeTicket::find()->where("`id`=12")->all(); } else { $TypeTicket = TypeTicket::find()->where("`age_min` <= '{$old}' AND `age_max` >= '{$old}'")->all(); } $type_ticket = $TypeTicket[0]->id; $o_date = $order->date; $TimePriceTicket = TimePriceTicket::find()->where("`date1` <= '{$o_date}' AND `date2` >= '{$o_date}'")->all(); if (count($TimePriceTicket) == 0) { $classPriceTicket = PriceTicket::find(); } elseif ($TimePriceTicket[0]->type == 1) { $classPriceTicket = PriceTicket::find(); } elseif ($TimePriceTicket[0]->type == 2) { $classPriceTicket = PriceTicket2::find(); } elseif ($TimePriceTicket[0]->type == 3) { $classPriceTicket = PriceTicket3::find(); } $type = $_REQUEST["type"]; if ($type == 1) { $people = Parents::find()->where("LOWER(`name`)='" . mb_strtolower($name) . "' AND LOWER(`surname`) = '" . mb_strtolower($surname) . "' AND \n\t\t\t\t\tLOWER(`father_name`) = '" . mb_strtolower($father_name) . "' AND `birthday` = " . $date_birthday)->all(); $type_people = 1; if (count($people) != 0) { $id_people = $people[0]->id; } else { $people = new Parents(); $people->name = $name; $people->surname = $surname; $people->father_name = $father_name; $people->birthday = $date_birthday; $people->phone = $phone; $people->save(); $id_people = $people->id; } //Перерасчет сопровождающий - гость if ($type_adult == 2) { $type_adult = 11; } else { $type_adult = 10; } $price = $classPriceTicket->where(["type_ticket" => $type_adult, "type_day" => $type_day, "hours" => $order->count_hours])->all(); $result["price"] = $price[0]->price; if (isset($_REQUEST["besplatno"])) { if ($_REQUEST["besplatno"] == "besplatno") { $result["price"] = 0; } } } elseif ($type == 2) { $kids = Kids::find()->where("LOWER(`name`)='" . mb_strtolower($name) . "' AND LOWER(`surname`) = '" . mb_strtolower($surname) . "' AND \n\t\t\t\t\tLOWER(`father_name`) = '" . mb_strtolower($father_name) . "' AND `birthday` = " . $date_birthday)->all(); $type_people = 2; if (count($kids) != 0) { $id_people = $kids[0]->id; } else { $kids = new Kids(); $kids->name = $name; $kids->surname = $surname; $kids->father_name = $father_name; $kids->birthday = $date_birthday; $kids->phone = $phone; $kids->save(); $id_people = $kids->id; } $price = $classPriceTicket->where(["type_ticket" => $type_ticket, "type_day" => $type_day, "hours" => $order->count_hours])->all(); $result["price"] = $price[0]->price; if (isset($_REQUEST["pitanie"])) { if ($_REQUEST["pitanie"] == "true") { $pitanie = DopPrice::find()->where(["name" => "pitanie"])->all(); $result["price"] += $pitanie[0]->price; } } if ($old <= 7) { $result["old"] = $old; } } } $RelOrderPeople = RelOrderPeople::find()->where(["id_order" => $session["order_id"], "id_people" => $id_people, "type_people" => $type_people])->all(); if (count($RelOrderPeople) == 0) { if ($_REQUEST["id_rel"] == "") { $RelOrderPeople = new RelOrderPeople(); } else { $RelOrderPeople = RelOrderPeople::findOne($_REQUEST["id_rel"]); } $RelOrderPeople->id_order = $session["order_id"]; $RelOrderPeople->id_people = $id_people; $RelOrderPeople->type_people = $type_people; $RelOrderPeople->type_tiket = $type_ticket; $RelOrderPeople->id_programm = $id_programm; $RelOrderPeople->qr = md5(time() . $id_people . $session["order_id"]); if (isset($_REQUEST["pitanie"])) { if ($_REQUEST["pitanie"] == "true") { $RelOrderPeople->pitanie = 1; } } $RelOrderPeople->summ = $result["price"] * 100; $RelOrderPeople->save(); } $RelOrderPeople = RelOrderPeople::find()->where(["id_order" => $session["order_id"], "id_people" => $id_people, "type_people" => $type_people])->all(); $result["id_rel"] = $RelOrderPeople[0]->id; $result["status"] = 'ok'; return json_encode($result); }