/** * Displays a single Users model. * @param integer $id * @return mixed */ public function actionView($id) { $modelInfo = UsersInfo::findOne(['user_id' => $id]); $modelEducation = UsersEducation::findAll(['user_id' => $id]); $modelTrain = UsersTrain::findAll(['user_id' => $id]); $modelVocational = UsersVocational::findAll(['user_id' => $id]); $modelPlayers = UsersPlayers::findAll(['user_id' => $id]); return $this->render('view', ['model' => $this->findModel($id), 'modelInfo' => $modelInfo, 'modelEducation' => $modelEducation, 'modelTrain' => $modelTrain, 'modelVocational' => $modelVocational, 'modelPlayers' => $modelPlayers]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UsersTrain::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'begin_time' => $this->begin_time, 'end_time' => $this->end_time, 'level' => $this->level, 'create_time' => $this->create_time, 'update_time' => $this->update_time]); $query->andFilterWhere(['like', 'credentials_number', $this->credentials_number])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'witness', $this->witness])->andFilterWhere(['like', 'witness_phone', $this->witness_phone])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'update_user', $this->update_user]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getUsersTrains() { return $this->hasMany(UsersTrain::className(), ['user_id' => 'id']); }
/** * Updates an existing UsersLevel model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if (Yii::$app->request->isPost) { $infoParams = Yii::$app->request->post(); if ($infoParams['UsersLevel']['status'] == UsersLevel::SEND_CARD) { $infoParams['UsersLevel']['end_date'] = date('Y-m-d', time() + 3600 * 24 * 365); } $userLevelInfo = $infoParams; if ($model->load($userLevelInfo) && $model->save()) { //如果状态更新为已经注册 if ($model->status == UsersLevel::SEND_CARD) { if ($model->level_id == 1) { //如果是注册学员升级市级教练 UsersLevel::updateAll(['status' => UsersLevel::LEVEL_UP], ['user_id' => $model->user_id, 'level_id' => $model->level_id]); $userInfo = UsersInfo::findOne(['user_id' => $model->user_id]); //新增一条用户和级别对应的信息 $userLevelModel = new UsersLevel(); $userLevelModel->user_id = $model->user_id; $userLevelModel->level_id = $model->level_id + 1; $userLevelModel->credentials_number = $userInfo['credentials_number']; $userLevelModel->district = $userInfo['account_location']; $userLevelModel->receive_address = $userInfo['contact_address']; $userLevelModel->postcode = $userInfo['contact_postcode']; $userLevelModel->status = UsersLevel::NO_TRAIN; if (!$userLevelModel->save()) { throw new ServerErrorHttpException(json_encode($userLevelModel->errors, JSON_UNESCAPED_UNICODE) . '!'); } else { Users::updateAll(['level_id' => $model->level_id + 1, 'level_order' => $model->level_id + 1], ['id' => $model->user_id]); } } $usersTrainInfo = UsersLevel::getUserTrainInfo($model->id); $teacherInfo = Teachers::findOne($usersTrainInfo['teachers_id']); $usersTrainModel = new UsersTrain(); $usersTrain['UsersTrain']['user_id'] = $usersTrainInfo['user_id']; $usersTrain['UsersTrain']['credentials_number'] = $usersTrainInfo['certificate_number']; $usersTrain['UsersTrain']['begin_time'] = $usersTrainInfo['begin_time']; $usersTrain['UsersTrain']['end_time'] = $usersTrainInfo['end_time']; $usersTrain['UsersTrain']['level'] = Level::getOneLevelNameById($usersTrainInfo['level_id']); $usersTrain['UsersTrain']['address'] = $usersTrainInfo['address']; $usersTrain['UsersTrain']['witness'] = $teacherInfo['name']; $usersTrain['UsersTrain']['witness_phone'] = $teacherInfo['phone']; $usersTrain['UsersTrain']['description'] = '通过培训课程' . $usersTrainInfo['content']; if ($usersTrainModel->load($usersTrain) && $usersTrainModel->save()) { $content = "很高兴的通知您,您已完成" . Level::getOneLevelNameById($model->level_id) . "级教练员的注册,注册时效为1年,您现在可以正式开展教练员工作。【教练系统】"; $userInfo = Users::findOne($model->user_id); $result = $this->sendMessage($content, Messages::REGISTER_SUCCESS, $model->user_id, $userInfo['mobile_phone'], '1'); if ($result != '0') { throw new ServerErrorHttpException($result); } else { return $this->redirect(['view', 'id' => $model->id]); } } else { throw new ServerErrorHttpException(json_encode($usersTrainModel->errors, JSON_UNESCAPED_UNICODE)); } } } } else { $photo = UsersInfo::getPhotoByUserId($model->user_id); return $this->render('update', ['model' => $model, 'photo' => $photo]); } }
public function actionRegisterTrain() { if (Yii::$app->request->isPost) { $infoParams = Yii::$app->request->post(); $userId = Yii::$app->user->id; $trainId = Yii::$app->request->post('train_id'); $modelInfo = new UsersTrain(); $infoParams['UsersTrain']['user_id'] = $userId; if (empty($infoParams['UsersTrain']['end_time'])) { $infoParams['UsersTrain']['end_time'] = date('Y-m-d H:i:s', time()); } $infoInfo = $infoParams; if ($modelInfo->load($infoInfo) && $modelInfo->save()) { return $this->redirect(['/user/register-train', 'train_id' => $trainId]); } else { throw new ServerErrorHttpException('系统错误,原因:' . json_encode($modelInfo->errors, JSON_UNESCAPED_UNICODE)); } } elseif (Yii::$app->request->get('id')) { if (UsersTrain::deleteAll(['id' => Yii::$app->request->get('id')])) { return $this->redirect(['/user/register-train', 'train_id' => Yii::$app->request->get('train_id')]); } else { throw new ServerErrorHttpException('系统错误,原因:删除失败!'); } } else { $userId = Yii::$app->user->id; $model = UsersTrain::findAll(['user_id' => $userId]); $trainId = Yii::$app->request->get('train_id'); $trainName = Train::getOneTrainNameById($trainId); return $this->render('register-train', ['model' => $model, 'train_id' => $trainId, 'trainName' => $trainName]); } }
/** * Finds the UsersTrain model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UsersTrain the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UsersTrain::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionUserTrain() { if (Yii::$app->request->isPost) { $infoParams = Yii::$app->request->post(); $infoParams['UsersTrain']['user_id'] = Yii::$app->user->id; if (empty($infoParams['UsersTrain']['end_time'])) { $infoParams['UsersTrain']['end_time'] = date('Y-m-d H:i:s', time()); } $infoInfo = $infoParams; $model = new UsersTrain(); if ($model->load($infoInfo) && $model->save()) { return $this->redirect('/user-center/user-info'); } else { throw new ServerErrorHttpException('系统错误,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE)); } } else { if (Yii::$app->request->get('id')) { UsersTrain::findOne(Yii::$app->request->get('id'))->delete(); return $this->redirect('/user-center/user-info'); } else { $model = UsersTrain::findAll(['user_id' => Yii::$app->user->id]); $levelName = Level::getOneLevelNameById(Yii::$app->user->identity->level_id); $photo = UsersInfo::getPhotoByUserId(\Yii::$app->user->id); $messageCount = MessagesUsers::getCountByUserIdAndType(\Yii::$app->user->id); $currentTrain = TrainUsers::getTrainByUserId(Yii::$app->user->id); $data = ['levelName' => $levelName, 'currentTrain' => $currentTrain, 'photo' => $photo, 'messageCount' => $messageCount]; return $this->render('user-train', ['data' => $data, 'model' => $model]); } } }
</tr> <tr> <td></td> <td><input type="submit" value="保 存" class="fixe_btn btnBoxset"/></td> </tr> </table> <?php ActiveForm::end(); ?> <p class="go_add"><a href="javascript:;">继续添加</a></p> </div> </div> </li> <li> <h1><span>教练员培训经历</span>已完善(<?php echo \app\models\UsersTrain::getCountByUserId(Yii::$app->user->id); ?> 条)</h1> <div style="display:none;" class="form_input"> <div class="divp_pt"> <table cellpadding="0" cellspacing="0" class="wans_content"> <tr> <th>序</th> <th>证书编号</th> <th>时间</th> <th>等级</th> <th>操作</th> </tr> <?php if (!empty($userTrain)) {