Beispiel #1
0
 /**
  * @return mixed这里取得是6位的GEOHASH。到时候要改成四位的
  */
 public static function getNearPersonsNoOrder()
 {
     $sql = ' SELECT userId FROM   tbl_myr_refresh
            WHERE geohash
            IN (:geohash1, 
                :geohash2, 
                :geohash3,
                :geohash4, 
                :geohash5, 
                :geohash6, 
                :geohash7, 
                :geohash8,
                :geohash9)';
     $geohashCode = UserRefreshForm::model()->getGeohash();
     $neighbors = $geohash->neighbors($geohashCode);
     array_push($neighbors, $geohashCode);
     $connection = Yii::app()->db;
     $command = $connection->createCommand($sql);
     $command->bindParam(":geohash1", $neighbors[0], PDO::PARAM_STR);
     $command->bindParam(":geohash2", $neighbors['top'], PDO::PARAM_STR);
     $command->bindParam(":geohash3", $neighbors['bottom'], PDO::PARAM_STR);
     $command->bindParam(":geohash4", ${$neighbors}['right'], PDO::PARAM_STR);
     $command->bindParam(":geohash5", $neighbors['left'], PDO::PARAM_STR);
     $command->bindParam(":geohash6", $neighbors['topleft'], PDO::PARAM_STR);
     $command->bindParam(":geohash7", $neighbors['topright'], PDO::PARAM_STR);
     $command->bindParam(":geohash8", $neighbors['bottomright'], PDO::PARAM_STR);
     $command->bindParam(":geohash9", $neighbors['bottomleft'], PDO::PARAM_STR);
     $result = $command->queryAll();
     foreach ($result as $key => $value) {
         $arr[$key] = $value['userId'];
     }
     return $arr;
 }
 public function actionDropList()
 {
     $dataFormat = new DataFormat();
     $currentCity = UserRefreshForm::model()->getCurrentCity();
     $criteria1 = new CDbCriteria();
     $criteria2 = new CDbCriteria();
     $criteria3 = new CDbCriteria();
     $dropListModel = DropList::model();
     $dropListData1 = null;
     $dropListData2 = null;
     $dropListData3 = null;
     $format2 = array();
     $format3 = array();
     $format1 = array();
     if (isset($_POST['DropList']['secenicName']) && !empty($_POST['DropList']['secenicName'])) {
         $secenicName = $_POST['DropList']['secenicName'];
         $criteria1->addSearchCondition(' secenicName', $secenicName);
         $criteria1->addCondition("cityName='{$currentCity}'");
         $dropListData1 = $dropListModel->findAll($criteria1);
         $format1 = $dataFormat->format($dropListData1, null);
         if (count($format1) <= 0) {
             //匹配整个数据库
             $criteria2->addSearchCondition(' secenicName', $secenicName);
             $dropListData2 = $dropListModel->findAll($criteria2);
             //分词
             $scws = new SCWS();
             $scws->sendMobile($secenicName);
             $param1 = $scws->result[0];
             if ($param1 != null) {
                 $criteria3->addCondition("cityName='{$param1}'");
             }
             if (count($scws->result) > 1) {
                 $param2 = $scws->result[1];
                 $criteria3->addSearchCondition(' secenicName', $param2);
             }
             // $total = $dropListModel->count($criteria);
             // $pager = new CPagination($total);
             // $pager->pageSize = 100;
             // $pager->applyLimit($criteria);
             $dropListData3 = $dropListModel->findAll($criteria3);
             $format2 = $dataFormat->format($dropListData2, null);
             $format3 = $dataFormat->format($dropListData3, null);
         }
         $format = array_merge($format1, $format2, $format3);
         //去除重复的ID
         if (count($format) > 0) {
             $this->sendMobile(0, $format);
         } else {
             $this->sendMobile(3, '数据为空');
         }
     } else {
         $this->sendMobile(1, '数据错误');
     }
     $this->render('dropList', array('dropList' => $dropListModel));
 }
 public function actionIndex()
 {
     $searchForm = new SearchForm();
     $gender = null;
     $residenceFlag = null;
     $location = null;
     $latitude = UserRefreshForm::model()->getLatitude();
     $longitude = UserRefreshForm::model()->getLongitude();
     $criteria = new CDbCriteria();
     if (isset($_POST['SearchForm'])) {
         $gender = $_POST['SearchForm']['gender'];
         $residenceFlag = $_POST['SearchForm']['residence'];
     }
     $nearPersons = MGetNear::getNearPersonsNoOrder();
     $criteria->select = ' t.*,tbl_myr_refresh.status as status,(ACOS(SIN((' . $latitude . '* 3.1415) / 180 ) *SIN((tbl_myr_refresh.latitude * 3.1415) / 180 ) +COS((' . $latitude . '* 3.1415) / 180 ) * COS((tbl_myr_refresh.latitude * 3.1415) / 180 ) *COS((' . $longitude . '* 3.1415) / 180 - (tbl_myr_refresh.longitude * 3.1415) / 180 ) ) * 6378.137)   as distance';
     $criteria->join = 'LEFT JOIN tbl_myr_refresh ON tbl_myr_refresh.userId=t.userId';
     $criteria->addInCondition('t.userId', $nearPersons);
     if ($gender != null) {
         $criteria->addCondition("gender={$gender}");
     }
     if ($residenceFlag != null) {
         $currentCity = UserRefreshForm::model()->getCurrentCity();
         $residence = Yii::app()->user->residence;
         switch ($residenceFlag) {
             case 0:
                 $criteria->addCondition("t.residence='{$currentCity}'");
                 break;
             case 1:
                 $criteria->addCondition("t.residence!='{$currentCity}'");
                 break;
             default:
                 break;
         }
     }
     $criteria->order = 'distance ASC';
     $UserModel = User::model();
     $total = $UserModel->count($criteria);
     $pager = new CPagination($total);
     $pager->pageSize = 10;
     $pager->applyLimit($criteria);
     $userList = $UserModel->findAll($criteria);
     $dataFormat = new DataFormat();
     $format = $dataFormat->format($userList, null, 'distance', 'status');
     $data = array('userList' => $format, 'pages' => $pager, 'searchForm' => $searchForm);
     $clientFlash = new clientFlash();
     if ($total > 0) {
         $clientFlash->pushMobile(0, $format);
     } else {
         $clientFlash->pushMobile(3, '数据为空');
     }
     $this->render('index', $data);
 }