コード例 #1
0
ファイル: MlnController.php プロジェクト: riros/tests
 /**
  * This command echoes what you have entered as the message.
  *
  * @param string $message the message to be echoed.
  */
 public function actionIndex($message = 'Million')
 {
     $card = new Card();
     //        $post = Yii::$app->request->post();
     //        if (!empty($post)) $new = false;
     //        $card->load($post);
     //        $count = $card->count;
     $c = 50;
     $card->sum = 0;
     $card->status = 0;
     $cdate = Yii::$app->formatter->asDatetime(new \DateTime(), 'Y-MM-dd HH:i:s');
     $card->sn = '1000000';
     $card->activity_date = $cdate;
     $card->deactivation_date = $cdate;
     $card->creation_date = $cdate;
     if ($card->validate()) {
         while ($c-- > 0) {
             $newcard = new Card($card);
             $newcard->count = 1;
             $newcard->sum = rand(1, 1000000);
             $newcard->save();
             echo $c . "\r";
         }
     } else {
         var_dump($card->errors);
     }
     //return $this->render('generator', $param);
     echo $message . "\n";
 }
コード例 #2
0
ファイル: CardController.php プロジェクト: riros/tests
 public function actionGen()
 {
     $card = new Card();
     $new = true;
     $post = Yii::$app->request->post();
     if (!empty($post)) {
         $new = false;
     }
     $card->load($post);
     $count = $card->count;
     $param = ['model' => $card, 'cnt' => $count, 'message' => "Готово. <a href='/card'>Перейти к списку.</a>", 'opstatus' => 'success', 'new' => $new];
     if ($count <= 1000000) {
         $c = $count;
         $card->sum = 0;
         $card->status = 0;
         $cdate = date('Y-m-d H:i:s');
         //            $cdate = Yii::$app->formatter->asDatetime(new \DateTime(), 'php:d-M-Y H:i:s');
         $card->creation_date = $cdate;
         if ($card->validate()) {
             while ($c-- > 0) {
                 $newcard = new Card($card);
                 $newcard->count = 1;
                 $newcard->sum = rand(1, 10000);
                 $newcard->save();
             }
         } else {
             $param['message'] = 'Ошибка проверки модели';
             $param['opstatus'] = 'danger';
         }
     } else {
         $param['message'] = 'Слишком большое число карточек > 1000000. Тут нужно использовать менеджер очереди. (например rabbitmq)';
         $param['opstatus'] = 'danger';
     }
     return $this->render('generator', $param);
 }