/** * Creates a new Code model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionImport() { $model = new Code(); if ($model->load(\App::$app->request->post())) { $id = \App::$app->request->post()['Code']['coupon_id']; $card = Card::find($id)->asArray()->one(); $num = \App::$app->request->post()['Code']['num']; for ($i = 0; $i <= $num; $i++) { $_model = new Code(); $_model->name = Code::createcode(18); $_model->coupon_id = \App::$app->request->post()['Code']['coupon_id']; $_model->rate = $card['rate']; $_model->validity_time = $card['validity_time']; $_model->use_end_time = $card['use_out_at']; $_model->use_at = $card['use_start_at']; $_model->display = Code::DISPLAY_USE; $_model->save(); } return $this->redirect(['index']); } else { return $this->render('import', ['model' => $model]); } }