public function actionView() { $id = Yii::$app->request->get('id'); $model = Teachers::findOne(['id' => $id]); $trainWind = News::getImgRecommendNewsByCategory(11, 12); return $this->render('view', ['data' => $model, 'trainWind' => $trainWind]); }
public static function rateTeacher($teacher, $stars) { $model = Teachers::findOne(['id' => $teacher]); $model->number_rated++; $model->stars += $stars; if ($model->save()) { return true; } return false; }
public function actionDelete() { Yii::$app->response->format = Response::FORMAT_JSON; $request = \Yii::$app->request; $data = $request->post(); $id = $data['id']; try { Teachers::findOne(['id' => $id])->delete(); return ['status' => 1, 'message' => 'Thành công']; } catch (Exception $ex) { return ['status' => 0, 'message' => 'Có lỗi xảy ra']; } }
/** * 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]); } }
/** * Finds the Teachers model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Teachers the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Teachers::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }