コード例 #1
0
 public function actionIndex()
 {
     $TypeTicket = TypeTicket::find()->all();
     $model = new PriceTicket();
     $model2 = new PriceTicket2();
     $model3 = new PriceTicket3();
     $model_programms = new PriceProgramms();
     $dt = Yii::$app->getRequest()->post('PriceTicket');
     $dt2 = Yii::$app->getRequest()->post('PriceTicket2');
     $dt3 = Yii::$app->getRequest()->post('PriceTicket3');
     $dt_dop_price = Yii::$app->getRequest()->post("DopPrice");
     if ($dt["price"]) {
         foreach ($dt["price"] as $type_day => $value) {
             foreach ($value as $type_ticket => $val) {
                 foreach ($val as $hours => $price) {
                     $res = PriceTicket::find()->where("type_day={$type_day} AND type_ticket={$type_ticket} AND hours={$hours}")->all();
                     if ($res) {
                         $id = $res[0]->id;
                         $record = PriceTicket::findOne($id);
                         $record->price = $price;
                         $record->update();
                     } else {
                         $record = new PriceTicket();
                         $record->type_day = $type_day;
                         $record->type_ticket = $type_ticket;
                         $record->hours = $hours;
                         $record->price = $price;
                         $record->insert();
                     }
                 }
             }
         }
     }
     if ($dt2["price"]) {
         foreach ($dt2["price"] as $type_day => $value) {
             foreach ($value as $type_ticket => $val) {
                 foreach ($val as $hours => $price) {
                     $res = PriceTicket2::find()->where("type_day={$type_day} AND type_ticket={$type_ticket} AND hours={$hours}")->all();
                     if ($res) {
                         $id = $res[0]->id;
                         $record = PriceTicket2::findOne($id);
                         $record->price = $price;
                         $record->update();
                     } else {
                         $record = new PriceTicket2();
                         $record->type_day = $type_day;
                         $record->type_ticket = $type_ticket;
                         $record->hours = $hours;
                         $record->price = $price;
                         $record->insert();
                     }
                 }
             }
         }
     }
     if ($dt3["price"]) {
         foreach ($dt3["price"] as $type_day => $value) {
             foreach ($value as $type_ticket => $val) {
                 foreach ($val as $hours => $price) {
                     $res = PriceTicket3::find()->where("type_day={$type_day} AND type_ticket={$type_ticket} AND hours={$hours}")->all();
                     if ($res) {
                         $id = $res[0]->id;
                         $record = PriceTicket3::findOne($id);
                         $record->price = $price;
                         $record->update();
                     } else {
                         $record = new PriceTicket3();
                         $record->type_day = $type_day;
                         $record->type_ticket = $type_ticket;
                         $record->hours = $hours;
                         $record->price = $price;
                         $record->insert();
                     }
                 }
             }
         }
     }
     $dt_programms = Yii::$app->getRequest()->post('PriceProgramms');
     if ($dt_programms["programms"]) {
         foreach ($dt_programms["programms"] as $id_programm => $programm) {
             foreach ($programm as $id_type_day => $price) {
                 $res = PriceProgramms::findOne(["id_programm" => $id_programm, "id_time" => $id_type_day]);
                 if ($res) {
                     $res->price = $price;
                     $res->save();
                 } else {
                     $res = new PriceProgramms();
                     $res->id_programm = $id_programm;
                     $res->id_time = $id_type_day;
                     $res->price = $price;
                     $res->save();
                 }
             }
         }
     }
     $data = PriceTicket::find()->all();
     $data2 = PriceTicket2::find()->all();
     $data3 = PriceTicket3::find()->all();
     foreach ($data as $key => $val) {
         $dt_val[$val["type_day"]][$val["type_ticket"]][$val["hours"]] = $val["price"];
     }
     foreach ($data2 as $key => $val) {
         $dt_val2[$val["type_day"]][$val["type_ticket"]][$val["hours"]] = $val["price"];
     }
     foreach ($data3 as $key => $val) {
         $dt_val3[$val["type_day"]][$val["type_ticket"]][$val["hours"]] = $val["price"];
     }
     $TypeHours = TypeHours::find()->all();
     foreach ($TypeHours as $val) {
         $dt_type_hours[$val->id] = $val->value;
     }
     $programms = Programms::find()->all();
     $programms_type_day = TypeDayProgramms::find()->all();
     $data_programms = PriceProgramms::find()->all();
     $dt_programms_val = "";
     foreach ($data_programms as $val) {
         $dt_programms_val[$val["id_programm"]][$val["id_time"]] = $val["price"];
     }
     $model_dop_price = new DopPrice();
     if (count($dt_dop_price) > 0) {
         foreach ($dt_dop_price as $key => $value) {
             $res = DopPrice::find()->where(["name" => $key])->all();
             $res[0]->price = $value;
             $res[0]->update();
         }
     }
     $DopPrice = DopPrice::find()->all();
     return $this->render('index', ['TypeTicket' => $TypeTicket, 'model' => $model, 'model2' => $model2, 'model3' => $model3, 'dt' => $dt, 'dt2' => $dt2, 'dt3' => $dt3, 'dt_val' => $dt_val, 'dt_val2' => $dt_val2, 'dt_val3' => $dt_val3, 'dt_type_hours' => $dt_type_hours, 'DopPrice' => $DopPrice, 'model_dop_price' => $model_dop_price, 'programms' => $programms, 'programms_type_day' => $programms_type_day, 'model_programms' => $model_programms, 'dt_val_programms' => $dt_programms_val]);
 }
コード例 #2
0
 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);
 }