public static function getService() { $data = self::find()->where(['guide_id' => User::getCurrentGuideId()])->asArray()->one(); $data['service_car'] = ServiceCar::find()->where(['service_id' => $data['id']])->asArray()->all(); $data['service_type'] = ServiceType::find()->select('rt_guide.vw_rt_guide_service_type.*, dict_type.name AS service_name')->leftJoin('rt_guide.vw_rt_dict_service_type AS dict_type', 'dict_type.id = rt_guide.vw_rt_guide_service_type.type_id')->where(['service_id' => $data['id']])->asArray()->all(); return $data; }
public static function getGuideCountries($limit = false) { $select = self::find()->select(['distinct(country.id) as id', 'country.name as name', 'country.name_genitive as nameGenetive'])->leftJoin('dict.vw_dict_country as country', 'rt_guide.vw_rt_guide_user_geo.country = country.id')->where(['rt_guide.vw_rt_guide_user_geo.guide_id' => User::getCurrentGuideId()])->asArray(); if ($limit) { $select->limit($limit); } return $select->all(); }
public static function getExcursion($id) { $data = self::find()->where(['id' => $id, 'guide_id' => User::getCurrentGuideId()])->asArray()->all(); if (!$data) { return false; } return $data[0]; }
public function actionAddorderexc() { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $data = ['status' => 'OK', 'message' => '']; $request = Yii::$app->request; $excId = $request->post('excId', false); $excursion = false; if (!$excId) { $countryId = $request->post('country', false); $cityId = $request->post('city', false); if (!$countryId || !$cityId) { $data['status'] = 'Err'; $data['message'] = 'не переданы параметры экскурсии или страны и города!'; return $data; } } else { $excursion = Excursion::getExcursion($excId); if (!$excursion) { $data['status'] = 'Err'; $data['message'] = 'не найдена экскурсия!'; return $data; } } $excDate = $request->post('excDate', false); $price = $request->post('price', false); $countBig = $request->post('countBig', false); $countSmall = $request->post('countSmall', false); $excComment = $request->post('excComment', false); $name = $request->post('name', false); $phone = $request->post('phone', false); $email = $request->post('email', false); if (!$excDate || !$excComment || !$name || !$phone || !$email) { $data['status'] = 'Err'; $data['message'] = 'не заполнены обязательные поля!'; return $data; } $validator = new \yii\validators\EmailValidator(); if (!$validator->validate($email)) { $data['status'] = 'Err'; $data['message'] = 'не корректный e-mail!'; return $data; } if (!$excursion) { $country = Country::getCountry($countryId); if (!$country) { $data['status'] = 'Err'; $data['message'] = 'страна не найдена!'; return $data; } $city = City::getCity($cityId); if (!$city) { $data['status'] = 'Err'; $data['message'] = 'город не найден!'; return $data; } $text = $country['name'] . ', ' . $city['name'] . '<br />'; $text .= 'Дата проведения экскурсии: ' . $excDate . '<br />'; $text .= $countBig ? 'Количество взрослых: ' . $countBig . '<br />' : ''; $text .= $countSmall ? 'Количество детей: ' . $countSmall . '<br />' : ''; $text .= $price ? 'Цена до: ' . $price . '<br />' : ''; $text .= '<br /><br />' . $excComment; $orderTbl = new AgencyOrder(); $orderTbl->manager_id = User::getCurrentGuideId(); $orderTbl->country_id = $countryId; $orderTbl->user_name = $name; $orderTbl->user_email = $email; $orderTbl->user_phone = $phone; $orderTbl->user_params = $text; $orderTbl->user_id = 0; $orderTbl->excursion_id = 0; $orderTbl->save(); } else { $text = 'Дата проведения экскурсии: ' . $excDate . '<br />'; if ($price) { $text .= 'Стоимость до: ' . $price . '<br />'; } $text .= $countBig ? 'Количество взрослых: ' . $countBig . '<br />' : ''; $text .= $countSmall ? 'Количество детей: ' . $countSmall . '<br />' : ''; $text .= '<br /><br />' . $excComment; $orderTbl = new AgencyOrder(); $orderTbl->manager_id = User::getCurrentGuideId(); $orderTbl->country_id = $excursion['country_id']; $orderTbl->user_name = $name; $orderTbl->user_email = $email; $orderTbl->user_phone = $phone; $orderTbl->user_params = $text; $orderTbl->user_id = 0; $orderTbl->excursion_id = $excursion['id']; $orderTbl->save(); } /** * @todo * добавить отправку заявки на e-mail */ return $data; }