<?php
/**
 * lionfish 商城系统
 *
 * ==========================================================================
 * @link      http://www.liofis.com/
 * @copyright Copyright (c) 2015 liofis.com. 
 * @license   http://www.liofis.com/license.html License
 * ==========================================================================
 *
 * @author    fish
 *
 */
namespace Admin\Model;
use Think\Model;
class SubjectModel extends Model{
	
	public function show_subject_page( $where = "" ){
		
		$sql='SELECT * FROM '.C('DB_PREFIX').'subject ';
		
		if(!empty($where))
		{
			$sql .= $where;
		}
		
		$count=count(M()->query($sql));
		
		$Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
		
		$show  = $Page->show();// 分页显示输出	
		
		$sql.=' order by add_time desc LIMIT '.$Page->firstRow.','.$Page->listRows;
		
		$list=M()->query($sql);

		
		return array(
			'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
			'list'=>$list,
			'page'=>$show
		);	
		
	}
	
	public function show_subjectgoods_page( $super_id =0){
	
	    //goods_id
	    $sql='SELECT g.name,g.image,g.quantity,g.type,g.lock_type,g.danprice,g.pinprice,g.seller_count,g.store_id,sg.id,sg.goods_id, sg.state,sg.addtime FROM '.C('DB_PREFIX').'subject_goods as sg, 
	        '.C('DB_PREFIX').'goods as g where sg.goods_id = g.goods_id  and sg.subject_id = '.$super_id;
	
	    $count=count(M()->query($sql));
	
	    $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
	
	    $show  = $Page->show();// 分页显示输出
	
	    $sql.=' order by sg.addtime desc LIMIT '.$Page->firstRow.','.$Page->listRows;
	
	    $list=M()->query($sql);
	    foreach ($list as $key => $value) {
	        $list[$key]['image']=resize($value['image'], 100, 100);
	    }
	
	    return array(
	        'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
	        'list'=>$list,
	        'page'=>$show
	    );
	
	}
	
	
}
?>