Browse Source

订单列表

zhengwei 5 năm trước cách đây
mục cha
commit
3624e2759c

BIN
WebContent/WEB-INF/lib/mysql-connector-java-5.1.20-bin.jar


+ 10 - 2
WebContent/static/web/js/user/orderList.js

@@ -18,12 +18,13 @@ layui.define(['laydate', 'layer', 'form'], function (exports) {
             {data:function(obj){
                 return '<input type="checkbox" lay-skin="primary" lay-filter="oneChoose" data-id="'+obj.id+'" />';
             }},
-            {data: 'order_no'},
+            {data: 'merchant_name'},
             {data: function(obj){
 					return web.getDictVal('order_status',obj.order_status);
             }},
             {data: 'order_amt',sClass:'text-r'},
             {data: 'pay_amt',sClass:'text-r'},
+            {data: 'product_name'},
             {data: 'product_qty',sClass:'text-c'},
             {data: function(obj){
 				return obj.consignee+"-"+obj.mobile;
@@ -119,7 +120,14 @@ layui.define(['laydate', 'layer', 'form'], function (exports) {
             layer.msg("请选择待使用订单");
         }
     });
-    
+    $("#btn-export").on('click',function(){
+        if (!$("#startCreateTime").val()||!$("#endCreateTime").val()){
+            layer.msg("请选择下单开始时间和结束时间");
+            return false;
+        }
+        window.open(base+"/userOrder/export?orderStatus="+$("#orderStatus").val()+"&startCreateTime="+$("#startCreateTime").val()+"&endCreateTime="+$("#endCreateTime").val());
+        return false;
+    });
     //查询
     $("#btn-query").on('click',function(){
     	 table.ajax.reload();

+ 39 - 35
WebContent/web/user/orderList.jsp

@@ -7,28 +7,31 @@
 <div class="container">
 	<form class="layui-form form-search" action="" onsubmit="return false" method="get">
 		<div class="layui-row layui-form-item">
-			<div class="layui-col-xs2_4"> 
-	        	<label class="layui-form-label layui-col-xs4">订单编号</label>
-           		<input type="text" id="orderNo" name="orderNo" autocomplete="off" 
-           			placeholder="请输入订单编号" class="layui-input layui-col-xs7">
-			</div>
+            <div class="layui-col-xs2_4">
+                <label class="layui-form-label layui-col-xs4">下单时间</label>
+                <input type="text" id="startCreateTime" name="startCreateTime" autocomplete="off"
+                       placeholder="开始时间" class="layui-input layui-col-xs7">
+            </div>
+            <div class="layui-col-xs2_4">
+                <label class="layui-form-label layui-col-xs4">至</label>
+                <input type="text" id="endCreateTime" name="endCreateTime" autocomplete="off"
+                       placeholder="结束时间" class="layui-input layui-col-xs7">
+            </div>
+
 			<div class="layui-col-xs2_4"> 
 	        	<label class="layui-form-label layui-col-xs4">订单状态</label>
 	        	<div class="layui-input-block layui-col-xs7"> 
            			<layui:select id="orderStatus" type="select" name="orderStatus" key="order_status"/>
            		</div>
 			</div>
-			<div class="layui-col-xs2_4"> 
-	        	<label class="layui-form-label layui-col-xs4">支付状态</label>
-           		<div class="layui-input-block layui-col-xs7"> 
-           			<layui:select id="payStatus" type="select" name="payStatus" key="pay_status"/>
-           		</div>
-			</div>
-			<div class="layui-col-xs2_4"> 
-	        	<label class="layui-form-label layui-col-xs4">收货人</label>
-           		<input type="text" id="consignee" name="consignee" autocomplete="off" 
-           			placeholder="请输入收货人" class="layui-input layui-col-xs7">
-			</div>
+            <div class="layui-col-xs2_4" id="merchant-div">
+                <label class="layui-form-label layui-col-xs4">商家</label>
+                <div class="layui-input-block layui-col-xs7">
+                    <layui:select id="merchantId" type="select" name="merchantId" dictTable="merchant"
+                                  dictField="id" dictText="merchant_name" dictCondition=" where status='1'"/>
+                </div>
+            </div>
+
 			<div class="layui-col-xs2_4 f0"> 
 	        	<button class="layui-btn layui-btn-small" id="btn-query"><i class="layui-icon">&#xe604;</i>查询</button>
 	        	<button class="layui-btn layui-btn-small layui-btn-primary" type="reset" id="btn-reset">重置</button>
@@ -36,41 +39,42 @@
 			</div>
 		</div>
 		<div class="layui-row layui-form-item query-more">
-			<div class="layui-col-xs2_4" id="merchant-div">
-				<label class="layui-form-label layui-col-xs4">商家</label>
-				<div class="layui-input-block layui-col-xs7">
-					<layui:select id="merchantId" type="select" name="merchantId" dictTable="merchant"
-								  dictField="id" dictText="merchant_name" dictCondition=" where status='1'"/>
-				</div>
-			</div>
-			<div class="layui-col-xs2_4"> 
-	        	<label class="layui-form-label layui-col-xs4">下单时间</label>
-           		<input type="text" id="startCreateTime" name="startCreateTime" autocomplete="off" 
-           			placeholder="开始时间" class="layui-input layui-col-xs7">
-			</div>
-			<div class="layui-col-xs2_4"> 
-	        	<label class="layui-form-label layui-col-xs4">至</label>
-           		<input type="text" id="endCreateTime" name="endCreateTime" autocomplete="off" 
-           			placeholder="结束时间" class="layui-input layui-col-xs7">
-			</div>
+            <div class="layui-col-xs2_4">
+                <label class="layui-form-label layui-col-xs4">订单编号</label>
+                <input type="text" id="orderNo" name="orderNo" autocomplete="off"
+                       placeholder="请输入订单编号" class="layui-input layui-col-xs7">
+            </div>
+            <div class="layui-col-xs2_4">
+                <label class="layui-form-label layui-col-xs4">支付状态</label>
+                <div class="layui-input-block layui-col-xs7">
+                    <layui:select id="payStatus" type="select" name="payStatus" key="pay_status"/>
+                </div>
+            </div>
+            <div class="layui-col-xs2_4">
+                <label class="layui-form-label layui-col-xs4">收货人</label>
+                <input type="text" id="consignee" name="consignee" autocomplete="off"
+                       placeholder="请输入收货人" class="layui-input layui-col-xs7">
+            </div>
 		</div>
 	</form>
 	<div class="btn-group">
         <button class="layui-btn layui-btn-small" id="btn-2"><i class="layui-icon">&#xe605;</i>完成</button>
         <button class="layui-btn layui-btn-small" id="btn-3"><i class="layui-icon">&#xe605;</i>退款</button>
+        <button class="layui-btn layui-btn-small" id="btn-export"><i class="layui-icon">&#xe609;</i>导出</button>
 	</div>
 	<div class="layui-form">
 		<table id="dateTable" class="layui-table" lay-even="" width="100%" lay-skin="line">
 	       	<thead>
 		    	<tr>
 		        	<th width="10"><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
-					<th>订单编号</th>
+                    <th>商家名称</th>
 					<th>订单状态</th>
 					<th>订单金额</th>
 					<th>付款金额</th>
+					<th width="200">商品名称</th>
 					<th>商品数量</th>
 					<th>收货人</th>
-					<th>收货地址</th>
+					<th width="200">收货地址</th>
 					<th>下单时间</th>
 					<th class="text-c">操作</th>
 				</tr>

+ 31 - 4
src/com/mall/controller/user/UserOrderController.java

@@ -4,10 +4,11 @@ package com.mall.controller.user;
 import java.math.BigDecimal;
 import java.util.*;
 
+import com.jfinal.ext.interceptor.GET;
 import com.mall.model.product.CutInfo;
 import com.mall.model.sys.SysControlParam;
 import com.mall.model.user.*;
-import com.mall.util.DateUtil;
+import com.mall.util.*;
 import org.apache.commons.lang.StringUtils;
 
 import com.jfinal.aop.Before;
@@ -28,8 +29,6 @@ import com.mall.model.merchant.Merchant;
 import com.mall.model.product.Product;
 import com.mall.model.product.ProductExchange;
 import com.mall.model.sys.SysUser;
-import com.mall.util.Ret;
-import com.mall.util.TemplateMsg;
 
 import net.sf.json.JSONObject;
 
@@ -37,7 +36,6 @@ import net.sf.json.JSONObject;
  * 类用途说明:订单
  * @author zhengwei
  */
-@Before(POST.class)
 public class UserOrderController extends BaseController{
 	
 	/**
@@ -73,6 +71,14 @@ public class UserOrderController extends BaseController{
 		int draw = getParaToInt("draw");
 		int pageNumber =getParaToInt("start") / getParaToInt("length")+1;
 		int pageSize = getParaToInt("length");
+		SysUser user = Constants.getLoginUser(getSession());
+		if(user==null) {
+			renderJson(map);
+			return;
+		}
+		if("30".equals(user.getStr("type"))) {
+			params.put("merchantId",user.getInt("merchant_id"));
+		}
 		Page<UserOrder> list= UserOrder.dao.queryOrderList(params,pageNumber, pageSize);
 		map.put("data", list.getList());
 		map.put("draw", draw);
@@ -863,4 +869,25 @@ public class UserOrderController extends BaseController{
 		ret.setData(res);
 		renderJson(ret);
 	}
+
+    public void export() throws Exception{
+        Map<String, Object> params = changeMap(getParaMap());
+        SysUser user = Constants.getLoginUser(getSession());
+        if("30".equals(user.getStr("type"))) {
+            params.put("merchantId",user.getInt("merchant_id"));
+        }
+        List<Record> list =UserOrder.dao.getExportList(params);
+        try{
+            Map<String,Object> model=new HashMap<String,Object>();
+            //设置需要的模板数据
+            model.put("list", list);
+            //传入模板,模板数据,导出成功后会返回生成的文件名
+            String filename="订单列表";
+            //生成Excel
+            new ExcelBuilder().export("com/mall/xls/order.xls", model,filename,getRequest(),getResponse());
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+        renderNull();
+    }
 }

+ 41 - 1
src/com/mall/model/user/UserOrder.java

@@ -145,11 +145,12 @@ public class UserOrder extends Model<UserOrder>
 		StringBuffer select = new StringBuffer();
 		List<Object> param=new ArrayList<Object>();
 		select.append(" select t.*,");
+		select.append(" (select merchant_name from merchant where id = t.merchant_id) merchant_name ,");
 		select.append(" (select pay_amt from user_order_pay where order_id = t.id limit 1) pay_amt ,");
 		select.append(" (select product_name from user_order_detail where order_id = t.id limit 1) product_name ");
 		sql.append(" from user_order t where t.order_status!='99'");
 		if(Utility.isNotEmpty(params.get("merchantId"))){
-			sql.append(" and a.merchant_id = ?");
+			sql.append(" and t.merchant_id = ?");
 			param.add(params.get("merchantId"));
 		}
 		if(Utility.isNotEmpty(params.get("orderNo"))){
@@ -186,6 +187,45 @@ public class UserOrder extends Model<UserOrder>
 		}
 	}
 
+
+	/**
+	 *
+	 * @Description 查询
+	 * @author zhengwei
+	 * @date 2017年8月25日 下午3:27:34
+	 * @return Page<ProductBrand>
+	 */
+	public List<Record> getExportList(Map<String, Object> params){
+		StringBuffer sql = new StringBuffer();
+		List<Object> param=new ArrayList<Object>();
+        sql.append(" select t.order_amt,t.product_qty,t.address,date_format(t.create_time,'%Y-%m-%d %H:%i:%s')as create_time,t.consignee,t.mobile,t.city,t.district,");
+        sql.append(" case t.order_status when '10' then '待付款' when '20' then '待使用' when '30' then '交易完成' when '98' then '退款' else '' end order_status,");
+        sql.append(" (select merchant_name from merchant where id = t.merchant_id) merchant_name ,");
+        sql.append(" (select product_name from user_order_detail where order_id = t.id limit 1) product_name ");
+		sql.append(" from user_order t where t.order_status!='99'");
+		if(Utility.isNotEmpty(params.get("merchantId"))){
+			sql.append(" and t.merchant_id = ?");
+			param.add(params.get("merchantId"));
+		}
+		if(Utility.isNotEmpty(params.get("orderStatus"))){
+			sql.append(" and t.order_status = ? ");
+			param.add(params.get("orderStatus"));
+		}
+		if(Utility.isNotEmpty(params.get("startCreateTime"))){
+			sql.append(" and date(t.create_time) >= ? ");
+			param.add(params.get("startCreateTime"));
+		}
+		if(Utility.isNotEmpty(params.get("endCreateTime"))){
+			sql.append(" and date(t.create_time) <= ? ");
+			param.add(params.get("endCreateTime"));
+		}
+		sql.append(" order by t.create_time desc");
+        if(param.isEmpty()){
+            return Db.find(sql.toString());
+        }else{
+            return Db.find(sql.toString(),param.toArray());
+        }
+	}
 	/**
 	 * 获取列表
 	 * @param openid

+ 0 - 2
src/com/mall/model/user/UserViewLog.java

@@ -48,7 +48,6 @@ public class UserViewLog extends Model<UserViewLog>
 	}
 	
 	public int getViewUser(String userType,String startDate,String endDate,String company,String merchant) {
-        long starttime = System.currentTimeMillis();
 		StringBuffer sql = new StringBuffer();
 		sql.append(" select count(distinct openid) num from user_view_log a where 1=1 ");
 		if(StringUtils.isNotEmpty(startDate)) {
@@ -75,7 +74,6 @@ public class UserViewLog extends Model<UserViewLog>
 			}
 		}
         Record record = Db.findFirst(sql.toString());
-        System.out.println("viewUser"+(System.currentTimeMillis()-starttime));
         return record.getLong("num").intValue();
 	}
 	

+ 177 - 0
src/com/mall/util/ExcelBuilder.java

@@ -0,0 +1,177 @@
+package com.mall.util;
+
+import net.sf.jxls.exception.ParsePropertyException;
+import net.sf.jxls.transformer.XLSTransformer;
+import org.apache.log4j.Logger;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * 根据模板导出excel到服务器本地
+ *
+ */
+public class ExcelBuilder {
+	private static final String CONTENT_TYPE = "application/x-msdownload;charset=UTF-8";
+    private Logger log = Logger.getLogger(this.getClass());
+
+    /**
+     * 
+     * @param config templates/s_ana_lus.xls
+     * @param model Map<String, Object>
+     * @return fileName
+     */
+    public String export(String config, Map<String, Object> model,HttpServletRequest request) throws IllegalAccessException {
+        String fileName = "ERROR";
+        InputStream in = null;
+        OutputStream out = null;
+        try {
+            log.debug("准备导出...");
+            String tmpFileName = UUID.randomUUID() + ".xls";
+            String output=request.getSession().getServletContext().getRealPath("download/" + tmpFileName);
+            log.debug("输出路径:" + output);
+            in = ExcelBuilder.class.getClassLoader().getResourceAsStream(config);
+            out = new FileOutputStream(output);
+            XLSTransformer transformer = new XLSTransformer();
+            transformer.transformXLS(in, model).write(out);
+            //导出成功后 才设置导出的文件名
+            fileName = tmpFileName;
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (ParsePropertyException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (in != null)
+                    in.close();
+                if (out != null)
+                    out.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        log.debug("返回文件名:" + fileName);
+        return fileName;
+    }
+    
+    
+    public String export(String config, Map<String, Object> model,String filename,HttpServletRequest request) throws IllegalAccessException {
+        String fileName = "ERROR";
+        InputStream in = null;
+        OutputStream out = null;
+        try {
+            log.debug("准备导出...");
+//            String tmpFileName = UUID.randomUUID() + ".xls";
+            String tmpFileName=filename+".xls";
+            String output=request.getSession().getServletContext().getRealPath("download/" + tmpFileName);
+            log.debug("输出路径:" + output);
+            in = ExcelBuilder.class.getClassLoader().getResourceAsStream(config);
+            out = new FileOutputStream(output);
+            XLSTransformer transformer = new XLSTransformer();
+            transformer.transformXLS(in, model).write(out);
+            //导出成功后 才设置导出的文件名
+            fileName = tmpFileName;
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (ParsePropertyException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (in != null)
+                    in.close();
+                if (out != null)
+                    out.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        log.debug("返回文件名:" + fileName);
+        return fileName;
+    }
+    
+    public String export(String config, Map<String, Object> model,String filename,String path) throws IllegalAccessException {
+        String fileName = "ERROR";
+        InputStream in = null;
+        OutputStream out = null;
+        try {
+			String tmpFileName=filename+".xls";
+			String tmpPath=path+tmpFileName;
+            in = ExcelBuilder.class.getClassLoader().getResourceAsStream(config);
+            out = new FileOutputStream(tmpPath);
+            XLSTransformer transformer = new XLSTransformer();
+            transformer.transformXLS(in, model).write(out);
+            //导出成功后 才设置导出的文件名
+            fileName = tmpFileName;
+        } catch (Exception e){
+            e.printStackTrace();
+        } finally {
+            try {
+                if (in != null)
+                    in.close();
+                if (out != null)
+                    out.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return fileName;
+    }
+    //模板导出excel
+    public String export(String config, Map<String, Object> model,String title,HttpServletRequest request, HttpServletResponse response) throws Exception {
+        String fileName = "ERROR";
+        InputStream in = null;
+        OutputStream out = null;
+        try {
+            log.debug("准备导出...");
+            String tmpFileName = UUID.randomUUID() + ".xls";//随机导出Excel名称
+			String file_title=title+".xls";
+			final String path="C:/files/export/";
+			final File filePath = new File(path);
+			if(!filePath.exists())	//没有目录的,自动创建目录
+			filePath.mkdirs();
+			String tmpPath=path+tmpFileName;//文件完整路径
+            log.debug("输出路径:" + tmpPath);
+
+            in = ExcelBuilder.class.getClassLoader().getResourceAsStream(config);
+            out = new FileOutputStream(tmpPath);
+            XLSTransformer transformer = new XLSTransformer();
+
+            HSSFWorkbook b =  transformer.transformXLS(in, model);
+            b.write(out);
+            //导出成功后 才设置导出的文件名
+            fileName = tmpFileName;
+
+			FileUtil fileUtil=new FileUtil();
+			response.setContentType(CONTENT_TYPE);
+			//下载生成的Excel
+			 fileUtil.doDownloadFile(tmpPath, file_title, request, response);
+			//删除生成的Excel
+			 fileUtil.doRemoveFile(tmpPath);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (ParsePropertyException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (in != null)
+                    in.close();
+                if (out != null)
+                    out.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        log.debug("返回文件名:" + fileName);
+        return fileName;
+    }
+}

+ 55 - 0
src/com/mall/util/FileUtil.java

@@ -0,0 +1,55 @@
+package com.mall.util;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URLEncoder;
+
+public class FileUtil {
+	private static final String CONTENT_TYPE = "application/x-msdownload;charset=UTF-8";
+	
+	/*
+	 * 下载文件
+	 */
+	public void doDownloadFile(String filePath, String filename, HttpServletRequest request, HttpServletResponse response) throws Exception {
+		BufferedInputStream bis = null;
+		BufferedOutputStream bos = null;
+		try {
+			long fileLength = new File(filePath).length();
+			filename = URLEncoder.encode(filename, "UTF-8");
+			response.reset();
+			response.setContentType(CONTENT_TYPE);
+			response.setHeader("Content-Length", String.valueOf(fileLength));
+			response.addHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
+			bis = new BufferedInputStream(new FileInputStream(filePath));
+			bos = new BufferedOutputStream(response.getOutputStream());
+			byte[] buff = new byte[2048];
+			int bytesRead;
+			while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
+				bos.write(buff, 0, bytesRead);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if (bis != null)
+				bis.close();
+			if (bos != null)
+				bos.close();
+		}
+	}
+	
+	//删除目录底下的文件
+	public void doRemoveFile(String filepath){
+		try{
+			File file=new File(filepath);
+			if(file.exists()){
+				boolean b=file.delete();
+			}
+		}catch(Exception e){
+			e.printStackTrace();
+			}
+	}
+}

BIN
src/com/mall/xls/order.xls