<?php
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
$directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
include_once($conf_basedir."base.inc.php");
$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', $search_type);
    } elseif($search_type == 'truename') {
        $conf_sql['uid'] = getUidbyKeyword($mc, $dbback, 'truename', $search_type);
    } elseif ($search_type == 'moblie') {
        $conf_sql['uid'] = getUidbyKeyword($mc, $dbback, 'telno', $search_type);
    }
}
//状态
if($stauts){
    $conf_sql['status'] = $status;
}

//排序
$asc_desc = $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_where)){
    $conf_num = count($conf_where);
    foreach ($conf_where as $key=>$value){
        $sql_where .= "'".$key."'='".$value."'"; 
        $sql_where .= $conf_num != 0 ? ' and ' : ''; 
        $conf_num--;        
    }    
}
if($type){
    if($type==1){
        $sql_where .= " and 'type' in('ASchool1','ASchool2','ASchool3','ASchool4')"; 
    }elseif ($type==2){
        $sql_where .= " and 'type' in('BSchool1','BSchool2','BSchool3','BSchool4')"; 
    }elseif ($type==3){
        $sql_where .= " and 'type' = 'GreatBroker' "; 
    }
}




$recordList = $vasSetPromotRecord->findBy($sql_where,$asc_desc,$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', "agentcode = '$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']
    );
}


//获取经纪人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/setpromotrecord"));
include_once(Template("footer"));














