public function actionRegisterPlayers() { if (Yii::$app->request->isPost) { $infoParams = Yii::$app->request->post(); $userId = Yii::$app->user->id; $trainId = Yii::$app->request->post('train_id'); $modelInfo = new UsersPlayers(); $infoParams['UsersPlayers']['user_id'] = $userId; if (empty($infoParams['UsersPlayers']['end_time'])) { $infoParams['UsersPlayers']['end_time'] = date('Y-m-d H:i:s', time()); } $infoInfo = $infoParams; if ($modelInfo->load($infoInfo) && $modelInfo->save()) { return $this->redirect(['/user/register-players', 'train_id' => $trainId]); } else { throw new ServerErrorHttpException('系统错误,原因:' . json_encode($modelInfo->errors, JSON_UNESCAPED_UNICODE)); } } elseif (Yii::$app->request->get('id')) { if (UsersPlayers::deleteAll(['id' => Yii::$app->request->get('id')])) { return $this->redirect(['/user/register-players', 'train_id' => Yii::$app->request->get('train_id')]); } else { throw new ServerErrorHttpException('系统错误,原因:删除失败!'); } } else { $userId = Yii::$app->user->id; $model = UsersPlayers::findAll(['user_id' => $userId]); $trainId = Yii::$app->request->get('train_id'); $trainName = Train::getOneTrainNameById($trainId); return $this->render('register-players', ['model' => $model, 'train_id' => $trainId, 'trainName' => $trainName]); } }