목차
5주문 조회 :" >5주문 조회 :
php教程 php手册 온라인몰 7--주문 모듈

온라인몰 7--주문 모듈

Nov 30, 2016 pm 11:59 PM

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.콩

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;
        ....
}
로그인 후 복사

 

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주문 조회

 

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 채팅 명령 및 사용 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)