<?php
/**
 * 限时促销控制器
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */
namespace Mobile\Controller;
use Think\Controller;
class PromotSaleController extends BaseController{
	/**
	 * 限时促销
	 */
    public function index($type = 0){
		$shop_id = get_wxsmall_shop_id();
		$getdata = I('param.');
		//限时促销信息
		$map['is_limit_time']=1;
		$map['pid']=0;
		$map['start_time']=array('lt',NOW_TIME);
		$map['end_time']=array('gt',NOW_TIME);
		$act_info=M('PromotAct')->where($map)->field(true)->find();
	//	if(empty($act_info)){$this->error('暂无促销活动',U('Index/index'));}
		$this->assign('act_info',$act_info);
		if($act_info['shop_id'] != '0' && !str_exists($act_info['shop_id'],','.$shop_id.',')){
			$data['goods_info']['list'] = array();
		}else{
			//限时商品信息
			$getdata['act_id'] = $act_info['id'];
			$data = D('Common/Promot')->get_promot_goods($getdata);
			
			$p = empty($getdata['page']) ? 1 : $getdata['page'];
			if($data['goods_info']['count'] > $p*$data['goods_info']['listRows']){
				$data['goods_info']['show'] = 1;
			}else{
				$data['goods_info']['show'] = 0;
			}
		}
		// echo "<pre>";print_r($data);exit;
		if ($type == 1) return $data['goods_info'];
		$this->assign($data['goods_info']);
        $this->assign('tplseo_title',$act_info['act_name'].'_限时促销'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','限时促销');
        $this->display();
    }
	/**
	 * 加载更多
	 */
	public function get_index_list(){
        $return['status'] = 0;
        $data = $this->index(1);
        if (empty($data['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('index_list');
        $return['data'] = $list_html;
		$return['show'] = $data['show'];
        $this->ajaxReturn($return);
    }
}
?>