<?php
/**
 * 行为模型
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */

namespace Admin\Model;
use Think\Model;
class LiveAnchorModel extends Model {
    /**分页获取直播历史中推荐商品
     * @return array
     */
    public function get_live_goodslist($id,$field='goods_info',$pagesize=0,$REQUEST=1){
        if(empty($id))return false;
        if(empty($pagesize))$pagesize=C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10;
        if($REQUEST>=1)$REQUEST = (array)I('request.');
        if(!isset($REQUEST['p'])&&isset($REQUEST['page']))$REQUEST['p']=$REQUEST['page'];
        if(intval($REQUEST['p'])<=0)$REQUEST['p']=1;
        $where['id'] = $id;
        $list = M('LiveHistory')->where($where)->getField($field);
        $list = unserialize($list);
        $listcount = count($list);
        $preve = (intval($REQUEST['p'])-1)*$pagesize;
        $Page = new \Common\Vendor\Page($listcount,$pagesize,$REQUEST);
        $return['page'] = $Page->show();
        $return['firstRow'] = $Page->firstRow;
        $return['listRows'] = $Page->listRows;
        $return['totalPages'] = $Page->totalPages;
        $return['list'] = array_slice($list, $preve, $pagesize);
        return $return;    
    }
}