easyUI导出数据模式

后台:

 //导出数据
public function index_doExport()
{
$search['diqu']=$_POST['diqu'];
$search['start']=$_POST['start'];
$search['end']=$_POST['end']; $search['diqu']=$search['diqu']?$search['diqu']:0;
$search['start']=$search['start']?strtotime($search['start']):1;
$search['end']=$search['end']?strtotime("+1 day",strtotime($end)):strtotime("+1 day",strtotime(date("Y-m-d"))); $this->success(U('Human/index_doExport_action',$search));
} public function index_doExport_action()
{
$search=$_GET;
$branchid=$search['diqu'];
$time1 = $search['start'];
$time2 =$search['end']; //做一个空数组存储数据
$attr = array(); if($branchid==0)
{
//取网点
$arr = M('branchs')->where("level = '服务处' ")->select(); //一个地区的数据统计
foreach($arr as $v)
{
$attr1 = array(); //缓存,临时
$attr1['branchid'] = $v['id']; //地区id
$branchid = $v['id']; $attr1['branchname'] = $v['name']; //地区名字 $attr2 = M('admin')->where(" roleid = 8 and branchid = $branchid ")->select(); //一个服务处所有的理财经理
$manager = count($attr2);
$attr1['manager'] = $manager; //理财经理 $attr3 = array(); //一个服务处所有注册客户
$attr31 = M('users')->where(" isqiye=0 and isloanuser = 0 and isdanbao = 0 and branchid = $branchid ")->select();
foreach($attr31 as $a)
{
array_push($attr3,$a['user_id']);
}
$attr32= D('UserdcView')->where("Users.branchid = $branchid ")->select();
foreach($attr32 as $b)
{
array_push($attr3,$b['user_id']);
}
array_unique($attr3);
$zhuce = count($attr3);
$attr1['zhuce'] = $zhuce; //注册的投资客户 $money=0; //充值金额
$count = 0; //有充值记录客户
foreach($attr3 as $t)
{
$attr4 = M('recharge')->where(" uid = $t ")->select();
$a = count($attr4);
if($a>0)
{
$count++;
foreach($attr4 as $tt)
{
$money += $tt['bzmoney'];
}
}
}
$attr1['touzi'] = $count;
$attr1['money'] = $money;
array_push($attr,$attr1);
}
}
else
{
$att['branchid']=$branchid; $branchname = M('branchs')->where(" id = $branchid")->getField("name");
$att['branchname'] = $branchname; //地区名字 $attr2 = M('admin')->where(" roleid = 8 and branchid = $branchid ")->select(); //指定服务处所有的理财经理
$manager = 0;
foreach($attr2 as $v)
{
$time = strtotime($v['regtime']);
if( $time >= $time1 && $time <= $time2)
{
$manager++;
}
}
$att['manager'] = $manager; //理财经理 $attr3 = array(); //指定服务处所有注册客户
$attr31 = M('users')->where(" isqiye=0 and isloanuser = 0 and isdanbao = 0 and branchid = $branchid and regtime >= $time1 and regtime <= $time2 ")->select();
foreach($attr31 as $a)
{
array_push($attr3,$a['user_id']);
}
$attr32= D('UserdcView')->where("Users.branchid = $branchid ")->select();
foreach($attr32 as $b)
{
array_push($attr3,$b['user_id']);
}
array_unique($attr3);
$zhuce = count($attr3);
$att['zhuce'] = $zhuce; //注册的投资客户 $money=0; //充值金额
$count = 0; //有充值记录客户
foreach($attr3 as $t)
{
$attr4 = M('recharge')->where(" uid = $t ")->select();
$a = count($attr4);
if($a>0)
{
$count++;
foreach($attr4 as $tt)
{
$money += $tt['bzmoney'];
}
}
}
$att['touzi'] = $count;
$att['money'] = $money; array_push($attr,$att);
} $list=$attr;
$list=keysortExcel($list,array('branchname','manager','zhuce','touzi','money'));
exportexcel($list,array('服务处网点','理财经理','注册会员','投资人数','标准业绩'),'人力资源统计-'.time());
}

前台代码:

 //导出数据
function doExport(that){
var diqu=$("#branchid").combobox('getValue');
var start=$("#a").datebox('getValue');
var end =$("#b").datebox('getValue');
$.post('<{:U('Human/index_doExport')}>', {diqu:diqu,start:start,end:end}, function(res){
if(!res.status){
$.messager.alert('提示信息', res.info, 'error');
}else{
window.open(res.info,'_blank');
}
}, 'json');
}
05-11 21:44