<?php

namespace app\model;

use think\Model;

class Base extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    //protected $table = 'test';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    public static function getByID($id)
    {
        if($id <= 0) return null;

        return self::where('id', $id)->findOrEmpty();
    }

    //根据ID更新数据
    public static function updateByID($id, $data)
    {
        return self::where('id', $id)->update($data);
    }

    //根据where条件和排序获取记录
    public static function getListByWhereAndOrder($where, $order, $limit = 1)
    {
        return self::where($where)
            ->order($order)
            ->limit($limit)
            ->select();
    }
}