Example #1
0
 /**
  * $geo 为要找的地理位置的hash编码
  */
 public function so($params, $geo)
 {
     $query = Goods::find();
     if ($this->load($params) && $this->validate()) {
         $query->andFilterWhere(['cate_id' => $this->cate_id, 'status' => $this->status]);
         $query->andFilterWhere(['like', 'name', $this->name]);
     }
     $tmp_geo = $geo;
     $lenth = strlen($tmp_geo);
     $query->andWhere('geohash like :geohash');
     $query->addParams([':geohash' => $tmp_geo . '%']);
     $countQuery = clone $query;
     for ($i = $lenth; $i > 0 && $countQuery->count() < 2; $i--) {
         $tmp_geo = substr($tmp_geo, 0, -1);
         $query->addParams([':geohash' => $tmp_geo . '%']);
         $countQuery = clone $query;
     }
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $list = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
     return ['list' => $list, 'pages' => $pages];
 }
Example #2
0
 /**
  * Finds the Goods model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Goods the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Goods::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }