package com.liu.shoppingmall.web.controller;
import com.github.pagehelper.PageInfo;
import com.liu.shoppingmall.common.model.Detail.OrderDetail;
import com.liu.shoppingmall.common.model.Goods;
import com.liu.shoppingmall.common.model.Order;
import com.liu.shoppingmall.common.model.OrderItem;
import com.liu.shoppingmall.common.model.User;
import com.liu.shoppingmall.common.service.OrderService;
import com.liu.shoppingmall.common.util.PaginateInfo;
import com.liu.shoppingmall.web.common.ClientLoginInterceptor;
import com.liu.shoppingmall.web.model.Cart;
import com.liu.shoppingmall.web.service.CartService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@Controller
public class OrderController {
// @DubboReference
private OrderService orderService;
private CartService cartService;
@Autowired
public void setCartService(CartService cartService) {
this.cartService = cartService;
}
@Autowired
public void setOrderService(OrderService orderService) {
this.orderService = orderService;
}
@GetMapping("/orders")
public String orderListPage(@RequestParam Map<String, Object> params,
HttpServletRequest request, HttpSession session) {
User user = (User) session.getAttribute(ClientLoginInterceptor.CLIENT_USER_KEY);
Integer pageNo;
Object pageObj = params.get("page");
if (ObjectUtils.isEmpty(pageObj)) {
pageNo = 1;
}else {
pageNo = pageObj instanceof Integer ? (Integer) pageObj : Integer.parseInt(pageObj.toString());
}
Order order = new Order();
System.out.println("userId:"+user.getUserId());
order.setUserId(user.getUserId());
PaginateInfo pi = new PaginateInfo(pageNo, 3);
request.setAttribute("pageInfo", pi);
Map<String, Object> orderMap = orderService.findOrderByUserId(order, pi);
List<OrderDetail> orders = (List<OrderDetail>) orderMap.get("data");
for (OrderDetail orderDetail : orders) {
System.out.println("orderDetail:"+orderDetail.getOrderId());
List<OrderItem> orderItemList = orderService.findDetail(orderDetail.getOrderId());
for (OrderItem orderItem : orderItemList) {
System.out.println("orderItem:"+orderItem.getGoodsName());
}
orderDetail.setOrderItemList(orderItemList);
}
// List<OrderItem> orderItemList = orderService.findDetail(67);
// System.out.println("orderItemList:"+orderItemList.getFirst().getGoodsName());
request.setAttribute("orderPageResult", orders);
request.setAttribute("path", "orders");
return "mall/my-orders";
}
@Transactional
@PostMapping("/saveOrder")
@ResponseBody
public Map<String,Object> saveOrder(@RequestBody Order order, HttpSession session) {
User user = (User) session.getAttribute(ClientLoginInterceptor.CLIENT_USER_KEY);
order.setUserId(user.getUserId());
int row = this.orderService.add(order);
Integer orderId = order.getOrderId();
String orderNo = order.getOrderNo();
System.out.println("orderNo"+orderNo);
List<Cart> carts = cartService.findByUserId(user.getUserId());
//遍历购物车,将购物车的商品数据保存到订单详情表中
for (Cart cart : carts) {
OrderItem orderItem = new OrderItem();
orderItem.setOrderId(orderId);
orderItem.setGoodsId(cart.getGoodsId());
orderItem.setPrice(cart.getPrice());
orderItem.setGoodsName(cart.getGoodsName());
orderItem.setGoodsNum(cart.getGoodsCount());
orderItem.setTotalPrice(cart.getTotalPrice());
orderService.addItem(orderItem);
}
return Map.of("success",true, "orderNo", orderNo,"order",order);
// return "redirect:/order/" + orderNo;
}
@GetMapping("/orders/{orderNo}")
public String orderDetail(HttpServletRequest request, HttpSession session,
@PathVariable("orderNo") String orderNo) {
User user = (User) session.getAttribute(ClientLoginInterceptor.CLIENT_USER_KEY);
System.out.println(orderNo);
//根据订单号,得到订单表的主键
Order order = orderService.findByOrderNo(orderNo);
request.setAttribute("order", order);
List<OrderItem> orderItems = orderService.findDetail(order.getOrderId());
request.setAttribute("orderItems", orderItems);
return "mall/order-detail";
}
//去支付
@GetMapping("/selectPayType")
public String selectPayType(HttpServletRequest request,
@RequestParam("orderNo") String orderNo,
HttpSession session) {
User user = (User) session.getAttribute(ClientLoginInterceptor.CLIENT_USER_KEY);
Order order = orderService.findByOrderNo(orderNo);
//判断订单是否属于当前用户
// if (!order.getUserId().equals(user.getUserId())) {
// //todo 抛出异常
// return "error";
// }
//判断订单状态是否为未支付状态
// if (order.getOrderStatus() != 0) {
// //todo 抛出异常
// return "error";
// }
request.setAttribute("orderNo", orderNo);
request.setAttribute("totalPrice", order.getTotalPrice());
//跳转到订单支付页面
return "mall/pay-select";
}
//具体支付界面
@GetMapping("/payPage")
public String payOrder(HttpServletRequest request,
@RequestParam("orderNo") String orderNo,
HttpSession session, @RequestParam("payType")
int payType) {
User user = (User) session.getAttribute(ClientLoginInterceptor.CLIENT_USER_KEY);
Order order = orderService.findByOrderNo(orderNo);
//判断订单是否属于当前用户
if (!order.getUserId().equals(user.getUserId())) {
//todo 抛出异常
return "error";
}
//判断订单状态是否为未支付状态
// if (order.getOrderStatus() != 0) {
// //todo 抛出异常
// return "error";
// }
request.setAttribute("orderNo", orderNo);
request.setAttribute("totalPrice", order.getTotalPrice());
if (payType == 1) {
return "mall/alipay";
} else {
return "mall/wxpay";
}
}
//支付成功
@GetMapping("/paySuccess")
@ResponseBody
public Map<String,Object> paySuccess(@RequestParam("orderNo") String orderNo,
@RequestParam("payType") int payType) {
// 更改订单状态
System.out.println("payType:"+payType);
Order order = orderService.findByOrderNo(orderNo);
int row = orderService.paySuccess(orderNo,payType);
return Map.of("success",true);
}
//取消订单
@PutMapping("/orders/{orderNo}/cancel")
@ResponseBody
public Map<String,Object> cancelOrder(@PathVariable("orderNo") String orderNo,
HttpSession session) {
User user = (User) session.getAttribute(ClientLoginInterceptor.CLIENT_USER_KEY);
Order order = orderService.findByOrderNo(orderNo);
if (!order.getUserId().equals(user.getUserId())) {
//todo 抛出异常
return Map.of("success",false,"message","非法操作");
没有合适的资源?快使用搜索试试~ 我知道了~
springboot+vue+dubbo+redis商城管理系统前后端分离源码分享
共494个文件
js:120个
html:72个
java:68个
需积分: 5 0 下载量 173 浏览量
2024-11-03
14:05:33
上传
评论
收藏 5.78MB ZIP 举报
温馨提示
springboot+vue+dubbo+redis商城管理系统前后端分离源码分享
资源推荐
资源详情
资源评论
收起资源包目录
springboot+vue+dubbo+redis商城管理系统前后端分离源码分享 (494个子文件)
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 7KB
adminlte.css 247KB
adminlte.min.css 201KB
bootstrap.css 183KB
bootstrap.min.css 137KB
bootstrap3.3.7.min.css 118KB
bootstrap-modal.css 106KB
style.css 51KB
ionicons.min.css 50KB
bootstrap-grid.css 37KB
website.css 31KB
bootstrap-grid.min.css 28KB
font-awesome.min.css 26KB
ui.jqgrid-bootstrap4.css 23KB
sweetalert2.min.css 20KB
ui.jqgrid.css 20KB
ui.jqgrid-bootstrap.css 19KB
select2.css 17KB
select2.min.css 15KB
style.css 15KB
swiper-bundle.min.css 13KB
index.css 9KB
order-detail.css 9KB
website.css 8KB
header.css 8KB
my-orders.css 8KB
order-settle.css 6KB
cart.css 6KB
pay.css 5KB
search.css 5KB
bootstrap-reboot.css 5KB
addresses.css 4KB
bootstrap-reboot.min.css 4KB
pay-select.css 3KB
detail.css 3KB
ebook.css 3KB
iconfont.css 3KB
login.css 2KB
personal.css 2KB
main.css 2KB
search.css 1KB
common.css 987B
ui.jqgrid-bootstrap-ui.css 662B
style.css 265B
style.css 137B
font-awesome.css 0B
font-awesome.min.css 0B
bootstrap.min.css 0B
bootstrap-grid.css 0B
bootstrap.css 0B
bootstrap-reboot.css 0B
bootstrap-grid.min.css 0B
bootstrap-reboot.min.css 0B
fontawesome-webfont.eot 75KB
fontawesome-webfont.eot 67KB
glyphicons-halflings-regular.eot 20KB
iconfont.eot 2KB
fontawesome-webfont.eot 0B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
tooltip.html 40KB
line.html 31KB
bar.html 28KB
api.html 27KB
legend.html 27KB
index.html 26KB
styling.html 26KB
axes.html 26KB
linear.html 26KB
elements.html 25KB
time.html 25KB
radar.html 24KB
charts.html 24KB
bubble.html 24KB
doughnut.html 23KB
usage.html 23KB
animations.html 22KB
index.html 22KB
plugins.html 22KB
modes.html 22KB
linear.html 22KB
category.html 22KB
area.html 22KB
responsive.html 22KB
polar.html 22KB
index.html 22KB
contributing.html 21KB
installation.html 21KB
colors.html 21KB
extensions.html 21KB
mixed.html 21KB
labelling.html 20KB
index.html 20KB
共 494 条
- 1
- 2
- 3
- 4
- 5
资源评论
程序猿小D
- 粉丝: 4193
- 资源: 843
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- java项目实战练习.zip
- java桌面小程序,主要为游戏.zip学习资料
- ember前端框架,一键部署到云开发平台.zip
- kero is a front-end model framework. - kero是一个前端模型框架,做为MVVM架构中Model层的增强,提供多维数据模型.zip
- PandaUi 是PandaX的前端框架,PandaX 是golang(go)语言微服务开发架构.zip
- v8垃圾回收机制 一篇技术分享文章
- libre后台管理系统前端,使用vue2开发.zip
- Java企业级快速开发平台 前后端分离基于nodejs+vue2+webpack+springboot.zip
- Java诊断工具.zip
- feHelper前端开发助手系统.zip开发
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功