首页>代码>基于SSM框架简单的商城购物车项目实例>/超市项目/shopcart/src/cn/sjzedu/controller/AccountController.java
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;
		
		
	}
}
最近下载更多
taoshen95  LV14 3月22日
gecongkai  LV8 2023年6月22日
yzshabzbbdvw  LV4 2023年4月15日
malike  LV3 2022年12月14日
lsglsg9  LV22 2022年11月26日
微信网友_6200823191523328  LV3 2022年11月11日
admin0108  LV9 2022年10月12日
1020132795  LV5 2022年9月25日
chj1234  LV4 2022年9月16日
13605416728  LV4 2022年6月20日
最近浏览更多
pangzhihui  LV12 4月17日
xiexin  LV1 4月13日
wddq123 4月2日
暂无贡献等级
xiongM  LV4 4月1日
xiaojie93  LV2 3月1日
lihao0217  LV1 2月15日
liiiyou  LV1 1月26日
戴凯凡 1月23日
暂无贡献等级
a2418735612  LV1 1月4日
潘潘123456  LV2 2023年12月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友