<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * 营销中心首页
 */

class bid_message extends MY_Controller{
    
   


    public function __construct($type = NULL) {
        parent::__construct($type);
        
    }
   
    
    //竞投提示消息
    public function index(){
        $broker_arr = $this->user_arr;
        $broker['id'] = $broker_arr['uid'];
        $broker['groupid'] = $broker_arr['groupid'];
        $broker['truename'] = $broker_arr['truename'];
		$broker['is_pay'] = $broker_arr['is_pay'];
        //经纪人成长值等级数据  
        $growthBrokerExp = new GrowthBrokerExp($broker);
        $broker['level'] = $growthBrokerExp->getLevel();
        if(!$this->cheak_bid_center_view_auth($broker)) {//没有权限结束，返回-1
            echo -1;exit;
        }
        $action = $this->input->get('action');
        $request = new Request();
        if($request->isAjax()) {
            $cookie_close_bid_tip = $this->input->cookie('close_bid_tip', TRUE);
          
            if($action=='msg') {
               
                if($cookie_close_bid_tip) {
                    //setcookie("close_bid_tip", 1, time()-1, "/", "zsb.house365.com",false,true);
                    //echo -1;exit;//已经关闭
                    $closeTips = unserialize($cookie_close_bid_tip);
                } else {
                    $closeTips = array();
                }
                        //积分
                $growthBrokerCredit = new GrowthBrokerCredit($broker);
                $myCredit = $growthBrokerCredit->getValidCredit();
                $broker['credit'] = $myCredit;
                $arr = array();
                $date = date("Y-m-d");

                $growthBidPeriods = new GrowthBidPeriods();
				if(!in_array('house', $closeTips)) {
                    $houseBidPeriod = $growthBidPeriods->currentBidPeriods(2);
                    $hasHouseBid = $date == substr($houseBidPeriod['start_time'], 0, 10);
                    //$hasHouseBid = 1;
                    if($hasHouseBid) {
                        $temp = array();
                        $temp['tips'] = "还在苦等刷新？竞投成功，强力曝光，流量大幅涨，助您立马开单！";
                        $temp['tips1'] = '竞投今天 <span class="bl_num">'.substr($houseBidPeriod['start_time'], -8,-3).'</span> 至 <span class="bl_num">'.substr($houseBidPeriod['end_time'], -8,-3).'</span> 开放。';
                        $temp['tips2'] = date("Y.m.d",strtotime($houseBidPeriod['tg_start_time'])).'-'.date("Y.m.d",strtotime($houseBidPeriod['tg_end_time']));//2014.04.1 - 2014.04.07 
                        $temp['qiangLink'] = '/market_index/';
                        $arr['house'] = $temp;
                    }
                }

                /*if(!in_array('block_expert', $closeTips)) {
                    $blockBidPeriod = $growthBidPeriods->currentBidPeriods(1);
                    $hasBlockBid = $date == substr($blockBidPeriod['start_time'], 0, 10);
                    //$hasBlockBid = 1;

                    if($hasBlockBid) {
                        $temp = array();
                        $temp['tips'] = "经纪人扎堆热门小区，做小区专家脱颖而出。客户来电接不停！ ";
                        $temp['tips1'] = '小区专家竞投今天 <span class="bl_num">'.substr($blockBidPeriod['start_time'], -8,-3).'</span> 至 <span class="bl_num">'.substr($blockBidPeriod['end_time'], -8,-3).'</span> 开放。';
                        $temp['tips2'] = date("Y.m.d",strtotime($blockBidPeriod['tg_start_time'])).'-'.date("Y.m.d",strtotime($blockBidPeriod['tg_end_time']));//2014.04.1 - 2014.04.07 
                        $temp['qiangLink'] = '/market_bid_block_expert/index/';
                        $arr['block_expert'] = $temp;
                        
                    }
                }
                if(!in_array('house', $closeTips)) {
                    $houseBidPeriod = $growthBidPeriods->currentBidPeriods(2);
                    $hasHouseBid = $date == substr($houseBidPeriod['start_time'], 0, 10);
                    //$hasHouseBid = 1;
                    if($hasHouseBid) {
                        $temp = array();
                        $temp['tips'] = "还在苦等刷新？竞投成功，强力曝光，流量大幅涨，助您立马开单！";
                        $temp['tips1'] = '二手房源竞投今天 <span class="bl_num">'.substr($houseBidPeriod['start_time'], -8,-3).'</span> 至 <span class="bl_num">'.substr($houseBidPeriod['end_time'], -8,-3).'</span> 开放。';
                        $temp['tips2'] = date("Y.m.d",strtotime($houseBidPeriod['tg_start_time'])).'-'.date("Y.m.d",strtotime($houseBidPeriod['tg_end_time']));//2014.04.1 - 2014.04.07 
                        $temp['qiangLink'] = '/market_bid_house_manage/all/';
                        $arr['house'] = $temp;
                    }
                }
             
                if(!in_array('rent', $closeTips)) {
                    $houseBidPeriod = $growthBidPeriods->currentBidPeriods(3);
                    $hasHouseBid = $date == substr($houseBidPeriod['start_time'], 0, 10);
                    //$hasHouseBid = 1;
                    if($hasHouseBid) {
                        $temp = array();
                        $temp['tips'] = "还在苦等刷新？竞投成功，强力曝光，流量大幅涨，助您立马开单！";
                        $temp['tips1'] = '租房源竞投今天 <span class="bl_num">'.substr($houseBidPeriod['start_time'], -8,-3).'</span> 至 <span class="bl_num">'.substr($houseBidPeriod['end_time'], -8,-3).'</span> 开放。';
                        $temp['tips2'] = date("Y.m.d",strtotime($houseBidPeriod['tg_start_time'])).'-'.date("Y.m.d",strtotime($houseBidPeriod['tg_end_time']));//2014.04.1 - 2014.04.07 
                        $temp['qiangLink'] = '/market_bid_rent_manage/all/';
                        $arr['rent'] = $temp;
                    }
                }*/

                if(count($arr)==0) {
                    echo -1;exit;
                }
                //print_r($blockBidPeriod);
                $data['broker'] = $broker;
                $data['arr'] = $arr;
                $this->load->view("bid_message",$data);
              
            }
            
            if($action=='close') {
                //到当天晚上12点
                if($cookie_close_bid_tip) {
                    $value = unserialize($cookie_close_bid_tip);
                } else {
                    $value = array();
                }
                $msgType = $this->input->get('msgType',TRUE);               
                $value[] = $msgType;
                //print_r($value);
        
                setcookie("close_bid_tip", serialize($value), strtotime(date("Y-m-d")." 23:59:59"), "/", $_SERVER['HTTP_HOST'],false,true);
            }
        }
    }


   
        /**
         * 检查营销中心竞投功能的使用权限
         * @param array $broker 经纪人数组，包含经纪人的等级，和是否付费
         * @return boolean 有权限返回true，没权限返回false
         */
        private function cheak_bid_center_view_auth($broker) {
            if($broker['is_pay'] != $this->config->item('is_pay')) {//免费的，没权限，返回false
                return false;
            }
            $brokerLevelNum = intval(substr($broker['level'],2));
            //经纪人操作等级最低权限
            $growthBidLowLevel = new GrowthBidLowLevel();
            $lowLevel = $growthBidLowLevel->findLevelByType(1);
            $lowLevelId = intval(substr($lowLevel,2));
            if ($brokerLevelNum < $lowLevelId) {
               return false;
            } else {
                return true;
            }
        }
}