/** * 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 actionRegisterInfo() { if (Yii::$app->request->isPost) { $infoParams = Yii::$app->request->post(); $trainId = Yii::$app->request->post('train_id'); $year = Yii::$app->request->post('year'); $month = Yii::$app->request->post('month'); $day = Yii::$app->request->post('day'); $userId = Yii::$app->user->id; if (!empty($infoParams['Users']['mobile_phone'])) { $isExist = Users::findOne(['mobile_phone' => $infoParams['Users']['mobile_phone']]); if ($isExist) { throw new ServerErrorHttpException('已经存在的手机!'); } } if (!empty($infoParams['Users']['email'])) { $isExist = Users::findOne(['email' => $infoParams['Users']['email']]); if ($isExist) { throw new ServerErrorHttpException('已经存在的email!'); } } if (!empty($infoParams['UsersInfo']['name'])) { $isExist = UsersInfo::findOne(['credentials_number' => $infoParams['UsersInfo']['credentials_number']]); if ($isExist) { throw new ServerErrorHttpException('已经存在的身份证号码!'); } } if (!empty($infoParams['UsersInfo']['telephone']) && !empty($infoParams['UsersInfo']['mobile_phone'])) { if ($infoParams['UsersInfo']['mobile_phone'] == $infoParams['UsersInfo']['telephone']) { throw new ServerErrorHttpException('联系电话不能和手机相同!'); } } $modelInfo = new UsersInfo(); $modelInfo->photo = UploadedFile::getInstance($modelInfo, 'photo'); if (!empty($modelInfo->photo)) { if (!in_array($modelInfo->photo->extension, ['jpg', 'gif'])) { throw new ServerErrorHttpException('不允许的格式'); } $photoFileName = time() . '.' . $modelInfo->photo->extension; $modelInfo->photo->saveAs('upload/images/users_info/photo/' . $photoFileName, true); if ($modelInfo->hasErrors('file')) { throw new ServerErrorHttpException($modelInfo->getErrors('file')); } else { $infoParams['UsersInfo']['photo'] = $photoFileName; } } else { $infoParams['UsersInfo']['photo'] = ''; } $modelInfo->credentials_photo = UploadedFile::getInstance($modelInfo, 'credentials_photo'); if (!empty($modelInfo->credentials_photo)) { if (!in_array($modelInfo->credentials_photo->extension, ['jpg', 'gif'])) { throw new ServerErrorHttpException('不允许的格式'); } $credentialsPhotoFileName = time() . '.' . $modelInfo->credentials_photo->extension; $modelInfo->credentials_photo->saveAs('upload/images/users_info/credentials_photo/' . $credentialsPhotoFileName, true); if ($modelInfo->hasErrors('file')) { throw new ServerErrorHttpException($modelInfo->getErrors('file')); } else { $infoParams['UsersInfo']['credentials_photo'] = $credentialsPhotoFileName; } } else { $infoParams['UsersInfo']['credentials_photo'] = ''; } $infoParams['UsersInfo']['user_id'] = $userId; $infoParams['UsersInfo']['birthday'] = $year . '-' . $month . '-' . $day . ' 00:00:00'; $transaction = Yii::$app->db->beginTransaction(); $infoInfo = $infoParams; if ($modelInfo->load($infoInfo) && $modelInfo->save()) { if (!empty($infoInfo['Users']['mobile_phone'])) { $result = Users::updateAll(['username' => $infoInfo['UsersInfo']['name'], 'status' => 1, 'mobile_phone' => $infoInfo['Users']['mobile_phone']], ['id' => $userId]); if (!$result) { $transaction->rollBack(); throw new ServerErrorHttpException('更新信息错误!'); } } else { $result = Users::updateAll(['username' => $infoInfo['UsersInfo']['name'], 'status' => 1, 'email' => $infoInfo['Users']['email'], 'phone_auth' => 1], ['id' => $userId]); if (!$result) { $transaction->rollBack(); throw new ServerErrorHttpException('更新信息错误!'); } } //更新级别信息的信息 $result = UsersLevel::updateAll(['credentials_number' => $infoParams['UsersInfo']['credentials_number'], 'district' => $infoParams['UsersInfo']['account_location'], 'receive_address' => $infoParams['UsersInfo']['contact_address'], 'postcode' => $infoParams['UsersInfo']['contact_postcode']], ['user_id' => $userId]); if (!$result) { $transaction->rollBack(); throw new ServerErrorHttpException('更新信息错误!'); } else { $content = "尊敬的学员,您已经申请报名,请耐心等待,谢谢!【教练系统】"; $this->sendMessage($content, Messages::SIGN, $userId, Yii::$app->user->identity->mobile_phone); $transaction->commit(); return $this->redirect(['/user/register-education', 'train_id' => $trainId]); } } else { throw new ServerErrorHttpException('系统错误,原因:' . json_encode($modelInfo->errors, JSON_UNESCAPED_UNICODE)); } } else { $model = UsersInfo::findOne(['user_id' => Yii::$app->user->id]); $trainId = Yii::$app->request->get('train_id'); $trainName = Train::getOneTrainNameById($trainId); $userModel = Users::findOne(Yii::$app->user->id); return $this->render('register-info', ['model' => $model, 'userModel' => $userModel, 'train_id' => $trainId, 'trainName' => $trainName]); } }
public function actionChangePassword() { $userId = Yii::$app->request->get('user_id'); Users::updateAll(['password' => md5(111111)], ['id' => $userId]); header("Content-type:text/html;charset=utf-8"); echo "<script language='javascript'>alert('该用户密码已经成功修改为111111');location.href='/Admin/users/index';</script>"; }
public function actionLevelUp() { $levelInfo = Level::findOne(['id' => Yii::$app->user->identity->level_id + 1]); $usersLevel = UsersLevel::findOne(['user_id' => Yii::$app->user->id, 'level_id' => Yii::$app->user->identity->level_id]); $usersLevelStatusCurrent = $usersLevel['status']; if ($usersLevelStatusCurrent != UsersLevel::SEND_CARD) { throw new ServerErrorHttpException('当前注册状态不符合!'); } $loginDuration = Users::getLoginDuration(Yii::$app->user->id); $loginDurationDiff = $levelInfo['login_duration'] - $loginDuration; if ($loginDurationDiff > 0) { throw new ServerErrorHttpException('当前注册时长不符合!'); } $scoreDiff = $levelInfo['score'] - Yii::$app->user->identity->score; if ($scoreDiff > 0) { throw new ServerErrorHttpException('当前一般活动积分不符合!'); } $creditDiff = $levelInfo['credit'] - Yii::$app->user->identity->credit; if ($creditDiff > 0) { throw new ServerErrorHttpException('当前公益活动积分不符合!'); } $transaction = Yii::$app->db->beginTransaction(); UsersLevel::updateAll(['status' => UsersLevel::LEVEL_UP], ['user_id' => Yii::$app->user->id, 'level_id' => Yii::$app->user->identity->level_id]); $userInfo = UsersInfo::findOne(['user_id' => Yii::$app->user->id]); //新增一条用户和级别对应的信息 $userLevelModel = new UsersLevel(); $userLevelModel->user_id = Yii::$app->user->id; $userLevelModel->level_id = Yii::$app->user->identity->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()) { $transaction->rollBack(); throw new ServerErrorHttpException('更新状态错误,原因:' . json_encode($userLevelModel->errors, JSON_UNESCAPED_UNICODE) . '!'); } else { Users::updateAll(['level_id' => Yii::$app->user->identity->level_id + 1, 'level_order' => Yii::$app->user->identity->level_order + 1], ['id' => Yii::$app->user->id]); $transaction->commit(); } return $this->redirect('/user-center/index'); }
public function actionIndex() { $step = Yii::$app->request->get('step'); $userId = Yii::$app->request->get('user_id'); if (empty($step)) { $step = 1; } $users = Users::findOne($userId); $username = $users['username']; $phone = $users['mobile_phone']; $phoneHidden = substr_replace($phone, '****', 4, 4); if (Yii::$app->request->isPost) { if ($step == 1) { $username = Yii::$app->request->post('username'); if (is_numeric($username)) { $where = ['mobile_phone' => $username]; } else { $where = ['email' => $username]; } $verifyCode = Yii::$app->request->post('verifyCode'); if (empty($verifyCode)) { throw new ServerErrorHttpException('请输入验证码!'); } if (!empty($_SESSION['__captcha/site/captcha'])) { if ($_SESSION['__captcha/site/captcha'] != $verifyCode) { throw new ServerErrorHttpException('验证码输入错误,请重新输入!'); } } else { } $userInfo = Users::findOne($where); if (empty($userInfo)) { throw new ServerErrorHttpException('不存在的用户!'); } return $this->redirect(['/find-password/index', 'step' => 2, 'user_id' => $userInfo['id']]); } elseif ($step == 2) { $checkNum = Yii::$app->request->post('check_num'); $session = Yii::$app->session; if ($checkNum != $session['checkNum']) { throw new ServerErrorHttpException('短信验证码输入错误,请重新输入!'); } else { return $this->redirect(['/find-password/index', 'step' => 3, 'user_id' => $userId]); } } elseif ($step == 3) { $username = Yii::$app->request->post('username'); $password = Yii::$app->request->post('password'); $password_confirm = Yii::$app->request->post('password_confirm'); if ($password != $password_confirm) { throw new ServerErrorHttpException('两次输入密码不一致,请重新输入!'); } $password = md5($password); $result = Users::updateAll(['password' => $password, 'username' => $username], ['id' => $userId]); if (!$result) { throw new ServerErrorHttpException('更新密码错误!'); } return $this->redirect(['/find-password/index', 'step' => 4]); } else { $success = 'true'; } } $data = ['users' => $users, 'step' => $step, 'phoneHidden' => $phoneHidden, 'phone' => $phone, 'username' => $username]; return $this->render('index', ['data' => $data]); }