Esempio n. 1
0
 public function actionIndex($num = 100, $userId = 0)
 {
     $rows = [];
     $time = time();
     foreach (range(1, $num) as $value) {
         $rows[$value]['code'] = Yii::$app->security->generateRandomString();
         $rows[$value]['user_id'] = $userId;
         $rows[$value]['created_at'] = $time;
         $rows[$value]['updated_at'] = $time;
     }
     if (!($count = static::saveAll(InviteCode::tableName(), $rows))) {
         throw new Exception(33007);
     }
     $this->stdout($count . "\n");
 }
Esempio n. 2
0
 public function validateAttribute($model, $attribute)
 {
     if (!InviteCode::findOne(['code' => $model->{$attribute}, 'status' => InviteCode::STATUS_NOT_USE])) {
         $this->addError($model, $attribute, \Yii::t('app', 'This invite code is can\'t use'));
     }
 }