package cn.sjzedu.controller;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import cn.sjzedu.pack.CashContext;
import cn.sjzedu.pojo.Cart;
import cn.sjzedu.pojo.Discount;
import cn.sjzedu.service.AccountService;
import cn.sjzedu.service.DiscountService;
@Controller
@RequestMapping("/Account")
public class AccountController {
@Autowired
private AccountService accountService;
@Autowired
private DiscountService discountService;
//添加商品
@RequestMapping("/account")
public ModelAndView account(HttpServletRequest req,HttpServletResponse rsp) throws Exception{
ModelAndView modelAndView = new ModelAndView();
List<Cart> listcart = accountService.findallcart();
if(listcart==null){
modelAndView.setViewName("account");
}else{
modelAndView.addObject("listcart", listcart);
modelAndView.setViewName("account");
}
return modelAndView;
}
//点击结算跳转的controller
@RequestMapping("/cashier")
public ModelAndView cashier(HttpServletRequest req,HttpServletResponse rsp) throws Exception{
ModelAndView modelAndView = new ModelAndView();
List<Cart> listcart = accountService.findallcart();
Iterator<Cart> iterator = listcart.iterator();
double totalprice = 0.0;
double discountprice = 0.0;
while(iterator.hasNext()){
Cart next = iterator.next();
int goodscount = next.getGoodscount();
double price = next.getGoodsprice();
totalprice =totalprice+ (double)goodscount *price;
}
modelAndView.addObject("totalprice", totalprice);
//查出现在的优惠
Discount discount = discountService.selectDiscount();
if(discount!=null){
double moneycondition = discount.getMoneycondition();
double moneyreturn = discount.getMoneyreturn();
double rate = discount.getRate();
//有折扣 没满减
if(moneycondition==0.0&&moneyreturn==0.0){
if(rate!=0.0){
CashContext csuper = new CashContext(rate);
double totalmoney = csuper.getResult(totalprice);
modelAndView.addObject("rebate",rate);
modelAndView.addObject("totalmoney", totalmoney);
}
}
//有满减 没折扣
if(rate==0.0){
if(moneycondition!=0.0&&moneyreturn!=0.0){
CashContext csuper = new CashContext(moneycondition,moneyreturn);
double totalmoney = csuper.getResult(totalprice);
modelAndView.addObject("man",moneycondition);
modelAndView.addObject("jian",moneyreturn);
modelAndView.addObject("totalmoney", totalmoney);
}
}
}else{
//没有活动
CashContext csuper = new CashContext();
double totalmoney = csuper.getResult(totalprice);
modelAndView.addObject("tell", "没有活动可以参与");
modelAndView.addObject("totalmoney", totalmoney);
}
modelAndView.setViewName("cashier");
return modelAndView;
}
}
最近下载更多
15342201772 LV9
2024年11月12日
Xppasdf LV3
2024年10月29日
taoshen95 LV16
2024年3月22日
gecongkai LV8
2023年6月22日
yzshabzbbdvw LV4
2023年4月15日
malike LV3
2022年12月14日
lsglsg9 LV23
2022年11月26日
微信网友_6200823191523328 LV3
2022年11月11日
admin0108 LV9
2022年10月12日
1020132795 LV5
2022年9月25日
最近浏览更多
vincemokea LV9
4月24日
xiaoaitx LV8
1月1日
hcghhh
2024年12月28日
暂无贡献等级
微信网友_7310057461567488
2024年12月24日
暂无贡献等级
三秋桂子 LV1
2024年12月22日
Ella0902
2024年12月18日
暂无贡献等级
n1234560090
2024年12月11日
暂无贡献等级
sjwc88 LV4
2024年12月4日
Xppasdf LV3
2024年10月29日
zouzou123 LV3
2024年10月18日

