34 lines
921 B
PHP
34 lines
921 B
PHP
<?php
|
|
|
|
namespace app\model;
|
|
|
|
class Book extends Base
|
|
{
|
|
protected $createTime = 'create_time';
|
|
protected $updateTime = false;
|
|
|
|
public static function getPageList($categoryID = 0, $name = '', $size = 20)
|
|
{
|
|
return self::alias('b')
|
|
->leftJoin('category c', 'b.category_id = c.id')
|
|
->field('b.*,c.name as category_name')
|
|
->when(!empty($categoryID) && $categoryID > 0, function($query) use($categoryID){
|
|
$query->where('b.category_id', $categoryID);
|
|
})
|
|
->when(!empty($name), function($query) use($name){
|
|
$query->where('b.name', 'like', "%$name%");
|
|
})
|
|
->order('b.id desc')
|
|
->paginate([
|
|
'list_rows'=> $size,
|
|
'var_page' => 'page',
|
|
]);
|
|
}
|
|
|
|
public static function getByName($name)
|
|
{
|
|
$name = trim($name);
|
|
return self::where('name', $name)->findOrEmpty();
|
|
}
|
|
|
|
} |