<?php

namespace app\model;

//大厅布局
class HallLayout 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[] = ['title', 'like', '%' . $keyword . '%'];
            $pageParam['keyword'] = $keyword;
        }

        $paginate = [
            'list_rows' => $per,
            'query' => $pageParam
        ];
        return self::when(count($whereMap) > 0, function ($query) use ($whereMap) {
            $query->where($whereMap);
        })
            ->order("sort desc")
            ->paginate($paginate, false);
    }

    public static function getAll(){
        return self::select()->toArray();
    }
}