<%@ page language="java" import="java.util.*,com.letousky.lottery.action.MemberCenter,com.letousky.exception.LotteryException,com.letousky.lottery.util.InsiderCenterFormat,jxl.Workbook,jxl.write.Label,jxl.write.WritableSheet,jxl.write.WritableWorkbook,com.util.DateUtil,com.util.GameCodeToGameType;" pageEncoding="UTF-8"%>
<%
	
	String[] params = new String[7];
	params[0] ="0";
	params[1] ="1";
	params[2] = request.getParameter("starTime");
	params[3] = request.getParameter("endTime");
	params[4] = request.getParameter("pages");
	params[5] = request.getParameter("every");
	params[6] = request.getParameter("buyType");//注意此buyType和accounttrade中的buyType不一样
	if(params[4]==null)params[4]="0";
	if(params[5]==null)params[5]="0";
	if(!"0".equals(params[5])){
	try{
	List list=new MemberCenter().accountDetailsList(params,request);
	
	String[] str=null;
	String d=",";
	Object[] obj=list.toArray();
	List items=(List)obj[0];
	String[] recod=(String[])obj[1];
	Object[] item=items.toArray();
	
	out.print("{\"result\":\"0000\",\"recod\":\""+recod[0]+"\",\"items\":[");
	for(int i=0;i<item.length;i++){
		
		str=(String[])item[i];
		
		if(i==(item.length-1)){ d=""; }
		
		
		out.print("{\"transactionNumber\":\""+str[0]+"\",\"OrderNumber\":\""+str[1]+"\",\"buyType\":\""+InsiderCenterFormat.getDealType(str[2])+"\",\"buyTime\":\""+str[3]+"\",\"lncome\":\""+str[4]+"\",\"ede\":\""+str[5]+"\",\"sxf\":\""+str[6]+"\",\"balance\":\""+str[7]+"\",\"source\":\""+InsiderCenterFormat.getSource(str[8])+"\"}"+d+"");
		
	}
	out.print("]}");
	}catch(LotteryException e){
	
		out.print("{\"result\":\""+e.getMessage()+"\"}");
	}
		
	}else{
		List list=new MemberCenter().accountDetailsList(params,request);
		String[] str=null;
		Object[] obj=list.toArray();
		List items=(List)obj[0];
		Object[] item=items.toArray();
		//导出到excel文件中attachment/inline打开方式两种
	    String filename = new String("彩票派奖记录".getBytes("GBK"),"iso8859-1"); 
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition",
                "inline; filename="+filename
                + DateUtil.toStringInYearMonthDayPattern(DateUtil
                        .getNowPreciseToDay()) + ".xls");
        ServletOutputStream os = response.getOutputStream();
        WritableWorkbook workbook = Workbook.createWorkbook(os);
        WritableSheet sheet = workbook.createSheet("日志", 0);

        Label label = null;
        label = new Label(0, 0, "交易时间");
        sheet.addCell(label);
        label = new Label(1, 0, "收入");
        sheet.addCell(label);
        label = new Label(2, 0, "支出");
        sheet.addCell(label);
        label = new Label(3, 0, "余额");
        sheet.addCell(label);
        label = new Label(4, 0, "交易类型");
        sheet.addCell(label);
        label = new Label(5, 0, "订单号");
        sheet.addCell(label);
        label = new Label(6, 0, "购买方式");
        sheet.addCell(label);
        label = new Label(7, 0, "购买信息");
        sheet.addCell(label);

    	
    	for(int i=0;i<item.length;i++){
    		str=(String[])item[i];
    		if("0".equals(str[9])){
    			str[9]="手机";
    		}
    		if("1".equals(str[9])){
    			str[9]="邮箱";
    		}
            if (str!=null) {
            	String userName = "";
                //**交易时间**
				label = new Label(0, i + 1, DateUtil.formaTime(str[3]));
	            sheet.addCell(label);             
                //**收入**
                label = new Label(1, i + 1, str[4]);
                sheet.addCell(label);
                //**支出**
                label = new Label(2, i + 1, str[5]);
                sheet.addCell(label);
                //**余额**
                label = new Label(3, i + 1, str[7]);
                sheet.addCell(label);
                //**交易类型**
                label = new Label(4, i + 1, InsiderCenterFormat.getDealType(str[2]));
                sheet.addCell(label);
                //**订单号**
                label = new Label(5, i + 1, str[1]);
                sheet.addCell(label);
                //**购买方式**
                label = new Label(6, i + 1, str[9]);
                sheet.addCell(label);
                //**购买信息**
                label = new Label(7, i + 1, str[10]);
                sheet.addCell(label);
            }
        }
        workbook.write();
        workbook.close();
        os.close();
        out.clear();  
        out = pageContext.pushBody();  
	}
%>