示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MeritTemplate::find();
     $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, 'method' => $this->method, 'event' => $this->event, 'action_type' => $this->action_type, 'rule_key' => $this->rule_key, 'rule_value' => $this->rule_value, 'increment' => $this->increment, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'unique_id', $this->unique_id]);
     return $dataProvider;
 }
示例#2
0
 public function hasMeritTemplate()
 {
     $uniqueId = Yii::$app->controller->action->uniqueId;
     // 必须是 GET 或者 POST 请求
     if (!in_array(Yii::$app->request->method, MeritTemplate::getMethods())) {
         return false;
     }
     $method = array_flip(MeritTemplate::getMethods())[Yii::$app->request->method];
     // 支持同一个 $uniqueId 不同 Type
     $meritTemplates = MeritTemplate::find()->where(['unique_id' => $uniqueId, 'status' => MeritTemplate::STATUS_ACTIVE, 'method' => $method])->all();
     if (!$meritTemplates) {
         return false;
     }
     return $meritTemplates;
 }