76 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
		
		
			
		
	
	
			76 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace app\controller;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use app\model\{Article as MArticle, Category, Block, Message, Article, Slide};
							 | 
						||
| 
								 | 
							
								use Exception;
							 | 
						||
| 
								 | 
							
								use think\exception\ValidateException;
							 | 
						||
| 
								 | 
							
								use think\facade\View;
							 | 
						||
| 
								 | 
							
								use app\service\Tool;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class Index extends Base
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    public function index()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $category   = Category::getIndex();
							 | 
						||
| 
								 | 
							
								        $categoryId = $category['id'] ?? 0;
							 | 
						||
| 
								 | 
							
								        $blocks     = Block::getByCategoryId($categoryId);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $this->news(5);
							 | 
						||
| 
								 | 
							
								        $this->data['categoryId'] = $categoryId;
							 | 
						||
| 
								 | 
							
								        $this->data['blocks']     = Block::convertValue($blocks);
							 | 
						||
| 
								 | 
							
								        $this->data['category']   = $category;
							 | 
						||
| 
								 | 
							
								        $this->data['topCategoryId'] = Category::firstGradeById($category['id']) ;
							 | 
						||
| 
								 | 
							
								        $this->data['isIndex'] = true;
							 | 
						||
| 
								 | 
							
								        $this->data['slide']      = Slide::getList();
							 | 
						||
| 
								 | 
							
								        $this->setSeo($this->system['seo_title'], $this->system['seo_keywords'], $this->system['seo_description']);
							 | 
						||
| 
								 | 
							
								        return $this->view();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // 新闻动态
							 | 
						||
| 
								 | 
							
								    private function news($num)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $this->data['newsList'] =  MArticle::getIndexList(Category::CATEGORY_NEWS, $num);
							 | 
						||
| 
								 | 
							
								        $topNews = MArticle::getIndexTop(Category::CATEGORY_NEWS);
							 | 
						||
| 
								 | 
							
								        $this->data['topNews']  = $topNews;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 留言
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @throws Exception
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function message()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        if ($this->request->isPost()) {
							 | 
						||
| 
								 | 
							
								            $item     = input('item/a', [], 'strip_tags');
							 | 
						||
| 
								 | 
							
								            $validate = $this->validateByApi($item, [
							 | 
						||
| 
								 | 
							
								                'code|验证码' => 'require',
							 | 
						||
| 
								 | 
							
								                'name|姓名'  => 'require',
							 | 
						||
| 
								 | 
							
								                'email|邮箱' => 'email',
							 | 
						||
| 
								 | 
							
								                'tel|联系方式' => 'require|mobile',
							 | 
						||
| 
								 | 
							
								                'content|留言内容' => 'require',
							 | 
						||
| 
								 | 
							
								            ]);
							 | 
						||
| 
								 | 
							
								            if ($validate !== true) {
							 | 
						||
| 
								 | 
							
								                return $validate;
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            if (!captcha_check($item['code'])) {
							 | 
						||
| 
								 | 
							
								                return $this->json(4001, '验证码错误');
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            Message::create([
							 | 
						||
| 
								 | 
							
								                'name'        => $item['name'],
							 | 
						||
| 
								 | 
							
								                'tel'         => $item['tel'],
							 | 
						||
| 
								 | 
							
								                'email'       => $item['email'],
							 | 
						||
| 
								 | 
							
								                'content'     => $item['content'],
							 | 
						||
| 
								 | 
							
								                'ip'          => request()->ip(),
							 | 
						||
| 
								 | 
							
								                'create_time' => time(),
							 | 
						||
| 
								 | 
							
								            ]);
							 | 
						||
| 
								 | 
							
								            return $this->json();
							 | 
						||
| 
								 | 
							
								        } else {
							 | 
						||
| 
								 | 
							
								            return $this->json('请求错误');
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 |