huwhois 2 years ago
parent
commit
a6b58d803e
4 changed files with 17 additions and 32 deletions
  1. 14 26
      app/common/model/Article.php
  2. 1 4
      app/index/route/app.php
  3. 1 1
      view/index/article/index.html
  4. 1 1
      view/index/layout.html

+ 14 - 26
app/common/model/Article.php

@@ -139,36 +139,24 @@ class Article extends Base
 
     public static function getNextPrev($id, $cid = null)
     {
+        $whereP = [];
+        $whereN = [];
+
+        $whereP[] = ['status', '=', 1];
+        $whereN[] = ['status', '=', 1];
+        
         if ($cid) {
-            $id_list = self::where(['status' => 1, 'cid' => $cid])
-                ->order(['sort' => 'desc', 'id' => 'desc'])
-                ->column('id');
-        } else {
-            $id_list = self::where(['status' => 1])->column('id');
+            $whereP[] = ['cid', '=', $cid];
+            $whereN[] = ['cid', '=', $cid];
         }
 
-        if (count($id_list)==1) {
-            $data_p = null;
-            $data_N = null;
-        } else {
-            $key = array_search($id, $id_list);
-            if ($key == 0) {
-                $data_p = null;
-                $N = $id_list[1];
-                $data_N = self::field('id,title,create_time')->find($N);
-            } elseif ($key == count($id_list) - 1) {
-                $P = $id_list[count($id_list) - 2];
-                $data_p = self::field('id,title,create_time')->find($P);
-                $data_N = null;
-            } else {
-                $P = $id_list[$key - 1];
-                $data_p =  self::field('id,title,create_time')->find($P);
-                $N = $id_list[$key + 1];
-                $data_N =  self::field('id,title,create_time')->find($N);
-            }
-        }
+        $whereP[] = ['id', ">", $id];
+        $whereN[] = ['id', "<", $id];
+
+        $data_P = self::where($whereP)->order("id desc")->limit(1)->find();
+        $data_N = self::where($whereN)->order("id desc")->limit(1)->find();
 
-        return ['prev' => $data_p, 'next' => $data_N];
+        return ['prev' => $data_P, 'next' => $data_N];
     }
 
     public static function createTimeArchive($limit = 0)

+ 1 - 4
app/index/route/app.php

@@ -30,7 +30,6 @@ Route::get('/guest_book', 'index/index/guestBook');
 Route::post('/save_guest_book', 'index/index/saveGuestBook');
 
 Route::get('/tags/:name', 'index/article/tags');
-Route::get('/time-<page?>', 'index/article/time')->append(['_aside' => true]);
 Route::get('/all-<page?>', 'index/article/index')->append(['cid' => 0]);
 Route::post('/dolike', 'index/article/dolike');
 Route::get('/:year/<month>-<day>/:id', 'index/article/read');
@@ -39,7 +38,5 @@ Route::get('/:year/<month>-<page?>', 'index/article/archive');
 $list = Category::getList();
 
 foreach ($list as $key => $value) {
-    if ($value->template == 'article') {
-        Route::get($value->route . '-<page?>', 'index/article/index')->append(['cid' => $value->id]);
-    }
+    Route::get($value->url . '-<page?>', $value->route)->append(['cid' => $value->id]);
 }

+ 1 - 1
view/index/article/index.html

@@ -2,7 +2,7 @@
   <div class="place">
     <a href="/all.html" class="{$cid==0 ? 'current_category': ''}">All</a>
     {foreach $cate_lists as $value}
-    <a href="{$value.route}" class="{$cid==$value.id ? 'current_category': ''}">{$value.name}</a>
+    <a href="{$value.url}" class="{$cid==$value.id ? 'current_category': ''}">{$value.name}</a>
     {/foreach}
   </div>
   <div class="blank"></div>

+ 1 - 1
view/index/layout.html

@@ -18,7 +18,7 @@
       <ul id="starlist">
         <li><a href="{:url('/index')}">网站首页</a></li>
         {foreach $categories as $val}
-        <li><a href="{:url($val.route)}">{$val.name}</a></li>
+        <li><a href="{:url($val.url)}">{$val.name}</a></li>
         {/foreach}
       </ul>
     </nav>