<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class BookTipping extends Model
{
    public static $maxTipping = 500;

    public static $nomalSize = 100000;

    public static $addSplice = 100000;
    
    public static function table()
    {
        return 'ig_booktipping';
    }

	public static function single($className = __CLASS__)
	{
		return parent::single($className);
	}

    public static function getMaxTipping($size)
    {
        if ($size < self::$nomalSize)
        {
            return self::$maxTipping;
        }
        
        return round($size / self::$addSplice) * self::$maxTipping;
    }

    public function userTodayTipping($uid, $bookId)
    {
        $num = $this->Db()->getValue('SELECT SUM(num) FROM '.self::table().' WHERE uid = '.$uid.' AND bookid = ' . $bookId . ' AND `date` = ' . S::sqlEscape(CDATE));
        
        return $num ? $num : 0;
    }
}