一、订单管理内容
1.商家
查看订单
发货-->“订单状态”:1:未发货、2:已发货、3:已签收、4:已撤单 (默认值1)
订单项的查看
实现思路:
订单表的查询
将订单表的订单状态由1改成2
通过订单的id到订单项表查询出对应的订单项
2、买家:
查看订单
撤单
签收
实现思路:
订单表的查询
将订单表的订单状态由1改成4
将订单表的订单状态由2改成3
二、编码
1、编码思路:
商家:
实体类:上期内容已写
Dao层:
OrderDao:新增两个方法:①、订单的查询,通过订单号查询 ②、修改订单状态
OrderItemDao:新增一个方法:①、通过外键订单id查询订单项表
买家:
实体类:上期内容已写
Dao层:
OrderDao:新增两个方法:①、订单的查询,通过订单号查询 ②、修改订单状态
2.实现编码
①实现未发货以及已发货功能
Order:
public class Order {
private long id;
private long uid;
// 查询时间的时候用这个格式
@JsonFormat(pattern="yyyy-mm-dd HH:mm:ss",timezone="GMT+8")
private Date orderTime;
private String consignee;
private String phone;
private String postalcode;
private String address;
private int sendType;
@JsonFormat(pattern="yyyy-mm-dd HH:mm:ss",timezone="GMT+8")
private Date sendTime;
private float orderPrice;
private int orderState;
}
OderDao:
// 按照订单时间倒序条件筛选查询
public List<Order> list(Order order, PageBean pageBean) throws Exception {
// String sql="select * from t_easyui_order order by orderTime desc";
String sql="select * from t_easyui_order where 1=1";
long id=order.getId();
if(id!=0) {
sql+=" and id ="+id;
}
// 用来根据订单状态筛选查询
int orderState = order.getOrderState();
if(orderState!=0) {
sql+=" and orderState ="+orderState;
}
sql+=" order by orderTime desc";
return super.executeQuery(sql, Order.class, pageBean);
}
// 修改订单状态
public void editState(Order t) throws Exception {
String sql="update t_easyui_order set orderState= ? where id= ? ";
// 如果是发货,则需要修改发货时间
int orderState=t.getOrderState();
if(orderState==2) {
sql="update t_easyui_order set orderState= ?,sendTime=now() where id= ? ";
}
super.executeUpdate(sql, t, new String[] {"orderState","id"});
}
Dao方法:
// 查询
public List<OrderItem> list(OrderItem oi, PageBean pageBean) throws Exception {
String sql="select * from t_easyui_orderItem where 1=1";
// oid是订单项的外键,关联了订单表的主键
long oid=oi.getOid();
if(oid!=0) {
sql+=" and oid="+ oid;
}
return super.executeQuery(sql, OrderItem.class, pageBean);
}
OrderAction:
public class OrderAction extends ActionSupport implements ModelDriver<Order>{
private Order order=new Order();
private OrderDao od=new OrderDao();
@Override
public Order getModel() {
// TODO Auto-generated method stub
return order;
}
// 查询所有订单
public void list(HttpServletRequest req, HttpServletResponse resp) {
PageBean pageBean=new PageBean();
pageBean.setRequest(req);
try {
List<Order> list = od.list(order, pageBean);
ResponseUtil.writeJson(resp, new R().data("total", pageBean.getTotal()).data("rows", list));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 关于发货、撤单、签收共用的方法
public void cancelAndReceive(HttpServletRequest req, HttpServletResponse resp) {
// order就已经包含了,将要修改的状态以及对应的订单id
try {
od.editState(order);
ResponseUtil.writeJson(resp, 1);
} catch (Exception e) {
e.printStackTrace();
try {
ResponseUtil.writeJson(resp, 0);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
配置:
<action path="/order" type="com.zw.web.OrderAction"></action>
商家发货:
买家签收及撤销:
②查看订单项
写子控制器OrderItemAction
public class OrderItemAction extends ActionSupport implements ModelDriver<OrderItem>{
private OrderItem oi=new OrderItem();
private OrderItemDao oid=new OrderItemDao();
@Override
public OrderItem getModel() {
// TODO Auto-generated method stub
return oi;
}
public void list(HttpServletRequest req, HttpServletResponse resp) {
PageBean pageBean=new PageBean();
pageBean.setRequest(req);
try {
List<OrderItem> list = oid.list(oi, pageBean);
ResponseUtil.writeJson(resp, new R().data("total", pageBean.getTotal()).data("rows", list));
} catch (Exception e) {
e.printStackTrace();
}
}
}
配置:
<action path="/orderItem" type="com.zw.web.OrderItemAction">
</action>
结果: