User.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\cms\AuthorManuscript;
  4. use app\admin\model\cms\AuthorService;
  5. use app\admin\model\cms\Comments;
  6. use app\admin\model\cms\Conference;
  7. use app\admin\model\cms\Email;
  8. use app\admin\model\cms\InviteReviewer;
  9. use app\admin\model\cms\Issue;
  10. use app\admin\model\cms\Participate;
  11. use app\admin\model\EmailContent;
  12. use app\common\controller\Api;
  13. use app\common\library\Ems;
  14. use app\common\library\Sms;
  15. use app\common\model\UserRoleContent;
  16. use app\common\model\UserRoleLog;
  17. use fast\Random;
  18. use think\Config;
  19. use think\Db;
  20. use think\exception\PDOException;
  21. use think\exception\ValidateException;
  22. use think\Validate;
  23. /**
  24. * 会员接口
  25. */
  26. class User extends Api
  27. {
  28. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
  29. protected $noNeedRight = '*';
  30. public function _initialize()
  31. {
  32. parent::_initialize();
  33. if (!Config::get('fastadmin.usercenter')) {
  34. $this->error(__('User center already closed'));
  35. }
  36. }
  37. /**
  38. * 会员中心
  39. */
  40. public function index()
  41. {
  42. $this->success('', ['welcome' => $this->auth->nickname]);
  43. }
  44. /**
  45. * 会员登录
  46. *
  47. * @ApiMethod (POST)
  48. * @param string $account 账号
  49. * @param string $password 密码
  50. */
  51. public function login()
  52. {
  53. $account = $this->request->post('account');
  54. $password = $this->request->post('password');
  55. if (!$account || !$password) {
  56. $this->error(__('Invalid parameters'));
  57. }
  58. $ret = $this->auth->login($account, $password);
  59. if ($ret) {
  60. $data = ['userinfo' => $this->auth->getUserinfo()];
  61. $this->success(__('Logged in successful'), $data);
  62. } else {
  63. $this->error($this->auth->getError());
  64. }
  65. }
  66. /**
  67. * 手机验证码登录
  68. *
  69. * @ApiMethod (POST)
  70. * @param string $mobile 手机号
  71. * @param string $captcha 验证码
  72. */
  73. public function mobilelogin()
  74. {
  75. $mobile = $this->request->post('mobile');
  76. $captcha = $this->request->post('captcha');
  77. if (!$mobile || !$captcha) {
  78. $this->error(__('Invalid parameters'));
  79. }
  80. if (!Validate::regex($mobile, "^1\d{10}$")) {
  81. $this->error(__('Mobile is incorrect'));
  82. }
  83. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  84. $this->error(__('Captcha is incorrect'));
  85. }
  86. $user = \app\common\model\User::getByMobile($mobile);
  87. if ($user) {
  88. if ($user->status != 'normal') {
  89. $this->error(__('Account is locked'));
  90. }
  91. //如果已经有账号则直接登录
  92. $ret = $this->auth->direct($user->id);
  93. } else {
  94. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
  95. }
  96. if ($ret) {
  97. Sms::flush($mobile, 'mobilelogin');
  98. $data = ['userinfo' => $this->auth->getUserinfo()];
  99. $this->success(__('Logged in successful'), $data);
  100. } else {
  101. $this->error($this->auth->getError());
  102. }
  103. }
  104. /**
  105. * 注册会员
  106. *
  107. * @ApiMethod (POST)
  108. * @param string $username 用户名
  109. * @param string $password 密码
  110. * @param string $email 邮箱
  111. * @param string $mobile 手机号
  112. * @param string $code 验证码
  113. */
  114. public function register()
  115. {
  116. $username = $this->request->post('username');
  117. $password = $this->request->post('password');
  118. $email = $this->request->post('email');
  119. $mobile = $this->request->post('mobile');
  120. $code = $this->request->post('code');
  121. if (!$username || !$password) {
  122. $this->error(__('Invalid parameters'));
  123. }
  124. if ($email && !Validate::is($email, "email")) {
  125. $this->error(__('Email is incorrect'));
  126. }
  127. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  128. $this->error(__('Mobile is incorrect'));
  129. }
  130. $ret = Sms::check($mobile, $code, 'register');
  131. if (!$ret) {
  132. $this->error(__('Captcha is incorrect'));
  133. }
  134. $ret = $this->auth->register($username, $password, $email, $mobile, []);
  135. if ($ret) {
  136. $data = ['userinfo' => $this->auth->getUserinfo()];
  137. $this->success(__('Sign up successful'), $data);
  138. } else {
  139. $this->error($this->auth->getError());
  140. }
  141. }
  142. /**
  143. * 退出登录
  144. * @ApiMethod (POST)
  145. */
  146. public function logout()
  147. {
  148. if (!$this->request->isPost()) {
  149. $this->error(__('Invalid parameters'));
  150. }
  151. $this->auth->logout();
  152. $this->success(__('Logout successful'));
  153. }
  154. /**
  155. * 修改会员个人信息
  156. *
  157. * @ApiMethod (POST)
  158. * @param string $avatar 头像地址
  159. * @param string $username 用户名
  160. * @param string $nickname 昵称
  161. * @param string $bio 个人简介
  162. */
  163. public function profile()
  164. {
  165. $user = $this->auth->getUser();
  166. $username = $this->request->post('username');
  167. $nickname = $this->request->post('nickname');
  168. $bio = $this->request->post('bio');
  169. $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
  170. $workplace = $this->request->post('workplace');
  171. $job_type = $this->request->post('job_type');
  172. $title = $this->request->post('title');
  173. $first_name = $this->request->post('first_name');
  174. $middle_name = $this->request->post('middle_name');
  175. $last_name = $this->request->post('last_name');
  176. $facebook = $this->request->post('facebook');
  177. $twitter = $this->request->post('twitter');
  178. $email = $this->request->post('email');
  179. $affiliation = $this->request->post('affiliation');
  180. $address = $this->request->post('address');
  181. $zip_code = $this->request->post('zip_code');
  182. $city = $this->request->post('city');
  183. $country = $this->request->post('country');
  184. $mail_smtp_host = $this->request->post('mail_smtp_host');
  185. $mail_smtp_port = $this->request->post('mail_smtp_port');
  186. $mail_smtp_user = $this->request->post('mail_smtp_user');
  187. $mail_smtp_pass = $this->request->post('mail_smtp_pass');
  188. if ($username) {
  189. $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
  190. if ($exists) {
  191. $this->error(__('Username already exists'));
  192. }
  193. $user->username = $username;
  194. }
  195. if ($nickname) {
  196. $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
  197. if ($exists) {
  198. $this->error(__('Nickname already exists'));
  199. }
  200. $user->nickname = $nickname;
  201. }
  202. $user->bio = $bio;
  203. $user->avatar = $avatar;
  204. $user->workplace = $workplace;
  205. $user->job_type = $job_type;
  206. $user->title = $title;
  207. $user->first_name = $first_name;
  208. $user->middle_name = $middle_name;
  209. $user->last_name = $last_name;
  210. $user->facebook = $facebook;
  211. $user->twitter = $twitter;
  212. $user->email = $email;
  213. $user->affiliation = $affiliation;
  214. $user->address = $address;
  215. $user->zip_code = $zip_code;
  216. $user->city = $city;
  217. $user->country = $country;
  218. $user->mail_smtp_host = $mail_smtp_host;
  219. $user->mail_smtp_port = $mail_smtp_port;
  220. $user->mail_smtp_user = $mail_smtp_user;
  221. $user->mail_smtp_pass = $mail_smtp_pass;
  222. $user->save();
  223. // 查询用户是否已有申请角色记录表
  224. $user_role_log = UserRoleLog::where(['user_id' => $user->id, 'type' => 'author', 'is_adopt' => ['in', ['review', 'fault', 'correct']]])->find();
  225. if (empty($user_role_log)) {
  226. $user_role = new UserRoleLog();
  227. $user_role->user_id = $user->id;
  228. $user_role->save();
  229. }
  230. $this->success();
  231. }
  232. /**
  233. * 修改邮箱
  234. *
  235. * @ApiMethod (POST)
  236. * @param string $email 邮箱
  237. * @param string $captcha 验证码
  238. */
  239. public function changeemail()
  240. {
  241. $user = $this->auth->getUser();
  242. $email = $this->request->post('email');
  243. $captcha = $this->request->post('captcha');
  244. if (!$email || !$captcha) {
  245. $this->error(__('Invalid parameters'));
  246. }
  247. if (!Validate::is($email, "email")) {
  248. $this->error(__('Email is incorrect'));
  249. }
  250. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  251. $this->error(__('Email already exists'));
  252. }
  253. $result = Ems::check($email, $captcha, 'changeemail');
  254. if (!$result) {
  255. $this->error(__('Captcha is incorrect'));
  256. }
  257. $verification = $user->verification;
  258. $verification->email = 1;
  259. $user->verification = $verification;
  260. $user->email = $email;
  261. $user->save();
  262. Ems::flush($email, 'changeemail');
  263. $this->success();
  264. }
  265. /**
  266. * 修改手机号
  267. *
  268. * @ApiMethod (POST)
  269. * @param string $mobile 手机号
  270. * @param string $captcha 验证码
  271. */
  272. public function changemobile()
  273. {
  274. $user = $this->auth->getUser();
  275. $mobile = $this->request->post('mobile');
  276. $captcha = $this->request->post('captcha');
  277. if (!$mobile || !$captcha) {
  278. $this->error(__('Invalid parameters'));
  279. }
  280. if (!Validate::regex($mobile, "^1\d{10}$")) {
  281. $this->error(__('Mobile is incorrect'));
  282. }
  283. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  284. $this->error(__('Mobile already exists'));
  285. }
  286. $result = Sms::check($mobile, $captcha, 'changemobile');
  287. if (!$result) {
  288. $this->error(__('Captcha is incorrect'));
  289. }
  290. $verification = $user->verification;
  291. $verification->mobile = 1;
  292. $user->verification = $verification;
  293. $user->mobile = $mobile;
  294. $user->save();
  295. Sms::flush($mobile, 'changemobile');
  296. $this->success();
  297. }
  298. /**
  299. * 第三方登录
  300. *
  301. * @ApiMethod (POST)
  302. * @param string $platform 平台名称
  303. * @param string $code Code码
  304. */
  305. public function third()
  306. {
  307. $url = url('user/index');
  308. $platform = $this->request->post("platform");
  309. $code = $this->request->post("code");
  310. $config = get_addon_config('third');
  311. if (!$config || !isset($config[$platform])) {
  312. $this->error(__('Invalid parameters'));
  313. }
  314. $app = new \addons\third\library\Application($config);
  315. //通过code换access_token和绑定会员
  316. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  317. if ($result) {
  318. $loginret = \addons\third\library\Service::connect($platform, $result);
  319. if ($loginret) {
  320. $data = [
  321. 'userinfo' => $this->auth->getUserinfo(),
  322. 'thirdinfo' => $result
  323. ];
  324. $this->success(__('Logged in successful'), $data);
  325. }
  326. }
  327. $this->error(__('Operation failed'), $url);
  328. }
  329. /**
  330. * 重置密码
  331. *
  332. * @ApiMethod (POST)
  333. * @param string $mobile 手机号
  334. * @param string $newpassword 新密码
  335. * @param string $captcha 验证码
  336. */
  337. public function resetpwd()
  338. {
  339. $type = $this->request->post("type");
  340. $mobile = $this->request->post("mobile");
  341. $email = $this->request->post("email");
  342. $newpassword = $this->request->post("newpassword");
  343. $captcha = $this->request->post("captcha");
  344. if (!$newpassword || !$captcha) {
  345. $this->error(__('Invalid parameters'));
  346. }
  347. //验证Token
  348. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  349. $this->error(__('Password must be 6 to 30 characters'));
  350. }
  351. if ($type == 'mobile') {
  352. if (!Validate::regex($mobile, "^1\d{10}$")) {
  353. $this->error(__('Mobile is incorrect'));
  354. }
  355. $user = \app\common\model\User::getByMobile($mobile);
  356. if (!$user) {
  357. $this->error(__('User not found'));
  358. }
  359. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  360. if (!$ret) {
  361. $this->error(__('Captcha is incorrect'));
  362. }
  363. Sms::flush($mobile, 'resetpwd');
  364. } else {
  365. if (!Validate::is($email, "email")) {
  366. $this->error(__('Email is incorrect'));
  367. }
  368. $user = \app\common\model\User::getByEmail($email);
  369. if (!$user) {
  370. $this->error(__('User not found'));
  371. }
  372. $ret = Ems::check($email, $captcha, 'resetpwd');
  373. if (!$ret) {
  374. $this->error(__('Captcha is incorrect'));
  375. }
  376. Ems::flush($email, 'resetpwd');
  377. }
  378. //模拟一次登录
  379. $this->auth->direct($user->id);
  380. $ret = $this->auth->changepwd($newpassword, '', true);
  381. if ($ret) {
  382. $this->success(__('Reset password successful'));
  383. } else {
  384. $this->error($this->auth->getError());
  385. }
  386. }
  387. /**
  388. * 提交申请角色
  389. *
  390. * @return void
  391. * @throws \think\db\exception\DataNotFoundException
  392. * @throws \think\db\exception\ModelNotFoundException
  393. * @throws \think\exception\DbException
  394. */
  395. public function apply_role()
  396. {
  397. $user = $this->auth->getUser();
  398. $param = $this->request->param();
  399. $field = $this->request->param('field');
  400. $degree = $this->request->param('degree');
  401. $resume = $this->request->param('resume', '', 'trim,strip_tags,htmlspecialchars');
  402. $affiliation = $this->request->param('affiliation');
  403. $publication = $this->request->param('publication');
  404. $orcid = $this->request->param('orcid');
  405. $homepage = $this->request->param('homepage');
  406. $review_journal = $this->request->param('review_journal');
  407. $interested_journal = $this->request->param('interested_journal');
  408. $journal_ids = implode(',', $param['journal_ids']);
  409. $type = $this->request->param('type');
  410. // 查询是否有对应的申请角色数据信息
  411. $user_content = UserRoleContent::where(['user_id' => $user->id, 'type' => $type])->find();
  412. if ($user_content) {
  413. $user_content->field = $field;
  414. $user_content->degree = $degree;
  415. $user_content->resume = $resume;
  416. $user_content->affiliation = $affiliation;
  417. $user_content->publication = $publication;
  418. $user_content->orcid = $orcid;
  419. $user_content->homepage = $homepage;
  420. $user_content->review_journal = $review_journal;
  421. $user_content->interested_journal = $interested_journal;
  422. $user_content->journal_ids = $journal_ids;
  423. $user_content->save();
  424. }
  425. // 查询用户是否已有申请角色记录表
  426. $user_role_log = UserRoleLog::where(['user_id' => $user->id, 'type' => $type, 'is_adopt' => ['in', ['review', 'fault', 'correct']]])->find();
  427. if (empty($user_role_log)) {
  428. $new_user_role = new UserRoleLog();
  429. $new_user_role->user_id = $user->id;
  430. $new_user_role->type = $type;
  431. if ($new_user_role->save()) {
  432. // 创建对应的信息
  433. $new_user_content = new UserRoleContent();
  434. $new_user_content->user_id = $user->id;
  435. $new_user_content->log_id = $new_user_role->id;
  436. $new_user_content->type = $type;
  437. $new_user_content->field = $field;
  438. $new_user_content->degree = $degree;
  439. $new_user_content->resume = $resume;
  440. $new_user_content->affiliation = $affiliation;
  441. $new_user_content->publication = $publication;
  442. $new_user_content->orcid = $orcid;
  443. $new_user_content->homepage = $homepage;
  444. $new_user_content->review_journal = $review_journal;
  445. $new_user_content->interested_journal = $interested_journal;
  446. $new_user_content->journal_ids = $journal_ids;
  447. $new_user_content->save();
  448. }
  449. }
  450. $this->success('Submit Success');
  451. }
  452. /**
  453. * 提交手稿
  454. *
  455. * @return void
  456. */
  457. public function manummscript()
  458. {
  459. $params = $this->request->post('row/a');
  460. if (!$params['manuscript_zip']) $this->error('Manuscript (Word/Zip) Cannot be Empty');
  461. if (!$params['journal']) $this->error('Journal Cannot be Empty');
  462. if (!$params['article_type']) $this->error('Article Type Cannot be Empty');
  463. if (!$params['title']) $this->error('Title Cannot be Empty');
  464. if (!$params['abstract']) $this->error('Abstract Cannot be Empty');
  465. if (!$params['keywords']) $this->error('Keywords Cannot be Empty');
  466. if (!$params['number_page']) $this->error('Number of Pages Cannot be Empty');
  467. if (!$params['author']) $this->error('Author Cannot be Empty');
  468. if (!$params['reviewer']) $this->error('Reviewer Cannot be Empty');
  469. if (!$params['country']) $this->error('Country Cannot be Empty');
  470. if (!$params['affiliation']) $this->error('Affiliation Cannot be Empty');
  471. if (!$params['name']) $this->error('Name Cannot be Empty');
  472. if (!$params['invoice_email']) $this->error('Invoice Email Cannot be Empty');
  473. if (!$params['order_email']) $this->error('Order Email Cannot be Empty');
  474. if (!$params['address']) $this->error('Address Cannot be Empty');
  475. if (!$params['zip_code']) $this->error('Zip Code Cannot be Empty');
  476. if (!$params['city']) $this->error('City Cannot be Empty');
  477. // 添加
  478. if (!$params['id']) {
  479. $result = false;
  480. Db::startTrans();
  481. try {
  482. $params['user_id'] = $this->auth->id;
  483. // 数组内容需转换为字符串
  484. $params['author_content'] = json_encode($params['author']);
  485. $params['review_content'] = json_encode($params['reviewer']);
  486. $model = new AuthorManuscript();
  487. $result = $model->allowField(true)->save($params);
  488. Db::commit();
  489. } catch (ValidateException|PDOException|Exception $e) {
  490. Db::rollback();
  491. $this->error($e->getMessage());
  492. }
  493. if ($result === false) {
  494. $this->error('No rows were inserted');
  495. }
  496. } else {
  497. // 修改操作
  498. $row = AuthorManuscript::where(['id' => $params['id']])->find();
  499. if (empty($row)) $this->error('Submit Failed');
  500. Db::startTrans();
  501. try {
  502. // 数组内容需转换为字符串
  503. $params['author_content'] = json_encode($params['author']);
  504. $params['review_contnet'] = json_encode($params['reviewer']);
  505. $result = $row->allowField(true)->save($params);
  506. Db::commit();
  507. } catch (ValidateException|PDOException|Exception $e) {
  508. Db::rollback();
  509. $this->error($e->getMessage());
  510. }
  511. if ($result === false) {
  512. $this->error('No rows were inserted');
  513. }
  514. }
  515. $this->success('Submit Success');
  516. }
  517. /**
  518. * 编辑、审稿人提交意见
  519. *
  520. * @return void
  521. */
  522. public function submit_comments()
  523. {
  524. $params = $this->request->post('row/a');
  525. $model = new Comments();
  526. Db::startTrans();
  527. try {
  528. $params['user_id'] = $this->auth->id;
  529. $result = $model->allowField(true)->save($params);
  530. Db::commit();
  531. } catch (ValidateException|PDOException|Exception $e) {
  532. Db::rollback();
  533. $this->error($e->getMessage());
  534. }
  535. if ($result === false) {
  536. $this->error('No rows were inserted');
  537. }
  538. $this->success('Submit Success');
  539. }
  540. /**
  541. * 提交特刊
  542. *
  543. * @return void
  544. */
  545. public function submit_issue()
  546. {
  547. $params = $this->request->post('row/a');
  548. $result = false;
  549. Db::startTrans();
  550. try {
  551. $params['user_id'] = $this->auth->id;
  552. // 数组内容需转换为字符串
  553. $params['editor'] = json_encode($params['editor']);
  554. $model = new Issue();
  555. $result = $model->allowField(true)->save($params);
  556. Db::commit();
  557. } catch (ValidateException|PDOException|Exception $e) {
  558. Db::rollback();
  559. $this->error($e->getMessage());
  560. }
  561. if ($result === false) {
  562. $this->error('No rows were inserted');
  563. }
  564. $this->success('Submit Success');
  565. }
  566. /**
  567. * 编辑邀请审稿人提交操作
  568. *
  569. * @return void
  570. */
  571. public function submit_invite_reviewer()
  572. {
  573. $params = $this->request->post('row/a');
  574. $reviewers = $params['reviewer'];
  575. $result = false;
  576. Db::startTrans();
  577. try {
  578. $reviewer_id_arr = [];
  579. foreach ($reviewers as $reviewer) {
  580. $reviewer_id_arr[] = $reviewer['user_id'];
  581. $data = [];
  582. $data['role_id'] = $reviewer['id'];
  583. $data['editor_id'] = $this->auth->id;
  584. $data['manuscript_id'] = $params['manuscript_id'];
  585. $reviewer_old = InviteReviewer::where(['role_id' => $reviewer['id'], 'editor_id' => $this->auth->id, 'manuscript_id' => $params['manuscript_id']])->find();
  586. // 如果存在选择数据则不进行插入操作
  587. if (!$reviewer_old) {
  588. $model = new InviteReviewer();
  589. $model->allowField(true)->save($data);
  590. }
  591. }
  592. $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find();
  593. $reviewer_ids_arr = explode(',', $manuscript['reviewer_ids']);
  594. // 合并数组
  595. $merged_reviewer_ids_arr = array_merge($reviewer_ids_arr, $reviewer_id_arr);
  596. // 去重数组
  597. $unique_reviewer_ids_arr = array_filter(array_unique($merged_reviewer_ids_arr));
  598. $manuscript['reviewer_ids'] = implode(',', $unique_reviewer_ids_arr);
  599. // $manuscript['status'] =
  600. $result = $manuscript->save();
  601. Db::commit();
  602. } catch (ValidateException|PDOException|Exception $e) {
  603. Db::rollback();
  604. $this->error($e->getMessage());
  605. }
  606. if ($result === false) {
  607. $this->error('No rows were inserted');
  608. }
  609. $this->success('Submit Success');
  610. }
  611. /**
  612. * 订阅邮箱
  613. *
  614. * @return void
  615. */
  616. public function email_subscription()
  617. {
  618. $email = $this->request->post('email');
  619. if (!$email) $this->error('Email cannot be empty');
  620. $old_email = Email::where(['email' => $email])->find();
  621. if ($old_email) $this->error('Email already exists');
  622. $result = false;
  623. Db::startTrans();
  624. try {
  625. $model = new Email();
  626. $result = $model->allowField(true)->save(['email' => $email, 'type' => 'journal', 'user_id' => $this->auth->id]);
  627. Db::commit();
  628. } catch (ValidateException|PDOException|Exception $e) {
  629. Db::rollback();
  630. $this->error($e->getMessage());
  631. }
  632. if ($result === false) {
  633. $this->error('No rows were inserted');
  634. }
  635. $this->success('Operation successful');
  636. }
  637. /**
  638. * 首页提交邮箱信息
  639. *
  640. * @return void
  641. */
  642. public function submit_email()
  643. {
  644. $params = $this->request->post();
  645. $email = $this->request->post('email');
  646. $value = $this->request->post('value');
  647. if (empty($email)) $this->error('Email cannot be empty');
  648. if (empty($value)) $this->error('The selected value cannot be empty');
  649. $model = new Email();
  650. Db::startTrans();
  651. try {
  652. $params['type'] = 'home';
  653. $params['user_id'] = $this->auth->id;
  654. $result = $model->allowField(true)->save($params);
  655. Db::commit();
  656. } catch (ValidateException|PDOException|Exception $e) {
  657. Db::rollback();
  658. $this->error($e->getMessage());
  659. }
  660. if ($result === false) {
  661. $this->error('Submit Error');
  662. }
  663. $this->success('Submit Success');
  664. }
  665. /**
  666. * 提交会议
  667. *
  668. * @return void
  669. */
  670. public function submit_conference()
  671. {
  672. if (!$this->auth->isLogin()) {
  673. $this->error("Please log in before proceeding", "index/user/login");
  674. }
  675. $params = $this->request->post('row/a');
  676. $captcha = $this->request->post('captcha');
  677. if (!captcha_check($captcha)) {
  678. $this->error("Incorrect verification code");
  679. }
  680. $model = new Conference();
  681. Db::startTrans();
  682. try {
  683. $params['user_id'] = $this->auth->id;
  684. $result = $model->allowField(true)->save($params);
  685. Db::commit();
  686. } catch (ValidateException|PDOException|Exception $e) {
  687. Db::rollback();
  688. $this->error($e->getMessage());
  689. }
  690. if ($result === false) {
  691. $this->error('Submit Error');
  692. }
  693. $this->success('Submit Success');
  694. }
  695. /**
  696. * 参与会议
  697. *
  698. * @return void
  699. */
  700. public function conference_participate()
  701. {
  702. $params = $this->request->post('row/a');
  703. $model = new Participate();
  704. Db::startTrans();
  705. try {
  706. $params['user_id'] = $this->auth->id;
  707. $result = $model->allowField(true)->save($params);
  708. Db::commit();
  709. } catch (ValidateException|PDOException|Exception $e) {
  710. Db::rollback();
  711. $this->error($e->getMessage());
  712. }
  713. if ($result === false) {
  714. $this->error('Submit Error');
  715. }
  716. $this->success('Submit Success');
  717. }
  718. /**
  719. * 提交作者服务
  720. *
  721. * @return void
  722. */
  723. public function submit_author_service()
  724. {
  725. $params = $this->request->post();
  726. $model = new AuthorService();
  727. Db::startTrans();
  728. try {
  729. $params['user_id'] = $this->auth->id;
  730. $result = $model->allowField(true)->save($params);
  731. Db::commit();
  732. } catch (ValidateException|PDOException|Exception $e) {
  733. Db::rollback();
  734. $this->error($e->getMessage());
  735. }
  736. if ($result === false) {
  737. $this->error('Submit Error');
  738. }
  739. $this->success('Submit Success');
  740. }
  741. /**
  742. * 已读邮件
  743. *
  744. * @return void
  745. * @throws \think\db\exception\DataNotFoundException
  746. * @throws \think\db\exception\ModelNotFoundException
  747. * @throws \think\exception\DbException
  748. */
  749. public function read_email()
  750. {
  751. $params = $this->request->post();
  752. if ($params['email_id']) {
  753. $email_content = EmailContent::where(['id' => $params['email_id']])->find();
  754. Db::startTrans();
  755. try {
  756. if ($email_content) {
  757. $email_content->status = 'normal';
  758. $result = $email_content->save();;
  759. }
  760. Db::commit();
  761. } catch (ValidateException|PDOException|Exception $e) {
  762. Db::rollback();
  763. $this->error($e->getMessage());
  764. }
  765. }
  766. if ($result === false) {
  767. $this->error('Submit Error');
  768. }
  769. $this->success('Success');
  770. }
  771. }