package com.controller;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
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 com.pojo.Goods;
import com.pojo.Orderitem;
import com.pojo.Torder;
import com.pojo.Userinfo;
import com.service.GoodsService;
import com.service.OrderitemService;
import com.service.TorderService;
import com.service.UserinfoService;
import com.util.Cart;
@Controller
public class BuyController {
@Autowired
private GoodsService goodsService;
@Autowired
private OrderitemService orderitemService;
@Autowired
private TorderService torderService;
@Autowired
private UserinfoService userinfoService;
@RequestMapping(value = "/addToCart")
public String addToCart(HttpServletResponse response,
HttpServletRequest request) throws Exception {
int goodsId = Integer.parseInt(request.getParameter("goodsId"));
int quantity = Integer.parseInt(request.getParameter("quantity"));
Goods goods = goodsService.queryGoodsById(goodsId);
Orderitem orderItem = new Orderitem();
orderItem.setGoods(goods);
orderItem.setGoodsQuantity(quantity);
Object obj = request.getSession().getAttribute("cart");
Cart cart = null;
if (obj == null) {
cart = new Cart();
} else {
cart = (Cart) obj;
}
cart.addGoods(goodsId, orderItem);
request.getSession().setAttribute("cart", cart);
request.setAttribute("path", "myCart.action");
return "/common/succeed.jsp";
}
@RequestMapping(value = "/myCart")
public String myCart(HttpServletResponse response,
HttpServletRequest request) throws Exception {
return "/qiantai/myCart/myCart.jsp";
}
@RequestMapping(value = "/orderQueren")
public String orderQueren(HttpServletRequest request) throws Exception {
Userinfo user = (Userinfo) request.getSession().getAttribute("user");
if (user != null) {
//生成订单
Cart cart = (Cart) request.getSession().getAttribute("cart");
Map<String, List<Orderitem>> map = new HashMap<String, List<Orderitem>>();
for (Iterator it = cart.getItems().values().iterator(); it.hasNext();) {
Orderitem orderItem = (Orderitem) it.next();
int goodid = orderItem.getGoods().getGoodsId();
String shid = "1";
if (map.containsKey(shid)) {
List<Orderitem> list = map.get(shid);
list.add(orderItem);
} else {
List<Orderitem> list = new ArrayList<Orderitem>();
list.add(orderItem);
map.put(shid, list);
}
}
Torder order =null;
for (Map.Entry<String, List<Orderitem>> entry : map.entrySet()) {
String key = entry.getKey();
List<Orderitem> list = entry.getValue();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
order = new Torder();
order.setOrderBianhao(new SimpleDateFormat("yyyyMMddHHmmss")
.format(new Date()));
order.setOrderDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date()));
order.setOrderZhuangtai("未付款");
order.setOrderUserId(user.getUserId());
order.setOrderJine(getTotalPrice(list));
order.setSjfk(cart.getfkPrice(list));
order.setStore("0");
order.setJifen(ppJifen(order.getOrderJine()));
order.setShid(Integer.parseInt(key));
torderService.insertTorder(order);
for (Iterator it = list.iterator(); it.hasNext();) {
Orderitem orderItem = (Orderitem) it.next();
orderItem.setOrderId(order.getOrderId());
orderItem.setGoodsId(orderItem.getGoods().getGoodsId());
orderitemService.insertOrderitem(orderItem);
Goods goods = goodsService.queryGoodsById(orderItem.getGoodsId());
int kucun = goods.getKucun()-orderItem.getGoodsQuantity();
kucun = kucun<0?0:kucun;
goods.setKucun(kucun);
goodsService.updateGoods(goods);
}
}
cart.getItems().clear();
cart.setSjfk(0);
request.getSession().setAttribute("cart", cart);
request.setAttribute("order", order);
return "/qiantai/order/orderQueren.jsp";
} else {
return "/qiantai/userlogin/userlogin.jsp";
}
}
@RequestMapping(value = "/toorderSubmit")
public String toorderSubmit(HttpServletRequest request) throws Exception {
Integer orderId = Integer.parseInt(request.getParameter("orderId")) ;
Torder order = torderService.queryTorderById(orderId);
request.setAttribute("order", order);
return "/qiantai/order/orderQueren.jsp";
}
@RequestMapping(value = "/orderSubmit")
public String orderSubmit(HttpServletRequest request) throws Exception {
Userinfo user = (Userinfo) request.getSession().getAttribute("user");
//通过id查询
Integer orderId = Integer.parseInt(request.getParameter("orderId")) ;
Torder order = torderService.queryTorderById(orderId);
String odderFukuangfangshi = request.getParameter("odderFukuangfangshi");
String odderSonghuodizhi = request.getParameter("odderSonghuodizhi");
int tjifen = order.getJifen();
order.setOrderZhuangtai("已付款");
order.setOrderFukuangfangshi(odderFukuangfangshi);
order.setOrderSonghuodizhi(odderSonghuodizhi);
torderService.updateTorder(order);
user.setJifen(user.getJifen() + tjifen);
userinfoService.updateUserinfo(user);
request.getSession().setAttribute("user", user);
return "/qiantai/order/orderSubmit.jsp";
}
// 添加物流
/**
* 积分按照1:10 进行累计
*
* @param orderJine
* @return
*/
private int ppJifen(Integer orderJine) {
int jifen = orderJine / 10; // 余数不需要
return jifen;
}
public int getTotalPrice(List list) {
int totalPrice = 0;
for (Iterator it = list.iterator(); it.hasNext();) {
Orderitem orderItem = (Orderitem) it.next();
Goods goods = orderItem.getGoods();
int quantity = orderItem.getGoodsQuantity();
totalPrice += goods.getGoodsShichangjia() * quantity;
}
return totalPrice;
}
@RequestMapping(value = "/myOrder")
public String myOrder(HttpServletRequest request) throws Exception {
Userinfo user = (Userinfo) request.getSession().getAttribute("user");
Torder qorder = new Torder();
qorder.setOrderUserId(user.getUserId());
List<Torder> orderList = torderService.queryTorderList(qorder);
request.setAttribute("orderList", orderList);
return "/qiantai/order/myOrder.jsp";
}
@RequestMapping(value = "/myjifen")
public String myjifen(HttpServletRequest request) throws Exception {
Userinfo user = (Userinfo) request.getSession().getAttribute("user");
Torder qorder = new Torder();
qorder.setOrderUserId(user.getUserId());
qorder.setOrderZhuangtai("-1");
List<Torder> orderList = torderService.queryTorderList(qorder);
request.setAttribute("orderList", orderList);
return "/qiantai/userinfo/points.jsp";
}
@RequestMapping(value = "/orderMana")
public String orderMana(HttpServletRequest request) throws Exception {
Torder qorder = new Torder();
List orderList = torderService.queryTorderList(qorder);
request.setAttribute("orderList", orderList);
return "/admin/order/orderMana.jsp";
}
@RequestMapping(value = "/orderDel")
public String orderDel(HttpServletRequest request) throws Exception// 用户自己删除订单
{
int orderId = Integer.parseInt(request.getParameter("orderId"));
torderService.deleteTorder(orderId);
request.setAttribute("message", "删除成功");
request.setAttribute("path", "myOrder.action");
return "common/succeed.jsp";
}
@RequestMapping(value = "/orderDelByAd")
public Str
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Java Web基于SSM框架+JSP的网上商城项目的功能: 用户功能: 用户注册:用户可以填写注册表单进行注册,输入用户名、密码、邮箱等信息。 用户登录:已注册的用户可以通过用户名和密码进行登录。 用户信息管理:用户登录后可以修改个人信息,包括密码、邮箱、头像等。 商品收藏:用户可以将心仪的商品添加到收藏夹中。 商品功能: 商品展示:网站首页可以展示热门商品、促销商品等。用户可以通过商品分类、关键字搜索等方式浏览商品列表。 商品详情:用户可以点击商品进入该商品的详情页面,查看商品的详细信息、价格、库存等。 商品评价:已购买商品的用户可以对商品进行评价和评分。 商品推荐:系统可以根据用户的购买历史和浏览记录推荐相关的商品。 购物车与订单功能: 添加商品至购物车:用户可以将商品加入购物车,选择购买数量。 购物车管理:用户可以查看购物车中的商品列表,修改商品数量、删除商品。 订单生成:用户确认购买后,可以生成订单,订单中包括选择的商品、数量、总价等信息。 订单管理:用户可以查看自己的订单列表,包括订单状态、付款情况等。管理员可以管理所有的订单信息,包括确认收款、发货等操作。 支付与
资源推荐
资源详情
资源评论
收起资源包目录
java web基于ssm框架+jsp的网上商城项目+mysql数据库脚本java毕业设计 (1180个子文件)
BuyController.class 13KB
GoodsController.class 8KB
GonggaoController.class 4KB
PinglunController.class 4KB
LiuyanController.class 4KB
UserinfoController.class 4KB
ShoucangController.class 4KB
loginService.class 3KB
GoodsServiceImpl.class 3KB
Goods.class 3KB
IndexController.class 3KB
Cart.class 3KB
Torder.class 3KB
Util.class 3KB
CatelogController.class 3KB
cartService.class 2KB
Userinfo.class 2KB
TGonggaoServiceImpl.class 2KB
PageBean.class 2KB
TorderServiceImpl.class 2KB
TLiuyanServiceImpl.class 2KB
TAdminController.class 2KB
ShoucangServiceImpl.class 2KB
UserinfoServiceImpl.class 2KB
OrderitemServiceImpl.class 2KB
TAdminServiceImpl.class 2KB
CatelogServiceImpl.class 2KB
PinglunServiceImpl.class 2KB
Pinglun.class 2KB
Shoucang.class 2KB
TGonggao.class 2KB
TLiuyan.class 2KB
GsonUtil.class 1KB
Catelog.class 1KB
Orderitem.class 1KB
catelog11Service.class 1KB
TAdmin.class 974B
Catelogsecond.class 968B
GoodsService.class 805B
GoodsMapper.class 677B
TGonggaoMapper.class 579B
TLiuyanMapper.class 568B
OrderitemMapper.class 556B
TGonggaoService.class 554B
ShoucangMapper.class 545B
UserinfoMapper.class 545B
TLiuyanService.class 542B
PinglunMapper.class 534B
CatelogMapper.class 534B
OrderitemService.class 532B
TorderMapper.class 523B
TAdminMapper.class 523B
ShoucangService.class 520B
UserinfoService.class 520B
PinglunService.class 508B
CatelogService.class 508B
TAdminService.class 496B
TorderService.class 496B
.classpath 852B
org.eclipse.wst.common.component 471B
components-rounded.css 382KB
amazeui.css 336KB
amazeui.flat.css 322KB
amazeui.flat.min.css 242KB
amazeui.min.css 241KB
bootstrap.min.css 150KB
YZHcommon.css 145KB
layout1.css 91KB
blue.css 66KB
style.css 60KB
plugins.css 48KB
ueditor.css 44KB
hmstyle.css 44KB
default.css 39KB
ueditor.min.css 34KB
product.css 27KB
font-awesome.min.css 23KB
video-js.css 21KB
common.css 19KB
common.css 19KB
image.css 19KB
style.css 17KB
vipstyle.css 17KB
CN_home.css 16KB
personal.css 15KB
video.css 15KB
attachment.css 15KB
demo.css 14KB
swiper.min.css 13KB
video-js.min.css 11KB
buylist.css 11KB
uniform.default.css 11KB
simple-line-icons.min.css 9KB
jsstyle.css 9KB
index.css 9KB
layout.css 9KB
infstyle.css 8KB
orstyle.css 7KB
cartstyle.css 7KB
shCoreDefault.css 7KB
共 1180 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
竹山全栈
- 粉丝: 2370
- 资源: 261
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功