/**
  * Creates a new InvitationCode model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new InvitationCode();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * 生成邀请码
  * @param $num
  * @return bool
  */
 public static function set_invitation($num = '5')
 {
     $count = 0;
     for ($i = 0; $i < $num; $i++) {
         // 判断邀请码是否已存在
         $code = self::random();
         do {
             $res = InvitationCode::findOne(['code' => $code]);
             if ($res) {
                 $code = self::random();
                 continue;
             } else {
                 break;
             }
         } while (true);
         $invia = new InvitationCode();
         $invia->code = self::random();
         $invia->status = InvitationCode::STATUS_ACTIVE;
         $flag = $invia->save();
         if (!$flag) {
             break;
         }
         $count++;
     }
     if ($count == $num) {
         return true;
     } else {
         return false;
     }
 }