<?php
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
$directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
include_once($conf_basedir."base.inc.php");
$js .= "<script src='".$conf_basedir."script/My97DatePicker/WdatePicker.js'></script>";
$title = '房源包装管理';
$request  = new Request();
$vasSetPromotRecord = new VasSetPromotRecord('vas_packing_house_record');

$settingType = array('0'=>'全部','1'=>'排期中','2'=>'已排期','3'=>'推广中','4'=>'完成推广');//推广状态
$productType = array('0'=>'全部','Search'=>'二手房搜搜','Mansionshow'=>'大宅秀','Videotext'=>'视频看房【文字】','Videoby'=>'视频看房【文字】');//产品类型
$settingSearch = array(0=>'请选择','username'=>'帐号','truename'=>'姓名','moblie'=>'手机号码');//查询条件
$settingOrderBy = array('ctime'=>'按交易时间排序');
$settingAscDesc = array('desc'=>'倒序排列','asc'=>'正序排列',);
$settingDispRows = array(20=>'20',30=>'30',40=>'40');



//查询条件，关键字
if($search_type&&$keyword) {
    $block = new Block();
    if ($search_type == 'username') {
        $conf_sql['uid'] = getUidbyKeyword($mc, $dbback, 'username', $keyword);
    } elseif($search_type == 'truename') {
        $conf_sql['uid'] = getUidbyKeyword($mc, $dbback, 'truename', $keyword);
    } elseif ($search_type == 'moblie') {
        $conf_sql['uid'] = getUidbyKeyword($mc, $dbback, 'telno', $keyword);
    }
}

//状态
if($status){
    $conf_sql['status'] = $status;
}

//排序
$asc_desc_str = $asc_desc ? " buy_time ".$asc_desc : " buy_time ".'desc';

//条数
$page_now = intval($page_now)==0?1:intval($page_now);
$disp_rows = intval($disp_rows)==0?20:intval($disp_rows);
$startRow = ($page_now-1)*$disp_rows;

//条件组装
if(CommonBase::isFullArray($conf_sql)){
    $conf_num = count($conf_sql);
    foreach ($conf_sql as $key=>$value){
        $sql_where .= $key."='".$value."'";
        $sql_where .= $conf_num != 1 ? ' and ' : '';
        $conf_num--;
    }
}
if($type){
    $sql_where .= $sql_where=="" ? "" : " and ";

        $sql_where .= "  type = '".$type."'";
    
}






$recordList = $vasSetPromotRecord->findBy($sql_where,$asc_desc_str,$disp_rows);




$total_num = $vasSetPromotRecord->findNumberBy($sql_where);
$page_total = ceil($total_num/$disp_rows);
$new_pagenavi = new_pagenavi2($page_now,$page_total,$total_num);


//获取经纪人的详细信息
function getBrokerDetail($mc, $dbback, $uid) {
	$sql = SqlCombinHelper::select_sql('broker', 'telno, username, truename,master', "uid =" . $uid);
	$brokerInfo = $mc->get($sql);
	if ($brokerInfo === false) {
		$brokerInfo = $dbback->getRow($sql);
		$mc->add($sql, $brokerInfo, 3600);
	}
    $sql = SqlCombinHelper::select_sql('home_auth', 'truename', "authname = '$brokerInfo[master]'");
	$manager = $mc->get($sql);
	if ($manager === false) {
		$manager = $dbback->getRow($sql);
		$mc->add($sql, $manager, 3600);
	}

    return array(
        'username' => $brokerInfo['username'], 'truename' => $brokerInfo['truename'],
         'manager' => $manager['truename'], 'telno' => $brokerInfo['telno']
    );
}

function getStatus($status){
    switch ($status){
        case '1': $return = '排期中';
            break;
        case '2': $return = "已排期";
            break;
        case '3': $return = "推广中";
            break;
        case '4': $return ="完成推广";
            break;
        default : $return = "";
    }
    return $return;
}


//获得订单详细房源信息
function gethousedetail($recordid){
     $Vas_packing_house = new VasRecord('vas_packing_house');
     $conf = "record_id =".$recordid;
     $housedetail = $Vas_packing_house->findBy($conf);
          if(is_array( $housedetail) && !empty($housedetail)){
                 $housestr='';
                 foreach($housedetail as $value2){
                   $housestr .= '<a class="c1" href="'.get_sellinfo_url($value2['houseid']).'" target="_blank">'.$value2['houseid'];
                   $housestr.= $value2['house_typ']==2?'备用</a> ':' </a>';
                    }
               }
               return $housestr;
}


//获取经纪人id
function getUidbyKeyword($mc, $dbback, $field, $keyword){
    $sql = SqlCombinHelper::select_sql('broker', 'uid', $field." = '".$keyword."'");
	$brokerUid = $mc->get($sql);
	if ($brokerUid === false) {
		$brokerUid = $dbback->getOne($sql);
		$mc->add($sql, $brokerUid, 3600);
	}
    return $brokerUid;
}

if(!function_exists('get_sellinfo_url')) {
	function get_sellinfo_url($id)
	{
		global $conf_city;
		if ($id == '') {return false;}
		return 'http://' . $conf_city . '.sell.house365.com/s_' . $id . '.html';
	}
}

include_once(Template("header"));
include_once(Template("vas/packing_house_record"));
include_once(Template("footer"));














