1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018 |
- <?php
- namespace app\api\controller;
- use app\admin\model\cms\AuthorManuscript;
- use app\admin\model\cms\AuthorService;
- use app\admin\model\cms\Channel;
- use app\admin\model\cms\Comments;
- use app\admin\model\cms\Conference;
- use app\admin\model\cms\Email;
- use app\admin\model\cms\InviteReviewer;
- use app\admin\model\cms\Issue;
- use app\admin\model\cms\ManuscriptLog;
- use app\admin\model\cms\Participate;
- use app\admin\model\EmailContent;
- use app\common\controller\Api;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use app\common\model\UserRoleContent;
- use app\common\model\UserRoleLog;
- use fast\Random;
- use think\Config;
- use think\Db;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- use think\Validate;
- /**
- * 会员接口
- */
- class User extends Api
- {
- protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- if (!Config::get('fastadmin.usercenter')) {
- $this->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->is_author = 'correct';
- $user->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 = $param['journal_ids'];
- $type = $this->request->param('type');
- Db::startTrans();
- try {
- // 查询是否有对应的申请角色数据信息
- $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();
- }
- } else {
- // 如果之前申请了主编或者编辑角色、并且已经通过了,则需要查看当前是否为主编或者编辑
- if ($type == 'editor') {
- if($user->is_chief == 'correct') {
- $user_role_log->is_adopt = 'fault';
- $user->is_chief = 'fault';
- }
- }
- if ($type == 'chief') {
- if ($user->is_ediot == 'correct') {
- $user_role_log->is_adopt = 'fault';
- $user->is_editor = 'fault';
- }
- }
- $user->save();
- $user_role_log->save();
- }
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('Submit Success');
- }
- /**
- * 提交手稿
- *
- * @return void
- */
- public function submit_manuscript()
- {
- $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['author']) $this->error('Author Cannot be Empty');
- if (array_key_exists('reviewer', $params)) {
- if (!$params['reviewer']) $this->error('Reviewer Cannot be Empty');
- }
- // 修改
- if ($params['id']) {
- // 修改操作
- $row = AuthorManuscript::where(['id' => $params['id']])->find();
- if (empty($row)) $this->error('Submit Failed');
- Db::startTrans();
- try {
- // 数组内容需转换为字符串
- $params['author_content'] = json_encode($params['author']);
- if (array_key_exists('reviewer', $params)) {
- $params['review_content'] = json_encode($params['reviewer']);
- }
- // 如果修改时状态是未编辑完得状态 提交后则修改完处理中状态
- if ($row['status'] == 'incomplete_submission') {
- $params['status'] = 'processing';
- }
- // 默认图片
- if ($params['image'] == '') {
- $params['image'] = 'https://dummyimage.com/205x128';
- }
- // 通过选择的期刊来绑定对应的主编
- if (!empty($params['journal'])) {
- $channel = Channel::get($params['journal']);
- if ($channel) {
- $params['chief_id'] = $channel['chief_id'];
- }
- }
- // 手稿状态日志
- $log = ManuscriptLog::where(['manuscript_id' => $params['id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
- if (!$log) {
- $log = new ManuscriptLog();
- $log->manuscript_id = $params['id'];
- $log->user_id = $this->auth->id;
- $log->type = 'user';
- }
- $log->status = $params['status'];
- $log->save();
- $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;
- // 获取手稿
- $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find();
- if ($manuscript) {
- $manuscript['status'] = $params['status'];
- $manuscript->save();
- }
- if ($params['type'] != 'author') {
- $result = $model->allowField(true)->save($params);
- } else {
- // 如果是作者则先查询是否有审稿意见回复,如果有则进行更新操作
- $result = Comments::where(['manuscript_id' => $params['manuscript_id'], 'user_id' => $this->auth->id, 'type' => 'author'])->find();
- if ($result) {
- $result->comments = $params['comments'];
- $result->save();
- } else {
- $result = $model->allowField(true)->save($params);
- }
- }
- // 手稿状态日志
- $log = ManuscriptLog::where(['manuscript_id' => $params['manuscript_id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
- if (!$log) {
- $log = new ManuscriptLog();
- $log->manuscript_id = $params['manuscript_id'];
- $log->user_id = $this->auth->id;
- $log->type = 'user';
- }
- $log->status = $params['status'];
- $log->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 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');
- $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find();
- $reviewers = $params['reviewer'];
- if (!$reviewers) $this->error('Please select 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(['manuscript_id' => $params['manuscript_id']])->select();
- foreach ($reviewer_old as $item) {
- $item->delete();
- }
- $model = new InviteReviewer();
- $model->allowField(true)->save($data);
- }
- $reviewer_ids_arr = [];
- // 合并数组
- $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'] = $params['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');
- }
- /**
- * 提交手稿(未全部提交)
- *
- * @return void
- */
- public function incomplete_submit()
- {
- $params = $this->request->post('row/a');
- // 数组内容需转换为字符串
- if (array_key_exists('author', $params) && !empty($params['author'])) {
- $params['author_content'] = json_encode($params['author']);
- }
- if (array_key_exists('reviewer', $params) && !empty($params['reviewer'])) {
- $params['review_content'] = json_encode($params['reviewer']);
- }
- if (empty($params['title'])) {
- $params['title'] = 'Incomplete editing' . rand(0, 4);
- }
- if (empty($params['image'])) {
- $params['image'] = 'https://dummyimage.com/205x128';
- }
- $params['status'] = 'incomplete_submission';
- $params['user_id'] = $this->auth->id;
- // 因使用create方法返回自增id,但是验证字段有前端自定义字段所以需要删除
- unset($params['author']);
- unset($params['reviewer']);
- $manuscript = new AuthorManuscript();
- Db::startTrans();
- try {
- if (!empty($params['id'])) {
- $manuscript = AuthorManuscript::where(['id' => $params['id']])->find();
- $manuscript = $manuscript->allowField(true)->save($params);
- } else {
- $manuscript = $manuscript->allowField(true)->create($params);
- }
- // 手稿状态日志
- $log = ManuscriptLog::where(['manuscript_id' => $params['id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
- if (!$log) {
- $log = new ManuscriptLog();
- $log->manuscript_id = $params['id'];
- $log->user_id = $this->auth->id;
- $log->type = 'user';
- }
- $log->status = $params['status'];
- $log->save();
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('Success', $manuscript->id ?? $params['id']);
- }
- /**
- * 发送邮件
- *
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function send_email()
- {
- $params = $this->request->post('row/a');
- $option = [
- 'mail_smtp_host' => $this->auth->mail_smtp_host,
- 'mail_smtp_port' => $this->auth->mail_smtp_port,
- 'mail_smtp_user' => $this->auth->mail_smtp_user,
- 'mail_smtp_pass' => $this->auth->mail_smtp_pass,
- 'mail_from' => $this->auth->mail_smtp_user,
- ];
- $email = new \app\common\library\Email($option);
- $result = $email
- ->to($params['send_user_email'])
- ->subject($params['title'])
- ->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . $params['content'] . '</div>')
- ->send();
- Db::startTrans();
- try {
- $receiver_user = \app\admin\model\User::where(['email' => $params['send_user_email']])->find();
- $params['type'] = 'user';
- $params['user_id'] = $this->auth->id;
- $params['receiver_id'] = $receiver_user['id'];
- $params['email'] = $params['send_user_email'];
- $email_model = new EmailContent();
- $result = $email_model->allowField(true)->save($params);
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success('Successfully sent');
- }
- /**
- * 邀请编辑
- *
- * @return void
- * @throws \think\exception\DbException
- */
- public function invite_editor()
- {
- $params = $this->request->post('row/a');
- $row = AuthorManuscript::get($params['manuscript_id']);
- Db::startTrans();
- try {
- if ($row) {
- $row['editor_ids'] = $params['editor_ids'];
- $row->save();
- }
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('Successfully');
- }
- }
|