123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- declare(strict_types=1);
- /**
- * @file Index.php
- * @date 2019-02-27 14:49:36
- * @author huwhis<huuwhois>
- * @version 0.0.6
- */
- namespace app\controller;
- use think\facade\View;
- use app\controller\Base;
- use app\model\Article;
- use app\model\GuestBook;
- use app\utils\ReUtils;
- class Index extends Base
- {
- public function index()
- {
- return View::fetch();
- }
- /**
- * 关于&留言
- */
- public function about()
- {
- return View::fetch();
- }
- public function saveGuestBook()
- {
- $param = $this->request->param('', '', ['strip_tags', 'htmlspecialchars']);
- if (empty($param['name']) or empty($param['contact'])) {
- return json(['msg' => "请填写必填字段(姓名,电子邮件)", 'code' => 1]);
- }
- if (empty($param['content'])) {
- return json(['msg' => "请留下内容", 'code' => 1]);
- }
- try {
- $bgu = new GuestBook();
- $bgu->save([
- 'content' => $param['content'],
- 'name' => $param['name'],
- 'contact' => $param['contact'],
- 'url' => $param['url'],
- 'time' => time(),
- ]);
- $bgu->datetime = date("Y-m-d", $bgu->time);
- return ReUtils::result($bgu);
- } catch (\Exception $e) {
- return ReUtils::error($e->getMessage());
- }
- }
- }
|