示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Medicine::find();
     if (isset($params['expand'])) {
         $expands = preg_split('/\\s*,\\s*/', $params['expand'], -1, PREG_SPLIT_NO_EMPTY);
         foreach ($expands as $item) {
             if ($item == 'specifications') {
                 $query->with(['specifications' => function ($query) {
                     $query->select(['id', 'name']);
                 }]);
             } elseif ($item == 'city') {
                 $query->with(['city' => function ($query) {
                     $query->select(['id', 'name']);
                 }]);
             } elseif ($item == 'serviceCategory') {
                 $query->with(['serviceCategory' => function ($query) {
                     $query->select(['id', '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, 'sid' => $this->sid, 'cid' => $this->cid, 'fid' => $this->fid, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'sexual_taste', $this->sexual_taste])->andFilterWhere(['like', 'channel_tropism', $this->channel_tropism])->andFilterWhere(['like', 'efficacy', $this->efficacy])->andFilterWhere(['like', 'amount', $this->amount])->andFilterWhere(['like', 'price', $this->price]);
     //伪删除, 返回delect大于 Dict::DEDLETE_FALSE 的
     $query->andWhere(['<', 'delect', 1]);
     return $dataProvider;
 }
示例#2
0
文件: City.php 项目: weiyiyi/base
 public function getMedicines()
 {
     return $this->hasMany(Medicine::className(), ['cid' => 'id']);
 }
示例#3
0
文件: Order.php 项目: weiyiyi/base
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMedicine()
 {
     return $this->hasOne(Medicine::className(), ['id' => 'medicine_id']);
 }
示例#4
0
 public function actionDelectAll()
 {
     $res = Medicine::find()->asArray()->where(['>', 'delect', 0])->with(['city', 'specifications', 'serviceCategory'])->all();
     return $res;
 }