User.php 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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\Channel;
  6. use app\admin\model\cms\Comments;
  7. use app\admin\model\cms\Conference;
  8. use app\admin\model\cms\Email;
  9. use app\admin\model\cms\InviteReviewer;
  10. use app\admin\model\cms\Issue;
  11. use app\admin\model\cms\ManuscriptLog;
  12. use app\admin\model\cms\Participate;
  13. use app\admin\model\EmailContent;
  14. use app\common\controller\Api;
  15. use app\common\library\Ems;
  16. use app\common\library\Sms;
  17. use app\common\model\UserRoleContent;
  18. use app\common\model\UserRoleLog;
  19. use fast\Random;
  20. use think\Config;
  21. use think\Db;
  22. use think\exception\PDOException;
  23. use think\exception\ValidateException;
  24. use think\Validate;
  25. /**
  26. * 会员接口
  27. */
  28. class User extends Api
  29. {
  30. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
  31. protected $noNeedRight = '*';
  32. public function _initialize()
  33. {
  34. parent::_initialize();
  35. if (!Config::get('fastadmin.usercenter')) {
  36. $this->error(__('User center already closed'));
  37. }
  38. }
  39. /**
  40. * 会员中心
  41. */
  42. public function index()
  43. {
  44. $this->success('', ['welcome' => $this->auth->nickname]);
  45. }
  46. /**
  47. * 会员登录
  48. *
  49. * @ApiMethod (POST)
  50. * @param string $account 账号
  51. * @param string $password 密码
  52. */
  53. public function login()
  54. {
  55. $account = $this->request->post('account');
  56. $password = $this->request->post('password');
  57. if (!$account || !$password) {
  58. $this->error(__('Invalid parameters'));
  59. }
  60. $ret = $this->auth->login($account, $password);
  61. if ($ret) {
  62. $data = ['userinfo' => $this->auth->getUserinfo()];
  63. $this->success(__('Logged in successful'), $data);
  64. } else {
  65. $this->error($this->auth->getError());
  66. }
  67. }
  68. /**
  69. * 手机验证码登录
  70. *
  71. * @ApiMethod (POST)
  72. * @param string $mobile 手机号
  73. * @param string $captcha 验证码
  74. */
  75. public function mobilelogin()
  76. {
  77. $mobile = $this->request->post('mobile');
  78. $captcha = $this->request->post('captcha');
  79. if (!$mobile || !$captcha) {
  80. $this->error(__('Invalid parameters'));
  81. }
  82. if (!Validate::regex($mobile, "^1\d{10}$")) {
  83. $this->error(__('Mobile is incorrect'));
  84. }
  85. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  86. $this->error(__('Captcha is incorrect'));
  87. }
  88. $user = \app\common\model\User::getByMobile($mobile);
  89. if ($user) {
  90. if ($user->status != 'normal') {
  91. $this->error(__('Account is locked'));
  92. }
  93. //如果已经有账号则直接登录
  94. $ret = $this->auth->direct($user->id);
  95. } else {
  96. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
  97. }
  98. if ($ret) {
  99. Sms::flush($mobile, 'mobilelogin');
  100. $data = ['userinfo' => $this->auth->getUserinfo()];
  101. $this->success(__('Logged in successful'), $data);
  102. } else {
  103. $this->error($this->auth->getError());
  104. }
  105. }
  106. /**
  107. * 注册会员
  108. *
  109. * @ApiMethod (POST)
  110. * @param string $username 用户名
  111. * @param string $password 密码
  112. * @param string $email 邮箱
  113. * @param string $mobile 手机号
  114. * @param string $code 验证码
  115. */
  116. public function register()
  117. {
  118. $username = $this->request->post('username');
  119. $password = $this->request->post('password');
  120. $email = $this->request->post('email');
  121. $mobile = $this->request->post('mobile');
  122. $code = $this->request->post('code');
  123. if (!$username || !$password) {
  124. $this->error(__('Invalid parameters'));
  125. }
  126. if ($email && !Validate::is($email, "email")) {
  127. $this->error(__('Email is incorrect'));
  128. }
  129. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  130. $this->error(__('Mobile is incorrect'));
  131. }
  132. $ret = Sms::check($mobile, $code, 'register');
  133. if (!$ret) {
  134. $this->error(__('Captcha is incorrect'));
  135. }
  136. $ret = $this->auth->register($username, $password, $email, $mobile, []);
  137. if ($ret) {
  138. $data = ['userinfo' => $this->auth->getUserinfo()];
  139. $this->success(__('Sign up successful'), $data);
  140. } else {
  141. $this->error($this->auth->getError());
  142. }
  143. }
  144. /**
  145. * 退出登录
  146. * @ApiMethod (POST)
  147. */
  148. public function logout()
  149. {
  150. if (!$this->request->isPost()) {
  151. $this->error(__('Invalid parameters'));
  152. }
  153. $this->auth->logout();
  154. $this->success(__('Logout successful'));
  155. }
  156. /**
  157. * 修改会员个人信息
  158. *
  159. * @ApiMethod (POST)
  160. * @param string $avatar 头像地址
  161. * @param string $username 用户名
  162. * @param string $nickname 昵称
  163. * @param string $bio 个人简介
  164. */
  165. public function profile()
  166. {
  167. $user = $this->auth->getUser();
  168. $username = $this->request->post('username');
  169. $nickname = $this->request->post('nickname');
  170. $bio = $this->request->post('bio');
  171. $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
  172. $workplace = $this->request->post('workplace');
  173. $job_type = $this->request->post('job_type');
  174. $title = $this->request->post('title');
  175. $first_name = $this->request->post('first_name');
  176. $middle_name = $this->request->post('middle_name');
  177. $last_name = $this->request->post('last_name');
  178. $facebook = $this->request->post('facebook');
  179. $twitter = $this->request->post('twitter');
  180. $email = $this->request->post('email');
  181. $affiliation = $this->request->post('affiliation');
  182. $address = $this->request->post('address');
  183. $zip_code = $this->request->post('zip_code');
  184. $city = $this->request->post('city');
  185. $country = $this->request->post('country');
  186. $mail_smtp_host = $this->request->post('mail_smtp_host');
  187. $mail_smtp_port = $this->request->post('mail_smtp_port');
  188. $mail_smtp_user = $this->request->post('mail_smtp_user');
  189. $mail_smtp_pass = $this->request->post('mail_smtp_pass');
  190. if ($username) {
  191. $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
  192. if ($exists) {
  193. $this->error(__('Username already exists'));
  194. }
  195. $user->username = $username;
  196. }
  197. if ($nickname) {
  198. $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
  199. if ($exists) {
  200. $this->error(__('Nickname already exists'));
  201. }
  202. $user->nickname = $nickname;
  203. }
  204. $user->bio = $bio;
  205. $user->avatar = $avatar;
  206. $user->workplace = $workplace;
  207. $user->job_type = $job_type;
  208. $user->title = $title;
  209. $user->first_name = $first_name;
  210. $user->middle_name = $middle_name;
  211. $user->last_name = $last_name;
  212. $user->facebook = $facebook;
  213. $user->twitter = $twitter;
  214. $user->email = $email;
  215. $user->affiliation = $affiliation;
  216. $user->address = $address;
  217. $user->zip_code = $zip_code;
  218. $user->city = $city;
  219. $user->country = $country;
  220. $user->mail_smtp_host = $mail_smtp_host;
  221. $user->mail_smtp_port = $mail_smtp_port;
  222. $user->mail_smtp_user = $mail_smtp_user;
  223. $user->mail_smtp_pass = $mail_smtp_pass;
  224. $user->is_author = 'correct';
  225. $user->save();
  226. $this->success();
  227. }
  228. /**
  229. * 修改邮箱
  230. *
  231. * @ApiMethod (POST)
  232. * @param string $email 邮箱
  233. * @param string $captcha 验证码
  234. */
  235. public function changeemail()
  236. {
  237. $user = $this->auth->getUser();
  238. $email = $this->request->post('email');
  239. $captcha = $this->request->post('captcha');
  240. if (!$email || !$captcha) {
  241. $this->error(__('Invalid parameters'));
  242. }
  243. if (!Validate::is($email, "email")) {
  244. $this->error(__('Email is incorrect'));
  245. }
  246. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  247. $this->error(__('Email already exists'));
  248. }
  249. $result = Ems::check($email, $captcha, 'changeemail');
  250. if (!$result) {
  251. $this->error(__('Captcha is incorrect'));
  252. }
  253. $verification = $user->verification;
  254. $verification->email = 1;
  255. $user->verification = $verification;
  256. $user->email = $email;
  257. $user->save();
  258. Ems::flush($email, 'changeemail');
  259. $this->success();
  260. }
  261. /**
  262. * 修改手机号
  263. *
  264. * @ApiMethod (POST)
  265. * @param string $mobile 手机号
  266. * @param string $captcha 验证码
  267. */
  268. public function changemobile()
  269. {
  270. $user = $this->auth->getUser();
  271. $mobile = $this->request->post('mobile');
  272. $captcha = $this->request->post('captcha');
  273. if (!$mobile || !$captcha) {
  274. $this->error(__('Invalid parameters'));
  275. }
  276. if (!Validate::regex($mobile, "^1\d{10}$")) {
  277. $this->error(__('Mobile is incorrect'));
  278. }
  279. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  280. $this->error(__('Mobile already exists'));
  281. }
  282. $result = Sms::check($mobile, $captcha, 'changemobile');
  283. if (!$result) {
  284. $this->error(__('Captcha is incorrect'));
  285. }
  286. $verification = $user->verification;
  287. $verification->mobile = 1;
  288. $user->verification = $verification;
  289. $user->mobile = $mobile;
  290. $user->save();
  291. Sms::flush($mobile, 'changemobile');
  292. $this->success();
  293. }
  294. /**
  295. * 第三方登录
  296. *
  297. * @ApiMethod (POST)
  298. * @param string $platform 平台名称
  299. * @param string $code Code码
  300. */
  301. public function third()
  302. {
  303. $url = url('user/index');
  304. $platform = $this->request->post("platform");
  305. $code = $this->request->post("code");
  306. $config = get_addon_config('third');
  307. if (!$config || !isset($config[$platform])) {
  308. $this->error(__('Invalid parameters'));
  309. }
  310. $app = new \addons\third\library\Application($config);
  311. //通过code换access_token和绑定会员
  312. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  313. if ($result) {
  314. $loginret = \addons\third\library\Service::connect($platform, $result);
  315. if ($loginret) {
  316. $data = [
  317. 'userinfo' => $this->auth->getUserinfo(),
  318. 'thirdinfo' => $result
  319. ];
  320. $this->success(__('Logged in successful'), $data);
  321. }
  322. }
  323. $this->error(__('Operation failed'), $url);
  324. }
  325. /**
  326. * 重置密码
  327. *
  328. * @ApiMethod (POST)
  329. * @param string $mobile 手机号
  330. * @param string $newpassword 新密码
  331. * @param string $captcha 验证码
  332. */
  333. public function resetpwd()
  334. {
  335. // $type = $this->request->post("type");
  336. // $mobile = $this->request->post("mobile");
  337. $email = $this->request->post("email");
  338. $newpassword = $this->request->post("newpassword");
  339. $captcha = $this->request->post("captcha");
  340. if (!$newpassword || !$captcha) {
  341. $this->error(__('Invalid parameters'));
  342. }
  343. //验证Token
  344. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  345. $this->error(__('Password must be 6 to 30 characters'));
  346. }
  347. // if ($type == 'mobile') {
  348. // if (!Validate::regex($mobile, "^1\d{10}$")) {
  349. // $this->error(__('Mobile is incorrect'));
  350. // }
  351. // $user = \app\common\model\User::getByMobile($mobile);
  352. // if (!$user) {
  353. // $this->error(__('User not found'));
  354. // }
  355. // $ret = Sms::check($mobile, $captcha, 'resetpwd');
  356. // if (!$ret) {
  357. // $this->error(__('Captcha is incorrect'));
  358. // }
  359. // Sms::flush($mobile, 'resetpwd');
  360. // } else {
  361. if (!Validate::is($email, "email")) {
  362. $this->error(__('Email is incorrect'));
  363. }
  364. $user = \app\common\model\User::getByEmail($email);
  365. if (!$user) {
  366. $this->error(__('User not found'));
  367. }
  368. $ret = Ems::check($email, $captcha, 'resetpwd');
  369. if (!$ret) {
  370. $this->error(__('Captcha is incorrect'));
  371. }
  372. Ems::flush($email, 'resetpwd');
  373. // }
  374. //模拟一次登录
  375. $this->auth->direct($user->id);
  376. $ret = $this->auth->changepwd($newpassword, '', true);
  377. if ($ret) {
  378. $this->success(__('Reset password successful'));
  379. } else {
  380. $this->error($this->auth->getError());
  381. }
  382. }
  383. /**
  384. * 提交申请角色
  385. *
  386. * @return void
  387. * @throws \think\db\exception\DataNotFoundException
  388. * @throws \think\db\exception\ModelNotFoundException
  389. * @throws \think\exception\DbException
  390. */
  391. public function apply_role()
  392. {
  393. $user = $this->auth->getUser();
  394. $param = $this->request->param();
  395. $field = $this->request->param('field');
  396. $degree = $this->request->param('degree');
  397. $resume = $this->request->param('resume', '', 'trim,strip_tags,htmlspecialchars');
  398. $affiliation = $this->request->param('affiliation');
  399. $publication = $this->request->param('publication');
  400. $orcid = $this->request->param('orcid');
  401. $homepage = $this->request->param('homepage');
  402. $review_journal = $this->request->param('review_journal');
  403. $interested_journal = $this->request->param('interested_journal');
  404. $journal_ids = $param['journal_ids'];
  405. $type = $this->request->param('type');
  406. Db::startTrans();
  407. try {
  408. // 查询是否有对应的申请角色数据信息
  409. $user_content = UserRoleContent::where(['user_id' => $user->id, 'type' => $type])->find();
  410. if ($user_content) {
  411. $user_content->field = $field;
  412. $user_content->degree = $degree;
  413. $user_content->resume = $resume;
  414. $user_content->affiliation = $affiliation;
  415. $user_content->publication = $publication;
  416. $user_content->orcid = $orcid;
  417. $user_content->homepage = $homepage;
  418. $user_content->review_journal = $review_journal;
  419. $user_content->interested_journal = $interested_journal;
  420. $user_content->journal_ids = $journal_ids;
  421. $user_content->save();
  422. }
  423. // 查询用户是否已有申请角色记录表
  424. $user_role_log = UserRoleLog::where(['user_id' => $user->id, 'type' => $type, 'is_adopt' => ['in', ['review', 'fault', 'correct']]])->find();
  425. if (empty($user_role_log)) {
  426. $new_user_role = new UserRoleLog();
  427. $new_user_role->user_id = $user->id;
  428. $new_user_role->type = $type;
  429. if ($new_user_role->save()) {
  430. // 创建对应的信息
  431. $new_user_content = new UserRoleContent();
  432. $new_user_content->user_id = $user->id;
  433. $new_user_content->log_id = $new_user_role->id;
  434. $new_user_content->type = $type;
  435. $new_user_content->field = $field;
  436. $new_user_content->degree = $degree;
  437. $new_user_content->resume = $resume;
  438. $new_user_content->affiliation = $affiliation;
  439. $new_user_content->publication = $publication;
  440. $new_user_content->orcid = $orcid;
  441. $new_user_content->homepage = $homepage;
  442. $new_user_content->review_journal = $review_journal;
  443. $new_user_content->interested_journal = $interested_journal;
  444. $new_user_content->journal_ids = $journal_ids;
  445. $new_user_content->save();
  446. }
  447. } else {
  448. // 如果之前申请了主编或者编辑角色、并且已经通过了,则需要查看当前是否为主编或者编辑
  449. if ($type == 'editor') {
  450. if($user->is_chief == 'correct') {
  451. $user_role_log->is_adopt = 'fault';
  452. $user->is_chief = 'fault';
  453. }
  454. }
  455. if ($type == 'chief') {
  456. if ($user->is_ediot == 'correct') {
  457. $user_role_log->is_adopt = 'fault';
  458. $user->is_editor = 'fault';
  459. }
  460. }
  461. $user->save();
  462. $user_role_log->save();
  463. }
  464. Db::commit();
  465. } catch (ValidateException|PDOException|Exception $e) {
  466. Db::rollback();
  467. $this->error($e->getMessage());
  468. }
  469. $this->success('Submit Success');
  470. }
  471. /**
  472. * 提交手稿
  473. *
  474. * @return void
  475. */
  476. public function submit_manuscript()
  477. {
  478. $params = $this->request->post('row/a');
  479. if (!$params['manuscript_zip']) $this->error('Manuscript (Word/Zip) Cannot be Empty');
  480. if (!$params['journal']) $this->error('Journal Cannot be Empty');
  481. if (!$params['article_type']) $this->error('Article Type Cannot be Empty');
  482. if (!$params['title']) $this->error('Title Cannot be Empty');
  483. if (!$params['abstract']) $this->error('Abstract Cannot be Empty');
  484. if (!$params['keywords']) $this->error('Keywords Cannot be Empty');
  485. if (!$params['author']) $this->error('Author Cannot be Empty');
  486. if (array_key_exists('reviewer', $params)) {
  487. if (!$params['reviewer']) $this->error('Reviewer Cannot be Empty');
  488. }
  489. // 修改
  490. if ($params['id']) {
  491. // 修改操作
  492. $row = AuthorManuscript::where(['id' => $params['id']])->find();
  493. if (empty($row)) $this->error('Submit Failed');
  494. Db::startTrans();
  495. try {
  496. // 数组内容需转换为字符串
  497. $params['author_content'] = json_encode($params['author']);
  498. if (array_key_exists('reviewer', $params)) {
  499. $params['review_content'] = json_encode($params['reviewer']);
  500. }
  501. // 如果修改时状态是未编辑完得状态 提交后则修改完处理中状态
  502. if ($row['status'] == 'incomplete_submission') {
  503. $params['status'] = 'processing';
  504. }
  505. // 默认图片
  506. if ($params['image'] == '') {
  507. $params['image'] = 'https://dummyimage.com/205x128';
  508. }
  509. // 通过选择的期刊来绑定对应的主编
  510. if (!empty($params['journal'])) {
  511. $channel = Channel::get($params['journal']);
  512. if ($channel) {
  513. $params['chief_id'] = $channel['chief_id'];
  514. }
  515. }
  516. // 手稿状态日志
  517. $log = ManuscriptLog::where(['manuscript_id' => $params['id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
  518. if (!$log) {
  519. $log = new ManuscriptLog();
  520. $log->manuscript_id = $params['id'];
  521. $log->user_id = $this->auth->id;
  522. $log->type = 'user';
  523. }
  524. $log->status = $params['status'];
  525. $log->save();
  526. $result = $row->allowField(true)->save($params);
  527. Db::commit();
  528. } catch (ValidateException|PDOException|Exception $e) {
  529. Db::rollback();
  530. $this->error($e->getMessage());
  531. }
  532. if ($result === false) {
  533. $this->error('No rows were inserted');
  534. }
  535. }
  536. $this->success('Submit Success');
  537. }
  538. /**
  539. * 编辑、审稿人提交意见
  540. *
  541. * @return void
  542. */
  543. public function submit_comments()
  544. {
  545. $params = $this->request->post('row/a');
  546. $model = new Comments();
  547. Db::startTrans();
  548. try {
  549. $params['user_id'] = $this->auth->id;
  550. // 获取手稿
  551. $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find();
  552. if ($manuscript) {
  553. $manuscript['status'] = $params['status'];
  554. $manuscript->save();
  555. }
  556. if ($params['type'] != 'author') {
  557. $result = $model->allowField(true)->save($params);
  558. } else {
  559. // 如果是作者则先查询是否有审稿意见回复,如果有则进行更新操作
  560. $result = Comments::where(['manuscript_id' => $params['manuscript_id'], 'user_id' => $this->auth->id, 'type' => 'author'])->find();
  561. if ($result) {
  562. $result->comments = $params['comments'];
  563. $result->save();
  564. } else {
  565. $result = $model->allowField(true)->save($params);
  566. }
  567. }
  568. // 手稿状态日志
  569. $log = ManuscriptLog::where(['manuscript_id' => $params['manuscript_id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
  570. if (!$log) {
  571. $log = new ManuscriptLog();
  572. $log->manuscript_id = $params['manuscript_id'];
  573. $log->user_id = $this->auth->id;
  574. $log->type = 'user';
  575. }
  576. $log->status = $params['status'];
  577. $log->save();
  578. Db::commit();
  579. } catch (ValidateException|PDOException|Exception $e) {
  580. Db::rollback();
  581. $this->error($e->getMessage());
  582. }
  583. if ($result === false) {
  584. $this->error('No rows were inserted');
  585. }
  586. $this->success('Submit Success');
  587. }
  588. /**
  589. * 提交特刊
  590. *
  591. * @return void
  592. */
  593. public function submit_issue()
  594. {
  595. $params = $this->request->post('row/a');
  596. $result = false;
  597. Db::startTrans();
  598. try {
  599. $params['user_id'] = $this->auth->id;
  600. // 数组内容需转换为字符串
  601. $params['editor'] = json_encode($params['editor']);
  602. $model = new Issue();
  603. $result = $model->allowField(true)->save($params);
  604. Db::commit();
  605. } catch (ValidateException|PDOException|Exception $e) {
  606. Db::rollback();
  607. $this->error($e->getMessage());
  608. }
  609. if ($result === false) {
  610. $this->error('No rows were inserted');
  611. }
  612. $this->success('Submit Success');
  613. }
  614. /**
  615. * 编辑邀请审稿人提交操作
  616. *
  617. * @return void
  618. */
  619. public function submit_invite_reviewer()
  620. {
  621. $params = $this->request->post('row/a');
  622. $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find();
  623. $reviewers = $params['reviewer'];
  624. if (!$reviewers) $this->error('Please select reviewer');
  625. $result = false;
  626. Db::startTrans();
  627. try {
  628. $reviewer_id_arr = [];
  629. foreach ($reviewers as $reviewer) {
  630. $reviewer_id_arr[] = $reviewer['user_id'];
  631. $data = [];
  632. $data['role_id'] = $reviewer['id'];
  633. $data['editor_id'] = $this->auth->id;
  634. $data['manuscript_id'] = $params['manuscript_id'];
  635. // 删除所有关于这个期刊的审稿人信息
  636. $reviewer_old = InviteReviewer::where(['manuscript_id' => $params['manuscript_id']])->select();
  637. foreach ($reviewer_old as $item) {
  638. $item->delete();
  639. }
  640. $model = new InviteReviewer();
  641. $model->allowField(true)->save($data);
  642. }
  643. $reviewer_ids_arr = [];
  644. // 合并数组
  645. $merged_reviewer_ids_arr = array_merge($reviewer_ids_arr, $reviewer_id_arr);
  646. // 去重数组
  647. $unique_reviewer_ids_arr = array_filter(array_unique($merged_reviewer_ids_arr));
  648. $manuscript['reviewer_ids'] = implode(',', $unique_reviewer_ids_arr);
  649. $manuscript['status'] = $params['status'];
  650. $result = $manuscript->save();
  651. Db::commit();
  652. } catch (ValidateException|PDOException|Exception $e) {
  653. Db::rollback();
  654. $this->error($e->getMessage());
  655. }
  656. if ($result === false) {
  657. $this->error('No rows were inserted');
  658. }
  659. $this->success('Submit Success');
  660. }
  661. /**
  662. * 订阅邮箱
  663. *
  664. * @return void
  665. */
  666. public function email_subscription()
  667. {
  668. $email = $this->request->post('email');
  669. if (!$email) $this->error('Email cannot be empty');
  670. $old_email = Email::where(['email' => $email])->find();
  671. if ($old_email) $this->error('Email already exists');
  672. $result = false;
  673. Db::startTrans();
  674. try {
  675. $model = new Email();
  676. $result = $model->allowField(true)->save(['email' => $email, 'type' => 'journal', 'user_id' => $this->auth->id]);
  677. Db::commit();
  678. } catch (ValidateException|PDOException|Exception $e) {
  679. Db::rollback();
  680. $this->error($e->getMessage());
  681. }
  682. if ($result === false) {
  683. $this->error('No rows were inserted');
  684. }
  685. $this->success('Operation successful');
  686. }
  687. /**
  688. * 首页提交邮箱信息
  689. *
  690. * @return void
  691. */
  692. public function submit_email()
  693. {
  694. $params = $this->request->post();
  695. $email = $this->request->post('email');
  696. $value = $this->request->post('value');
  697. if (empty($email)) $this->error('Email cannot be empty');
  698. if (empty($value)) $this->error('The selected value cannot be empty');
  699. $model = new Email();
  700. Db::startTrans();
  701. try {
  702. $params['type'] = 'home';
  703. $params['user_id'] = $this->auth->id;
  704. $result = $model->allowField(true)->save($params);
  705. Db::commit();
  706. } catch (ValidateException|PDOException|Exception $e) {
  707. Db::rollback();
  708. $this->error($e->getMessage());
  709. }
  710. if ($result === false) {
  711. $this->error('Submit Error');
  712. }
  713. $this->success('Submit Success');
  714. }
  715. /**
  716. * 提交会议
  717. *
  718. * @return void
  719. */
  720. public function submit_conference()
  721. {
  722. if (!$this->auth->isLogin()) {
  723. $this->error("Please log in before proceeding", "index/user/login");
  724. }
  725. $params = $this->request->post('row/a');
  726. $captcha = $this->request->post('captcha');
  727. if (!captcha_check($captcha)) {
  728. $this->error("Incorrect verification code");
  729. }
  730. $model = new Conference();
  731. Db::startTrans();
  732. try {
  733. $params['user_id'] = $this->auth->id;
  734. $result = $model->allowField(true)->save($params);
  735. Db::commit();
  736. } catch (ValidateException|PDOException|Exception $e) {
  737. Db::rollback();
  738. $this->error($e->getMessage());
  739. }
  740. if ($result === false) {
  741. $this->error('Submit Error');
  742. }
  743. $this->success('Submit Success');
  744. }
  745. /**
  746. * 参与会议
  747. *
  748. * @return void
  749. */
  750. public function conference_participate()
  751. {
  752. $params = $this->request->post('row/a');
  753. $model = new Participate();
  754. Db::startTrans();
  755. try {
  756. $params['user_id'] = $this->auth->id;
  757. $result = $model->allowField(true)->save($params);
  758. Db::commit();
  759. } catch (ValidateException|PDOException|Exception $e) {
  760. Db::rollback();
  761. $this->error($e->getMessage());
  762. }
  763. if ($result === false) {
  764. $this->error('Submit Error');
  765. }
  766. $this->success('Submit Success');
  767. }
  768. /**
  769. * 提交作者服务
  770. *
  771. * @return void
  772. */
  773. public function submit_author_service()
  774. {
  775. $params = $this->request->post();
  776. $model = new AuthorService();
  777. Db::startTrans();
  778. try {
  779. $params['user_id'] = $this->auth->id;
  780. $result = $model->allowField(true)->save($params);
  781. Db::commit();
  782. } catch (ValidateException|PDOException|Exception $e) {
  783. Db::rollback();
  784. $this->error($e->getMessage());
  785. }
  786. if ($result === false) {
  787. $this->error('Submit Error');
  788. }
  789. $this->success('Submit Success');
  790. }
  791. /**
  792. * 已读邮件
  793. *
  794. * @return void
  795. * @throws \think\db\exception\DataNotFoundException
  796. * @throws \think\db\exception\ModelNotFoundException
  797. * @throws \think\exception\DbException
  798. */
  799. public function read_email()
  800. {
  801. $params = $this->request->post();
  802. if ($params['email_id']) {
  803. $email_content = EmailContent::where(['id' => $params['email_id']])->find();
  804. Db::startTrans();
  805. try {
  806. if ($email_content) {
  807. $email_content->status = 'normal';
  808. $result = $email_content->save();;
  809. }
  810. Db::commit();
  811. } catch (ValidateException|PDOException|Exception $e) {
  812. Db::rollback();
  813. $this->error($e->getMessage());
  814. }
  815. }
  816. if ($result === false) {
  817. $this->error('Submit Error');
  818. }
  819. $this->success('Success');
  820. }
  821. /**
  822. * 提交手稿(未全部提交)
  823. *
  824. * @return void
  825. */
  826. public function incomplete_submit()
  827. {
  828. $params = $this->request->post('row/a');
  829. // 数组内容需转换为字符串
  830. if (array_key_exists('author', $params) && !empty($params['author'])) {
  831. $params['author_content'] = json_encode($params['author']);
  832. }
  833. if (array_key_exists('reviewer', $params) && !empty($params['reviewer'])) {
  834. $params['review_content'] = json_encode($params['reviewer']);
  835. }
  836. if (empty($params['title'])) {
  837. $params['title'] = 'Incomplete editing' . rand(0, 4);
  838. }
  839. if (empty($params['image'])) {
  840. $params['image'] = 'https://dummyimage.com/205x128';
  841. }
  842. $params['status'] = 'incomplete_submission';
  843. $params['user_id'] = $this->auth->id;
  844. // 因使用create方法返回自增id,但是验证字段有前端自定义字段所以需要删除
  845. unset($params['author']);
  846. unset($params['reviewer']);
  847. $manuscript = new AuthorManuscript();
  848. Db::startTrans();
  849. try {
  850. if (!empty($params['id'])) {
  851. $manuscript = AuthorManuscript::where(['id' => $params['id']])->find();
  852. $manuscript = $manuscript->allowField(true)->save($params);
  853. } else {
  854. $manuscript = $manuscript->allowField(true)->create($params);
  855. }
  856. // 手稿状态日志
  857. $log = ManuscriptLog::where(['manuscript_id' => $params['id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
  858. if (!$log) {
  859. $log = new ManuscriptLog();
  860. $log->manuscript_id = $params['id'];
  861. $log->user_id = $this->auth->id;
  862. $log->type = 'user';
  863. }
  864. $log->status = $params['status'];
  865. $log->save();
  866. Db::commit();
  867. } catch (ValidateException|PDOException|Exception $e) {
  868. Db::rollback();
  869. $this->error($e->getMessage());
  870. }
  871. $this->success('Success', $manuscript->id ?? $params['id']);
  872. }
  873. /**
  874. * 发送邮件
  875. *
  876. * @return void
  877. * @throws \think\db\exception\DataNotFoundException
  878. * @throws \think\db\exception\ModelNotFoundException
  879. * @throws \think\exception\DbException
  880. */
  881. public function send_email()
  882. {
  883. $params = $this->request->post('row/a');
  884. $option = [
  885. 'mail_smtp_host' => $this->auth->mail_smtp_host,
  886. 'mail_smtp_port' => $this->auth->mail_smtp_port,
  887. 'mail_smtp_user' => $this->auth->mail_smtp_user,
  888. 'mail_smtp_pass' => $this->auth->mail_smtp_pass,
  889. 'mail_from' => $this->auth->mail_smtp_user,
  890. ];
  891. $email = new \app\common\library\Email($option);
  892. $result = $email
  893. ->to($params['send_user_email'])
  894. ->subject($params['title'])
  895. ->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . $params['content'] . '</div>')
  896. ->send();
  897. Db::startTrans();
  898. try {
  899. $receiver_user = \app\admin\model\User::where(['email' => $params['send_user_email']])->find();
  900. $params['type'] = 'user';
  901. $params['user_id'] = $this->auth->id;
  902. $params['receiver_id'] = $receiver_user['id'];
  903. $params['email'] = $params['send_user_email'];
  904. $email_model = new EmailContent();
  905. $result = $email_model->allowField(true)->save($params);
  906. Db::commit();
  907. } catch (ValidateException|PDOException|Exception $e) {
  908. Db::rollback();
  909. $this->error($e->getMessage());
  910. }
  911. if (false === $result) {
  912. $this->error(__('No rows were updated'));
  913. }
  914. $this->success('Successfully sent');
  915. }
  916. /**
  917. * 邀请编辑
  918. *
  919. * @return void
  920. * @throws \think\exception\DbException
  921. */
  922. public function invite_editor()
  923. {
  924. $params = $this->request->post('row/a');
  925. $row = AuthorManuscript::get($params['manuscript_id']);
  926. Db::startTrans();
  927. try {
  928. if ($row) {
  929. $row['editor_ids'] = $params['editor_ids'];
  930. $row->save();
  931. }
  932. Db::commit();
  933. } catch (ValidateException|PDOException|Exception $e) {
  934. Db::rollback();
  935. $this->error($e->getMessage());
  936. }
  937. $this->success('Successfully');
  938. }
  939. }