Novel.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\model;
  4. use think\exception\HttpException;
  5. use app\model\Base;
  6. use think\facade\Config;
  7. class Novel extends Base
  8. {
  9. protected $pk = 'id';
  10. protected $schema = [
  11. "id" => "integer",
  12. "name" => "varchar",
  13. "path" => "varchar",
  14. "size" => "varchar",
  15. "md5_file" => "varchar",
  16. "is_show" => "int",
  17. "is_import" => "int",
  18. "create_time" => "int",
  19. "update_time" => "int"
  20. ];
  21. public static function queryPage($params)
  22. {
  23. $limit = empty($params['limit']) ? Config::get('app.page_size', 20) : (int)$params['limit'];
  24. $order = ['id desc'];
  25. $list = self::where('is_show',1)
  26. ->field('id,name,create_time')
  27. ->order($order)->paginate(['list_rows'=>$limit, 'query' => $params]);
  28. // halt(self::getLastSql());
  29. return $list;
  30. }
  31. public static function getNextPrev($id, $cid = null)
  32. {
  33. $whereP = [];
  34. $whereN = [];
  35. // $whereP[] = ['status', '=', 1];
  36. // $whereN[] = ['status', '=', 1];
  37. if ($cid) {
  38. $whereP[] = ['cid', '=', $cid];
  39. $whereN[] = ['cid', '=', $cid];
  40. }
  41. $whereP[] = ['id', ">", $id];
  42. $whereN[] = ['id', "<", $id];
  43. $data_P = self::where($whereP)->order("id desc")->limit(1)->find();
  44. $data_N = self::where($whereN)->order("id desc")->limit(1)->find();
  45. return ['prev' => $data_P, 'next' => $data_N];
  46. }
  47. public static function createTimeArchive($limit = 0)
  48. {
  49. if ($limit == 0) {
  50. $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->select();
  51. } else {
  52. $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->limit($limit)->select();
  53. }
  54. return $timeList;
  55. }
  56. }