User.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. <?php
  2. namespace app\index\controller;
  3. use addons\wechat\model\WechatCaptcha;
  4. use app\admin\model\Admin;
  5. use app\admin\model\cms\AuthorManuscript;
  6. use app\admin\model\cms\Channel;
  7. use app\admin\model\cms\Comment;
  8. use app\admin\model\cms\Comments;
  9. use app\admin\model\cms\InviteReviewer;
  10. use app\admin\model\cms\Issue;
  11. use app\admin\model\cms\Participate;
  12. use app\admin\model\EmailContent;
  13. use app\common\controller\Frontend;
  14. use app\common\library\Ems;
  15. use app\common\library\Sms;
  16. use app\common\model\Attachment;
  17. use app\common\model\UserRoleContent;
  18. use app\common\model\UserRoleLog;
  19. use app\manytenant\model\Manytenant;
  20. use think\Config;
  21. use think\Cookie;
  22. use think\Db;
  23. use think\Hook;
  24. use think\Session;
  25. use think\Validate;
  26. /**
  27. * 会员中心
  28. */
  29. class User extends Frontend
  30. {
  31. protected $layout = 'default';
  32. protected $noNeedLogin = ['login', 'register', 'third', 'jump'];
  33. protected $noNeedRight = ['*'];
  34. public function _initialize()
  35. {
  36. parent::_initialize();
  37. $auth = $this->auth;
  38. if (!Config::get('fastadmin.usercenter')) {
  39. $this->error(__('User center already closed'), '/');
  40. }
  41. //监听注册登录退出的事件
  42. Hook::add('user_login_successed', function ($user) use ($auth) {
  43. $expire = input('post.keeplogin') ? 30 * 86400 : 0;
  44. Cookie::set('uid', $user->id, $expire);
  45. Cookie::set('token', $auth->getToken(), $expire);
  46. });
  47. Hook::add('user_register_successed', function ($user) use ($auth) {
  48. Cookie::set('uid', $user->id);
  49. Cookie::set('token', $auth->getToken());
  50. });
  51. Hook::add('user_delete_successed', function ($user) use ($auth) {
  52. Cookie::delete('uid');
  53. Cookie::delete('token');
  54. });
  55. Hook::add('user_logout_successed', function ($user) use ($auth) {
  56. Cookie::delete('uid');
  57. Cookie::delete('token');
  58. });
  59. }
  60. /**
  61. * 会员中心
  62. */
  63. public function index()
  64. {
  65. $this->view->assign('title', __('User center'));
  66. return $this->view->fetch();
  67. }
  68. /**
  69. * 注册会员
  70. */
  71. public function register()
  72. {
  73. $url = $this->request->request('url', '', 'trim');
  74. if ($this->auth->id) {
  75. $this->success('You\'ve logged in, do not login again', $url ? $url : url('user/index'));
  76. }
  77. if ($this->request->isPost()) {
  78. $username = $this->request->post('username');
  79. $password = $this->request->post('password');
  80. $password_confirm = $this->request->post('password_confirm');
  81. // 判断密码是否一致
  82. if ($password != $password_confirm) {
  83. $this->error('Inconsistent password input', null, ['token' => $this->request->token()]);
  84. }
  85. $email = $this->request->post('email');
  86. $mobile = $this->request->post('mobile', '');
  87. $token = $this->request->post('__token__');
  88. $rule = [
  89. 'username' => 'require|length:3,30',
  90. 'password' => 'require|length:6,30',
  91. '__token__' => 'require|token',
  92. ];
  93. $msg = [
  94. 'username.require' => 'Username can not be empty',
  95. 'username.length' => 'Username must be 3 to 30 characters',
  96. 'password.require' => 'Password can not be empty',
  97. 'password.length' => 'Password must be 6 to 30 characters',
  98. ];
  99. $data = [
  100. 'username' => $username,
  101. 'password' => $password,
  102. 'email' => $email,
  103. 'mobile' => $mobile,
  104. '__token__' => $token,
  105. ];
  106. $validate = new Validate($rule, $msg);
  107. $result = $validate->check($data);
  108. if (!$result) {
  109. $this->error($validate->getError(), null, ['token' => $this->request->token()]);
  110. }
  111. if ($this->auth->register($username, $password)) {
  112. $this->success('Registration successful, please go to the corresponding email to check and verify', $url ? $url : url('user/login'));
  113. } else {
  114. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  115. }
  116. }
  117. //判断来源
  118. $referer = $this->request->server('HTTP_REFERER');
  119. if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
  120. && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
  121. $url = $referer;
  122. }
  123. $this->view->assign('url', $url);
  124. $this->view->assign('title', 'Register');
  125. return $this->view->fetch();
  126. }
  127. /**
  128. * 会员登录
  129. */
  130. public function login()
  131. {
  132. $url = $this->request->request('url', '', 'trim');
  133. if ($this->auth->id) {
  134. $this->success('You\'ve logged in, do not login again', $url ? $url : url('user/index'));
  135. }
  136. if ($this->request->isPost()) {
  137. $account = $this->request->post('account');
  138. $password = $this->request->post('password');
  139. $keeplogin = (int)$this->request->post('keeplogin');
  140. $token = $this->request->post('__token__');
  141. $rule = [
  142. 'account' => 'require|length:3,50',
  143. 'password' => 'require|length:6,30',
  144. '__token__' => 'require|token',
  145. ];
  146. $msg = [
  147. 'account.require' => 'Account can not be empty',
  148. 'account.length' => 'Account must be 3 to 50 characters',
  149. 'password.require' => 'Password can not be empty',
  150. 'password.length' => 'Password must be 6 to 30 characters',
  151. ];
  152. $data = [
  153. 'account' => $account,
  154. 'password' => $password,
  155. '__token__' => $token,
  156. ];
  157. $validate = new Validate($rule, $msg);
  158. $result = $validate->check($data);
  159. if (!$result) {
  160. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  161. return false;
  162. }
  163. if ($this->auth->login($account, $password)) {
  164. // $this->success('Logged in successful', $url ? $url : url('user/index'));
  165. $this->success('Logged in successful', url('/'));
  166. } else {
  167. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  168. }
  169. }
  170. //判断来源
  171. $referer = $this->request->server('HTTP_REFERER');
  172. if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
  173. && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
  174. $url = $referer;
  175. }
  176. $this->view->assign('url', $url);
  177. $this->view->assign('title', __('Login'));
  178. return $this->view->fetch();
  179. }
  180. /**
  181. * 退出登录
  182. */
  183. public function logout()
  184. {
  185. if ($this->request->isPost()) {
  186. $this->token();
  187. //退出本站
  188. $this->auth->logout();
  189. // $this->success(__('Logout successful'), url('user/index'));
  190. // $this->success('Logout successful', url('/'));
  191. $this->redirect(url('user/jump'));
  192. }
  193. $html = "<form id='logout_submit' name='logout_submit' action='' method='post'>" . token() . "<input type='submit' value='ok' style='display:none;'></form>";
  194. $html .= "<script>document.forms['logout_submit'].submit();</script>";
  195. return $html;
  196. }
  197. /**
  198. * 退出登录
  199. *
  200. * @return string
  201. * @throws \think\Exception
  202. */
  203. public function jump()
  204. {
  205. $this->view->assign('title', 'Logout out');
  206. return $this->view->fetch();
  207. }
  208. /**
  209. * 个人信息
  210. */
  211. public function profile()
  212. {
  213. $this->view->assign('title', __('Profile'));
  214. return $this->view->fetch();
  215. }
  216. /**
  217. * 修改密码
  218. */
  219. public function changepwd()
  220. {
  221. if ($this->request->isPost()) {
  222. $oldpassword = $this->request->post("oldpassword");
  223. $newpassword = $this->request->post("newpassword");
  224. $renewpassword = $this->request->post("renewpassword");
  225. $token = $this->request->post('__token__');
  226. $rule = [
  227. 'oldpassword' => 'require|regex:\S{6,30}',
  228. 'newpassword' => 'require|regex:\S{6,30}',
  229. 'renewpassword' => 'require|regex:\S{6,30}|confirm:newpassword',
  230. '__token__' => 'token',
  231. ];
  232. $msg = [
  233. 'renewpassword.confirm' => __('Password and confirm password don\'t match')
  234. ];
  235. $data = [
  236. 'oldpassword' => $oldpassword,
  237. 'newpassword' => $newpassword,
  238. 'renewpassword' => $renewpassword,
  239. '__token__' => $token,
  240. ];
  241. $field = [
  242. 'oldpassword' => __('Old password'),
  243. 'newpassword' => __('New password'),
  244. 'renewpassword' => __('Renew password')
  245. ];
  246. $validate = new Validate($rule, $msg, $field);
  247. $result = $validate->check($data);
  248. if (!$result) {
  249. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  250. return false;
  251. }
  252. $ret = $this->auth->changepwd($newpassword, $oldpassword);
  253. if ($ret) {
  254. $this->success(__('Reset password successful'), url('user/login'));
  255. } else {
  256. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  257. }
  258. }
  259. $this->view->assign('title', __('Change password'));
  260. return $this->view->fetch();
  261. }
  262. public function attachment()
  263. {
  264. //设置过滤方法
  265. $this->request->filter(['strip_tags']);
  266. if ($this->request->isAjax()) {
  267. $mimetypeQuery = [];
  268. $where = [];
  269. $filter = $this->request->request('filter');
  270. $filterArr = (array)json_decode($filter, true);
  271. if (isset($filterArr['mimetype']) && preg_match("/(\/|\,|\*)/", $filterArr['mimetype'])) {
  272. $this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['mimetype' => '']))]);
  273. $mimetypeQuery = function ($query) use ($filterArr) {
  274. $mimetypeArr = array_filter(explode(',', $filterArr['mimetype']));
  275. foreach ($mimetypeArr as $index => $item) {
  276. $query->whereOr('mimetype', 'like', '%' . str_replace("/*", "/", $item) . '%');
  277. }
  278. };
  279. } elseif (isset($filterArr['mimetype'])) {
  280. $where['mimetype'] = ['like', '%' . $filterArr['mimetype'] . '%'];
  281. }
  282. if (isset($filterArr['filename'])) {
  283. $where['filename'] = ['like', '%' . $filterArr['filename'] . '%'];
  284. }
  285. if (isset($filterArr['createtime'])) {
  286. $timeArr = explode(' - ', $filterArr['createtime']);
  287. $where['createtime'] = ['between', [strtotime($timeArr[0]), strtotime($timeArr[1])]];
  288. }
  289. $search = $this->request->get('search');
  290. if ($search) {
  291. $where['filename'] = ['like', '%' . $search . '%'];
  292. }
  293. $model = new Attachment();
  294. $offset = $this->request->get("offset", 0);
  295. $limit = $this->request->get("limit", 0);
  296. $total = $model
  297. ->where($where)
  298. ->where($mimetypeQuery)
  299. ->where('user_id', $this->auth->id)
  300. ->order("id", "DESC")
  301. ->count();
  302. $list = $model
  303. ->where($where)
  304. ->where($mimetypeQuery)
  305. ->where('user_id', $this->auth->id)
  306. ->order("id", "DESC")
  307. ->limit($offset, $limit)
  308. ->select();
  309. $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
  310. foreach ($list as $k => &$v) {
  311. $v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
  312. }
  313. unset($v);
  314. $result = array("total" => $total, "rows" => $list);
  315. return json($result);
  316. }
  317. $mimetype = $this->request->get('mimetype', '');
  318. $mimetype = substr($mimetype, -1) === '/' ? $mimetype . '*' : $mimetype;
  319. $this->view->assign('mimetype', $mimetype);
  320. $this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
  321. return $this->view->fetch();
  322. }
  323. /**
  324. * 我的个人主页
  325. */
  326. public function homepage()
  327. {
  328. $this->view->assign('title', 'My Personal Homepage');
  329. return $this->view->fetch();
  330. }
  331. /**
  332. * 我得邮箱页
  333. */
  334. public function inbox()
  335. {
  336. // 获取当前用户的邮箱内容信息
  337. $email_contents = EmailContent::where(['email' => $this->auth->email])->paginate();
  338. foreach ($email_contents as $content) {
  339. $content['user'] = \app\admin\model\User::where(['id' => $content['user_id']])->find();
  340. if ($content['type'] == 'admin') {
  341. $content['user'] = Admin::where(['id' => $content['user_id']])->find();
  342. }
  343. $content['createtime'] = date('Y-m-d', $content['createtime']);
  344. if ($content['status'] == 'normal') {
  345. $content['status'] = 'READ';
  346. } else {
  347. $content['status'] = 'Unread';
  348. }
  349. }
  350. $this->view->assign('list', $email_contents);
  351. $this->view->assign('title', 'INBOX');
  352. return $this->view->fetch();
  353. }
  354. /**
  355. * 我的未读邮件页
  356. */
  357. public function unread()
  358. {
  359. // 获取当前用户的邮箱内容信息
  360. $email_contents = EmailContent::where(['email' => $this->auth->email, 'status' => 'hidden'])->paginate();
  361. foreach ($email_contents as $content) {
  362. $content['user'] = \app\admin\model\User::where(['id' => $content['user_id']])->find();
  363. if ($content['type'] == 'admin') {
  364. $content['user'] = Admin::where(['id' => $content['user_id']])->find();
  365. }
  366. $content['createtime'] = date('Y-m-d', $content['createtime']);
  367. $content['status'] = 'Unread';
  368. }
  369. $this->view->assign('list', $email_contents);
  370. $this->view->assign('title', 'Unread');
  371. return $this->view->fetch();
  372. }
  373. /**
  374. * 提交手稿
  375. */
  376. public function submit_manuscript($id = null)
  377. {
  378. $row = [
  379. 'id' => '',
  380. 'manuscript_zip' => '',
  381. 'manuscript_pdf' => '',
  382. 'cover_letter' => '',
  383. 'graphical_abstract' => '',
  384. 'non_material' => '',
  385. 'is_copyright' => '',
  386. 'copyright_files' => '',
  387. 'image' => '',
  388. 'journal' => '',
  389. 'article_type' => '',
  390. 'title' => '',
  391. 'abstract' => '',
  392. 'keywords' => '',
  393. 'number_page' => '',
  394. 'is_funding' => '',
  395. 'funding_content' => '',
  396. 'is_interest' => '',
  397. 'interest_content' => '',
  398. 'statement_type' => '',
  399. 'article_one' => '',
  400. 'article_two' => '',
  401. 'article_three' => '',
  402. 'country' => '',
  403. 'affiliation' => '',
  404. 'name' => '',
  405. 'invoice_email' => '',
  406. 'order_email' => '',
  407. 'address' => '',
  408. 'zip_code' => '',
  409. 'city' => '',
  410. 'telephone' => '',
  411. 'fax' => '',
  412. 'vat' => '',
  413. ];
  414. $id = $this->request->param('id');
  415. if ($id) {
  416. $row = AuthorManuscript::where(['id' => $id])->find();
  417. $row->author_content = json_decode($row->author_content, true);
  418. $row->review_content = json_decode($row->review_content, true);
  419. }
  420. $this->view->assign('row', $row);
  421. $this->view->assign('title', 'Submit Manuscript');
  422. return $this->view->fetch();
  423. }
  424. /**
  425. * 手稿状态
  426. */
  427. public function display_submitted()
  428. {
  429. // 构建分页参数
  430. $limit = $this->request->param('limit', 10);
  431. $status = $this->request->param('status', 'all');
  432. $where = [];
  433. if ($status != 'all') {
  434. $where = ['status' => $status];
  435. }
  436. // 查询当前用户手稿
  437. $manuscripts = AuthorManuscript::where(['user_id' => $this->auth->id])
  438. ->where($where)
  439. ->field('id,title,image,createtime,journal,status')
  440. ->order('createtime', 'DESC')
  441. ->paginate($limit);
  442. $author_edit_status = config('site.author_edit_status');
  443. $author_comments_status = config('site.author_comments_status');
  444. foreach ($manuscripts as $manuscript) {
  445. $manuscript['journal'] = Channel::where(['id' => $manuscript['journal']])->value('name');
  446. $manuscript['is_edit'] = false;
  447. $manuscript['is_comments'] = false;
  448. if (in_array($manuscript['status'], $author_edit_status)) {
  449. $manuscript['is_edit'] = true;
  450. }
  451. if (in_array($manuscript['status'], $author_comments_status)) {
  452. $manuscript['is_comments'] = true;
  453. }
  454. }
  455. if ($this->request->isAjax()) {
  456. $keyword = $this->request->param('keyword');
  457. $manuscripts = AuthorManuscript::where(['user_id' => $this->auth->id])
  458. ->where(function ($query) use ($keyword, $status) {
  459. if ($status != 'all') {
  460. return $query->where(['status' => $status]);
  461. }
  462. if ($keyword != '') {
  463. return $query->where(['title' => ['like', '%'. $keyword .'%']]);
  464. }
  465. })->field('id,title,image,createtime,journal,status')
  466. ->order('createtime', 'DESC')
  467. ->paginate($limit);
  468. foreach ($manuscripts as $manuscript) {
  469. $manuscript['createtime'] = date('Y-m-d', $manuscript['createtime']);
  470. $manuscript['journal'] = Channel::where(['id' => $manuscript['journal']])->value('name') ?? '';
  471. $manuscript['is_edit'] = false;
  472. $manuscript['is_comments'] = false;
  473. if (in_array($manuscript['status'], $author_edit_status)) {
  474. $manuscript['is_edit'] = true;
  475. }
  476. if (in_array($manuscript['status'], $author_comments_status)) {
  477. $manuscript['is_comments'] = true;
  478. }
  479. }
  480. $this->success('', '', $manuscripts);
  481. }
  482. $this->view->assign('status', $status);
  483. $this->view->assign('list', $manuscripts);
  484. $this->view->assign('title', 'Dispaly Submitted');
  485. return $this->view->fetch();
  486. }
  487. /**
  488. * 审核人信息
  489. */
  490. public function reviewer_information()
  491. {
  492. $user_role = UserRoleLog::where(['user_id' => $this->auth->id, 'type' => 'review', 'is_adopt' => ['in', ['review', 'fault']]])->order('createtime', 'DESC')->find();
  493. $user_content = UserRoleContent::where(['user_id' => $this->auth->id, 'type' => 'review'])->find();
  494. if (empty($user_content)) {
  495. $user_content['field'] = '';
  496. $user_content['degree'] = '';
  497. $user_content['affiliation'] = '';
  498. $user_content['publication'] = '';
  499. $user_content['orcid'] = '';
  500. $user_content['homepage'] = '';
  501. $user_content['review_journal'] = '';
  502. $user_content['interested_journal'] = '';
  503. $user_content['resume'] = '';
  504. $user_content['journal_ids'] = '';
  505. }
  506. $this->view->assign('row', $user_content);
  507. $this->view->assign('user_role', $user_role);
  508. $this->view->assign('title', 'Reviewer Information');
  509. return $this->view->fetch();
  510. }
  511. /**
  512. * 审阅的手稿
  513. */
  514. public function show_reviewed_manuscripts()
  515. {
  516. $limit = $this->request->param('limit', 10);
  517. $status = $this->request->param('status', 'comment_submission');
  518. $where = ['status' => $status];
  519. // 查询当前用户手稿
  520. $manuscripts = AuthorManuscript::whereRaw("FIND_IN_SET(". $this->auth->id .", `reviewer_ids`)")
  521. ->where($where)
  522. ->field('id,title,image,createtime,journal')
  523. ->order('createtime', 'DESC')
  524. ->paginate($limit);
  525. foreach ($manuscripts as $manuscript) {
  526. $manuscript['journal'] = Channel::where(['id' => $manuscript['journal']])->value('name');
  527. }
  528. if ($this->request->isAjax()) {
  529. $keyword = $this->request->param('keyword');
  530. $manuscripts = AuthorManuscript::where(['title' => ['like', '%'. $keyword .'%'], 'status' => $status])
  531. ->whereRaw("FIND_IN_SET(". $this->auth->id .", `reviewer_ids`)")
  532. ->field('id,title,image,createtime,journal')
  533. ->order('createtime', 'DESC')
  534. ->paginate($limit);
  535. foreach ($manuscripts as $manuscript) {
  536. $manuscript['createtime'] = date('Y-m-d', $manuscript['createtime']);
  537. $manuscript['journal'] = Channel::where(['id' => $manuscript['journal']])->value('name') ?? '';
  538. }
  539. $this->success('', '', $manuscripts);
  540. }
  541. $this->view->assign('status', $status);
  542. $this->view->assign('list', $manuscripts);
  543. $this->view->assign('title', 'Show Reviewed Manuscripts');
  544. return $this->view->fetch();
  545. }
  546. /**
  547. * 手稿详情
  548. */
  549. public function article_details($id = null)
  550. {
  551. $id = $this->request->param('id');
  552. $type = $this->request->param('type');
  553. $status = $this->request->param('status', 'reviewer_details');
  554. $row = AuthorManuscript::where(['id' => $id])->find();
  555. $row['review_content'] = json_decode($row['review_content'], true);
  556. if ($row) {
  557. $row['keywords'] = explode(',', $row['keywords']);
  558. }
  559. // 判断是审稿人还是编辑,如果是编辑则可以看到全部意见
  560. $comments = Comments::where(['manuscript_id' => $row['id']])->select();
  561. if ($type == 'reviewer') {
  562. $comments = Comments::where(['manuscript_id' => $row['id'], 'type' => 'reviewer'])->select();
  563. }
  564. if ($type == 'editor') {
  565. $reviewers = InviteReviewer::where(['manuscript_id' => $row['id']])->select();
  566. // 邀请的审稿人信息
  567. if ($status == 'reviewer_details') {
  568. foreach ($reviewers as $reviewer) {
  569. $reviewer_role = UserRoleContent::where(['id' => $reviewer['role_id']])->find();
  570. if ($reviewer_role) {
  571. // 查询审稿人提交意见信息
  572. $reviewer_comment = Comments::where(['user_id' => $reviewer_role['user_id'], 'manuscript_id' => $row['id']])
  573. ->order('createtime', 'DESC')
  574. ->find();
  575. $reviewer_user = \app\admin\model\User::where(['id' => $reviewer_role['user_id']])->find();
  576. if ($reviewer_comment) {
  577. $reviewer['reply_time'] = date('Y-m-d', $reviewer_comment['createtime'] ?? time());
  578. $reviewer['submission_time'] = date('Y-m-d', $reviewer_comment['createtime'] ?? time());
  579. $reviewer['status'] = $reviewer_comment['recommendation'] ?? '';
  580. }
  581. }
  582. $reviewer['nickname'] = $reviewer_user['nickname'];
  583. $reviewer['invited_time'] = date('Y-m-d', $reviewer['createtime']);
  584. }
  585. }
  586. // 审稿人信息
  587. if ($status == 'reviewer_suggestion') {
  588. foreach ($reviewers as $reviewer) {
  589. $reviewer_role = UserRoleContent::where(['id' => $reviewer['role_id']])->find();
  590. if ($reviewer_role) {
  591. // 查询审稿人提交意见数量
  592. $reviewer_comment_num = Comments::where(['user_id' => $reviewer_role['user_id'], 'manuscript_id' => $row['id']])
  593. ->count();
  594. $reviewer_user = \app\admin\model\User::where(['id' => $reviewer_role['user_id']])->find();
  595. }
  596. $reviewer['nickname'] = $reviewer_user['nickname'];
  597. $reviewer['affiliation'] = $reviewer_role['affiliation'];
  598. $reviewer['comment_num'] = $reviewer_comment_num;
  599. }
  600. }
  601. // 审稿人意见信息
  602. if ($status == 'review_report') {
  603. foreach ($reviewers as $reviewer) {
  604. $reviewer_role = UserRoleContent::where(['id' => $reviewer['role_id']])->find();
  605. if ($reviewer_role) {
  606. // 查询审稿人提交意见信息
  607. $reviewer_comment = Comments::where(['user_id' => $reviewer_role['user_id'], 'manuscript_id' => $row['id']])
  608. ->order('createtime', 'DESC')
  609. ->find();
  610. $reviewer_user = \app\admin\model\User::where(['id' => $reviewer_role['user_id']])->find();
  611. }
  612. $reviewer['nickname'] = $reviewer_user['nickname'];
  613. $reviewer['recommendation'] = $reviewer_comment['recommendation'];
  614. $reviewer['comment'] = $reviewer_comment['comments'];
  615. $reviewer['createtime'] = date('Y-m-d', $reviewer_comment['createtime']);
  616. }
  617. }
  618. if ($status == 'author_report') {
  619. // 查询作者提交意见信息回复
  620. $author_comment = Comments::where(['user_id' => $row['user_id'], 'manuscript_id' => $row['id'], 'type' => 'author'])
  621. ->order('createtime', 'DESC')
  622. ->find();
  623. if ($author_comment) {
  624. $author_user = \app\admin\model\User::where(['id' => $row['user_id']])->find();
  625. $author['nickname'] = $author_user['nickname'] ?? '';
  626. $author['comment'] = $author_comment['comments'] ?? '';
  627. $author['createtime'] = date('Y-m-d', $author_comment['createtime']);
  628. }
  629. }
  630. $row['reviewer'] = $reviewers;
  631. $row['author'] = $author ?? [];
  632. }
  633. $row['comments'] = $comments ?? [];
  634. $this->view->assign('status', $status);
  635. $this->view->assign('row', $row);
  636. $this->view->assign('type', $type);
  637. $this->view->assign('title', 'Article Details');
  638. return $this->view->fetch();
  639. }
  640. /**
  641. * 审稿页面
  642. */
  643. public function conduct_review($id = null)
  644. {
  645. $id = $this->request->param('id');
  646. $type = $this->request->param('type');
  647. $row = Comments::where(['manuscript_id' => $id, 'type' => $type])->find();
  648. $manuscript = AuthorManuscript::where(['id' => $id])->find();
  649. $this->view->assign('row', $row);
  650. $this->view->assign('manuscript', $manuscript);
  651. $this->view->assign('id', $id);
  652. $this->view->assign('type', $type);
  653. $this->view->assign('title', 'Conduct Review');
  654. return $this->view->fetch();
  655. }
  656. /**
  657. * 申请创建特刊
  658. */
  659. public function special_issue($id = null)
  660. {
  661. $special_issue = [
  662. 'image' => '',
  663. 'journal' => '',
  664. 'issue_name' => '',
  665. 'proposal_text' => '',
  666. 'publication_cycle' => '',
  667. 'editor' => '',
  668. 'statement_type' => '',
  669. ];
  670. if ($id) {
  671. $special_issue = Issue::where(['id' => $id])->find();
  672. $special_issue->editor = json_decode($special_issue['editor']);
  673. }
  674. $this->view->assign('row', $special_issue);
  675. $this->view->assign('title', 'Apply to creat a special issue');
  676. return $this->view->fetch();
  677. }
  678. /**
  679. * 申请成为编辑
  680. */
  681. public function become_an_editor()
  682. {
  683. $user_content = UserRoleContent::where(['user_id' => $this->auth->id, 'type' => ['in', ['editor', 'chief']]])->find();
  684. $user = \app\common\model\User::get($this->auth->id);
  685. // 因为是主编和编辑共用一个页面所以只查询这两个角色下最后一个申请记录就可以
  686. $user_role_log = UserRoleLog::where(['user_id' => $this->auth->id, 'type' => ['in', ['editor', 'chief']]])->order('createtime', 'DESC')->find();
  687. if (empty($user_content)) {
  688. $user_content['degree'] = '';
  689. $user_content['affiliation'] = '';
  690. $user_content['publication'] = '';
  691. $user_content['orcid'] = '';
  692. $user_content['homepage'] = '';
  693. $user_content['review_journal'] = '';
  694. $user_content['interested_journal'] = '';
  695. $user_content['resume'] = '';
  696. $user_content['journal_ids'] = '';
  697. $user_content['is_chief'] = '';
  698. $user_content['is_editor'] = '';
  699. } else {
  700. $user_content['is_chief'] = $user['is_chief'];
  701. $user_content['is_editor'] = $user['is_editor'];
  702. }
  703. $this->view->assign('row', $user_content);
  704. $this->view->assign('user_role', $user_role_log);
  705. $this->view->assign('user', $user);
  706. $this->view->assign('title', 'Apply to become an editor');
  707. return $this->view->fetch();
  708. }
  709. /**
  710. * 编辑手稿
  711. */
  712. public function editing_manuscripts()
  713. {
  714. $limit = $this->request->param('limit', 10);
  715. $type = $this->request->param('type');
  716. $status = $this->request->param('status', 'all');
  717. $where = [];
  718. if ($status != 'all') {
  719. $where = ['status' => $status];
  720. }
  721. $user = $this->auth;
  722. // 查询当前用户手稿
  723. $manuscripts = AuthorManuscript::where(function ($query) use ($user) {
  724. if ($user->is_chief == 'correct') {
  725. $query->where(['chief_id' => $this->auth->id]);
  726. }
  727. if ($user->is_editor == 'correct') {
  728. $query->whereRaw("FIND_IN_SET(". $this->auth->id .", `editor_ids`)");
  729. }
  730. })->where($where)->field('id,title,image,createtime,journal')
  731. ->order('createtime', 'DESC')
  732. ->paginate($limit);
  733. foreach ($manuscripts as $manuscript) {
  734. $manuscript['journal'] = Channel::where(['id' => $manuscript['journal']])->value('name');
  735. }
  736. if ($this->request->isAjax()) {
  737. $keyword = $this->request->param('keyword');
  738. $manuscripts = AuthorManuscript::where(['title' => ['like', '%'. $keyword .'%']])->whereRaw("FIND_IN_SET(". $this->auth->id .", `editor_ids`)")->field('id,title,image,createtime,journal')->order('createtime', 'DESC')->paginate($limit);
  739. foreach ($manuscripts as $manuscript) {
  740. $manuscript['is_chief'] = false;
  741. $manuscript['createtime'] = date('Y-m-d', $manuscript['createtime']);
  742. $manuscript['journal'] = Channel::where(['id' => $manuscript['journal']])->value('name') ?? '';
  743. if ($this->auth->is_chief == 'correct') {
  744. $manuscript['is_chief'] = true;
  745. }
  746. }
  747. $this->success('', '', $manuscripts);
  748. }
  749. $this->view->assign('status', $status);
  750. $this->view->assign('type', $type);
  751. $this->view->assign('list', $manuscripts);
  752. $this->view->assign('title', 'Editing Manuscripts');
  753. return $this->view->fetch();
  754. }
  755. /**
  756. * 提交处理意见
  757. */
  758. public function handing_suggestions()
  759. {
  760. $id = $this->request->param('id');
  761. $type = $this->request->param('type');
  762. $row = Comments::where(['manuscript_id' => $id, 'type' => $type, 'user_id' => $this->auth->id])->find();
  763. $manuscript = AuthorManuscript::where(['id' => $id])->find();
  764. if (empty($row)) {
  765. $row['is_interest'] = '';
  766. }
  767. $this->view->assign('row', $row);
  768. $this->view->assign('manuscript', $manuscript);
  769. $this->view->assign('id', $id);
  770. $this->view->assign('type', $type);
  771. $this->view->assign('title', 'Submit Handing Suggestions');
  772. return $this->view->fetch();
  773. }
  774. /**
  775. * 邀请审稿人
  776. */
  777. public function invite_reviewers()
  778. {
  779. $id = $this->request->param('id');
  780. // 构建分页参数
  781. $limit = $this->request->param('limit', 10);
  782. $manuscript = AuthorManuscript::get($id);
  783. $manuscript_review_id_arr = explode(',', $manuscript['reviewer_ids']);
  784. $review_user_content = UserRoleContent::where(['user_id' => ['in', $manuscript_review_id_arr], 'type' => 'review'])->select();
  785. // 获取审稿人信息
  786. $review_id_arr = \app\common\model\User::where(['is_review' => 'correct', 'id' => ['not in', $manuscript->user_id]])->column('id');
  787. $list = UserRoleContent::with(['user'])->where(['user_id' => ['in', $review_id_arr], 'type' => 'review'])->select();
  788. // $list = UserRoleContent::with(['user'])->where(['user_id' => ['in', $review_id_arr], 'type' => 'review'])->paginate($limit);
  789. foreach ($list as $value) {
  790. $channel_name_arr = Channel::where(['id' => ['in', explode(',', $value['journal_ids'])]])->column('name');
  791. $value['journal'] = implode(',', $channel_name_arr);
  792. $value['is_checked'] = false;
  793. if (in_array($value['user_id'], $manuscript_review_id_arr)) {
  794. $value['is_checked'] = true;
  795. }
  796. }
  797. $this->view->assign('id', $id);
  798. $this->view->assign('list', $list);
  799. $this->view->assign('reviewer_user_content', $review_user_content);
  800. $this->view->assign('title', 'Invite Reviewers');
  801. return $this->view->fetch();
  802. }
  803. /**
  804. * 获取审稿人列表
  805. *
  806. * @return void
  807. * @throws \think\exception\DbException
  808. */
  809. public function getReviewerList()
  810. {
  811. // 构建分页参数
  812. $limit = $this->request->param('limit', 10);
  813. // 获取审稿人信息
  814. $review_id_arr = \app\common\model\User::where(['is_review' => 'correct'])->column('id');
  815. $data = UserRoleContent::with(['user'])->where(['user_id' => ['in', $review_id_arr], 'type' => 'review'])->paginate($limit);
  816. // 返回表格数据和分页信息
  817. $this->success('', '', $data);
  818. }
  819. /**
  820. * 提交会议
  821. *
  822. * @return string
  823. * @throws \think\Exception
  824. */
  825. public function submit_conference()
  826. {
  827. $this->view->assign('title', 'Submit Conference');
  828. return $this->view->fetch();
  829. }
  830. /**
  831. * 参加会议
  832. *
  833. * @return string
  834. * @throws \think\Exception
  835. */
  836. public function conference_participate()
  837. {
  838. $param = $this->request->param();
  839. $id = $param['id'];
  840. $row = Participate::where(['id' => $id])->find();
  841. $this->view->assign('id', $id);
  842. $this->view->assign('row', $row);
  843. $this->view->assign('title', 'Submit Conference');
  844. return $this->view->fetch();
  845. }
  846. /**
  847. * 特刊列表页
  848. *
  849. * @return string
  850. * @throws \think\Exception
  851. * @throws \think\exception\DbException
  852. */
  853. public function special_issue_list()
  854. {
  855. $status = $this->request->param('status', 'all');
  856. $where = ['user_id' => $this->auth->id];
  857. if ($status != 'all') {
  858. $where = ['status' => $status, 'user_id' => $this->auth->id];
  859. }
  860. if ($status == 'all') {
  861. unset($where['status']);
  862. }
  863. $special_issues = Issue::where($where)->order('createtime', 'DESC')->paginate();
  864. if ($this->request->isAjax()) {
  865. $keyword = $this->request->param('keyword');
  866. if ($status == 'all') {
  867. $status = '';
  868. }
  869. $special_issues = Issue::where(['user_id' => $this->auth->id, 'issue_name' => ['like', '%'. $keyword .'%']])
  870. ->where(function ($query) use ($status) {
  871. if ($status) {
  872. $query->where(['status' => $status]);
  873. }
  874. })->field('id,issue_name,image,createtime,journal')
  875. ->order('createtime', 'DESC')
  876. ->paginate();
  877. foreach ($special_issues as $special_issue) {
  878. $special_issue['createtime'] = date('Y-m-d', $special_issue['createtime']);
  879. $special_issue['journal'] = Channel::where(['id' => $special_issue['journal']])->value('name');
  880. }
  881. $this->success('', '', $special_issues);
  882. }
  883. foreach ($special_issues as $special_issue) {
  884. $special_issue['createtime'] = date('Y-m-d', $special_issue['createtime']);
  885. $special_issue['journal'] = Channel::where(['id' => $special_issue['journal']])->value('name');
  886. }
  887. $this->view->assign('status', $status);
  888. $this->view->assign('title', 'Special Issue List');
  889. $this->view->assign('list', $special_issues);
  890. return $this->view->fetch();
  891. }
  892. /**
  893. * 作者审稿意见
  894. *
  895. * @return string
  896. * @throws \think\Exception
  897. * @throws \think\db\exception\DataNotFoundException
  898. * @throws \think\db\exception\ModelNotFoundException
  899. * @throws \think\exception\DbException
  900. */
  901. public function review_comments()
  902. {
  903. $param = $this->request->param();
  904. $type = $param['type'];
  905. $row = Comments::where(['manuscript_id' => $param['id']])->find();
  906. $manuscript = AuthorManuscript::get($param['id']);
  907. if (empty($row)) {
  908. $row['manuscript_id'] = $param['id'];
  909. $row['comments'] = '';
  910. $row['status'] = $manuscript['status'];
  911. }
  912. $this->view->assign('row', $row);
  913. $this->view->assign('type', $type);
  914. return $this->view->fetch();
  915. }
  916. /**
  917. * 发送邮件列表
  918. *
  919. * @return string
  920. * @throws \think\Exception
  921. * @throws \think\exception\DbException
  922. */
  923. public function send_email()
  924. {
  925. $param = $this->request->param();
  926. $type = $param['type'];
  927. $row = AuthorManuscript::get($param['id']);
  928. // 身份是不同的则需要查询不同人的列表
  929. if ($type == 'author') {
  930. /** 审稿人 编辑 */
  931. $review_ids = explode(',', $row['reviewer_ids']);
  932. $editor_ids = explode(',', $row['editor_ids']);
  933. $user_arr = array_merge($review_ids, $editor_ids);
  934. $user_arr = array_unique($user_arr);
  935. }
  936. if ($type == 'reviewer') {
  937. /** 作者 编辑 */
  938. $editor_ids = explode(',', $row['editor_ids']);
  939. $author_ids = [$row['user_id']];
  940. $user_arr = array_merge($editor_ids, $author_ids);
  941. $user_arr = array_unique($user_arr);
  942. }
  943. if ($type == 'editor') {
  944. /** 作者 审稿人 */
  945. $author_ids = [$row['user_id']];
  946. $review_ids = explode(',', $row['reviewer_ids']);
  947. $user_arr = array_merge($review_ids, $author_ids);
  948. $user_arr = array_unique($user_arr);
  949. }
  950. $user_list = \app\admin\model\User::where(['id' => ['in', $user_arr]])->column('email', 'id');
  951. $this->view->assign('type', $type);
  952. $this->view->assign('user_list', $user_list);
  953. $this->view->assign('row', $row);
  954. $this->view->assign('mail_smtp_host', $this->auth->mail_smtp_host);
  955. $this->view->assign('mail_smtp_port', $this->auth->mail_smtp_port);
  956. $this->view->assign('mail_smtp_user', $this->auth->mail_smtp_user);
  957. $this->view->assign('mail_smtp_pass', $this->auth->mail_smtp_pass);
  958. $this->view->assign('title', 'Send Email');
  959. return $this->view->fetch();
  960. }
  961. /**
  962. * 邀请编辑页
  963. *
  964. * @return string
  965. * @throws \think\Exception
  966. * @throws \think\exception\DbException
  967. */
  968. public function invite_editor()
  969. {
  970. $param = $this->request->param();
  971. $type = $param['type'];
  972. $row = AuthorManuscript::get($param['id']);
  973. $this->view->assign('row', $row);
  974. $this->view->assign('type', $type);
  975. $this->view->assign('title', 'Invite Editor');
  976. return $this->view->fetch();
  977. }
  978. /**
  979. * 选择编辑
  980. *
  981. * @return \think\response\Json
  982. * @throws \think\db\exception\DataNotFoundException
  983. * @throws \think\db\exception\ModelNotFoundException
  984. * @throws \think\exception\DbException
  985. */
  986. public function choose_editor()
  987. {
  988. $info = \app\common\model\User::where(['is_editor' => 'correct', 'id' => ['not in', $this->auth->id]])->field('nickname, id')->select();
  989. $params = $this->request->request();
  990. if (array_key_exists('name', $params) && $params['name']) {
  991. $info = \app\common\model\User::where(['is_editor' => 'correct', 'nickname' => ['like', '%' . $params['name'] . '%'], 'id' => ['not in', $this->auth->id]])->field('nickname, id')->select();
  992. }
  993. if ($this->request->request("keyValue")) {
  994. $id_arr = $this->request->request('keyValue');
  995. $info = \app\common\model\User::where(['id' => ['in', $id_arr]])->field('nickname, id')->select();
  996. }
  997. $arr = [];
  998. foreach ($info as $item) {
  999. $v['id'] = $item['id'];
  1000. $v['name'] = $item['nickname'];
  1001. $arr[] = $v;
  1002. }
  1003. $data['list'] = $arr;
  1004. $data['total'] = count($arr);
  1005. return json($data);
  1006. }
  1007. /**
  1008. * 选择期刊
  1009. *
  1010. * @return \think\response\Json
  1011. * @throws \think\db\exception\DataNotFoundException
  1012. * @throws \think\db\exception\ModelNotFoundException
  1013. * @throws \think\exception\DbException
  1014. */
  1015. public function choose_journal()
  1016. {
  1017. $type = $this->request->request("type");
  1018. $where = [];
  1019. if ($type == 'author') {
  1020. $where['chief_id'] = ['<>', 0];
  1021. }
  1022. $info = Channel::where(['parent_id' => 1])->where($where)->field('name, id')->select();
  1023. $params = $this->request->request();
  1024. if (array_key_exists('name', $params) && $params['name']) {
  1025. $info = Channel::where(['parent_id' => 1, 'name' => ['like', '%' . $params['name'] . '%']])->where($where)->field('name, id')->select();
  1026. }
  1027. if ($this->request->request("keyValue")) {
  1028. $id_arr = $this->request->request('keyValue');
  1029. $info = Channel::where(['id' => ['in', $id_arr]])->where($where)->field('name, id')->select();
  1030. }
  1031. $arr = [];
  1032. foreach ($info as $item) {
  1033. $v['id'] = $item['id'];
  1034. $v['name'] = $item['name'];
  1035. $arr[] = $v;
  1036. }
  1037. $data['list'] = $arr;
  1038. $data['total'] = count($arr);
  1039. return json($data);
  1040. }
  1041. }