<?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 = '定投推广设置';
$typeArr = array('ASchool1','BSchool1','ASchool2','BSchool2','ASchool3','BSchool3','ASchool4','BSchool4','GreatBroker');
$request  = new Request();
$vasSetPromotRecord = new VasSetPromotRecord();

$settingType = array('0'=>'全部','1'=>'排期中','2'=>'已排期','3'=>'推广中','4'=>'完成推广');//推广状态
$productType = array('0'=>'全部','1'=>'学区定投-黄金展位','2'=>'学区定投-白银展位','3'=>'优秀经纪人');//产品类型
$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_order = $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 ";
    if($type==1){
        $sql_where .= "  type in('ASchool1','ASchool2','ASchool3','ASchool4')"; 
    }elseif ($type==2){
        $sql_where .= "  type in('BSchool1','BSchool2','BSchool3','BSchool4')"; 
    }elseif ($type==3){
        $sql_where .= "  type = 'GreatBroker' "; 
    }
}




$recordList = $vasSetPromotRecord->findBy($sql_where,$asc_desc_order,$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 getProductType($type){    
    switch ($type){
    case 'ASchool1': $returnType = '力学小学学区定投-黄金展位';
        break;
    case 'ASchool2': $returnType = '琅琊路小学学区定投-黄金展位';
        break;
    case 'ASchool3': $returnType = '拉萨路小学学区定投-黄金展位';
        break;
    case 'ASchool4': $returnType = '北京东路小学学区定投-黄金展位';
        break;
    case 'BSchool1': $returnType = '力学小学学区定投-白银展位';
        break;
    case 'BSchool2': $returnType = '琅琊路小学学区定投-白银展位';
        break;
    case 'BSchool3': $returnType = '拉萨路小学学区定投-白银展位';
        break;
    case 'BSchool4': $returnType = '北京东路小学学区定投-白银展位';
        break;
    case 'GreatBroker': $returnType = '优秀经纪人';
        break;
    default : $returnType = '';
    }
    return $returnType;
}
//获取经纪人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;
}
    
include_once(Template("header"));
include_once(Template("vas/set_promot_record"));
include_once(Template("footer"));














