<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class HistoryAction extends BaseAction
{
    public function run()
    {
        $pageSize = 20;
        $count = $this->db()->getValue("SELECT COUNT(1) FROM `".Sales::table()."` WHERE `begin` < '{$this->getController()->begin()}'");
        $pageObj = new iPage();
        $pageObj->setTotalRecord($count);
        $pageObj->setPageSize($pageSize);
        $offset = ($pageObj->getCurrentPage() - 1) * $pageSize;
    
        $sql = "SELECT id,subject,win_uid,win_username,win_amount FROM `".Sales::table()."` WHERE `begin` < '{$this->getController()->begin()}' ORDER BY id DESC LIMIT $offset,$pageSize";
        $result = $this->db()->setQueryString($sql)->find();
        $floor = $count - ($pageObj->getCurrentPage() - 1) * $pageSize;
        
        $this->getController()->render('history',array(
                'result' => $result,
                'floor' => $floor,
                'pageObj' => $pageObj
            )
        );
    }
}