目标:
一:卖家的发货功能,未发货、已发货、已签收、订单项数据的查看
二:买家的撤单、签收功能的实现,以及未发货、已发货、已签收的数据查看
一:卖家功能
第一步:写dao层方法(OrderDao、OrderItemDao)
OrderDao
package com.sg.dao; import java.util.List; import com.sg.entity.Order; import com.zking.util.BaseDao; import com.zking.util.PageBean; public class OrderDao extends BaseDao<Order>{ /** * 购物车结算生成订单 * @param order * @throws Exception */ public void add(Order order) throws Exception { String sql="insert into t_easyui_order(uid,orderTime,consignee,phone,postalcode,address,sendType,sendTime,orderPrice,orderState) values(?,now(),?,?,?,?,?,?,?,?)"; super.executeUpdate(sql, order, new String[] {"uid","consignee","phone","postalcode","address","sendType","sendTime","orderPrice","orderState"}); } /** * 按照订单时间倒序查询 * @param order * @param pageBean * @return * @throws Exception */ public List<Order> list( Order order, PageBean pageBean) throws Exception { 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 order) throws Exception { String sql="update t_easyui_order set orderState = ? where id =?"; int orderState = order.getOrderState(); if(orderState==2) { sql="update t_easyui_order set orderState = ?,sendTime=now() where id =?"; } super.executeUpdate(sql, order, new String[] {"orderState","id"}); } }
OrderItemDao
package com.sg.dao; import java.util.List; import com.sg.entity.OrderItem; import com.zking.util.BaseDao; import com.zking.util.PageBean; public class OrderItemDao extends BaseDao<OrderItem>{ /** * 购物车结算生成订单项 * @param OrderItem * @throws Exception */ public void add(OrderItem orderItem) throws Exception { String sql="insert into t_easyui_orderitem(oid,bid,quantity) values(?,?,?)"; super.executeUpdate(sql, orderItem, new String[] {"oid","bid","quantity"}); } public List<OrderItem> list(OrderItem orderItem, PageBean pageBean) throws Exception { // TODO Auto-generated method stub String sql="select * from t_easyui_orderItem where 1=1"; long oid = orderItem.getId(); if(oid!=0) { sql+=" and oid="+oid; } return super.executeQuery(sql, OrderItem.class, pageBean); } }
第二步:web层(OrderAction、OrderItemAction)
OrderAction
package com.sg.web; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.sg.dao.OrderDao; import com.sg.entity.Order; import com.zking.framework.ActionSupport; import com.zking.framework.ModelDriver; import com.zking.util.PageBean; import com.zking.util.R; import com.zking.util.ResponseUtil; public class OrderAction extends ActionSupport implements ModelDriver<Order>{ private Order order=new Order(); private OrderDao orderDao=new OrderDao(); @Override public Order getModel() { // TODO Auto-generated method stub return order; } public void list(HttpServletRequest req, HttpServletResponse resp) { // TODO Auto-generated method stub PageBean pageBean=new PageBean(); pageBean.setRequest(req); try { List<Order> list = orderDao.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(); } } /** * 发货、撤单、签收公用方法 * @param req * @param resp */ public void cancelAndReceive(HttpServletRequest req, HttpServletResponse resp) { // TODO Auto-generated method stub try { orderDao.editState(order); ResponseUtil.writeJson(resp, 1); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); try { ResponseUtil.writeJson(resp, 0); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }
OrderItemAction
package com.sg.web; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.sg.dao.OrderItemDao; import com.sg.entity.OrderItem; import com.zking.framework.ActionSupport; import com.zking.framework.ModelDriver; import com.zking.util.PageBean; import com.zking.util.R; import com.zking.util.ResponseUtil; public class OrderItemAction extends ActionSupport implements ModelDriver<OrderItem>{ private OrderItem orderItem=new OrderItem(); private OrderItemDao orderItemDao=new OrderItemDao(); @Override public OrderItem getModel() { // TODO Auto-generated method stub return orderItem; } public void list(HttpServletRequest req, HttpServletResponse resp) { // TODO Auto-generated method stub PageBean pageBean=new PageBean(); pageBean.setRequest(req); try { List<OrderItem> list = orderItemDao.list(orderItem, pageBean); ResponseUtil.writeJson(resp, new R().data("total", pageBean.getTotal()).data("rows", list)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
第三步:配置文件
<action path="/order" type="com.sg.web.OrderAction"> </action> <action path="/orderItem" type="com.sg.web.OrderItemAction"> </action>
页面展示:
![]()
在未发货页面点击发货(发货张三)
![]()
二:买家
买家的功能也已经实现了
因为OrderAction中的
/** * 发货、撤单、签收公用方法 * @param req * @param resp */ public void cancelAndReceive(HttpServletRequest req, HttpServletResponse resp) { // TODO Auto-generated method stub try { orderDao.editState(order); ResponseUtil.writeJson(resp, 1); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); try { ResponseUtil.writeJson(resp, 0); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
这个方法是公用的
效果展示:
在未发货页面点击撤单(撤单张三)
在已发货页面点击签收(签收99)
![]()
今天就到这了,拜拜各位!!!