@@ -455,9 +455,9 @@ public static function randomBlog($limit)
455455 * @example
456456 * // $option 说明
457457 * // 发布时间倒序
458- * $option = [ 'order'=>['postTime ', 'desc'] ];
458+ * $option = [ 'order'=>['id ', 'desc'] ];
459459 * // 发布时间顺序
460- * $option = [ 'order'=>['postTime ', 'asc'] ];
460+ * $option = [ 'order'=>['id ', 'asc'] ];
461461 * // 增加检索条件
462462 * $option = [ 'where'=>['id'=>1] ];
463463 */
@@ -522,15 +522,14 @@ public static function listBlogByYear($option = [])
522522 {
523523
524524 $ records = Blog::query ()->where (['isPublished ' => true ])
525- ->where ('postTime ' , '< ' , date ('Y-m-d H:i:s ' ))
526- ->orderBy ('postTime ' , 'desc ' )
527- ->get (['id ' , 'images ' , 'tag ' , 'title ' , 'categoryId ' , 'postTime ' ])
525+ ->orderBy ('id ' , 'desc ' )
526+ ->get (['id ' , 'images ' , 'tag ' , 'title ' , 'categoryId ' , 'created_at ' ])
528527 ->toArray ();
529528 $ records = self ::buildRecords ($ records );
530529
531530 $ yearRecords = [];
532531 foreach ($ records as $ i => $ v ) {
533- $ year = date ('Y ' , strtotime ($ v ['postTime ' ]));
532+ $ year = date ('Y ' , strtotime ($ v ['created_at ' ]));
534533 if (!isset ($ yearRecords [$ year ])) {
535534 $ yearRecords [$ year ] = [
536535 'count ' => 0 ,
@@ -653,10 +652,10 @@ public static function tagRecords()
653652 public static function archiveMonthCounts ($ year )
654653 {
655654 $ archiveCounts = Blog::query ()
656- ->where ('postTime ' , '< ' , date ('Y-m-d H:i:s ' ))
657- ->where ('postTime ' , '>= ' , $ year . '-01-01 00:00:00 ' )
658- ->where ('postTime ' , '<= ' , $ year . '-12-31 23:59:59 ' )
659- ->select ([DB ::raw ("DATE_FORMAT(`postTime `,'%m') AS `month` " ), DB ::raw ("COUNT(*) AS total " )])
655+ ->where ('created_at ' , '< ' , date ('Y-m-d H:i:s ' ))
656+ ->where ('created_at ' , '>= ' , $ year . '-01-01 00:00:00 ' )
657+ ->where ('created_at ' , '<= ' , $ year . '-12-31 23:59:59 ' )
658+ ->select ([DB ::raw ("DATE_FORMAT(`created_at `,'%m') AS `month` " ), DB ::raw ("COUNT(*) AS total " )])
660659 ->groupBy ('month ' )
661660 ->orderBy ('month ' , 'desc ' )
662661 ->get ()->toArray ();
@@ -680,9 +679,8 @@ public static function archiveMonthCounts($year)
680679 */
681680 public static function archiveYearCounts ()
682681 {
683- $ archiveCounts = Blog::query ()
684- ->where ('postTime ' , '< ' , date ('Y-m-d H:i:s ' ))
685- ->select ([DB ::raw ("DATE_FORMAT(`postTime`,'%Y') AS `year` " ), DB ::raw ("COUNT(*) AS total " )])
682+ $ archiveCounts = Blog::published ()
683+ ->select ([DB ::raw ("DATE_FORMAT(`created_at`,'%Y') AS `year` " ), DB ::raw ("COUNT(*) AS total " )])
686684 ->groupBy ('year ' )
687685 ->orderBy ('year ' , 'desc ' )
688686 ->get ()->toArray ();
0 commit comments