网上商城7--订单模块
2018-06-22 05:02:08来源:未知 阅读 ()
1.建表:
CREATE TABLE `orders` ( `oid` int(11) NOT NULL AUTO_INCREMENT, `total` double DEFAULT NULL, `ordertime` datetime DEFAULT NULL, `state` int(11) DEFAULT NULL, `name` varchar(20) DEFAULT NULL, `addr` varchar(100) DEFAULT NULL, `phone` varchar(20) DEFAULT NULL, `uid` int(11) DEFAULT NULL, PRIMARY KEY (`oid`), KEY `FKC3DF62E5AA3D9C7` (`uid`), CONSTRAINT `FKC3DF62E5AA3D9C7` FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; CREATE TABLE `orderitem` ( `itemid` int(11) NOT NULL AUTO_INCREMENT, `count` int(11) DEFAULT NULL, `subtotal` double DEFAULT NULL, `pid` int(11) DEFAULT NULL, `oid` int(11) DEFAULT NULL, PRIMARY KEY (`itemid`), KEY `FKE8B2AB6166C01961` (`oid`), KEY `FKE8B2AB6171DB7AE4` (`pid`), CONSTRAINT `FKE8B2AB6166C01961` FOREIGN KEY (`oid`) REFERENCES `orders` (`oid`), CONSTRAINT `FKE8B2AB6171DB7AE4` FOREIGN KEY (`pid`) REFERENCES `product` (`pid`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

2.bean
public class Order {
private Integer oid;
private Double total;
private Date ordertime;
private String name;
private String addr;
private String phone;
private Integer state;
// 与用户的关联关系
private User user;
// 与订单项关联关系
private Set<OrderItem> orderItems = new HashSet<OrderItem>();
....
}
public class OrderItem {
private Integer itemid;
private Integer count;
private Double subtotal;
private Product product;
private Order order;
....
}
注意:Product以后 只能做假删除了 不然没法从从订单查询名称
3.生成订单
public String createOrder() {
// 将Order对象存入到数据库中:
// 封装Order对象:
Order order = new Order();
// 封装总价---从购物车的信息获得.
// 获得购物车:
Cart cart = (Cart) ServletActionContext.getRequest().getSession()
.getAttribute("cart");
// 判断:
if (cart == null) {
this.addActionError("亲!您还没有购物!请先去购物!");
return "msg";
}
// 设置所属用户:
User existUser = (User) ServletActionContext.getRequest().getSession()
.getAttribute("existUser");
if (existUser == null) {
this.addActionError("亲!您还没有登录!请先去登录!");
return "msg";
}
order.setUser(existUser);
order.setTotal(cart.getTotal());
// 封装时间
order.setOrdertime(new Date());
// 封装状态
order.setState(1); // 1 未付款 2 已经付款,未发货 3.已经发货,没有确认收货 4.订单完成.
// 为订单设置订单项集合:
for (CartItem cartItem : cart.getCartItems()) {
// 将购物项的数据封装到订单项中.
OrderItem orderItem = new OrderItem();
orderItem.setCount(cartItem.getCount());
orderItem.setSubtotal(cartItem.getSubtotal());
orderItem.setProduct(cartItem.getProduct());
orderItem.setOrder(order);
// 放入订单的集合:
order.getOrderItems().add(orderItem);
}
// 购物车清空了.
cart.clearCart();
// 调用Service保存订单的操作:
orderService.save(order);
// 将订单存入到值栈中:
ActionContext.getContext().getValueStack().set("order", order);
// 页面跳转:
return "createOrderSuccess";
}
4.查询我的订单
1.根据用户的id查询订单
5.查询某个订单:
1.跟单订单id查询订单
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- PHP提交订单,信息的传递 2019-02-25
- PHP电商订单自动确认收货redis队列 2018-06-22
- PHP浮点数运算精度造成的,订单金额支付经常少1分的问题 2018-06-22
- C#得到某月最后一天晚上23:59:59和某月第一天00:00:00 2018-06-22
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
