SearchController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace frontend\controllers;
  3. use common\library\ZM_Geohash;
  4. use common\models\Building;
  5. use common\models\HotSearch;
  6. use common\models\ImageSource;
  7. use Yii;
  8. use yii\web\Controller;
  9. /**
  10. * 我的位置 controller
  11. */
  12. class SearchController extends BasewechatController
  13. {
  14. public function actionIndex()
  15. {
  16. return $this->render('index');
  17. }
  18. public function actionList()
  19. {
  20. $cookie = Yii::$app->request->cookies;
  21. $latitude = "";
  22. $longitude = "";
  23. if($cookie->has('localtion'))
  24. {
  25. $lcookie = $cookie->getValue('localtion');
  26. $latitude=$lcookie['lat'];
  27. $longitude=$lcookie['lng'];
  28. }
  29. $search = Yii::$app->request->get('search');
  30. $datas = Building::find()->where(['posted'=>Building::POSTED_YES]);
  31. $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.'%']);
  32. $arrs = $datas->orderBy('created_at DESC')->all();
  33. $geohash = new ZM_Geohash();
  34. foreach ($arrs as $list)
  35. {
  36. if(!empty($latitude)&&!empty($longitude)&&!empty($list->latitude)&&!empty($list->longitude))
  37. {
  38. $distance = $geohash->getDistance($latitude,$longitude,$list->latitude,$list->longitude);
  39. $list->distance = $distance;
  40. }
  41. }
  42. return $this->render('list',['arrs'=>$arrs]);
  43. }
  44. // 搜索条件
  45. public static function hotsearch(){
  46. $datas = HotSearch::find()->where(['status'=>HotSearch::HOT_SEARCH_COMMON])->all();
  47. return $datas;
  48. }
  49. //弹窗提示
  50. function admin_alert($alert,$href=''){
  51. if(empty($href)){
  52. exit("<script>alert('{$alert}');history.back();</script>");
  53. }else{
  54. exit("<script>alert('{$alert}');window.location.href='{$href}';</script>");
  55. }
  56. }
  57. }