1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace frontend\controllers;
- use common\library\ZM_Geohash;
- use common\models\Building;
- use common\models\HotSearch;
- use common\models\ImageSource;
- use Yii;
- use yii\web\Controller;
- /**
- * 我的位置 controller
- */
- class SearchController extends BasewechatController
- {
- public function actionIndex()
- {
- return $this->render('index');
- }
- public function actionList()
- {
- $cookie = Yii::$app->request->cookies;
- $latitude = "";
- $longitude = "";
- if($cookie->has('localtion'))
- {
- $lcookie = $cookie->getValue('localtion');
- $latitude=$lcookie['lat'];
- $longitude=$lcookie['lng'];
- }
- $search = Yii::$app->request->get('search');
- $datas = Building::find()->where(['posted'=>Building::POSTED_YES]);
- $datas = $datas->andWhere('name like :search or address like :search or layout like :search or stage like :search or pattern like :search or style like :search ',[':search'=>'%'.$search.'%']);
- $arrs = $datas->orderBy('created_at DESC')->all();
- $geohash = new ZM_Geohash();
- foreach ($arrs as $list)
- {
- if(!empty($latitude)&&!empty($longitude)&&!empty($list->latitude)&&!empty($list->longitude))
- {
- $distance = $geohash->getDistance($latitude,$longitude,$list->latitude,$list->longitude);
- $list->distance = $distance;
- }
- }
- return $this->render('list',['arrs'=>$arrs]);
- }
- // 搜索条件
- public static function hotsearch(){
- $datas = HotSearch::find()->where(['status'=>HotSearch::HOT_SEARCH_COMMON])->all();
- return $datas;
- }
- //弹窗提示
- function admin_alert($alert,$href=''){
- if(empty($href)){
- exit("<script>alert('{$alert}');history.back();</script>");
- }else{
- exit("<script>alert('{$alert}');window.location.href='{$href}';</script>");
- }
- }
- }
|