public function safeUp()
 {
     $wechat = new Wechat();
     $wechat->setAttributes(['name' => '示例公众号', 'token' => 'lL2hcT4c41H3wL21Hlftlz4A4w22j12L', 'account' => 'example', 'original' => 'gh_example12345', 'type' => Wechat::TYPE_SUBSCRIBE, 'key' => 'wxd8cce40cc50ce6c7', 'secret' => '8e850dfed1befa106ea0bbe7cb67ad25', 'encoding_aes_key' => '8J4In8J3R3ppqWgQkCXhOvU1ZxaPFa5eSDZ8u3XNy45', 'avatar' => 'example_avatar.png', 'qrcode' => 'example_qr_code.png', 'address' => '测试地址', 'description' => '该条记录并不是真实的公众号记录.只作为本地测试示例使用', 'username' => '*****@*****.**', 'password' => 'example', 'status' => Wechat::STATUS_ACTIVE]);
     echo "\nexample测试示例公众号数据创建" . ($wechat->save() ? '成功' : '失败') . "\n";
     $rule = new ReplyRule();
     $rule->setAttributes(['wid' => $wechat->id, 'name' => '示例规则', 'mid' => 'example', 'status' => ReplyRule::STATUS_ACTIVE]);
     echo "\nexample示例规则数据创建" . ($rule->save() ? '成功' : '失败') . "\n";
     //
     //        $ruleKeyword = new ReplyRuleKeyword;
     //        $ruleKeyword->setAttributes([
     //            'rid' => $rule->id,
     //            'keyword' => 'example',
     //            'type' => ReplyRuleKeyword::TYPE_MATCH
     //        ]);
     //        echo "\nexample示例规则关键字数据创建" . ($ruleKeyword->save() ? '成功' : '失败') ."\n";
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ReplyRule::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, 'wid' => $this->wid, 'status' => $this->status, 'priority' => $this->priority, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'mid', $this->mid]);
     return $dataProvider;
 }
 /**
  * 回复规则表
  */
 public function initReplyRuleTable()
 {
     $tableName = ReplyRule::tablename();
     $this->createTable($tableName, ['id' => Schema::TYPE_PK, 'wid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属微信公众号ID'", 'name' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '规则名称'", 'mid' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '处理的插件模块'", 'processor' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '处理类'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '状态'", 'priority' => Schema::TYPE_BOOLEAN . "(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '优先级'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'"]);
     $this->createIndex('wid', $tableName, 'wid');
     $this->createIndex('mid', $tableName, 'mid');
     // 回复规则关键字表
     $tableName = ReplyRuleKeyword::tablename();
     $this->createTable($tableName, ['id' => Schema::TYPE_PK, 'rid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属规则ID'", 'keyword' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '规则关键字'", 'type' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '关键字类型'", 'priority' => Schema::TYPE_BOOLEAN . "(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '优先级'", 'start_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '开始时间'", 'end_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '结束时间'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'"]);
     $this->createIndex('rid', $tableName, 'rid');
     $this->createIndex('keyword', $tableName, 'keyword');
     $this->createIndex('type', $tableName, 'type');
     $this->createIndex('start_at', $tableName, 'start_at');
     $this->createIndex('end_at', $tableName, 'end_at');
 }
 /**
  * Finds the ReplyRule model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ReplyRule the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ReplyRule::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * 关联的回复规则
  * @return \yii\db\ActiveQuery
  */
 public function getRule()
 {
     return $this->hasOne(ReplyRule::className(), ['id' => 'rid']);
 }