正在显示
9 个修改的文件
包含
201 行增加
和
83 行删除
@@ -10,6 +10,7 @@ namespace app\portal\controller; | @@ -10,6 +10,7 @@ namespace app\portal\controller; | ||
10 | 10 | ||
11 | use app\admin\model\HospitalModel; | 11 | use app\admin\model\HospitalModel; |
12 | use app\admin\model\JobModel; | 12 | use app\admin\model\JobModel; |
13 | +use app\portal\model\PortalPostModel; | ||
13 | use app\user\model\UserModel; | 14 | use app\user\model\UserModel; |
14 | use cmf\controller\HomeBaseController; | 15 | use cmf\controller\HomeBaseController; |
15 | use EasyWeChat\Foundation\Application; | 16 | use EasyWeChat\Foundation\Application; |
@@ -27,6 +28,9 @@ class IndexController extends WeChatBaseController | @@ -27,6 +28,9 @@ class IndexController extends WeChatBaseController | ||
27 | $targetUrl=url('register'); | 28 | $targetUrl=url('register'); |
28 | header('location:'. $targetUrl); | 29 | header('location:'. $targetUrl); |
29 | } | 30 | } |
31 | + $Article=new PortalPostModel(); | ||
32 | + $article=$Article->getRecommend()->toArray(); | ||
33 | + $this->assign('article',$article); | ||
30 | return $this->fetch(); | 34 | return $this->fetch(); |
31 | } | 35 | } |
32 | 36 |
@@ -10,6 +10,8 @@ | @@ -10,6 +10,8 @@ | ||
10 | // +---------------------------------------------------------------------- | 10 | // +---------------------------------------------------------------------- |
11 | namespace app\portal\controller; | 11 | namespace app\portal\controller; |
12 | 12 | ||
13 | +use app\portal\model\PortalPostModel; | ||
14 | +use app\portal\model\SearchModel; | ||
13 | use cmf\controller\HomeBaseController; | 15 | use cmf\controller\HomeBaseController; |
14 | 16 | ||
15 | class SearchController extends HomeBaseController | 17 | class SearchController extends HomeBaseController |
@@ -27,6 +29,14 @@ class SearchController extends HomeBaseController | @@ -27,6 +29,14 @@ class SearchController extends HomeBaseController | ||
27 | } | 29 | } |
28 | 30 | ||
29 | public function index(){ | 31 | public function index(){ |
32 | + $user_id=cmf_get_current_user_id(); | ||
33 | + if (empty($user_id)){ | ||
34 | + $this->error(); | ||
35 | + } | ||
36 | + $map['user_id']=$user_id; | ||
37 | + $Search=new SearchModel(); | ||
38 | + $keyword=$Search->getKeyword($user_id)->toArray(); | ||
39 | + $this->assign('keyword',$keyword); | ||
30 | return $this->fetch(); | 40 | return $this->fetch(); |
31 | } | 41 | } |
32 | 42 | ||
@@ -34,5 +44,26 @@ class SearchController extends HomeBaseController | @@ -34,5 +44,26 @@ class SearchController extends HomeBaseController | ||
34 | return $this->fetch(); | 44 | return $this->fetch(); |
35 | } | 45 | } |
36 | 46 | ||
47 | + public function searchResult(){ | ||
48 | + $keyword=input('keyword/s'); | ||
49 | + $this->assign('keyword',$keyword); | ||
50 | + | ||
51 | + if(empty($keyword)){ | ||
52 | + $this->error('无效关键词'); | ||
53 | + } | ||
54 | + /*记录到搜索库*/ | ||
55 | + $user_id=cmf_get_current_user_id(); | ||
56 | + $Serarch=new SearchModel(); | ||
57 | + $Serarch->serarchAdd($user_id,$keyword); | ||
58 | + $Article=new PortalPostModel(); | ||
59 | + $result=$Article->getArticleByKeyword($keyword)->toArray(); | ||
60 | + if (empty($result)){ | ||
61 | + $this->error('没有找到相应的内容!'); | ||
62 | + } | ||
63 | + | ||
64 | + $this->assign('result',$result); | ||
65 | + return $this->fetch(); | ||
66 | + } | ||
67 | + | ||
37 | 68 | ||
38 | } | 69 | } |
@@ -356,6 +356,27 @@ class PortalPostModel extends Model | @@ -356,6 +356,27 @@ class PortalPostModel extends Model | ||
356 | return $article; | 356 | return $article; |
357 | } | 357 | } |
358 | 358 | ||
359 | + public function getRecommend(){ | ||
360 | + $map['recommended']='1'; | ||
361 | + $info=$this->field('id,post_title,post_content,more,published_time,create_time')->where($map)->select(); | ||
362 | + return $info; | ||
363 | + } | ||
359 | 364 | ||
360 | - | 365 | + /** |
366 | + * 获取搜索到的文章 | ||
367 | + * @param $keyword | ||
368 | + * @return false|\PDOStatement|string|\think\Collection | ||
369 | + * @throws \think\db\exception\DataNotFoundException | ||
370 | + * @throws \think\db\exception\ModelNotFoundException | ||
371 | + * @throws \think\exception\DbException | ||
372 | + */ | ||
373 | + public function getArticleByKeyword($keyword){ | ||
374 | + $map['post_keywords']=['like',$keyword.'%']; | ||
375 | + $map1['post_title']=['like',$keyword.'%']; | ||
376 | + $result=$this->field('id,post_title,post_content,more,published_time,create_time') | ||
377 | + ->where($map) | ||
378 | + ->whereOr($map1) | ||
379 | + ->select(); | ||
380 | + return $result; | ||
381 | + } | ||
361 | } | 382 | } |
app/portal/model/SearchModel.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * auther: sgj | ||
5 | + * Date: 2018/12/11 | ||
6 | + * Time: 16:33 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace app\portal\model; | ||
10 | + | ||
11 | + | ||
12 | +use think\Model; | ||
13 | +use traits\model\SoftDelete; | ||
14 | + | ||
15 | +class SearchModel extends Model | ||
16 | +{ | ||
17 | + use SoftDelete; | ||
18 | + protected $deleteTime = 'delete_time'; | ||
19 | + // 开启自动写入时间戳字段 | ||
20 | + // protected $autoWriteTimestamp = true; | ||
21 | + // protected $insert =['add_time']; | ||
22 | + | ||
23 | + protected function setAddTimeAttr() | ||
24 | + { | ||
25 | + return time(); | ||
26 | + } | ||
27 | + | ||
28 | + /** | ||
29 | + * 获取搜索关键字 | ||
30 | + * @param $user_id | ||
31 | + * @return false|\PDOStatement|string|\think\Collection | ||
32 | + * @throws \think\db\exception\DataNotFoundException | ||
33 | + * @throws \think\db\exception\ModelNotFoundException | ||
34 | + * @throws \think\exception\DbException | ||
35 | + */ | ||
36 | + public function getKeyword($user_id,$limit='8'){ | ||
37 | + $return=$this->where('user_id',$user_id)->limit($limit)->select(); | ||
38 | + return $return; | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * 关键字添加信息 | ||
43 | + * @param $user_id | ||
44 | + * @param $keyword | ||
45 | + * @throws \think\db\exception\DataNotFoundException | ||
46 | + * @throws \think\db\exception\ModelNotFoundException | ||
47 | + * @throws \think\exception\DbException | ||
48 | + */ | ||
49 | + public function serarchAdd($user_id,$keyword){ | ||
50 | + $data['user_id']=$user_id; | ||
51 | + $data['name']=$keyword; | ||
52 | + /*判断之前是否有相关数据*/ | ||
53 | + $info=$this->getKeyword($user_id)->toArray(); | ||
54 | + if (!empty($info)){ | ||
55 | + foreach ($info as $k=>$v) { | ||
56 | + if ($v['name']==$keyword){ | ||
57 | + $this::destroy($v); | ||
58 | + } | ||
59 | + } | ||
60 | + } | ||
61 | + $this->insert($data); | ||
62 | + } | ||
63 | + | ||
64 | + | ||
65 | + | ||
66 | + | ||
67 | + | ||
68 | +} | ||
69 | + |
@@ -117,7 +117,7 @@ | @@ -117,7 +117,7 @@ | ||
117 | </span> | 117 | </span> |
118 | </foreach> | 118 | </foreach> |
119 | </td> | 119 | </td> |
120 | - <td>{$vo.user_nickname}</td> | 120 | + <td>{$vo.user_login}</td> |
121 | <td>{$vo.post_hits|default=0}</td> | 121 | <td>{$vo.post_hits|default=0}</td> |
122 | <td> | 122 | <td> |
123 | <notempty name="vo.comment_count"> | 123 | <notempty name="vo.comment_count"> |
@@ -39,6 +39,7 @@ | @@ -39,6 +39,7 @@ | ||
39 | <script type="text/javascript" src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script> | 39 | <script type="text/javascript" src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script> |
40 | <script> | 40 | <script> |
41 | $(document).ready(function () { | 41 | $(document).ready(function () { |
42 | + | ||
42 | $('.search').click(function (res) { | 43 | $('.search').click(function (res) { |
43 | 44 | ||
44 | console.log(res); | 45 | console.log(res); |
@@ -57,83 +57,22 @@ | @@ -57,83 +57,22 @@ | ||
57 | <div class="content_item"> | 57 | <div class="content_item"> |
58 | <div class="content_title">最新活动</div> | 58 | <div class="content_title">最新活动</div> |
59 | <div class="content"> | 59 | <div class="content"> |
60 | - <div class="item_box"> | ||
61 | - <div> | ||
62 | - <div class="item_title">人参一斤 不如糙米一升</div> | ||
63 | - <div class="item_content"> | ||
64 | - 精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候...精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候... | 60 | + <volist name="article" id="vo"> |
61 | + <a href="{:url('portal/article/index',['id'=>$vo.id])}"> | ||
62 | + <div class="item_box"> | ||
63 | + <div> | ||
64 | + <div class="item_title">{$vo.post_title}</div> | ||
65 | + <div class="item_content"> | ||
66 | + {:getDescirpe($vo.post_content)}... | ||
67 | + </div> | ||
68 | + <div>{:date('Y.m.d',$vo.create_time)}</div> | ||
65 | </div> | 69 | </div> |
66 | - <div>2018.08.15</div> | ||
67 | - </div> | ||
68 | - <div> | ||
69 | - <img src="__TMPL__/public/assets/images/dpic06@2x.png" alt=""> | ||
70 | - </div> | ||
71 | - </div> | ||
72 | - | ||
73 | - | ||
74 | - <div class="item_box"> | ||
75 | - <div> | ||
76 | - <div class="item_title">人参一斤 不如糙米一升</div> | ||
77 | - <div class="item_content"> | ||
78 | - 精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候...精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候... | ||
79 | - </div> | ||
80 | - <div>2018.08.15</div> | ||
81 | - </div> | ||
82 | - <div> | ||
83 | - <img src="__TMPL__/public/assets/images/dpic06@2x.png" alt=""> | ||
84 | - </div> | ||
85 | - </div> | ||
86 | - | ||
87 | - <div class="item_box"> | ||
88 | - <div> | ||
89 | - <div class="item_title">人参一斤 不如糙米一升</div> | ||
90 | - <div class="item_content"> | ||
91 | - 精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候...精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候... | 70 | + <div> |
71 | + <img src="{:cmf_get_image_preview_url($vo.more.thumbnail)}" alt=""> | ||
92 | </div> | 72 | </div> |
93 | - <div>2018.08.15</div> | ||
94 | - </div> | ||
95 | - <div> | ||
96 | - <img src="__TMPL__/public/assets/images/dpic06@2x.png" alt=""> | ||
97 | </div> | 73 | </div> |
98 | - </div> | ||
99 | - | ||
100 | - | ||
101 | - <div class="item_box"> | ||
102 | - <div> | ||
103 | - <div class="item_title">人参一斤 不如糙米一升</div> | ||
104 | - <div class="item_content"> | ||
105 | - 精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候...精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候... | ||
106 | - </div> | ||
107 | - <div>2018.08.15</div> | ||
108 | - </div> | ||
109 | - <div> | ||
110 | - <img src="__TMPL__/public/assets/images/dpic06@2x.png" alt=""> | ||
111 | - </div> | ||
112 | - </div> | ||
113 | - <div class="item_box"> | ||
114 | - <div> | ||
115 | - <div class="item_title">人参一斤 不如糙米一升</div> | ||
116 | - <div class="item_content"> | ||
117 | - 精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候...精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候... | ||
118 | - </div> | ||
119 | - <div>2018.08.15</div> | ||
120 | - </div> | ||
121 | - <div> | ||
122 | - <img src="__TMPL__/public/assets/images/dpic06@2x.png" alt=""> | ||
123 | - </div> | ||
124 | - </div> | ||
125 | - <div class="item_box"> | ||
126 | - <div> | ||
127 | - <div class="item_title">人参一斤 不如糙米一升</div> | ||
128 | - <div class="item_content"> | ||
129 | - 精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候...精致,是一种对生活热爱且认真负责的态度。如今人们在选择食物的时候... | ||
130 | - </div> | ||
131 | - <div>2018.08.15</div> | ||
132 | - </div> | ||
133 | - <div> | ||
134 | - <img src="__TMPL__/public/assets/images/dpic06@2x.png" alt=""> | ||
135 | - </div> | ||
136 | - </div> | 74 | + </a> |
75 | + </volist> | ||
137 | </div> | 76 | </div> |
138 | </div> | 77 | </div> |
139 | </div> | 78 | </div> |
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | <div class="search_item"> | 14 | <div class="search_item"> |
15 | <div class="iconfont icon-sousuo"></div> | 15 | <div class="iconfont icon-sousuo"></div> |
16 | <div class="input_box"> | 16 | <div class="input_box"> |
17 | - <input type="text" placeholder="输入搜索相关内容"> | 17 | + <input id="keyword" type="text" placeholder="输入搜索相关内容"> |
18 | <!--<div class="iconfont icon-cha"></div>--> | 18 | <!--<div class="iconfont icon-cha"></div>--> |
19 | </div> | 19 | </div> |
20 | </div> | 20 | </div> |
@@ -29,9 +29,9 @@ | @@ -29,9 +29,9 @@ | ||
29 | </div> | 29 | </div> |
30 | </div> | 30 | </div> |
31 | <div class="content_item"> | 31 | <div class="content_item"> |
32 | - <div class="lable_item">红豆薏米的功效</div> | ||
33 | - <div class="lable_item">健康管理</div> | ||
34 | - <div class="lable_item">如何补钙</div> | 32 | + <volist name="keyword" id="vo" empty="暂无数据"> |
33 | + <a href="{:url('portal/search/searchResult',['keyword'=>$vo.name])}"> <div class="lable_item">{$vo.name}</div></a> | ||
34 | + </volist> | ||
35 | </div> | 35 | </div> |
36 | </div> | 36 | </div> |
37 | </div> | 37 | </div> |
@@ -40,9 +40,13 @@ | @@ -40,9 +40,13 @@ | ||
40 | <script> | 40 | <script> |
41 | $(document).ready(function () { | 41 | $(document).ready(function () { |
42 | $('.search').click(function (res) { | 42 | $('.search').click(function (res) { |
43 | - $.() | ||
44 | - console.log(res); | ||
45 | - // window.location.href="{:url('portal/serarch')}" | 43 | + var keyword1=$('#keyword').val() |
44 | + console.log(keyword1); | ||
45 | + if (!keyword1){ | ||
46 | + alert('请输入正确的关键词!'); | ||
47 | + return; | ||
48 | + } | ||
49 | + window.location.href="{:url('portal/search/searchResult')}"+'?keyword='+keyword1; | ||
46 | }) | 50 | }) |
47 | }) | 51 | }) |
48 | </script> | 52 | </script> |
1 | +<!doctype html> | ||
2 | +<html> | ||
3 | +<head> | ||
4 | + <meta charset="utf-8"> | ||
5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
6 | + <title>搜索</title> | ||
7 | + <link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_859074_afg7uk9zst.css"/> | ||
8 | + <link href="__TMPL__/public/assets/css/init.css" rel="stylesheet" type="text/css"> | ||
9 | + <link rel="stylesheet" href="__TMPL__/public/assets/css/search.css"> | ||
10 | +</head> | ||
11 | +<body style="background-color: #fff;"> | ||
12 | +<div class="warp"> | ||
13 | + <div class="serach_box" style="border-bottom: 1px solid #EBEBEB;"> | ||
14 | + <div class="search_item"> | ||
15 | + <div class="iconfont icon-sousuo"></div> | ||
16 | + <div class="input_box"> | ||
17 | + <input type="text" value="{$keyword}" placeholder="输入搜索相关内容"> | ||
18 | + <!--<div class="iconfont icon-cha"></div>--> | ||
19 | + </div> | ||
20 | + </div> | ||
21 | + <a href="{:url('portal/search/index')}"> <div style="color: #000;">取消</div></a> | ||
22 | + </div> | ||
23 | + <!-- begin:搜索结果 --> | ||
24 | + <div class="search_result"> | ||
25 | + <ul class="reco_public"> | ||
26 | + | ||
27 | + <volist name="result" id="vo"> | ||
28 | + <a href="{:url('portal/article/index',['id'=>$vo.id])}"> | ||
29 | + <li> | ||
30 | + <div class="mmend_right"> | ||
31 | + <p class="mmend_title">{$vo.post_title}</p> | ||
32 | + <p class="mmend_name"> {:getDescirpe($vo.post_content)}...</p> | ||
33 | + <p class="mmend_num">{:date('Y.m.d',$vo.create_time)}</p> | ||
34 | + </div> | ||
35 | + <div class="mmend_left"><img src="__TMPL__/public/assets/images/apic01@2x.png"></div> | ||
36 | + </li> | ||
37 | + </a> | ||
38 | + </volist> | ||
39 | + </ul> | ||
40 | + </div> | ||
41 | + | ||
42 | +</div> | ||
43 | + | ||
44 | +<script type="text/javascript" src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script> | ||
45 | +<script type="text/javascript" src="__TMPL__/public/assets/js/fontsize.js"></script> | ||
46 | +<script> | ||
47 | +</script> | ||
48 | +</body> | ||
49 | +</html> |
-
请 注册 或 登录 后发表评论