123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831 |
- <?php
- namespace app\api\controller;
- use app\admin\model\cms\AuthorManuscript;
- use app\admin\model\cms\AuthorService;
- 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\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->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');
- }
- }
|