wesmiler 5 лет назад
Родитель
Сommit
7c6c23cda5

+ 8 - 3
app/index/controller/IndexController.php

@@ -104,10 +104,15 @@ class IndexController extends HomeBaseController
 
 
         // 热点新闻
-        $newsHot = NewsService::getHotList();
+        $recNews = NewsService::getNewList(6);
 
         // 加盟问答
-        $answerList = NewsService::getListByLevel(1, 13);
+        $answerList = Db::name('know')->whereIn('status',[1,2])
+            ->field('id,title,description')
+            ->order('create_time desc')
+            ->limit(13)
+            ->select();
+//        $answerList = NewsService::getListByLevel(1, 13);
 
         // 课堂列表
         $courseList = NewsService::getListByLevel(2, 7);
@@ -158,7 +163,7 @@ class IndexController extends HomeBaseController
         $this->assign('cateNews2',$cateNews2);
         $this->assign('cateNews2',$cateNews2);
         $this->assign('newsCates',$newsCates);
-        $this->assign('newsHot',$newsHot);
+        $this->assign('recNews',$recNews);
         $this->assign('answerList',$answerList);
         $this->assign('jmMessages',$jmMessages);
         $this->assign('courseList',$courseList);

+ 1 - 1
app/index/controller/KnowController.php

@@ -6,7 +6,7 @@ class KnowController extends HomeBaseController
 {
     public function index()
     {
-        $lists = Db::name('know')->field('id,title,username,author,create_time')->paginate(20);
+        $lists = Db::name('know')->whereIn('status',[1,2])->field('id,title,username,author,create_time')->paginate(20);
         $this->assign('lists',$lists);
         return $this->fetch();
     }

+ 21 - 0
app/index/service/NewsService.php

@@ -66,6 +66,27 @@ class NewsService
     }
 
     /**
+     * 获最新发布信息
+     * @param int $num 记录数
+     * @param string $field 字段
+     * @return array|\PDOStatement|string|\think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getNewList($num=6, $field=''){
+        $field = $field? $field : 'id,title,thumb,keywords,description,create_time';
+        $result = Db::name('news')
+            ->where('status',1)
+            ->field($field)
+            ->order('update_time desc, create_time desc,id desc')
+            ->limit($num)
+            ->select();
+
+        return $result? $result->toArray() : [];
+    }
+
+    /**
      * 获取分类对应的信息列表
      * @param $cateId 分类ID:数组则为多个分类
      * @param $num 记录数

+ 7 - 7
public/themes/mjmls/index/index/news/join.html

@@ -12,7 +12,7 @@
         </h2>
         <div class="join-infor">
             <div class="fl join-infor-left">
-                <foreach name="newsHot" id="v">
+                <foreach name="recNews" id="v">
                     <if condition="$key eq 0">
                         <div>
                             <a href="/news{$v.id}/" target="_blank" title="{$v.title}">
@@ -29,7 +29,7 @@
                     </if>
                 </foreach>
                 <ul class="jmzx-list">
-                    <foreach name="newsHot" id="v">
+                    <foreach name="recNews" id="v">
                         <if condition="$key gt 0">
                             <li><a href="/news{$v.id}/" target="_blank" title="{$v.title}">{$v.title}</a></li>
                         </if>
@@ -67,22 +67,22 @@
                 </div>
             </div>
             <div class="fr join-infor-right">
-                <div class="wd-tit">加盟问答<a href="/news/level-1.shtml" target="_blank">更多 ></a></div>
+                <div class="wd-tit">加盟问答<a href="/know/" target="_blank">更多 ></a></div>
                 <foreach name="answerList" id="v">
                     <if condition="$key eq 0">
                     <div class="infor-rd">
                         <h3 class="nowrap">
                             <i>热点</i>
-                            <a href="/news{$v.id}/" target="_blank" title="{$v.title}">{$v.title}</a>
+                            <a href="/know/detail/{$v.id}/" target="_blank" title="{$v.title}">{$v.title}</a>
                         </h3>
-                        <p>{$v.description}<a href="/news{$v.id}/" target="_blank">【详情】</a></p>
+                        <p>{$v.description}<a href="/know/detail/{$v.id}/" target="_blank">【详情】</a></p>
                     </div>
                     </if>
                 </foreach>
                 <ul class="jmzx-list">
-                    <foreach name="answerList" id="newsList">
+                    <foreach name="answerList" id="v">
                         <if condition="$key gt 0">
-                        <li><a href="/news{$v.id}/" target="_blank" title="{$v.title}">{$v.title}</a></li>
+                        <li><a href="/know/detail/{$v.id}/" target="_blank" title="{$v.title}">{$v.title}</a></li>
                         </if>
                     </foreach>
                 </ul>