52 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
		
		
			
		
	
	
			52 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
|  | <?php | ||
|  | 
 | ||
|  | namespace app\model; | ||
|  | 
 | ||
|  | //大厅
 | ||
|  | class Hall extends Base | ||
|  | { | ||
|  |     protected $autoWriteTimestamp = true; | ||
|  | 
 | ||
|  |     public static function onAfterInsert($item) | ||
|  |     { | ||
|  |         $item->sort = $item->id; | ||
|  |         $item->save(); | ||
|  |     } | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  |     /** | ||
|  |      * 获取列表 | ||
|  |      * @param int $per 每页数量 | ||
|  |      * @param string $keyword 关键词 | ||
|  |      * @return \think\Paginator | ||
|  |      * @throws \think\db\exception\DbException | ||
|  |      */ | ||
|  |     public static function getList( $per = 20, $keyword = '') | ||
|  |     { | ||
|  |         $whereMap = []; | ||
|  |         $pageParam = []; | ||
|  | 
 | ||
|  |         if (!empty($keyword)) { | ||
|  |             $whereMap[] = ['a.title', 'like', '%' . $keyword . '%']; | ||
|  |             $pageParam['keyword'] = $keyword; | ||
|  |         } | ||
|  | 
 | ||
|  |         $paginate = [ | ||
|  |             'list_rows' => $per, | ||
|  |             'query' => $pageParam | ||
|  |         ]; | ||
|  |         return self::alias("a")->join("hall_layout b","a.layout_id = b.id")->when(count($whereMap) > 0, function ($query) use ($whereMap) { | ||
|  |             $query->where($whereMap); | ||
|  |         }) | ||
|  |             ->order("a.sort desc") | ||
|  |             ->field('a.*,b.layout_img,b.title as layout_title') | ||
|  |             ->paginate($paginate, false); | ||
|  |     } | ||
|  | 
 | ||
|  |     public function setImgsAttr($name){ | ||
|  |        return json_encode($name); | ||
|  |     } | ||
|  | 
 | ||
|  | } |