<?php
/** App登录控制器
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoq <xiaoq@570035208.com>
 */

namespace Uapp\Controller;
class ActivityController extends BaseController {
	public function _initialize(){
        parent::_initialize ();
    }
    public function index(){
        $param=I('param.');
        $user_info=$this->checkuserauth();
        $param['uid']=$user_info['id'];
        $param['shop_id']=$user_info['HCshop']['bind_shop_id'];//追加当前会员匹配的门店
        $return=D('Wxsmall/Activity')->get_index($param);
        $this->ajaxReturn($return);
    }
    public function addcart(){
        $param=I('param.');
        $user_info=$this->checkuserauth();
        $param['uid']=$user_info['id'];
        $return=D('Wxsmall/Activity')->get_index($param);
        $this->ajaxReturn($return);
    }

    /**
     * 优惠活动列表
     */
    public function activity_list(){
        $return=array("status"=>2,'msg'=>"没有更多数据了");
        $user_info=$this->checkuserauth();
        $shop_id=$user_info['HCshop']['bind_shop_id'];//追加当前会员匹配的门店
        //$shop_id=get_wxsmall_shop_id();
        $page=I('get.page')?I('get.page'):1;
        $map = array();
        $map['start_time'] = array('lt', NOW_TIME);
        $map['end_time'] = array('gt', NOW_TIME);
        $map['act_type'] = array('in', array(1,2,3,4));
        $map['is_pt'] = 0;//排除拼团
        $map['is_limit_time'] = 0;//限时促销
        $map['is_check'] = array("elt",1);//审核过
        $map['_string'] = 'shop_id = '.$shop_id.' or shop_id = 0';
        $list = page_list('PromotAct', $map, 'sort desc', '', '', '',$page);
        if(empty($list['list']))$this->ajaxReturn($return);
        $return['data']=$list['list'];
        $return['status']=1;
        $this->ajaxReturn($return);
    }

    /**
     * 限时促销
     */
    public function promat_sale(){
        $return=array('status'=>3);
        $getdata = I('param.');
        $user_info=$this->checkuserauth();
        $shop_id=$user_info['HCshop']['bind_shop_id'];//追加当前会员匹配的门店
        //限时促销信息
        $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;
                }
            }
        }
        if(empty($data['goods_info']['list'])){
            $return['status']=2;$return['msg']="没有更多数据了";$this->ajaxReturn($return);
        }
        $return['status']=1;
        $return['data']['list']=$data;
        $return['data']['act_info']=$act_info;
        $return['data']['web_goods_page']=C('WEB_GOODS_PAGE');
        $this->ajaxReturn($return);
    }
}