订单管理
OrderController
查询订单列表
//查询订单列表
@RequestMapping("/user/orderManage_{pageCurrent}_{pageSize}_{pageCount}")
public String orderManage(Model model, Order order,
@PathVariable Integer pageCurrent,
@PathVariable Integer pageSize,
@PathVariable Integer pageCount){
if (pageCurrent == 0) {
pageCurrent = 1;
}
if (pageSize == 0){
pageSize = 50;
}
int rows = orderMapper.list(order).size();
if (pageCount == 0) {
pageCount = (rows % pageSize) == 0 ? (rows / pageSize) : (rows / pageSize) + 1;
}
//设置order实例中的属性
order.setMinOrderTime(DateUtil.strToDate(order.getMinOrderTimeStr()));
order.setMaxOrderTime(DateUtil.strToDate(order.getMaxOrderTimeStr()));
order.setStart((pageCurrent - 1) * pageSize);
order.setEnd(pageSize);
model.addAttribute("order", order);
//将order实例中的信息存到orderItem中
orderList = orderMapper.list(order);
for (Order i : orderList) {
String orderId = i.getOrderId();
if (orderItemMapper.selectByPrimaryOrderKey(orderId) != null){
OrderItem orderItem = orderItemMapper.selectByPrimaryOrderKey(orderId);
i.setItemTitle(orderItem.getTitle());
i.setTotalFee(orderItem.getTotalFee());
i.setNum(orderItem.getNum());
i.setStatusStr(getStatusStrById(i.getStatus()));
i.setDateStr1(DateUtil.getDateStr(i.getCreateTime()));
i.setPaymentTypeStr(getPaymentTypeById(i.getPaymentType()));
}
}
model.addAttribute("orderList", orderList);
//设置动态url
String pageHTML = PageUtil.getPageContent("orderManage_{pageCurrent}_{pageSize}_{pageCount}?title=" + order.getItemTitle() + "&orderId" + order.getOrderId() + "&minOrderTimeStr" + order.getMinOrderTimeStr() + "&maxOrderTimeStr" + order.getMaxOrderTimeStr(), pageCurrent, pageSize, pageCount);
model.addAttribute("pageHTML", pageHTML);
return "order/orderManage";
}
查看订单详细信息
/*查看详情*/
@GetMapping("/user/orderDetails")
public String orderDetailsGet(Model model, Order order){
String orderId = order.getOrderId(); //查询该id
Order order1 = orderMapper.selectByPrimaryKey(orderId); //查询该id对应的数据
//设置order信息,显示出来
if (orderItemMapper.selectByPrimaryOrderKey(orderId) != null){
OrderItem orderItem = orderItemMapper.selectByPrimaryOrderKey(orderId);
order1.setNum(orderItem.getNum());
order1.setStatusStr(getStatusStrById(order1.getStatus()));
order1.setPaymentTypeStr(getPaymentTypeById(order1.getPaymentType()));
order1.setItemTitle(orderItem.getTitle());
order1.setTotalFee(orderItem.getTotalFee());
order1.setItemId(orderItem.getItemId());
order1.setBuyerRateStr(getBuyerRateStrById(order1.getBuyerRate()));
order1.setDateStr1(DateUtil.getDateStr(order1.getCreateTime()));
order1.setDateStr2(DateUtil.getDateStr(order1.getUpdateTime()));
order1.setDateStr3(DateUtil.getDateStr(order1.getPaymentTime()));
order1.setDateStr4(DateUtil.getDateStr(order1.getConsignTime()));
order1.setDateStr5(DateUtil.getDateStr(order1.getEndTime()));
model.addAttribute("order", order1);
}
return "order/orderDetails";
}
导出订单Excel表
/*导出excel表*/
@RequestMapping("user/download2")
public void orderExcel(HttpServletResponse response) throws IOException {
//导出Excel表
LinkedHashMap<String, String> fieldMap = new LinkedHashMap<String, String>();
fieldMap.put("orderId", "订单id");
fieldMap.put("payment", "实付金额");
fieldMap.put("paymentType", "支付类型,1、在线支付,2、货到付款");
fieldMap.put("postFee", "邮费");
fieldMap.put("status", "状态:1、未付款,2、已付款,3、未发货,4、已发货,5、交易成功,6、交易关闭");
fieldMap.put("createTime", "订单创建时间");
fieldMap.put("updateTime", "订单更新时间");
fieldMap.put("paymentTime", "付款时间");
fieldMap.put("consignTime", "发货时间");
fieldMap.put("endTime", "交易完成时间");
fieldMap.put("closeTime", "交易关闭时间");
fieldMap.put("shippingName", "物流名称");
fieldMap.put("shippingCode", "物流单号");
fieldMap.put("userId", "用户id");
fieldMap.put("buyerMessage", "买家留言");
fieldMap.put("buyerNick", "买家昵称");
fieldMap.put("buyerRate", "买家是否已经评价");
String sheetName = "订单管理表"; //设置表名
response.setContentType("application/octet-stream"); //设置下载流
response.setHeader("Content-disposition", "attachment;filename = orderManage.xls"); //设置默认文件名
response.flushBuffer(); //将buffer的内容写到客户端中
OutputStream ops = response.getOutputStream(); //导出流
//利用excel工具类将列表导出成表格
try {
ExcelUtil.listToExcel(orderList, fieldMap, sheetName, ops);
} catch (Exception e) {
e.printStackTrace();
}
}
@PostMapping("user/orderDetails")
public String orderDetailPost(){
return null;
}
查询订单退款列表
/*订单退款管理*/
@RequestMapping("user/orderRefund_{pageCurrent}_{pageSize}_{pageCount}")
public String orderRefund(Model model, Order order,
@PathVariable Integer pageCurrent,
@PathVariable Integer pageSize,
@PathVariable Integer pageCount){
if (pageCurrent == 0){
pageCurrent = 1;
}
if (pageSize == 0){
pageSize = 50;
}
int rows = orderMapper.list(order).size();
if (pageCount == 0){
pageCount = (rows % pageSize) == 0 ? (rows / pageSize) : (rows / pageSize) + 1;
}
order.setStart((pageCurrent - 1) * pageSize);
order.setEnd(pageSize);
model.addAttribute("order", order);
orderList = orderMapper.listRefund(order);
for (Order order1 : orderList) {
String orderId = order1.getOrderId();
if (orderItemMapper.selectByPrimaryOrderKey(orderId) != null) {
OrderItem orderItem = orderItemMapper.selectByPrimaryOrderKey(orderId);
order1.setItemTitle(orderItem.getTitle());
order1.setTotalFee(orderItem.getTotalFee());
order1.setNum(orderItem.getNum());
order1.setStatusStr(getStatusStrById(order1.getStatus()));
order1.setDateStr1(DateUtil.getDateStr(order1.getCreateTime()));
order1.setPaymentTypeStr(getPaymentTypeById(order1.getPaymentType()));
order1.setRefundStatusStr(getRefundStatusStr(order1.getRefundStatus()));
}
}
model.addAttribute("orderList", orderList);
//设置动态url
String pageHTML = PageUtil.getPageContent("orderRefund_{pageCurrent}_{pageSize}_{pageCount}?status=" + order.getRefundStatus(), pageCurrent, pageSize, pageCount);
model.addAttribute("pageHTML", pageHTML);
return "order/orderRefund";
}
审核订单退款
/*审批*/
@GetMapping("user/orderCheck")
public String orderCheckGet(Model model, Order order){
String orderId = order.getOrderId(); //查询该id
Order order1 = orderMapper.selectByPrimaryKey(orderId); //查询该id对应的实例信息
//如果该id的商品信息不为空的话,设置它的信息
if (orderItemMapper.selectByPrimaryOrderKey(orderId) != null){
OrderItem orderItem = orderItemMapper.selectByPrimaryOrderKey(orderId);
order1.setItemTitle(orderItem.getTitle());
order1.setTotalFee(orderItem.getTotalFee());
order1.setNum(orderItem.getNum());
order1.setStatusStr(getStatusStrById(order1.getStatus()));
order1.setItemId(orderItem.getItemId());
order1.setBuyerRateStr(getBuyerRateStrById(order1.getBuyerRate()));
order1.setDateStr1(DateUtil.getDateStr(order1.getCreateTime()));
order1.setDateStr3(DateUtil.getDateStr(order1.getPaymentTime()));
order1.setPaymentTypeStr(getPaymentTypeById(order1.getPaymentType()));
order1.setRefundStatus(null);
model.addAttribute("order", order1);
}
return "order/orderCheck";
}
@PostMapping("user/orderCheck")
public String orderCheckPost(Order order) {
if (order.getRefundStatus() == null) {
order.setRefundStatus(0);
}
if (order.getOrderId() != null) {
orderMapper.updateByPrimaryKey(order);
}
return "redirect:orderRefund_0_0_0";
}
还有几个辅助方法
//获取该id对应的状态字符串
public String getStatusStrById(int i) {
switch (i) {
case 1:
return "未付款";
case 2:
return "已付款";
case 3:
return "未发货";
case 4:
return "已发货";
case 5:
return "交易成功";
case 6:
return "交易关闭";
}
return null;
}
//获取该id对应的支付类型
public String getPaymentTypeById(int i) {
switch (i) {
case 1:
return "在线支付";
case 2:
return "货到付款";
}
return null;
}
//获取该id是否下单
public String getBuyerRateStrById(int i) {
switch (i) {
case 0:
return "否";
case 1:
return "是";
}
return null;
}
//获取该id退款状态
public String getRefundStatusStr(int i) {
switch (i) {
case 1:
return "申请退款";
case 2:
return "退款失败";
case 3:
return "退款成功";
}
return null;
}
发货管理
OrderShippingController
查询发货列表
@RequestMapping("/user/shippingManage_{pageCurrent}_{pageSize}_{pageCount}")
public String orderShippingGet(Model model, OrderShipping orderShipping,
@PathVariable Integer pageCurrent,
@PathVariable Integer pageSize,
@PathVariable Integer pageCount){
if (pageCurrent == 0)
pageCurrent = 1;
if (pageSize == 0)
pageSize = 50;
int row = orderShippingMapper.selectAll().size();
if (pageCount == 0){
pageCount = row%pageSize == 0 ? (row/pageSize) : (row/pageSize)+1;
}
orderShipping.setStart((pageCurrent - 1) * pageSize);
orderShipping.setEnd(pageSize);
model.addAttribute("orderShipping", orderShipping);
//设置创建更新时间字符串
List<OrderShipping> orderShippingList = orderShippingMapper.selectAll();
for (OrderShipping orderShipping1 : orderShippingList){
orderShipping1.setCreatedStr(DateUtil.getDateStr(orderShipping1.getCreated()));
orderShipping1.setUpdatedStr(DateUtil.getDateStr(orderShipping1.getUpdated()));
}
model.addAttribute("orderShippingList", orderShippingList);
//设置动态url
String pageHTML = PageUtil.getPageContent("shippingManage_{pageCurrent}_{pageSize}_{pageCount}", pageCurrent, pageSize, pageCount);
model.addAttribute("pageHTML", pageHTML);
return "order/shippingManage";
}
删除列表
//删除操作
@ResponseBody
@PostMapping("/user/shippingEditState")
public ResObeject<Object> shippingEditState(OrderShipping orderShipping){
orderShippingMapper.deleteByPrimaryKey(orderShipping.getOrderId());
ResObeject<Object> object = new ResObeject<Object>(Constant.Code01, Constant.Msg01, null, null);
return object;
}
功能全部完成了。后续应该还会再添加一些技术。