开发工具:idea或eclipse
数据库:mysql 数据库连接工具:navcat
技术栈:
后端采用 springboot2.1 springmvc mybaits
前端采用bootstrap jquery thymeleaf html
数据库mysql jdk1.8
开发工具:eclipse idea myeclipse sts等java开发工具
演示视频:
基于springboot在线鲜花交易商城源码含论文
package flowershop.mall.controller.mall;
import flowershop.mall.common.ServiceResultEnum;
import flowershop.mall.controller.vo.ShoppingCartItemVO;
import flowershop.mall.controller.vo.UserVO;
import flowershop.mall.entity.Comment;
import flowershop.mall.entity.Goods;
import flowershop.mall.entity.MallUser;
import flowershop.mall.entity.Order;
import flowershop.mall.service.CommentService;
import flowershop.mall.service.GoodsService;
import flowershop.mall.service.ShoppingCartService;
import flowershop.mall.common.Constants;
import flowershop.mall.common.NewShopMallException;
import flowershop.mall.controller.vo.OrderDetailVO;
import flowershop.mall.service.OrderService;
import flowershop.mall.util.PageQueryUtil;
import flowershop.mall.util.Result;
import flowershop.mall.util.ResultGenerator;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Controller
public class MallOrderController {
@Resource
private ShoppingCartService shoppingCartService;
@Resource
private OrderService orderService;
@Resource
private GoodsService goodsService;
@Resource
private CommentService commentService;
@GetMapping("/orders/{orderNo}")
public String orderDetailPage(HttpServletRequest request, @PathVariable("orderNo") String orderNo, HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
OrderDetailVO orderDetailVO = orderService.getOrderDetailByOrderNo(orderNo, user.getUserId());
if (orderDetailVO == null) {
return "error/error_5xx";
}
request.setAttribute("orderDetailVO", orderDetailVO);
return "mall/order-detail";
}
@GetMapping("/orders")
public String orderListPage(@RequestParam Map<String, Object> params, HttpServletRequest request, HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
params.put("userId", user.getUserId());
if (StringUtils.isEmpty(params.get("page"))) {
params.put("page", 1);
}
params.put("limit", Constants.ORDER_SEARCH_PAGE_LIMIT);
//封装我的订单数据
PageQueryUtil pageUtil = new PageQueryUtil(params);
request.setAttribute("orderPageResult", orderService.getMyOrders(pageUtil));
request.setAttribute("path", "orders");
return "mall/my-orders";
}
@GetMapping("/saveOrder")
public String saveOrder(HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
List<ShoppingCartItemVO> myShoppingCartItems = shoppingCartService.getMyShoppingCartItems(user.getUserId());
if (StringUtils.isEmpty(user.getAddress().trim())) {
//无收货地址
NewShopMallException.fail(ServiceResultEnum.NULL_ADDRESS_ERROR.getResult());
}
if (CollectionUtils.isEmpty(myShoppingCartItems)) {
//购物车中无数据则跳转至错误页
NewShopMallException.fail(ServiceResultEnum.SHOPPING_ITEM_ERROR.getResult());
}
//保存订单并返回订单号
String saveOrderResult = orderService.saveOrder(user, myShoppingCartItems);
//跳转到订单详情页
return "redirect:/orders/" + saveOrderResult;
}
@PutMapping("/orders/{orderNo}/cancel")
@ResponseBody
public Result cancelOrder(@PathVariable("orderNo") String orderNo, HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
String cancelOrderResult = orderService.cancelOrder(orderNo, user.getUserId());
if (ServiceResultEnum.SUCCESS.getResult().equals(cancelOrderResult)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult(cancelOrderResult);
}
}
@PutMapping("/orders/{orderNo}/finish")
@ResponseBody
public Result finishOrder(@PathVariable("orderNo") String orderNo, HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
String finishOrderResult = orderService.finishOrder(orderNo, user.getUserId());
if (ServiceResultEnum.SUCCESS.getResult().equals(finishOrderResult)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult(finishOrderResult);
}
}
@GetMapping("/selectPayType")
public String selectPayType(HttpServletRequest request, @RequestParam("orderNo") String orderNo, HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
Order order = orderService.getNewBeeMallOrderByOrderNo(orderNo);
//todo 判断订单userId
//todo 判断订单状态
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 httpSession, @RequestParam("payType") int payType) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
Order order = orderService.getNewBeeMallOrderByOrderNo(orderNo);
//todo 判断订单userId
//todo 判断订单状态
request.setAttribute("orderNo", orderNo);
request.setAttribute("totalPrice", order.getTotalPrice());
if (payType == 1) {
return "mall/alipay";
} else {
return "mall/wxpay";
}
}
@GetMapping("/paySuccess")
@ResponseBody
public Result paySuccess(@RequestParam("orderNo") String orderNo, @RequestParam("payType") int payType) {
String payResult = orderService.paySuccess(orderNo, payType);
if (ServiceResultEnum.SUCCESS.getResult().equals(payResult)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult(payResult);
}
}
@PostMapping("/addComment")
@ResponseBody
public Result updateInfo(@RequestBody Comment comment, HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
Date date = new Date();//获取当前的日期
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String str = df.format(date);
comment.setCreateTime(str);
comment.setState(0);
Goods goods = goodsService.getNewBeeMallGoodsById(comment.getGoodsId().longValue());
if(goods==null){
comment.setGoodsName("该商品已删除");
}else{
comment.setGoodsName(goods.getGoodsName());
}
comment.setNickName(user.getNickName());
if (commentService.insert(comment)==0) {
Result result = ResultGenerator.genFailResult("新增失败");
return result;
} else {
//返回成功
Result result = ResultGenerator.genSuccessResult();
return result;
}
}
}
package flowershop.mall.controller.mall;
import flowershop.mall.common.ServiceResultEnum;
import flowershop.mall.controller.vo.ShoppingCartItemVO;
import flowershop.mall.controller.vo.UserVO;
import flowershop.mall.entity.ShoppingCartItem;
import flowershop.mall.service.ShoppingCartService;
import flowershop.mall.common.Constants;
import flowershop.mall.util.Result;
import flowershop.mall.util.ResultGenerator;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
@Controller
public class ShoppingCartController {
@Resource
private ShoppingCartService shoppingCartService;
@GetMapping("/shop-cart")
public String cartListPage(HttpServletRequest request,
HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
int itemsTotal = 0;
int priceTotal = 0;
List<ShoppingCartItemVO> myShoppingCartItems = shoppingCartService.getMyShoppingCartItems(user.getUserId());
if (!CollectionUtils.isEmpty(myShoppingCartItems)) {
//购物项总数
itemsTotal = myShoppingCartItems.stream().mapToInt(ShoppingCartItemVO::getGoodsCount).sum();
if (itemsTotal < 1) {
return "error/error_5xx";
}
//总价
for (ShoppingCartItemVO shoppingCartItemVO : myShoppingCartItems) {
priceTotal += shoppingCartItemVO.getGoodsCount() * shoppingCartItemVO.getSellingPrice();
}
if (priceTotal < 1) {
return "error/error_5xx";
}
}
request.setAttribute("itemsTotal", itemsTotal);
request.setAttribute("priceTotal", priceTotal);
request.setAttribute("myShoppingCartItems", myShoppingCartItems);
return "mall/cart";
}
@PostMapping("/shop-cart")
@ResponseBody
public Result saveNewBeeMallShoppingCartItem(@RequestBody ShoppingCartItem shoppingCartItem,
HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
shoppingCartItem.setUserId(user.getUserId());
//todo 判断数量
String saveResult = shoppingCartService.saveNewBeeMallCartItem(shoppingCartItem);
//添加成功
if (ServiceResultEnum.SUCCESS.getResult().equals(saveResult)) {
return ResultGenerator.genSuccessResult();
}
//添加失败
return ResultGenerator.genFailResult(saveResult);
}
@PutMapping("/shop-cart")
@ResponseBody
public Result updateNewBeeMallShoppingCartItem(@RequestBody ShoppingCartItem shoppingCartItem,
HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
shoppingCartItem.setUserId(user.getUserId());
//todo 判断数量
String updateResult = shoppingCartService.updateNewBeeMallCartItem(shoppingCartItem);
//修改成功
if (ServiceResultEnum.SUCCESS.getResult().equals(updateResult)) {
return ResultGenerator.genSuccessResult();
}
//修改失败
return ResultGenerator.genFailResult(updateResult);
}
@DeleteMapping("/shop-cart/{newBeeMallShoppingCartItemId}")
@ResponseBody
public Result updateNewBeeMallShoppingCartItem(@PathVariable("newBeeMallShoppingCartItemId") Long newBeeMallShoppingCartItemId,
HttpSession httpSession) {
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
Boolean deleteResult = shoppingCartService.deleteById(newBeeMallShoppingCartItemId);
//删除成功
if (deleteResult) {
return ResultGenerator.genSuccessResult();
}
//删除失败
return ResultGenerator.genFailResult(ServiceResultEnum.OPERATE_ERROR.getResult());
}
@GetMapping("/shop-cart/settle")
public String settlePage(HttpServletRequest request,
HttpSession httpSession) {
int priceTotal = 0;
UserVO user = (UserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
List<ShoppingCartItemVO> myShoppingCartItems = shoppingCartService.getMyShoppingCartItems(user.getUserId());
if (CollectionUtils.isEmpty(myShoppingCartItems)) {
//无数据则不跳转至结算页
return "/shop-cart";
} else {
//总价
for (ShoppingCartItemVO shoppingCartItemVO : myShoppingCartItems) {
priceTotal += shoppingCartItemVO.getGoodsCount() * shoppingCartItemVO.getSellingPrice();
}
if (priceTotal < 1) {
return "error/error_5xx";
}
}
request.setAttribute("priceTotal", priceTotal);
request.setAttribute("myShoppingCartItems", myShoppingCartItems);
return "mall/order-settle";
}
}