Index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @file Index.php
  5. * @date 2019-02-27 14:49:36
  6. * @author huwhis<huuwhois>
  7. * @version 0.0.6
  8. */
  9. namespace app\controller;
  10. use think\facade\View;
  11. use app\controller\Base;
  12. use app\model\Article;
  13. use app\model\GuestBook;
  14. use app\utils\ReUtils;
  15. class Index extends Base
  16. {
  17. public function index()
  18. {
  19. return View::fetch();
  20. }
  21. /**
  22. * 关于&留言
  23. */
  24. public function about()
  25. {
  26. return View::fetch();
  27. }
  28. public function saveGuestBook()
  29. {
  30. $param = $this->request->param('', '', ['strip_tags', 'htmlspecialchars']);
  31. if (empty($param['name']) or empty($param['contact'])) {
  32. return json(['msg' => "请填写必填字段(姓名,电子邮件)", 'code' => 1]);
  33. }
  34. if (empty($param['content'])) {
  35. return json(['msg' => "请留下内容", 'code' => 1]);
  36. }
  37. try {
  38. $bgu = new GuestBook();
  39. $bgu->save([
  40. 'content' => $param['content'],
  41. 'name' => $param['name'],
  42. 'contact' => $param['contact'],
  43. 'url' => $param['url'],
  44. 'time' => time(),
  45. ]);
  46. $bgu->datetime = date("Y-m-d", $bgu->time);
  47. return ReUtils::result($bgu);
  48. } catch (\Exception $e) {
  49. return ReUtils::error($e->getMessage());
  50. }
  51. }
  52. }