1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- declare(strict_types=1);
- namespace app\model;
- use think\exception\HttpException;
- use app\model\Base;
- use think\facade\Config;
- class Novel extends Base
- {
- protected $pk = 'id';
- protected $schema = [
- "id" => "integer",
- "name" => "varchar",
- "path" => "varchar",
- "size" => "varchar",
- "md5_file" => "varchar",
- "is_show" => "int",
- "is_import" => "int",
- "create_time" => "int",
- "update_time" => "int"
- ];
- public static function queryPage($params)
- {
- $limit = empty($params['limit']) ? Config::get('app.page_size', 20) : (int)$params['limit'];
-
- $order = ['id desc'];
- $list = self::where('is_show',1)
- ->field('id,name,create_time')
- ->order($order)->paginate(['list_rows'=>$limit, 'query' => $params]);
- // halt(self::getLastSql());
- return $list;
- }
- public static function getNextPrev($id, $cid = null)
- {
- $whereP = [];
- $whereN = [];
- // $whereP[] = ['status', '=', 1];
- // $whereN[] = ['status', '=', 1];
-
- if ($cid) {
- $whereP[] = ['cid', '=', $cid];
- $whereN[] = ['cid', '=', $cid];
- }
- $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];
- }
- public static function createTimeArchive($limit = 0)
- {
- 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();
- }
- return $timeList;
- }
- }
|