Exemple #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Order::find();
     if (isset($params['expand'])) {
         $expands = preg_split('/\\s*,\\s*/', $params['expand'], -1, PREG_SPLIT_NO_EMPTY);
         foreach ($expands as $item) {
             if ($item == 'hotsale') {
                 $query->with(['hotsale' => function ($query) {
                     $query->select(['id', 'name']);
                 }]);
             } elseif ($item == 'medicine') {
                 $query->with(['medicine' => function ($query) {
                     $query->select(['id', 'name', 'amount', 'price', 'fid', 'cid']);
                 }]);
             } elseif ($item == 'user') {
                 $query->with(['user' => function ($query) {
                     $query->select(['id', 'email', 'phone', 'client_name']);
                 }]);
             }
         }
     }
     $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, 'user_id' => $this->user_id, 'medicine_id' => $this->medicine_id, 'hotsale_id' => $this->hotsale_id, 'amount' => $this->amount, 'create_time' => $this->create_time, 'street_number' => $this->street_number, 'status' => $this->status, 'update_time' => $this->update_time, 'delect' => $this->delect, 'total' => $this->total]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'street', $this->street])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'zipcord', $this->zipcord]);
     //伪删除, 返回delect大于 1 的
     $query->andWhere(['<', 'delect', 1]);
     return $dataProvider;
 }
Exemple #2
0
 public function actionDelectAll()
 {
     $res = Order::find()->asArray()->where(['>', 'delect', 0])->with(['hotsale', 'medicine', 'user'])->all();
     return $res;
 }