<?php
/**
 * 限时促销控制器
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */
namespace Uapp\Controller;
use Think\Controller;
class PromotSaleController extends BaseController{
	/**
	 * 限时促销
	 */
    public function index($type = 0){
		$return=array('status'=>3);
        $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)){$return['status']=2;$return['msg']="暂无促销活动";$this->ajaxReturn($return);}
        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);
            if($data['goods_info']['list']) {
                foreach ($data['goods_info']['list'] as $key => $val) {
                    $price_info=D('Common/Takeout')->get_min_price($shop_id,$val['id']);
                    $data['goods_info']['list'][$key]['shop_price'] = $price_info['goods_price'];
                    $img=format_url($val['img']);
                    $img=str_replace('https','http',$img);
                    $data['goods_info']['list'][$key]['goods_img']=$img;
                }
            }
        }
        
        $return['status']=1;
        $return['data']['list']=$data;
        $return['data']['act_info']=$act_info;
        $return['data']['web_goods_page']=C('WEB_GOODS_PAGE');
        $map = array();
        $map['id'] = array('gt', 0);
        $map['status'] = 1;
        $cate = M('PurchaseCategory')->where($map)->field('id,name')->order('sort asc,id asc')->select();
        $return['data']['cate_list']=$cate;
        if(empty($data['goods_info']['list'])){
            $return['status']=2;$return['msg']="没有更多数据了";$this->ajaxReturn($return);
        }
        $this->ajaxReturn($return);
    }
}
?>