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

/**
 * 首页功能类 
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * 
 */
class welcome_zhou_model extends MY_Model{
    
    public function __construct() {
        parent::__construct(1,1,3);
   }
   
   /**
    * 查询经纪人收藏的应用管理
    * get_app_custom
    * @param int $uid
    * @return array
    */
   public function get_app_custom($uid){
        
        $key = $this->config_cityflag . '_get_app_custom_' . $uid;
        $cache = $this->mc->get($key);

        if($cache['isok'] == 1)
        {
            $return_data = $cache['data'];
        }
        else
        {
            //查询字段
            $this->dbback->select('app_custom');
            //查询条件
            $this->dbback->where("uid = '".$uid."'");
            //查询
            $arr_data = $this->dbback->get('broker_sub')->row_array();
            $return_data = isset($arr_data['app_custom']) ? $arr_data['app_custom'] : '';

            $this->mc->set($key, array('isok'=>1, 'data'=>$return_data), 86400);
        }

        return $return_data;
   }
   
   /**
    * 修改经纪人应用管理
    * udpate_app_custom
    * @param array $app_arr 应用数组
    * @param int $uid 用户id
    */
   public function update_app_custom($uid,$active_app_s){

       $key = $this->config_cityflag . '_get_app_custom_' . $uid;

       $data = array('uid' => $uid, 'app_custom' => $active_app_s);
       $this->db->replace('broker_sub',$data);

       $this->mc->delete($key);
   }
   
   /**
   * 获取经纪人诚信logo
   * @param int $uid 用户id
   * @return int
   */
   public function get_honesty_status($uid)
   {
       $key = $this->config_cityflag.'_get_honesty_status_'.$uid;
	  
       $cache = $this->mc->get($key);
		
       if($cache['isok'] == 1)
       {
           $data = $cache['data'];
       }
       else
       {
           $list = $this->dbback->select('honesty_status')->get_where('broker',array('uid'=>$uid))->row_array();
		   
           $data = $list['honesty_status'];
           $this->mc->set($key, array('isok'=>1, 'data'=>$data), 600);
       }
	   
       return $data;
   }


   /**
   * 获取经纪人删除数据
   * @param int $uid 用户id
   * @return int
   */
   public function get_delete_data($uid)
   {
	   //error_reporting(7);
	   //ini_set("display_errors",true);

       $key = $this->config_cityflag.'_get_delete_data3_'.$uid;
	  
       $cache = $this->mc->get($key);

	   $this->mc->delete($key);
		
       if($cache['isok'] == 1)
       {	

           $data = $cache['data'];
       }
       else
       {
		   $result =  $this->dbback->query("select count(id) as num_total  from  broker_delete_record where uid ='$uid' and ctime >1456156800");
			
           $arr =$result->result_array();
		   
		   if(is_array($arr) && empty($arr))
		   {
			   $data =10;
		   }
		   else
		   {
			   $data = $arr[0]['num_total'];
			   $data = 10-$data%5;
		   }
		   echo $data."<br/>";
		   
           $this->mc->set($key, array('isok'=>1, 'data'=>$data), 60);
       }
	   
       return $data;
   }

   /**
   * 获取经纪人冻结数据
   * @param int $uid 用户id
   * @return int
   */
   public function get_freeze_data($uid)
   {
       $key = $this->config_cityflag.'_get_freeze_data2_'.$uid;
	  
       $cache = $this->mc->get($key);
		
	   $this->mc->delete($key);

       if($cache['isok'] == 1)
       {	

           $data = $cache['data'];
       }
       else
       {
		   $result =  $this->dbback->query("select count(id) as num_total from broker_freeze_record where uid ='$uid' and ctime >1456156800");
		
           $arr =$result->result_array();
	
		   if(is_array($arr) && empty($arr))
		   {
			   $data =2;
		   }
		   else
		   {
			   $data_total = $arr[0]['num_total'];
			   
			   $data_mod   =$data_total%2;
			   $data       =2-$data_mod;
		   }
		  
           $this->mc->set($key, array('isok'=>1, 'data'=>$data), 60);
       }
	   
       return $data;
   }
   
   
   
    
}




