📄 sale.java
字号:
/**
* @name Sale.java
* @version 1.1
* @author Administrator/pan
* @date 2009/2/11
*/
package com.digitstore.process.sale;
import java.io.Serializable;
import java.util.Date;
import com.digitstore.process.manageruser.Customer;
import com.digitstore.process.sale.Cart;
import com.digitstore.process.OrderForm;
import com.digitstore.process.server.PricingStrategyFactory;
import com.digitstore.process.server.sale.CashPayment;
import com.digitstore.process.server.sale.CompositeBestForCustomerPricingStrategy;
import com.digitstore.process.server.sale.CreditPayment;
import com.digitstore.process.server.sale.Payment;
import com.digitstore.process.server.sale.PercentDiscountPricingStrategy;
import com.digitstore.process.server.sale.VirtualMoneyPayment;
public class Sale implements Serializable {
//顾客编号
private String customerID;
//时间
private Date date;
//是否购物完成
private boolean isCompleted;
//所购商品的总价
private double total = 0;
//购物车
private Cart cart;
//账单
private Payment payment;
//订单
private OrderForm orderForm;
//获取顾客最有组合定价策略
private CompositeBestForCustomerPricingStrategy compBFCPstra = PricingStrategyFactory.getInstance().getCompBestCustPriStrategy();
//构造函数
public Sale(String customerID){
date = new Date();
isCompleted = false;
cart = new Cart();
this.customerID = customerID;
}
//对应的get/set方法
public String getCustomerID(){
return customerID;
}
public void setCustomerID(String customerID){
this.customerID = customerID;
}
public Date getDate(){
return date;
}
public void setDate(Date date){
this.date = date;
}
public boolean getIscompleted(){
return isCompleted;
}
public void setIscompleted(boolean isCompleted){
this.isCompleted = isCompleted;
}
public Cart getCart(){
return cart;
}
public void setCart(Cart cart){
this.cart = cart;
}
public Payment getPayment(){
return payment;
}
public void setPayment(Payment payment){
this.payment = payment;
}
public OrderForm getOrderForm(){
return orderForm;
}
public void setOrderForm(OrderForm orderForm){
this.orderForm = orderForm;
}
//购物完毕的设置方法
public void becomeCompleted(){
this.isCompleted = true;
}
//添加物品,默认是添加1
public void makeLineItem(String itemID){
cart.addSalesLineItem(itemID);
}
//移除商品
public void removeSalesLineItem(String itemID){
cart.removeSalesLineItem(itemID);
}
//更新指定的SalesLineItem的商品数量
public void setQuntitySLI(String itemID, int quantity){
cart.setQuntitySLI(itemID, quantity);
}
//用货币支付商品款项
public void makeCashPayment(String customerID){
payment = new CashPayment(customerID, total);
}
//用信用卡支付商品货款
public void makeCreditPayment(String customerID){
payment = new CreditPayment(customerID, total);
}
//使用虚拟货币支付
public void makeVirtualPayment(String customerID){
payment = new VirtualMoneyPayment(customerID, total);
}
//填写表单
public void makeOrderForm(){
orderForm = new OrderForm();
}
//算总账,没有折扣
public double getTotal(){
//设置总价格
setTotal(cart.getTotal());
return total;
}
//算总账,有折扣
public double getTotal(Sale sale){
//设置总价格
setTotal(compBFCPstra.getTotal(sale));
return total;
}
//设置商品总价格
public void setTotal(double total){
this.total = total;
}
//输入用户类型,计算本次折扣
public void enterCustomerForDiscount(Customer customer){
PercentDiscountPricingStrategy percDPStrategy = PricingStrategyFactory.getInstance().getPercDisPriStrategy();
percDPStrategy.setPercentage(customer.getDiscount());
compBFCPstra.add(percDPStrategy);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -