<?php
/**
 * 店铺管理业务逻辑
 * 
 */
load_m('shop_base_model');
class Shop_model extends Shop_base_model{
    public function __construct() {
        parent::__construct(1,1,0);
    }
    
    /**use_rec_count
     * 二手房、租房推荐使用情况
     * @access public
     * @param $type,$uid
     * @return int 
     */
    public function  use_rec_count($type='sell',$uid){
        
        $tbl = $type == 'sell' ? 'sell' : 'rent';         
        $cond_where = "uid = '".$uid."' and esta='1' and agentcode = 'B000' and istop = '2' ";
        $this->dbback->where( $cond_where );
        $arr_data = $this->dbback->from($tbl)->count_all_results();      
        return $arr_data;
    }
    
    /**house_recommend_info
     * 二手房、租房房源是否推荐
     * @access public
     * @param int $houseid ,$uid   string $tbl
     * @return array
     */
    public function house_recommend_info($houseid,$uid,$tbl){
         $cond_where = "id = $houseid AND uid = $uid AND esta='1'";
         $this->dbback->select('istop,remark,district,address,isstar');
         $this->dbback->where($cond_where);
         $arr_data = $this->dbback->get($tbl)->row_array();         
         return $arr_data;
    } 
    
    /**update_house_istop
     * 房源表添加、删除推荐标志位
     */
    public function update_house_istop($type,$houseid,$uid,$tbl)
    {
        $cond_where = array('id'=>$houseid,'uid'=>$uid,'esta'=>1);
        $this->db->where($cond_where);
        
        if($type=='add')
        {
            $data = array('istop'=>'2');
        }
        elseif($type == 'del')
        {
            $data = array('istop'=>'0');
        }
        $arrModule = array('sell', 'rent');
	$tbl = in_array($tbl, $arrModule) ? $tbl : $arrModule[0];
        $this->db->update($tbl, $data); 
    }
    
    /**
     * insert_broker_house
     * 添加推荐店铺房源
     */
    public function insert_broker_house($data_array){
        $tbl = 'broker_house';
        $this->db->insert($tbl, $data_array);
    }
    
    /**
     * delete_broker_hosue
     * 删除推荐店铺房源
     */
    public function delete_broker_house($tbl,$houseid){
        $data_arr = array('tbl'=>$tbl,'rowid'=>$houseid);
        $this->db->delete('broker_house', $data_arr); 

    }
    
}