public function getQuery() { $query = new Query(Yii::app()->db); $query->from('groupon as g'); if ($this->id) { $query->andWhere('g.id=:id', array(':id' => $this->id)); } if ($this->title) { $query->andWhere(array('like', 'g.title', '%' . $this->title . '%')); } if ($this->state) { $now = time(); switch ($this->state) { case 'online': //在线 $query->andWhere('g.begin_time<=:time and g.end_time>=:time', array(':time' => $now)); break; case 'offline': //下线 $query->andWhere('g.end_time<:time', array(':time' => $now)); break; case 'beonline': //即将上线 $query->andWhere('g.begin_time>:time', array(':time' => $now)); break; default: break; } } return $query; }
/** * 根据分类id获取分类名 * @param type $id * @param type $level * @return type */ public static function getCateName($id, $level = null) { $query = new Query(Yii::app()->db); $query->select('name'); $query->from('groupon_cates'); $query->andWhere('id=:id', array(':id' => $id)); if ($level) { $query->andWhere('level=:level', array(':level' => $level)); } $name = $query->queryScalar(); return $name; }
/** * Функция добавления условий поиска. * @param Query $query Экземпляр выборки. * @param string $attribute Имя отрибута по которому нужно искать. * @param boolean $partialMatch Тип добавляемого сравнения. Строгое совпадение или частичное. */ protected function addCondition($query, $attribute, $partialMatch = false) { $value = $this->{$attribute}; if (trim($value) === '') { return; } if ($partialMatch) { $query->andWhere(['like', $attribute, $value]); } else { $query->andWhere([$attribute => $value]); } }
public function getQuery() { $query = new Query(Yii::app()->db); $query->select('id,biz_id,name,city_id,area_id,is_reservation'); $query->from('groupon_biz_shop'); if ($this->biz_id) { $query->andWhere('biz_id=:bid', array(':bid' => $this->biz_id)); } if ($this->name) { $query->andWhere(array('like', 'name', '%' . $this->name . '%')); } return $query; }
public function getQuery() { $query = new Query(Yii::app()->db); $query->from('groupon_biz'); $query->andWhere('display=' . ARBiz::DISPLAY); if ($this->id) { $query->andWhere('id=:id', array(':id' => trim($this->id))); } if ($this->title) { $query->andWhere(array('like', 'title', '%' . $this->title . '%')); } if ($this->status) { $query->andWhere('examine_status=:status', array(':status' => $this->status)); } $query->order('id desc'); return $query; }
/** * 获取子市区的键值对列表 * @param int/null $pid 父ID * @param int $grade 等级 * @return array */ public static function getAreas($pid = null, $grade = self::GRADE_PROVINCE) { $key = 'arealist_' . $grade . '_' . $pid; $areas = Yii::app()->cache->get($key); // dump($areas); if ($areas === false) { $query = new Query(Yii::app()->db); $query->select('id,name'); $query->from('area'); if ($pid == null) { $query->andWhere('parent_id is null'); } else { $query->andWhere('parent_id=:pid', array(':pid' => $pid)); } $areas = $query->queryAll(); if (!empty($areas)) { $areas = A::map($areas, 'id', 'name'); } Yii::app()->cache->set($key, $areas, 60 * 60 * 24); } // dump($areas); return $areas; }
public function actionAutocomplete($search = null, $id = null, $object_id = null) { /** * @todo Добавить отображение вложенности */ $out = ['more' => false]; if (!is_null($search)) { $query = new Query(); $query->select(Property::tableName() . '.id, ' . Property::tableName() . '.name AS text')->from(Property::tableName())->andWhere(['like', Property::tableName() . '.name', $search])->limit(100); if (!is_null($object_id)) { $query->leftJoin(PropertyGroup::tableName(), PropertyGroup::tableName() . '.id = ' . Property::tableName() . '.property_group_id'); $query->andWhere([PropertyGroup::tableName() . '.id' => $object_id]); } $command = $query->createCommand(); $data = $command->queryAll(); $out['results'] = array_values($data); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => Property::findOne($id)->name]; } else { $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')]; } echo Json::encode($out); }