<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action{
    public function index(){
        $groupon = D('Grouponinfo','admin','apps');
        $today_time = time();
        $id = $_GET['id'];
        if($id)
        {
            $grouponinfo = $groupon->where("id=$id")->relation(true)->find();
        }
        else{
            $grouponinfo = $groupon->where("start_time<='$today_time' AND end_time>='$today_time'")->relation(true)->find();
        }
        //不符合条件则跳转到邮件订阅
        if(!$grouponinfo)
        {
            $this->assign("jumpUrl","/apps/help/index.php/index/subscribe");
            $this->success("暂无团购信息");
        }
        $grouponinfo['price_now'] = $grouponinfo['price']*($grouponinfo['rebate']*0.1); //原价乘以折扣等于打折后的价格
        $grouponinfo['small_price'] = $grouponinfo['price']-$grouponinfo['price_now']; //节省下来的价格
        preg_match('/src=\"(.+?)\"/',$grouponinfo['content'],$arr);
        $grouponinfo['img'] = $arr[1];
//seo部分
        $seo = M('Seo');
        $seo_data = $seo->where("seo_page_address='index'")->find();
        $this->assign("seo_data",$seo_data);
        $this->assign("grouponinfo",$grouponinfo);
        $shop = M('Shop');
        $grouponinfo_id = $grouponinfo["id"];
        $shoplist = $shop->where("grouponinfo_id=$grouponinfo_id")->findAll();
        $shopsum = count($shoplist);
        $ch = $grouponinfo['count_person']-$shopsum; //还差多少人
        $func = 180/$grouponinfo['count_person']*$shopsum; //进度条换算;总像素值除以团购上线人数乘以团购报名人数等于进度
//计算团购剩余天数
        $day = intval(($grouponinfo["end_time"]-time())/86400); //差多少天结束
        $hours = intval($day*24);//还差多少小时结束
        $minute = intval($day*24*60*60); //还差多少分
        $sumday = intval($grouponinfo["end_time"]-$grouponinfo["start_time"])/86400; //共23天
        $difference_day = array('day'=>$day,'hours'=>$hours,'minute'=>$minute);
        $this->assign("func",$func);
        $this->assign("difference_day",$difference_day);
        $this->assign("ch",$ch);
        $this->assign("shopsum",$shopsum);
        $this->assign("username",$_SESSION['username']);
        $this->display();
    }

}
?>