error(__('User center already closed')); } } /** * 会员中心 */ public function index() { $this->success('', ['welcome' => $this->auth->nickname]); } /** * 会员登录 * * @ApiMethod (POST) * @param string $account 账号 * @param string $password 密码 */ public function login() { $account = $this->request->post('account'); $password = $this->request->post('password'); if (!$account || !$password) { $this->error(__('Invalid parameters')); } $ret = $this->auth->login($account, $password); if ($ret) { $data = ['userinfo' => $this->auth->getUserinfo()]; $this->success(__('Logged in successful'), $data); } else { $this->error($this->auth->getError()); } } /** * 手机验证码登录 * * @ApiMethod (POST) * @param string $mobile 手机号 * @param string $captcha 验证码 */ public function mobilelogin() { $mobile = $this->request->post('mobile'); $captcha = $this->request->post('captcha'); if (!$mobile || !$captcha) { $this->error(__('Invalid parameters')); } if (!Validate::regex($mobile, "^1\d{10}$")) { $this->error(__('Mobile is incorrect')); } if (!Sms::check($mobile, $captcha, 'mobilelogin')) { $this->error(__('Captcha is incorrect')); } $user = \app\common\model\User::getByMobile($mobile); if ($user) { if ($user->status != 'normal') { $this->error(__('Account is locked')); } //如果已经有账号则直接登录 $ret = $this->auth->direct($user->id); } else { $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []); } if ($ret) { Sms::flush($mobile, 'mobilelogin'); $data = ['userinfo' => $this->auth->getUserinfo()]; $this->success(__('Logged in successful'), $data); } else { $this->error($this->auth->getError()); } } /** * 注册会员 * * @ApiMethod (POST) * @param string $username 用户名 * @param string $password 密码 * @param string $email 邮箱 * @param string $mobile 手机号 * @param string $code 验证码 */ public function register() { $username = $this->request->post('username'); $password = $this->request->post('password'); $email = $this->request->post('email'); $mobile = $this->request->post('mobile'); $code = $this->request->post('code'); if (!$username || !$password) { $this->error(__('Invalid parameters')); } if ($email && !Validate::is($email, "email")) { $this->error(__('Email is incorrect')); } if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) { $this->error(__('Mobile is incorrect')); } $ret = Sms::check($mobile, $code, 'register'); if (!$ret) { $this->error(__('Captcha is incorrect')); } $ret = $this->auth->register($username, $password, $email, $mobile, []); if ($ret) { $data = ['userinfo' => $this->auth->getUserinfo()]; $this->success(__('Sign up successful'), $data); } else { $this->error($this->auth->getError()); } } /** * 退出登录 * @ApiMethod (POST) */ public function logout() { if (!$this->request->isPost()) { $this->error(__('Invalid parameters')); } $this->auth->logout(); $this->success(__('Logout successful')); } /** * 修改会员个人信息 * * @ApiMethod (POST) * @param string $avatar 头像地址 * @param string $username 用户名 * @param string $nickname 昵称 * @param string $bio 个人简介 */ public function profile() { $user = $this->auth->getUser(); $username = $this->request->post('username'); $nickname = $this->request->post('nickname'); $bio = $this->request->post('bio'); $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars'); $workplace = $this->request->post('workplace'); $job_type = $this->request->post('job_type'); $title = $this->request->post('title'); $first_name = $this->request->post('first_name'); $middle_name = $this->request->post('middle_name'); $last_name = $this->request->post('last_name'); $facebook = $this->request->post('facebook'); $twitter = $this->request->post('twitter'); $email = $this->request->post('email'); $affiliation = $this->request->post('affiliation'); $address = $this->request->post('address'); $zip_code = $this->request->post('zip_code'); $city = $this->request->post('city'); $country = $this->request->post('country'); $mail_smtp_host = $this->request->post('mail_smtp_host'); $mail_smtp_port = $this->request->post('mail_smtp_port'); $mail_smtp_user = $this->request->post('mail_smtp_user'); $mail_smtp_pass = $this->request->post('mail_smtp_pass'); if ($username) { $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find(); if ($exists) { $this->error(__('Username already exists')); } $user->username = $username; } if ($nickname) { $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find(); if ($exists) { $this->error(__('Nickname already exists')); } $user->nickname = $nickname; } $user->bio = $bio; $user->avatar = $avatar; $user->workplace = $workplace; $user->job_type = $job_type; $user->title = $title; $user->first_name = $first_name; $user->middle_name = $middle_name; $user->last_name = $last_name; $user->facebook = $facebook; $user->twitter = $twitter; $user->email = $email; $user->affiliation = $affiliation; $user->address = $address; $user->zip_code = $zip_code; $user->city = $city; $user->country = $country; $user->mail_smtp_host = $mail_smtp_host; $user->mail_smtp_port = $mail_smtp_port; $user->mail_smtp_user = $mail_smtp_user; $user->mail_smtp_pass = $mail_smtp_pass; $user->save(); // 查询用户是否已有申请角色记录表 $user_role_log = UserRoleLog::where(['user_id' => $user->id, 'type' => 'author', 'is_adopt' => ['in', ['review', 'fault', 'correct']]])->find(); if (empty($user_role_log)) { $user_role = new UserRoleLog(); $user_role->user_id = $user->id; $user_role->save(); } $this->success(); } /** * 修改邮箱 * * @ApiMethod (POST) * @param string $email 邮箱 * @param string $captcha 验证码 */ public function changeemail() { $user = $this->auth->getUser(); $email = $this->request->post('email'); $captcha = $this->request->post('captcha'); if (!$email || !$captcha) { $this->error(__('Invalid parameters')); } if (!Validate::is($email, "email")) { $this->error(__('Email is incorrect')); } if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) { $this->error(__('Email already exists')); } $result = Ems::check($email, $captcha, 'changeemail'); if (!$result) { $this->error(__('Captcha is incorrect')); } $verification = $user->verification; $verification->email = 1; $user->verification = $verification; $user->email = $email; $user->save(); Ems::flush($email, 'changeemail'); $this->success(); } /** * 修改手机号 * * @ApiMethod (POST) * @param string $mobile 手机号 * @param string $captcha 验证码 */ public function changemobile() { $user = $this->auth->getUser(); $mobile = $this->request->post('mobile'); $captcha = $this->request->post('captcha'); if (!$mobile || !$captcha) { $this->error(__('Invalid parameters')); } if (!Validate::regex($mobile, "^1\d{10}$")) { $this->error(__('Mobile is incorrect')); } if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) { $this->error(__('Mobile already exists')); } $result = Sms::check($mobile, $captcha, 'changemobile'); if (!$result) { $this->error(__('Captcha is incorrect')); } $verification = $user->verification; $verification->mobile = 1; $user->verification = $verification; $user->mobile = $mobile; $user->save(); Sms::flush($mobile, 'changemobile'); $this->success(); } /** * 第三方登录 * * @ApiMethod (POST) * @param string $platform 平台名称 * @param string $code Code码 */ public function third() { $url = url('user/index'); $platform = $this->request->post("platform"); $code = $this->request->post("code"); $config = get_addon_config('third'); if (!$config || !isset($config[$platform])) { $this->error(__('Invalid parameters')); } $app = new \addons\third\library\Application($config); //通过code换access_token和绑定会员 $result = $app->{$platform}->getUserInfo(['code' => $code]); if ($result) { $loginret = \addons\third\library\Service::connect($platform, $result); if ($loginret) { $data = [ 'userinfo' => $this->auth->getUserinfo(), 'thirdinfo' => $result ]; $this->success(__('Logged in successful'), $data); } } $this->error(__('Operation failed'), $url); } /** * 重置密码 * * @ApiMethod (POST) * @param string $mobile 手机号 * @param string $newpassword 新密码 * @param string $captcha 验证码 */ public function resetpwd() { $type = $this->request->post("type"); $mobile = $this->request->post("mobile"); $email = $this->request->post("email"); $newpassword = $this->request->post("newpassword"); $captcha = $this->request->post("captcha"); if (!$newpassword || !$captcha) { $this->error(__('Invalid parameters')); } //验证Token if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) { $this->error(__('Password must be 6 to 30 characters')); } if ($type == 'mobile') { if (!Validate::regex($mobile, "^1\d{10}$")) { $this->error(__('Mobile is incorrect')); } $user = \app\common\model\User::getByMobile($mobile); if (!$user) { $this->error(__('User not found')); } $ret = Sms::check($mobile, $captcha, 'resetpwd'); if (!$ret) { $this->error(__('Captcha is incorrect')); } Sms::flush($mobile, 'resetpwd'); } else { if (!Validate::is($email, "email")) { $this->error(__('Email is incorrect')); } $user = \app\common\model\User::getByEmail($email); if (!$user) { $this->error(__('User not found')); } $ret = Ems::check($email, $captcha, 'resetpwd'); if (!$ret) { $this->error(__('Captcha is incorrect')); } Ems::flush($email, 'resetpwd'); } //模拟一次登录 $this->auth->direct($user->id); $ret = $this->auth->changepwd($newpassword, '', true); if ($ret) { $this->success(__('Reset password successful')); } else { $this->error($this->auth->getError()); } } /** * 提交申请角色 * * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function apply_role() { $user = $this->auth->getUser(); $param = $this->request->param(); $field = $this->request->param('field'); $degree = $this->request->param('degree'); $resume = $this->request->param('resume', '', 'trim,strip_tags,htmlspecialchars'); $affiliation = $this->request->param('affiliation'); $publication = $this->request->param('publication'); $orcid = $this->request->param('orcid'); $homepage = $this->request->param('homepage'); $review_journal = $this->request->param('review_journal'); $interested_journal = $this->request->param('interested_journal'); $journal_ids = implode(',', $param['journal_ids']); $type = $this->request->param('type'); // 查询是否有对应的申请角色数据信息 $user_content = UserRoleContent::where(['user_id' => $user->id, 'type' => $type])->find(); if ($user_content) { $user_content->field = $field; $user_content->degree = $degree; $user_content->resume = $resume; $user_content->affiliation = $affiliation; $user_content->publication = $publication; $user_content->orcid = $orcid; $user_content->homepage = $homepage; $user_content->review_journal = $review_journal; $user_content->interested_journal = $interested_journal; $user_content->journal_ids = $journal_ids; $user_content->save(); } // 查询用户是否已有申请角色记录表 $user_role_log = UserRoleLog::where(['user_id' => $user->id, 'type' => $type, 'is_adopt' => ['in', ['review', 'fault', 'correct']]])->find(); if (empty($user_role_log)) { $new_user_role = new UserRoleLog(); $new_user_role->user_id = $user->id; $new_user_role->type = $type; if ($new_user_role->save()) { // 创建对应的信息 $new_user_content = new UserRoleContent(); $new_user_content->user_id = $user->id; $new_user_content->log_id = $new_user_role->id; $new_user_content->type = $type; $new_user_content->field = $field; $new_user_content->degree = $degree; $new_user_content->resume = $resume; $new_user_content->affiliation = $affiliation; $new_user_content->publication = $publication; $new_user_content->orcid = $orcid; $new_user_content->homepage = $homepage; $new_user_content->review_journal = $review_journal; $new_user_content->interested_journal = $interested_journal; $new_user_content->journal_ids = $journal_ids; $new_user_content->save(); } } $this->success('Submit Success'); } /** * 提交手稿 * * @return void */ public function manummscript() { $params = $this->request->post('row/a'); if (!$params['manuscript_zip']) $this->error('Manuscript (Word/Zip) Cannot be Empty'); if (!$params['journal']) $this->error('Journal Cannot be Empty'); if (!$params['article_type']) $this->error('Article Type Cannot be Empty'); if (!$params['title']) $this->error('Title Cannot be Empty'); if (!$params['abstract']) $this->error('Abstract Cannot be Empty'); if (!$params['keywords']) $this->error('Keywords Cannot be Empty'); if (!$params['number_page']) $this->error('Number of Pages Cannot be Empty'); if (!$params['author']) $this->error('Author Cannot be Empty'); if (!$params['reviewer']) $this->error('Reviewer Cannot be Empty'); if (!$params['country']) $this->error('Country Cannot be Empty'); if (!$params['affiliation']) $this->error('Affiliation Cannot be Empty'); if (!$params['name']) $this->error('Name Cannot be Empty'); if (!$params['invoice_email']) $this->error('Invoice Email Cannot be Empty'); if (!$params['order_email']) $this->error('Order Email Cannot be Empty'); if (!$params['address']) $this->error('Address Cannot be Empty'); if (!$params['zip_code']) $this->error('Zip Code Cannot be Empty'); if (!$params['city']) $this->error('City Cannot be Empty'); // 添加 if (!$params['id']) { $result = false; Db::startTrans(); try { $params['user_id'] = $this->auth->id; // 数组内容需转换为字符串 $params['author_content'] = json_encode($params['author']); $params['review_content'] = json_encode($params['reviewer']); $model = new AuthorManuscript(); $result = $model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('No rows were inserted'); } } else { // 修改操作 $row = AuthorManuscript::where(['id' => $params['id']])->find(); if (empty($row)) $this->error('Submit Failed'); Db::startTrans(); try { // 数组内容需转换为字符串 $params['author_content'] = json_encode($params['author']); $params['review_contnet'] = json_encode($params['reviewer']); $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('No rows were inserted'); } } $this->success('Submit Success'); } /** * 编辑、审稿人提交意见 * * @return void */ public function submit_comments() { $params = $this->request->post('row/a'); $model = new Comments(); Db::startTrans(); try { $params['user_id'] = $this->auth->id; $result = $model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('No rows were inserted'); } $this->success('Submit Success'); } /** * 提交特刊 * * @return void */ public function submit_issue() { $params = $this->request->post('row/a'); $result = false; Db::startTrans(); try { $params['user_id'] = $this->auth->id; // 数组内容需转换为字符串 $params['editor'] = json_encode($params['editor']); $model = new Issue(); $result = $model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('No rows were inserted'); } $this->success('Submit Success'); } /** * 编辑邀请审稿人提交操作 * * @return void */ public function submit_invite_reviewer() { $params = $this->request->post('row/a'); $reviewers = $params['reviewer']; $result = false; Db::startTrans(); try { $reviewer_id_arr = []; foreach ($reviewers as $reviewer) { $reviewer_id_arr[] = $reviewer['user_id']; $data = []; $data['role_id'] = $reviewer['id']; $data['editor_id'] = $this->auth->id; $data['manuscript_id'] = $params['manuscript_id']; $reviewer_old = InviteReviewer::where(['role_id' => $reviewer['id'], 'editor_id' => $this->auth->id, 'manuscript_id' => $params['manuscript_id']])->find(); // 如果存在选择数据则不进行插入操作 if (!$reviewer_old) { $model = new InviteReviewer(); $model->allowField(true)->save($data); } } $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find(); $reviewer_ids_arr = explode(',', $manuscript['reviewer_ids']); // 合并数组 $merged_reviewer_ids_arr = array_merge($reviewer_ids_arr, $reviewer_id_arr); // 去重数组 $unique_reviewer_ids_arr = array_filter(array_unique($merged_reviewer_ids_arr)); $manuscript['reviewer_ids'] = implode(',', $unique_reviewer_ids_arr); // $manuscript['status'] = $result = $manuscript->save(); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('No rows were inserted'); } $this->success('Submit Success'); } /** * 订阅邮箱 * * @return void */ public function email_subscription() { $email = $this->request->post('email'); if (!$email) $this->error('Email cannot be empty'); $old_email = Email::where(['email' => $email])->find(); if ($old_email) $this->error('Email already exists'); $result = false; Db::startTrans(); try { $model = new Email(); $result = $model->allowField(true)->save(['email' => $email, 'type' => 'journal', 'user_id' => $this->auth->id]); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('No rows were inserted'); } $this->success('Operation successful'); } /** * 首页提交邮箱信息 * * @return void */ public function submit_email() { $params = $this->request->post(); $email = $this->request->post('email'); $value = $this->request->post('value'); if (empty($email)) $this->error('Email cannot be empty'); if (empty($value)) $this->error('The selected value cannot be empty'); $model = new Email(); Db::startTrans(); try { $params['type'] = 'home'; $params['user_id'] = $this->auth->id; $result = $model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('Submit Error'); } $this->success('Submit Success'); } /** * 提交会议 * * @return void */ public function submit_conference() { if (!$this->auth->isLogin()) { $this->error("Please log in before proceeding", "index/user/login"); } $params = $this->request->post('row/a'); $captcha = $this->request->post('captcha'); if (!captcha_check($captcha)) { $this->error("Incorrect verification code"); } $model = new Conference(); Db::startTrans(); try { $params['user_id'] = $this->auth->id; $result = $model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('Submit Error'); } $this->success('Submit Success'); } /** * 参与会议 * * @return void */ public function conference_participate() { $params = $this->request->post('row/a'); $model = new Participate(); Db::startTrans(); try { $params['user_id'] = $this->auth->id; $result = $model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('Submit Error'); } $this->success('Submit Success'); } /** * 提交作者服务 * * @return void */ public function submit_author_service() { $params = $this->request->post(); $model = new AuthorService(); Db::startTrans(); try { $params['user_id'] = $this->auth->id; $result = $model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error('Submit Error'); } $this->success('Submit Success'); } /** * 已读邮件 * * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function read_email() { $params = $this->request->post(); if ($params['email_id']) { $email_content = EmailContent::where(['id' => $params['email_id']])->find(); Db::startTrans(); try { if ($email_content) { $email_content->status = 'normal'; $result = $email_content->save();; } Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } } if ($result === false) { $this->error('Submit Error'); } $this->success('Success'); } }