Exemplo n.º 1
0
 public function actionDelete()
 {
     $request = Yii::app()->request;
     $id = $request->getQuery("id");
     $delete = Pharmacy::model()->findByAttributes(array('id' => $id));
     $delete->delete();
 }
Exemplo n.º 2
0
 public function getNearPharmacy($lat, $lng, $limit, $offset)
 {
     $retVal = array();
     $criteria = new CDbCriteria();
     if (!empty($lat) && !empty($lng)) {
         $criteria->select = "t.*, (2 * (3959 * ATAN2(\n          SQRT(\n            POWER(SIN((RADIANS(" . $lat . " - `t`.`laititude` ) ) / 2 ), 2 ) +\n            COS(RADIANS(`t`.`laititude`)) *\n            COS(RADIANS(" . $lat . ")) *\n            POWER(SIN((RADIANS(" . $lng . " - `t`.`longitude` ) ) / 2 ), 2 )\n          ),\n          SQRT(1-(\n            POWER(SIN((RADIANS(" . $lat . " - `t`.`laititude` ) ) / 2 ), 2 ) +\n            COS(RADIANS(`t`.`laititude`)) *\n            COS(RADIANS(" . $lat . ")) *\n            POWER(SIN((RADIANS(" . $lng . " - `t`.`longitude` ) ) / 2 ), 2 )\n          ))\n        )\n      )) as\n            distance";
         $criteria->having = 'distance < 3';
         $criteria->group = 't.id';
     }
     $criteria->order = 'distance ASC';
     $criteria->limit = $limit;
     $criteria->offset = $offset;
     $data = Pharmacy::model()->findAll($criteria);
     $attrs = $this->attributeLabels();
     foreach ($data as $item) {
         $itemArr = array();
         foreach ($attrs as $key => $value) {
             $itemArr[$key] = $item->{$key};
         }
         $itemArr['stars'] = Review::model()->sumRating($item->id, 2);
         $itemArr['reviews'] = Review::model()->countReview($item->id, 2);
         $retVal[] = $itemArr;
     }
     return $retVal;
 }
Exemplo n.º 3
0
 public function actionGetNearPharmacy()
 {
     try {
         $request = Yii::app()->request;
         $lat = StringHelper::filterString($request->getQuery('lat'));
         $lng = StringHelper::filterString($request->getQuery('lng'));
         $limit = StringHelper::filterString($request->getQuery('limit'));
         $offset = StringHelper::filterString($request->getQuery('offset'));
         $data = Pharmacy::model()->getNearPharmacy($lat, $lng, $limit, $offset);
         ResponseHelper::JsonReturnSuccess($data, 'success');
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }