|
@@ -96,12 +96,12 @@ class Article extends Base
|
|
$list = self::where($where)
|
|
$list = self::where($where)
|
|
->field('id,cid,title,titlepic,username,summary,content_type,hits,sort,status,create_time')
|
|
->field('id,cid,title,titlepic,username,summary,content_type,hits,sort,status,create_time')
|
|
->with(['category'])
|
|
->with(['category'])
|
|
- ->order($order)->paginate($limit, false, ['query' => $params]);
|
|
|
|
|
|
+ ->order($order)->paginate(['list_rows'=>$limit, 'query' => $params]);
|
|
|
|
|
|
return $list;
|
|
return $list;
|
|
}
|
|
}
|
|
|
|
|
|
- public static function getListByCid($cid = 0, $limit = 10, $order = [])
|
|
|
|
|
|
+ public static function getListByCid($cid = 0, $limit = 10, $order = "")
|
|
{
|
|
{
|
|
$where = [];
|
|
$where = [];
|
|
|
|
|
|
@@ -112,10 +112,12 @@ class Article extends Base
|
|
$where[] = ['cid', '=', $cid];
|
|
$where[] = ['cid', '=', $cid];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ $where[] = ['status', '=', 1];
|
|
|
|
|
|
- $order = !empty($order) ? array_merge($order, ['id' => 'desc']) : ['id' => 'desc'];
|
|
|
|
|
|
+ $order = $order ?? "sort ASC,id DESC";
|
|
|
|
|
|
- return self::where($where)
|
|
|
|
|
|
+ return self::with('category')->where($where)
|
|
->field('id,cid,title,titlepic,username,summary,hits,sort,status,create_time')
|
|
->field('id,cid,title,titlepic,username,summary,hits,sort,status,create_time')
|
|
->order($order)->limit($limit)->select();
|
|
->order($order)->limit($limit)->select();
|
|
}
|
|
}
|
|
@@ -123,7 +125,7 @@ class Article extends Base
|
|
public static function getTop($limit)
|
|
public static function getTop($limit)
|
|
{
|
|
{
|
|
return self::with('category')->field('id,cid,title,titlepic,summary,username,hits,sort,status,create_time')
|
|
return self::with('category')->field('id,cid,title,titlepic,summary,username,hits,sort,status,create_time')
|
|
- ->order('sort desc')->limit($limit)->select();
|
|
|
|
|
|
+ ->order('sort ASC, id DESC')->limit($limit)->select();
|
|
}
|
|
}
|
|
|
|
|
|
public static function getOne($id)
|
|
public static function getOne($id)
|
|
@@ -169,15 +171,13 @@ class Article extends Base
|
|
return ['prev' => $data_p, 'next' => $data_N];
|
|
return ['prev' => $data_p, 'next' => $data_N];
|
|
}
|
|
}
|
|
|
|
|
|
- public static function createTimeArchive()
|
|
|
|
|
|
+ public static function createTimeArchive($limit = 0)
|
|
{
|
|
{
|
|
- $create_times = self::order('create_time desc')->column('create_time');
|
|
|
|
- $timeList = [];
|
|
|
|
- foreach ($create_times as $value) {
|
|
|
|
- $yearAndMonth = date("Y-m", $value);
|
|
|
|
- $timeList[] = $yearAndMonth;
|
|
|
|
|
|
+ if ($limit == 0) {
|
|
|
|
+ $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->select();
|
|
|
|
+ } else {
|
|
|
|
+ $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->limit($limit)->select();
|
|
}
|
|
}
|
|
- $timeList = array_unique($timeList);
|
|
|
|
|
|
|
|
return $timeList;
|
|
return $timeList;
|
|
}
|
|
}
|