首页>代码>高仿京东商城SSH源代码下载>/京东源码/JingDongSSH/src/com/softeem/jingdong/action/OrderAction.java
package com.softeem.jingdong.action;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.softeem.jingdong.entity.OrderBean;
import com.softeem.jingdong.entity.UsersBean;
import com.softeem.jingdong.service.OrderService;
/**
 * 订单 Action
 * @author Administrator
 */
public class OrderAction extends ActionSupport {

	private static final long serialVersionUID = 8189598361091118151L;
	private OrderService orderService;
	private String name;
	private String address;
	private String phone;
	private String email;
	private String payWay;
	private OrderBean order = new OrderBean();
	
	/**
	 * 添加订单
	 */
	public String addOrder(){
		
		//添加订单号
		order.setNo(this.getID());
		order.setConsignee(name);
		order.setAddress(address);
		order.setPhone(phone);
		order.setEmail(email);
		order.setPayWay(payWay);
		order.setTime( new Timestamp( new Date().getTime() ));
		
		HttpSession session = ServletActionContext.getRequest().getSession(true);
		
		//调用 下订单方法
		orderService.addOrder(order, (UsersBean)session.getAttribute("users"));
		
		//跳转到成功页面
		return SUCCESS;
	}
	
	/**
	 * 获取订单编号 13位
	 * yyyyMMdd + 5位随机数
	 */
	public long getID(){
		
		//yyyyMMdd
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String t = sdf.format(new Date());
		
		//5位随机数
		Random r = new Random();
		int m = 0;
		
		while( (m=r.nextInt(100000)) > 10000){
			break;
		}
		
		//拼接 返回 随机 订单号
		return Long.parseLong(t + m); 
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPayWay() {
		return payWay;
	}
	public void setPayWay(String payWay) {
		this.payWay = payWay;
	}
	public OrderBean getOrder() {
		return order;
	}
	public void setOrder(OrderBean order) {
		this.order = order;
	}
	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}
	
}
最近下载更多
baoligeer  LV5 2022年6月6日
任星浩  LV1 2021年11月18日
giantinheart  LV3 2021年5月23日
wusiyin  LV14 2020年12月17日
曾学成  LV2 2020年12月14日
refreshbird  LV1 2020年12月14日
方立亮  LV1 2020年11月6日
渺无人烟  LV11 2020年7月31日
cpemy_abc  LV10 2020年6月9日
远大帅比  LV6 2020年5月19日
最近浏览更多
czx5450  LV16 4月1日
linlin01  LV1 1月2日
2486624997  LV1 2023年12月22日
2385649653  LV7 2023年12月12日
limin123  LV6 2023年11月20日
heqian  LV16 2023年10月31日
zhaozhiqi  LV5 2023年10月21日
微信网友_6680567232876544  LV8 2023年10月10日
mengmeng12323423  LV3 2023年9月8日
543539666  LV7 2023年8月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友