<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Sell_tag_model CLASS
 *
 * 出售房源Real房属性类
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * @author          xz     
 */

//加载父类
load_m("sell_real_base_model");

class Sell_real_model extends Sell_real_base_model {
      
    /*
     * 构造函数
     */
    public function __construct() 
    {
        parent::__construct();
    }



    public function getWeekVrData(){
        $date = date('Y-m-d');
        $time = time();
        $week = array('周日','周一','周二','周三','周四','周五','周六');
        $week_array = array();
        $defaut = 0;

        $guoqin = array('10-01','10-02','10-03','10-04','10-05','10-06','10-07');
        $r = 0;
        for($i=0;$i<20;$i++){

            $next_date = date('Y-m-d',strtotime( '+'. $i+1 .' days',$time));

            $next_date_new = date('m-d',strtotime( '+'. $i+1 .' days',$time));
            if(in_array($next_date_new,$guoqin)){
                continue;
            }
            //获取每天的剩余数量
            $count_manage = $this->dbback->from('vr_count_manage')->where(array('order_date'=>$next_date))->get()->row_array();
            if($count_manage){
                $total_count = $count_manage['count'];
            }else{
                $total_count = 60;
            }

            $next_date_geshi = date('m月d日',strtotime( '+'. $i+1 .' days',$time));
            $newtime = strtotime($next_date);
            $week_ = date('w',$newtime);
            $week_name = $week[$week_];
            //计算当日预约剩余数量

            $applay_count = $this->db->from('vr_applay')->where(array('order_date'=>$next_date))->where_not_in('shot_status',array(5,6,9))->count_all_results();
            if($applay_count >$total_count){
                $applay_count = $total_count;
            }
            $week_array[$r]['default_check'] = 0;

            $remain = $total_count-$applay_count;
            if(!$defaut && $remain>0){
                $defaut = 1;
                $week_array[$r]['default_check'] = 1;
            }
            $week_array[$r]['date'] = $next_date;
            $week_array[$r]['next_date_format'] = $next_date_geshi;
            $week_array[$r]['week_num'] = $week_;
            $week_array[$r]['week_name'] = $week_name;
            $week_array[$r]['remain_count'] = $remain;
            if(count($week_array) == 7){
                break;
            }
            $r++;
        }
        return $week_array;
    }

}