卖家订单
标签(空格分隔): springboot java wechat
Dao层处理
- 全部订单
/**
* 卖家端查询列表
* @param pageable
* @return
*/
@Override
public Page<OrderMasterDTO> findList(Pageable pageable) {
Page<OrderMaster> orderMasterPage = orderMasterRepository.findAll(pageable);
List<OrderMasterDTO> orderMasterDTOS = OrderMaster2OrderDtoConverter.covert(orderMasterPage.getContent());
return new PageImpl<OrderMasterDTO>(orderMasterDTOS,pageable,orderMasterPage.getTotalElements());
}
controller层的处理
- 枚举特例使用(前台回显枚举值)
# java单继承特性,所有枚举已经继承过后,只能实现接口
public interface CodeEnum {
Integer getCode();
}
public enum OrderStatusEnum implements CodeEnum
public enum PayStatusEnum implements CodeEnum
# 便利枚举显示
public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass){
for(T each : enumClass.getEnumConstants()){
if(code.equals(each.getCode())){
return each;
}
}
return null;
}
# 回显页面返回枚举对象
/** 前台显示. */
@JsonIgnore
public OrderStatusEnum getOrderStatus(){
return EnumUtil.getByCode(orderStatus,OrderStatusEnum.class);
}
#JsonIngore json显示隐藏该字段
/** 前台显示. */
@JsonIgnore
public PayStatusEnum getPayStatus(){
return EnumUtil.getByCode(payStauts,PayStatusEnum.class);
}
#前台展示字段
${orderMaster.getOrderStatusEnum().message}
- 取消订单操作
通过传送orderId的方式进行取消订单,回显成功或者错误页面,回调主界面
<#if orderMaster.getOrderStatusEnum().message!="取消订单">
<a href="/sell/seller/order/cancel?orderId=${orderMaster.orderId}">取消</a>
</#if>
/**
* 取消订单
* @param orderId
* @param map
* @return
*/
@GetMapping("/order/cancel")
public ModelAndView cancel(@RequestParam("orderId") String orderId,Map<String,Object> map){
try{
OrderMasterDTO orderMasterDTO = orderService.findOne(orderId);
orderService.cancle(orderMasterDTO);
map.put("msg", ResultEnum.ORDER_CANCEL_SUCCESS.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/success",map);
}catch (SellException e){
log.error("【取消订单】 订单取消错误={}",e.getMessage());
map.put("msg",e.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/error",map);
}
}
<html>
<head>
<meta charset="utf-8">
<link href="https://cdn.bootcss.com/bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet">
<title>操作提示</title>
</head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="alert alert-dismissable alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4>
成功!
</h4> <strong>${msg}!</strong> <a href="${url}" class="alert-link">3S后自动跳转!</a>
</div>
</div>
</div>
</div>
<script>
setTimeout('location.href="${url}"',3000);
</script>
</body>
</html>
-
详情表查看
通过id回显订单详情
@GetMapping("/order/detail")
public ModelAndView detail(@RequestParam("orderId") String orderId,Map<String,Object> map){
OrderMasterDTO orederMasterDTO = new OrderMasterDTO();
try{
orederMasterDTO = orderService.findOne(orderId);
}
catch (SellException e){
log.error("【查看订单详情】 错误={}",e.getMessage());
map.put("msg",e.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/error",map);
}
map.put("orderMasterDTO",orederMasterDTO);
return new ModelAndView("order/detail",map);
}
<html>
<head>
<meta charset="utf-8">
<link href="https://cdn.bootcss.com/bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet">
<title>买家订单详情展示</title>
</head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-4 column">
<table class="table table-bordered">
<thead>
<tr>
<th>编号</th>
<th>订单总金额</th>
</tr>
</thead>
<tbody>
<tr>
<td>${orderMasterDTO.orderId}</td>
<td>${orderMasterDTO.orderAmount}</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-12 column">
<table class="table table-bordered">
<thead>
<tr>
<th>商品ID</th>
<th>商品名称</th>
<th>价格</th>
<th>数量</th>
<th>总金额</th>
</tr>
</thead>
<tbody>
<tr>
<#list orderMasterDTO.orderDetailList as orderDetail>
<td>${orderDetail.productId}</td>
<td>${orderDetail.productName}</td>
<td>${orderDetail.productPrice}</td>
<td>${orderDetail.productQuantity}</td>
<td>${orderDetail.productQuantity * orderDetail.productPrice}</td>
</#list>
</tr>
</tbody>
</table>
</div>
<div class="col-md-12 column">
<#if orderMasterDTO.getOrderStatusEnum().message=="新订单">
<a href="/sell/seller/order/finish?orderId=${orderMasterDTO.orderId}" type="button" class="btn btn-default btn-info">完结订单</a>
<a href="/sell/seller/order/cancel?orderId=${orderMasterDTO.orderId}" type="button" class="btn btn-default btn-danger">取消订单</a>
</#if>
</div>
</div>
</div>
</body>
</html>
- 完结订单
@GetMapping("/order/finish")
public ModelAndView finish(@RequestParam("orderId") String orderId,Map<String,Object> map){
try {
OrderMasterDTO orderMasterDTO = orderService.findOne(orderId);
orderService.finish(orderMasterDTO);
}catch (SellException e){
log.error("【卖家完结订单】 错误={}",e.getMessage());
map.put("msg",e.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/error",map);
}
map.put("msg",ResultEnum.ORDER_FINISH_SUCCESS.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/success",map);
}
- 原视频UP主慕课网(SpringBoot企业级微信点餐项目)
- 本篇博客撰写人: XiaoJinZi 转载请注明出处
- 学生能力有限 附上邮箱: 986209501@qq.com 不足以及误处请大佬指责