|
@@ -139,36 +139,24 @@ class Article extends Base
|
|
|
|
|
|
public static function getNextPrev($id, $cid = null)
|
|
public static function getNextPrev($id, $cid = null)
|
|
{
|
|
{
|
|
|
|
+ $whereP = [];
|
|
|
|
+ $whereN = [];
|
|
|
|
+
|
|
|
|
+ $whereP[] = ['status', '=', 1];
|
|
|
|
+ $whereN[] = ['status', '=', 1];
|
|
|
|
+
|
|
if ($cid) {
|
|
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)
|
|
public static function createTimeArchive($limit = 0)
|