Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Product::find()->with('category');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'is_del' => $this->is_del, 'is_hot' => $this->is_hot, 'is_new' => $this->is_new, 'is_best' => $this->is_best, 'category_id' => $this->category_id, 'is_free_shipping' => $this->is_free_shipping, 'quantity' => $this->quantity, 'brand_id' => $this->brand_id, 'shipping' => $this->shipping, 'price' => $this->price, 'market_price' => $this->market_price, 'shop_price' => $this->shop_price, 'is_promote' => $this->is_promote, 'promote_price' => $this->promote_price, 'promote_start_date' => $this->promote_start_date, 'promote_end_date' => $this->promote_end_date, 'points' => $this->points, 'tax_class_id' => $this->tax_class_id, 'date_available' => $this->date_available, 'weight' => $this->weight, 'length' => $this->length, 'width' => $this->width, 'height' => $this->height, 'mini_mum' => $this->mini_mum, 'viewed' => $this->viewed, 'sort' => $this->sort, 'status' => $this->status, 'stock_status' => $this->stock_status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     //->andFilterWhere(['like', 'model', $this->model])
     $query->andFilterWhere(['like', 'sku', $this->sku])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'brief', $this->brief])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * 以ajax的方式返回搜索到的用户信息,
  * 并返回定制后的select数据源
  * @return array
  * @throws NotFoundHttpException
  */
 public function actionGetProduct()
 {
     if (Yii::$app->getRequest()->isAjax) {
         $params = Yii::$app->request->queryParams;
         $limit = isset($params['limit']) ? $params['limit'] : 10;
         $model = new Product();
         $model->name = isset($params['q']) ? $params['q'] : '';
         $query = Product::find();
         $query->andFilterWhere(['like', 'name', $model->name]);
         $query->limit($limit);
         $models = $query->all();
         $products = [];
         foreach (ArrayHelper::map($models, 'id', 'name') as $key => $value) {
             $products[] = ['id' => $key, 'text' => $value];
         }
         echo Json::encode(['status' => 0, 'msg' => $products]);
     } else {
         throw new NotFoundHttpException('404 This Is Ajax Page!');
     }
 }