User.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  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->save();
  225. // 查询用户是否已有申请角色记录表
  226. $user_role_log = UserRoleLog::where(['user_id' => $user->id, 'type' => 'author', 'is_adopt' => ['in', ['review', 'fault', 'correct']]])->find();
  227. if (empty($user_role_log)) {
  228. $user_role = new UserRoleLog();
  229. $user_role->user_id = $user->id;
  230. $user_role->save();
  231. }
  232. $this->success();
  233. }
  234. /**
  235. * 修改邮箱
  236. *
  237. * @ApiMethod (POST)
  238. * @param string $email 邮箱
  239. * @param string $captcha 验证码
  240. */
  241. public function changeemail()
  242. {
  243. $user = $this->auth->getUser();
  244. $email = $this->request->post('email');
  245. $captcha = $this->request->post('captcha');
  246. if (!$email || !$captcha) {
  247. $this->error(__('Invalid parameters'));
  248. }
  249. if (!Validate::is($email, "email")) {
  250. $this->error(__('Email is incorrect'));
  251. }
  252. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  253. $this->error(__('Email already exists'));
  254. }
  255. $result = Ems::check($email, $captcha, 'changeemail');
  256. if (!$result) {
  257. $this->error(__('Captcha is incorrect'));
  258. }
  259. $verification = $user->verification;
  260. $verification->email = 1;
  261. $user->verification = $verification;
  262. $user->email = $email;
  263. $user->save();
  264. Ems::flush($email, 'changeemail');
  265. $this->success();
  266. }
  267. /**
  268. * 修改手机号
  269. *
  270. * @ApiMethod (POST)
  271. * @param string $mobile 手机号
  272. * @param string $captcha 验证码
  273. */
  274. public function changemobile()
  275. {
  276. $user = $this->auth->getUser();
  277. $mobile = $this->request->post('mobile');
  278. $captcha = $this->request->post('captcha');
  279. if (!$mobile || !$captcha) {
  280. $this->error(__('Invalid parameters'));
  281. }
  282. if (!Validate::regex($mobile, "^1\d{10}$")) {
  283. $this->error(__('Mobile is incorrect'));
  284. }
  285. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  286. $this->error(__('Mobile already exists'));
  287. }
  288. $result = Sms::check($mobile, $captcha, 'changemobile');
  289. if (!$result) {
  290. $this->error(__('Captcha is incorrect'));
  291. }
  292. $verification = $user->verification;
  293. $verification->mobile = 1;
  294. $user->verification = $verification;
  295. $user->mobile = $mobile;
  296. $user->save();
  297. Sms::flush($mobile, 'changemobile');
  298. $this->success();
  299. }
  300. /**
  301. * 第三方登录
  302. *
  303. * @ApiMethod (POST)
  304. * @param string $platform 平台名称
  305. * @param string $code Code码
  306. */
  307. public function third()
  308. {
  309. $url = url('user/index');
  310. $platform = $this->request->post("platform");
  311. $code = $this->request->post("code");
  312. $config = get_addon_config('third');
  313. if (!$config || !isset($config[$platform])) {
  314. $this->error(__('Invalid parameters'));
  315. }
  316. $app = new \addons\third\library\Application($config);
  317. //通过code换access_token和绑定会员
  318. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  319. if ($result) {
  320. $loginret = \addons\third\library\Service::connect($platform, $result);
  321. if ($loginret) {
  322. $data = [
  323. 'userinfo' => $this->auth->getUserinfo(),
  324. 'thirdinfo' => $result
  325. ];
  326. $this->success(__('Logged in successful'), $data);
  327. }
  328. }
  329. $this->error(__('Operation failed'), $url);
  330. }
  331. /**
  332. * 重置密码
  333. *
  334. * @ApiMethod (POST)
  335. * @param string $mobile 手机号
  336. * @param string $newpassword 新密码
  337. * @param string $captcha 验证码
  338. */
  339. public function resetpwd()
  340. {
  341. // $type = $this->request->post("type");
  342. // $mobile = $this->request->post("mobile");
  343. $email = $this->request->post("email");
  344. $newpassword = $this->request->post("newpassword");
  345. $captcha = $this->request->post("captcha");
  346. if (!$newpassword || !$captcha) {
  347. $this->error(__('Invalid parameters'));
  348. }
  349. //验证Token
  350. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  351. $this->error(__('Password must be 6 to 30 characters'));
  352. }
  353. // if ($type == 'mobile') {
  354. // if (!Validate::regex($mobile, "^1\d{10}$")) {
  355. // $this->error(__('Mobile is incorrect'));
  356. // }
  357. // $user = \app\common\model\User::getByMobile($mobile);
  358. // if (!$user) {
  359. // $this->error(__('User not found'));
  360. // }
  361. // $ret = Sms::check($mobile, $captcha, 'resetpwd');
  362. // if (!$ret) {
  363. // $this->error(__('Captcha is incorrect'));
  364. // }
  365. // Sms::flush($mobile, 'resetpwd');
  366. // } else {
  367. if (!Validate::is($email, "email")) {
  368. $this->error(__('Email is incorrect'));
  369. }
  370. $user = \app\common\model\User::getByEmail($email);
  371. if (!$user) {
  372. $this->error(__('User not found'));
  373. }
  374. $ret = Ems::check($email, $captcha, 'resetpwd');
  375. if (!$ret) {
  376. $this->error(__('Captcha is incorrect'));
  377. }
  378. Ems::flush($email, 'resetpwd');
  379. // }
  380. //模拟一次登录
  381. $this->auth->direct($user->id);
  382. $ret = $this->auth->changepwd($newpassword, '', true);
  383. if ($ret) {
  384. $this->success(__('Reset password successful'));
  385. } else {
  386. $this->error($this->auth->getError());
  387. }
  388. }
  389. /**
  390. * 提交申请角色
  391. *
  392. * @return void
  393. * @throws \think\db\exception\DataNotFoundException
  394. * @throws \think\db\exception\ModelNotFoundException
  395. * @throws \think\exception\DbException
  396. */
  397. public function apply_role()
  398. {
  399. $user = $this->auth->getUser();
  400. $param = $this->request->param();
  401. $field = $this->request->param('field');
  402. $degree = $this->request->param('degree');
  403. $resume = $this->request->param('resume', '', 'trim,strip_tags,htmlspecialchars');
  404. $affiliation = $this->request->param('affiliation');
  405. $publication = $this->request->param('publication');
  406. $orcid = $this->request->param('orcid');
  407. $homepage = $this->request->param('homepage');
  408. $review_journal = $this->request->param('review_journal');
  409. $interested_journal = $this->request->param('interested_journal');
  410. $journal_ids = $param['journal_ids'];
  411. $type = $this->request->param('type');
  412. // 查询是否有对应的申请角色数据信息
  413. $user_content = UserRoleContent::where(['user_id' => $user->id, 'type' => $type])->find();
  414. if ($user_content) {
  415. $user_content->field = $field;
  416. $user_content->degree = $degree;
  417. $user_content->resume = $resume;
  418. $user_content->affiliation = $affiliation;
  419. $user_content->publication = $publication;
  420. $user_content->orcid = $orcid;
  421. $user_content->homepage = $homepage;
  422. $user_content->review_journal = $review_journal;
  423. $user_content->interested_journal = $interested_journal;
  424. $user_content->journal_ids = $journal_ids;
  425. $user_content->save();
  426. }
  427. // 查询用户是否已有申请角色记录表
  428. $user_role_log = UserRoleLog::where(['user_id' => $user->id, 'type' => $type, 'is_adopt' => ['in', ['review', 'fault', 'correct']]])->find();
  429. if (empty($user_role_log)) {
  430. $new_user_role = new UserRoleLog();
  431. $new_user_role->user_id = $user->id;
  432. $new_user_role->type = $type;
  433. if ($new_user_role->save()) {
  434. // 创建对应的信息
  435. $new_user_content = new UserRoleContent();
  436. $new_user_content->user_id = $user->id;
  437. $new_user_content->log_id = $new_user_role->id;
  438. $new_user_content->type = $type;
  439. $new_user_content->field = $field;
  440. $new_user_content->degree = $degree;
  441. $new_user_content->resume = $resume;
  442. $new_user_content->affiliation = $affiliation;
  443. $new_user_content->publication = $publication;
  444. $new_user_content->orcid = $orcid;
  445. $new_user_content->homepage = $homepage;
  446. $new_user_content->review_journal = $review_journal;
  447. $new_user_content->interested_journal = $interested_journal;
  448. $new_user_content->journal_ids = $journal_ids;
  449. $new_user_content->save();
  450. }
  451. }
  452. $this->success('Submit Success');
  453. }
  454. /**
  455. * 提交手稿
  456. *
  457. * @return void
  458. */
  459. public function submit_manuscript()
  460. {
  461. $params = $this->request->post('row/a');
  462. if (!$params['manuscript_zip']) $this->error('Manuscript (Word/Zip) Cannot be Empty');
  463. if (!$params['journal']) $this->error('Journal Cannot be Empty');
  464. if (!$params['article_type']) $this->error('Article Type Cannot be Empty');
  465. if (!$params['title']) $this->error('Title Cannot be Empty');
  466. if (!$params['abstract']) $this->error('Abstract Cannot be Empty');
  467. if (!$params['keywords']) $this->error('Keywords Cannot be Empty');
  468. if (!$params['number_page']) $this->error('Number of Pages Cannot be Empty');
  469. if (!$params['author']) $this->error('Author Cannot be Empty');
  470. if (array_key_exists('reviewer', $params)) {
  471. if (!$params['reviewer']) $this->error('Reviewer Cannot be Empty');
  472. }
  473. // 修改
  474. if ($params['id']) {
  475. // 修改操作
  476. $row = AuthorManuscript::where(['id' => $params['id']])->find();
  477. if (empty($row)) $this->error('Submit Failed');
  478. Db::startTrans();
  479. try {
  480. // 数组内容需转换为字符串
  481. $params['author_content'] = json_encode($params['author']);
  482. if (array_key_exists('reviewer', $params)) {
  483. $params['review_content'] = json_encode($params['reviewer']);
  484. }
  485. // 如果修改时状态是未编辑完得状态 提交后则修改完处理中状态
  486. if ($row['status'] == 'incomplete_submission') {
  487. $params['status'] = 'processing';
  488. }
  489. // 通过选择的期刊来绑定对应的主编
  490. if (!empty($params['journal'])) {
  491. $channel = Channel::get($params['journal']);
  492. if ($channel) {
  493. $params['chief_id'] = $channel['chief_id'];
  494. }
  495. }
  496. // 手稿状态日志
  497. $log = ManuscriptLog::where(['manuscript_id' => $params['id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
  498. if (!$log) {
  499. $log = new ManuscriptLog();
  500. $log->manuscript_id = $params['id'];
  501. $log->user_id = $this->auth->id;
  502. $log->type = 'user';
  503. }
  504. $log->status = $params['status'];
  505. $log->save();
  506. $result = $row->allowField(true)->save($params);
  507. Db::commit();
  508. } catch (ValidateException|PDOException|Exception $e) {
  509. Db::rollback();
  510. $this->error($e->getMessage());
  511. }
  512. if ($result === false) {
  513. $this->error('No rows were inserted');
  514. }
  515. }
  516. $this->success('Submit Success');
  517. }
  518. /**
  519. * 编辑、审稿人提交意见
  520. *
  521. * @return void
  522. */
  523. public function submit_comments()
  524. {
  525. $params = $this->request->post('row/a');
  526. $model = new Comments();
  527. Db::startTrans();
  528. try {
  529. $params['user_id'] = $this->auth->id;
  530. // 获取手稿
  531. $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find();
  532. if ($manuscript) {
  533. $manuscript['status'] = $params['status'];
  534. $manuscript->save();
  535. }
  536. if ($params['type'] != 'author') {
  537. $result = $model->allowField(true)->save($params);
  538. } else {
  539. // 如果是作者则先查询是否有审稿意见回复,如果有则进行更新操作
  540. $result = Comments::where(['manuscript_id' => $params['manuscript_id'], 'user_id' => $this->auth->id, 'type' => 'author'])->find();
  541. if ($result) {
  542. $result->comments = $params['comments'];
  543. $result->save();
  544. } else {
  545. $result = $model->allowField(true)->save($params);
  546. }
  547. }
  548. // 手稿状态日志
  549. $log = ManuscriptLog::where(['manuscript_id' => $params['manuscript_id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
  550. if (!$log) {
  551. $log = new ManuscriptLog();
  552. $log->manuscript_id = $params['manuscript_id'];
  553. $log->user_id = $this->auth->id;
  554. $log->type = 'user';
  555. }
  556. $log->status = $params['status'];
  557. $log->save();
  558. Db::commit();
  559. } catch (ValidateException|PDOException|Exception $e) {
  560. Db::rollback();
  561. $this->error($e->getMessage());
  562. }
  563. if ($result === false) {
  564. $this->error('No rows were inserted');
  565. }
  566. $this->success('Submit Success');
  567. }
  568. /**
  569. * 提交特刊
  570. *
  571. * @return void
  572. */
  573. public function submit_issue()
  574. {
  575. $params = $this->request->post('row/a');
  576. $result = false;
  577. Db::startTrans();
  578. try {
  579. $params['user_id'] = $this->auth->id;
  580. // 数组内容需转换为字符串
  581. $params['editor'] = json_encode($params['editor']);
  582. $model = new Issue();
  583. $result = $model->allowField(true)->save($params);
  584. Db::commit();
  585. } catch (ValidateException|PDOException|Exception $e) {
  586. Db::rollback();
  587. $this->error($e->getMessage());
  588. }
  589. if ($result === false) {
  590. $this->error('No rows were inserted');
  591. }
  592. $this->success('Submit Success');
  593. }
  594. /**
  595. * 编辑邀请审稿人提交操作
  596. *
  597. * @return void
  598. */
  599. public function submit_invite_reviewer()
  600. {
  601. $params = $this->request->post('row/a');
  602. $reviewers = $params['reviewer'];
  603. if (!$reviewers) $this->error('Please select reviewer');
  604. $result = false;
  605. Db::startTrans();
  606. try {
  607. $reviewer_id_arr = [];
  608. foreach ($reviewers as $reviewer) {
  609. $reviewer_id_arr[] = $reviewer['user_id'];
  610. $data = [];
  611. $data['role_id'] = $reviewer['id'];
  612. $data['editor_id'] = $this->auth->id;
  613. $data['manuscript_id'] = $params['manuscript_id'];
  614. $reviewer_old = InviteReviewer::where(['role_id' => $reviewer['id'], 'editor_id' => $this->auth->id, 'manuscript_id' => $params['manuscript_id']])->find();
  615. // 如果存在选择数据则不进行插入操作
  616. if (!$reviewer_old) {
  617. $model = new InviteReviewer();
  618. $model->allowField(true)->save($data);
  619. }
  620. }
  621. $manuscript = AuthorManuscript::where(['id' => $params['manuscript_id']])->find();
  622. $reviewer_ids_arr = explode(',', $manuscript['reviewer_ids']);
  623. // 合并数组
  624. $merged_reviewer_ids_arr = array_merge($reviewer_ids_arr, $reviewer_id_arr);
  625. // 去重数组
  626. $unique_reviewer_ids_arr = array_filter(array_unique($merged_reviewer_ids_arr));
  627. $manuscript['reviewer_ids'] = implode(',', $unique_reviewer_ids_arr);
  628. $manuscript['status'] = $params['status'];
  629. $result = $manuscript->save();
  630. Db::commit();
  631. } catch (ValidateException|PDOException|Exception $e) {
  632. Db::rollback();
  633. $this->error($e->getMessage());
  634. }
  635. if ($result === false) {
  636. $this->error('No rows were inserted');
  637. }
  638. $this->success('Submit Success');
  639. }
  640. /**
  641. * 订阅邮箱
  642. *
  643. * @return void
  644. */
  645. public function email_subscription()
  646. {
  647. $email = $this->request->post('email');
  648. if (!$email) $this->error('Email cannot be empty');
  649. $old_email = Email::where(['email' => $email])->find();
  650. if ($old_email) $this->error('Email already exists');
  651. $result = false;
  652. Db::startTrans();
  653. try {
  654. $model = new Email();
  655. $result = $model->allowField(true)->save(['email' => $email, 'type' => 'journal', 'user_id' => $this->auth->id]);
  656. Db::commit();
  657. } catch (ValidateException|PDOException|Exception $e) {
  658. Db::rollback();
  659. $this->error($e->getMessage());
  660. }
  661. if ($result === false) {
  662. $this->error('No rows were inserted');
  663. }
  664. $this->success('Operation successful');
  665. }
  666. /**
  667. * 首页提交邮箱信息
  668. *
  669. * @return void
  670. */
  671. public function submit_email()
  672. {
  673. $params = $this->request->post();
  674. $email = $this->request->post('email');
  675. $value = $this->request->post('value');
  676. if (empty($email)) $this->error('Email cannot be empty');
  677. if (empty($value)) $this->error('The selected value cannot be empty');
  678. $model = new Email();
  679. Db::startTrans();
  680. try {
  681. $params['type'] = 'home';
  682. $params['user_id'] = $this->auth->id;
  683. $result = $model->allowField(true)->save($params);
  684. Db::commit();
  685. } catch (ValidateException|PDOException|Exception $e) {
  686. Db::rollback();
  687. $this->error($e->getMessage());
  688. }
  689. if ($result === false) {
  690. $this->error('Submit Error');
  691. }
  692. $this->success('Submit Success');
  693. }
  694. /**
  695. * 提交会议
  696. *
  697. * @return void
  698. */
  699. public function submit_conference()
  700. {
  701. if (!$this->auth->isLogin()) {
  702. $this->error("Please log in before proceeding", "index/user/login");
  703. }
  704. $params = $this->request->post('row/a');
  705. $captcha = $this->request->post('captcha');
  706. if (!captcha_check($captcha)) {
  707. $this->error("Incorrect verification code");
  708. }
  709. $model = new Conference();
  710. Db::startTrans();
  711. try {
  712. $params['user_id'] = $this->auth->id;
  713. $result = $model->allowField(true)->save($params);
  714. Db::commit();
  715. } catch (ValidateException|PDOException|Exception $e) {
  716. Db::rollback();
  717. $this->error($e->getMessage());
  718. }
  719. if ($result === false) {
  720. $this->error('Submit Error');
  721. }
  722. $this->success('Submit Success');
  723. }
  724. /**
  725. * 参与会议
  726. *
  727. * @return void
  728. */
  729. public function conference_participate()
  730. {
  731. $params = $this->request->post('row/a');
  732. $model = new Participate();
  733. Db::startTrans();
  734. try {
  735. $params['user_id'] = $this->auth->id;
  736. $result = $model->allowField(true)->save($params);
  737. Db::commit();
  738. } catch (ValidateException|PDOException|Exception $e) {
  739. Db::rollback();
  740. $this->error($e->getMessage());
  741. }
  742. if ($result === false) {
  743. $this->error('Submit Error');
  744. }
  745. $this->success('Submit Success');
  746. }
  747. /**
  748. * 提交作者服务
  749. *
  750. * @return void
  751. */
  752. public function submit_author_service()
  753. {
  754. $params = $this->request->post();
  755. $model = new AuthorService();
  756. Db::startTrans();
  757. try {
  758. $params['user_id'] = $this->auth->id;
  759. $result = $model->allowField(true)->save($params);
  760. Db::commit();
  761. } catch (ValidateException|PDOException|Exception $e) {
  762. Db::rollback();
  763. $this->error($e->getMessage());
  764. }
  765. if ($result === false) {
  766. $this->error('Submit Error');
  767. }
  768. $this->success('Submit Success');
  769. }
  770. /**
  771. * 已读邮件
  772. *
  773. * @return void
  774. * @throws \think\db\exception\DataNotFoundException
  775. * @throws \think\db\exception\ModelNotFoundException
  776. * @throws \think\exception\DbException
  777. */
  778. public function read_email()
  779. {
  780. $params = $this->request->post();
  781. if ($params['email_id']) {
  782. $email_content = EmailContent::where(['id' => $params['email_id']])->find();
  783. Db::startTrans();
  784. try {
  785. if ($email_content) {
  786. $email_content->status = 'normal';
  787. $result = $email_content->save();;
  788. }
  789. Db::commit();
  790. } catch (ValidateException|PDOException|Exception $e) {
  791. Db::rollback();
  792. $this->error($e->getMessage());
  793. }
  794. }
  795. if ($result === false) {
  796. $this->error('Submit Error');
  797. }
  798. $this->success('Success');
  799. }
  800. /**
  801. * 提交手稿(未全部提交)
  802. *
  803. * @return void
  804. */
  805. public function incomplete_submit()
  806. {
  807. $params = $this->request->post('row/a');
  808. // 数组内容需转换为字符串
  809. if (array_key_exists('author', $params) && !empty($params['author'])) {
  810. $params['author_content'] = json_encode($params['author']);
  811. }
  812. if (array_key_exists('reviewer', $params) && !empty($params['reviewer'])) {
  813. $params['review_content'] = json_encode($params['reviewer']);
  814. }
  815. if (empty($params['title'])) {
  816. $params['title'] = 'Incomplete editing' . rand(0, 4);
  817. }
  818. if (empty($params['image'])) {
  819. $params['image'] = 'https://dummyimage.com/205x128';
  820. }
  821. $params['status'] = 'incomplete_submission';
  822. $params['user_id'] = $this->auth->id;
  823. // 因使用create方法返回自增id,但是验证字段有前端自定义字段所以需要删除
  824. unset($params['author']);
  825. unset($params['reviewer']);
  826. $manuscript = new AuthorManuscript();
  827. Db::startTrans();
  828. try {
  829. if (!empty($params['id'])) {
  830. $manuscript = AuthorManuscript::where(['id' => $params['id']])->find();
  831. $manuscript = $manuscript->allowField(true)->save($params);
  832. } else {
  833. $manuscript = $manuscript->allowField(true)->create($params);
  834. }
  835. // 手稿状态日志
  836. $log = ManuscriptLog::where(['manuscript_id' => $params['id'], 'user_id' => $this->auth->id, 'type' => 'user', 'status' => $params['status']])->find();
  837. if (!$log) {
  838. $log = new ManuscriptLog();
  839. $log->manuscript_id = $params['id'];
  840. $log->user_id = $this->auth->id;
  841. $log->type = 'user';
  842. }
  843. $log->status = $params['status'];
  844. $log->save();
  845. Db::commit();
  846. } catch (ValidateException|PDOException|Exception $e) {
  847. Db::rollback();
  848. $this->error($e->getMessage());
  849. }
  850. $this->success('Success', $manuscript->id ?? $params['id']);
  851. }
  852. /**
  853. * 发送邮件
  854. *
  855. * @return void
  856. * @throws \think\db\exception\DataNotFoundException
  857. * @throws \think\db\exception\ModelNotFoundException
  858. * @throws \think\exception\DbException
  859. */
  860. public function send_email()
  861. {
  862. $params = $this->request->post('row/a');
  863. $option = [
  864. 'mail_smtp_host' => $this->auth->mail_smtp_host,
  865. 'mail_smtp_port' => $this->auth->mail_smtp_port,
  866. 'mail_smtp_user' => $this->auth->mail_smtp_user,
  867. 'mail_smtp_pass' => $this->auth->mail_smtp_pass,
  868. 'mail_from' => $this->auth->mail_smtp_user,
  869. ];
  870. $email = new \app\common\library\Email($option);
  871. $result = $email
  872. ->to($params['send_user_email'])
  873. ->subject($params['title'])
  874. ->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . $params['content'] . '</div>')
  875. ->send();
  876. Db::startTrans();
  877. try {
  878. $receiver_user = \app\admin\model\User::where(['email' => $params['send_user_email']])->find();
  879. $params['type'] = 'user';
  880. $params['user_id'] = $this->auth->id;
  881. $params['receiver_id'] = $receiver_user['id'];
  882. $params['email'] = $params['send_user_email'];
  883. $email_model = new EmailContent();
  884. $result = $email_model->allowField(true)->save($params);
  885. Db::commit();
  886. } catch (ValidateException|PDOException|Exception $e) {
  887. Db::rollback();
  888. $this->error($e->getMessage());
  889. }
  890. if (false === $result) {
  891. $this->error(__('No rows were updated'));
  892. }
  893. $this->success('Successfully sent');
  894. }
  895. /**
  896. * 邀请编辑
  897. *
  898. * @return void
  899. * @throws \think\exception\DbException
  900. */
  901. public function invite_editor()
  902. {
  903. $params = $this->request->post('row/a');
  904. $row = AuthorManuscript::get($params['manuscript_id']);
  905. Db::startTrans();
  906. try {
  907. if ($row) {
  908. $row['editor_ids'] = $params['editor_ids'];
  909. $row->save();
  910. }
  911. Db::commit();
  912. } catch (ValidateException|PDOException|Exception $e) {
  913. Db::rollback();
  914. $this->error($e->getMessage());
  915. }
  916. $this->success('Successfully');
  917. }
  918. }