<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class JoinListAction extends BaseAction
{
    public function run()
    {
        $pageSize = 20;
        $id = S::gp('id', 'G', 2);
        $sale = $this->db()->select()->from(Sales::table())->where('id='.$id)->find(true);
        if (empty($sale))
        {
            throw new iSystemException('不存在的抢拍');
        }
        $count = $this->db()->getValue("SELECT COUNT(DISTINCT uid) AS c FROM ".SaleJoins::table()." WHERE sale_id = $id");
        $pageObj = new iPage();
        $pageObj->setTotalRecord($count);
        $pageObj->setPageSize($pageSize);
        $offset = ($pageObj->getCurrentPage() - 1) * $pageSize;
    
        $sql = "SELECT uid,username FROM ".SaleJoins::table()." WHERE sale_id = $id GROUP BY uid ORDER BY id DESC LIMIT $offset,$pageSize";
        $result = $this->db()->setQueryString($sql)->find();
    
        $floor = $count - ($pageObj->getCurrentPage() - 1) * $pageSize;
        
        $this->getController()->render('joinlist',array(
                'sale' => $sale,
                'result' => $result,
                'pageObj' => $pageObj,
                'floor' => $floor,
            )
        );
    }
}