/** * @param $cityId 城市编号 * @return 返回 ViewSpot[ID,NameCn] */ public static function getViewSpotNameForCityId($cityId) { $viewSpotS = new ViewSpot(); if (!empty($cityId) && is_numeric($cityId)) { $criteria = new CDbCriteria(); $criteria->select = "ID,NameCn,Lng,Lat"; $criteria->condition = "CityID=:CityID"; $criteria->params = array(':CityID' => $cityId); $viewSpotS = ViewSpot::model()->findAll($criteria); } return $viewSpotS; }
public function ActionAjaxRrip() { $attractions = array(); //全部行程规划 $start_date = Yii::app()->request->getParam('start_date'); //开始日期 $end_date = Yii::app()->request->getParam('end_date'); //返回日期 $city_ids = Yii::app()->request->getParam('city_ids'); //游玩城市id字符串 $city_arr = explode(",", $city_ids); //游玩城市id数组 $days = round((strtotime($end_date) - strtotime($start_date)) / 3600 / 24); //游玩天数 $day_ave_num = 3; //平均每天游玩景点数 //获取所有城市信息[S] $city_condition = new CDbCriteria(); $city_condition->addInCondition('ID', $city_arr); $city_list = City::model()->findAll($city_condition); //获取所有城市信息[E] //计算每个城市游玩天数[S] $ave_day = floor($days / count($city_arr)); $les_day = $days % count($city_arr); foreach ($city_list as $val) { if ($les_day > 0) { $pay_days = $ave_day + 1; $les_day--; } else { $pay_days = $ave_day; } $attractions[$val['ID']]['CityName'] = $val['NameCn']; $attractions[$val['ID']]['pay_days'] = $pay_days; $attractions[$val['ID']]['Lat'] = $val['Lat']; $attractions[$val['ID']]['Lng'] = $val['Lng']; } //计算每个城市游玩天数[E] foreach ($attractions as $k => $v) { if (isset($v['Lat']) && !empty($v['Lat']) && isset($v['Lng']) && !empty($v['Lng'])) { $lat = $v['Lat']; $lng = $v['Lng']; $attraction_sql = "select * from ( select `ID`, `NameCn`, `NameEn`, `NameCnShort`, `NamePin`, `NamePinShort`, `ContinentID`, `CountryID`, `CityID`, `Theme`, `ViewSpotLevel`, `Tel`, `Fax`, `Website`, `Zipcode`, `Address`, `Station`, `TrafficType`, `TicketPrice`, `BusinessHours`, `BusinessMonths`, `MoneyType`, `TravelTime`, `Lng`, `Lat`, `Hot`, `ParkService`, `Des`, `Note`, `SightCharacteristic`, `UID`, `CreateTime`, `UpdateTime`, `Status`, `Valid`,lat_long_distance(" . $lat . ", " . $lng . ", p.Lat, p.Lng) as distance from view_spot as p) as d where d.distance>0 and d.distance <5000 order by distance asc"; $attr = ViewSpot::model()->findAllBySql($attraction_sql); $attr = array_slice($attr, 0, $v['pay_days'] * $day_ave_num); $attr = array_chunk($attr, $day_ave_num, false); $attractions[$k]['trip'] = $attr; } } echo CJSON::encode($attractions); }
/** * 添加景点图片 */ public function actionAddViewSpotPicture() { $isPost = Yii::app()->request->isPostRequest; if (empty($isPost)) { $viewSpot_id = intval(Yii::app()->request->getParam('viewSpot_id')); $viewSpot_model = ViewSpot::model()->findByPk($viewSpot_id); $this->render('add_view_spot_picture', array('viewSpot_model' => $viewSpot_model)); } else { //生成图的名称(大,中,小图)[S] $picture_name = isset($_GET['picture_name']) ? $_GET['picture_name'] : ""; $picture_title = isset($_GET['picture_title']) ? $_GET['picture_title'] : ""; $picture_desc = isset($_GET['picture_description']) ? $_GET['picture_description'] : ""; //解析图片名称和扩展名 $name_noext = substr($picture_name, 0, strrpos($picture_name, '.')); //名称(无扩展名) $name_ext = strrchr($picture_name, "."); //扩展名 $name_rand = md5(time() . mt_rand(1, 1000000)); //将图片中文名称转换为拼音 $name_noext_arr = IconvEncode::gbk2Pinyin($name_noext); $name_noext_pinyin = implode("", $name_noext_arr) . $name_rand; //中、小图名称 $picture_middle_name = $name_noext_pinyin . "_middle" . $name_ext; //中规格图名称 $picture_samll_name = $name_noext_pinyin . "_samll" . $name_ext; //小规格图名称 //生成图的名称(大,中,小图)[E] $viewSpot_Id = Yii::app()->request->getParam('viewSpot_Id'); //景点ID $viewSpot_count = ViewSpot::model()->count('ID=:id', array(':id' => $viewSpot_Id)); if ($viewSpot_count > 0) { //判断该景点是否存在 //创建图片路径 $pic_dir_path = IMAGES_PATH . 'viewspot' . '/' . date("Y-m") . '/'; DirectoryFile::dirCreate($pic_dir_path); //大、中、小图上传 $pic_big_src = $pic_dir_path . $name_noext_pinyin . $name_ext; $pic_middle_src = $pic_dir_path . $picture_middle_name; $pic_small_src = $pic_dir_path . $picture_samll_name; //上传原始图片并生产规定格式的中图和小图 file_put_contents($pic_big_src, file_get_contents('php://input')); //存放大图 ImageChange::imgResize($pic_big_src, $pic_middle_src, 380, 210); //生成中图 ImageChange::imgResize($pic_big_src, $pic_small_src, 180, 120); //生成小图 //图片信息存入数据库 if (empty($picture_title)) { $picture_title = $name_noext; } //图片路径保存到数据库 $ViewSpotSource['big'] = new ViewSpotSource(); $ViewSpotSource['big']->PicSrc = $pic_big_src; $ViewSpotSource['big']->PicTitle = $picture_title; $ViewSpotSource['big']->PicDes = $picture_desc; $ViewSpotSource['big']->VS_Id = $viewSpot_Id; $ViewSpotSource['big']->SizeType = 0; $ViewSpotSource['middle'] = new ViewSpotSource(); $ViewSpotSource['middle']->PicSrc = $pic_middle_src; $ViewSpotSource['middle']->PicTitle = $picture_title; $ViewSpotSource['middle']->PicDes = $picture_desc; $ViewSpotSource['middle']->VS_Id = $viewSpot_Id; $ViewSpotSource['middle']->SizeType = 1; $ViewSpotSource['small'] = new ViewSpotSource(); $ViewSpotSource['small']->PicSrc = $pic_small_src; $ViewSpotSource['small']->PicTitle = $picture_title; $ViewSpotSource['small']->PicDes = $picture_desc; $ViewSpotSource['small']->VS_Id = $viewSpot_Id; $ViewSpotSource['small']->SizeType = 2; //事务[S] $transaction = Yii::app()->db->beginTransaction(); //开启事务 try { foreach ($ViewSpotSource as $pic_src) { if (!$pic_src->save()) { throw new Exception(); } } $transaction->commit(); //提交事务 } catch (Exception $e) { $transaction->rollBack(); //回滚事务 } //事务[E] echo $pic_dir_path; } } }