博主介绍: ?至今服务客户已经1000+、专注于Java技术领域、项目定制、技术答疑、开发工具、毕业项目实战 ?
🍅 文末获取源码联系 🍅
👇🏻 精彩专栏 推荐订阅 👇🏻 不然下次找不到
Java项目精品实战专区https://blog.csdn.net/java18343246781/category_12537229.htmlJava各种开发工具资源包网站http://62.234.13.119:9000/html/visitor/softwareResourceList.html
软件安装+项目部署专区https://blog.csdn.net/java18343246781/category_12539864.htmlv
系列文章目录
? 在快节奏的现代生活中,网上点餐系统成为了满足用户便捷用餐需求的重要工具。本文将为您介绍一款多功能而智能的网上点餐系统,为用户提供了全方位的用餐体验。该系统的前端设计涵盖了各类便捷功能,使得用户可以轻松浏览菜单、分类点菜、加入购物车、下单,同时享受查看订单、管理钱包、地址、留言等一系列便捷服务。同时,后端管理功能丰富,包括对菜单、用户、留言、订单、餐桌等的全面管理,为商家提供了高效的运营工具。
? 用户可以通过系统直观而美观的界面,轻松浏览丰富的菜单,根据个人口味和需求分类点菜,并随时加入购物车,构建个性化的点餐体验。一键下单后,用户可以方便地查看自己的订单,进行支付,同时管理自己的钱包、地址等信息。系统还提供了投诉信息和留言功能,用户可以通过系统表达建议、意见和需求,促进用户与商家的有效沟通。
? 对于商家而言,后端管理系统为其提供了高效的工具,可以对菜单进行灵活管理,维护用户信息,处理留言和投诉,以及有效管理订单和餐桌。这使得商家能够更好地把握经营状况,提高服务水平。
? 希望这款网上点餐系统能够为用户和商家之间搭建起一座便捷而愉悦的沟通桥梁,为现代餐饮行业注入更多智能化、便捷化的元素。
系统采用了JDK 1.8作为基础开发环境,并搭建在Spring Boot框架之上,实现了快速、简便的Java应用程序开发。数据库方面选择了MySQL,作为可靠的关系型数据库管理系统,用于存储和管理商品、用户以及订单等相关数据。持久层框架方面使用了MyBatis和MyBatis Plus,简化了数据访问层的开发,提供了便捷的操作和功能。
? ? ? ? 在前端设计上,系统使用了Layui框架,为用户提供了直观而美观的界面,包括商城列表、购物车、订单列表等功能。同时,为了实现动态页面生成,系统引入了Thymeleaf技术,与Spring框架良好集成,使得前端页面与后端数据更加紧密地结合,提升了用户体验。
代码如下(示例):
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wl.dto.OrdersDto;
import com.wl.enums.OrdersStateEnum;
import com.wl.enums.OrdersTypeEnum;
import com.wl.enums.TableStateEnum;
import com.wl.mapper.OrdersEntryMapper;
import com.wl.po.*;
import com.wl.service.*;
import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* 表现层控制类
*/
@Controller
@RequestMapping("cart")
@Slf4j
public class ShoppingCartController {
@Autowired
private ShoppingCartService shoppingCartService;
@Autowired
private AddressService addressService;
@Autowired
private WalletService walletService;
@Autowired
private UserService userService;
@Autowired
private DeskService deskService;
@Autowired
private MenuService menuService;
@Autowired
private OrdersService ordersService;
@Autowired
private OrdersEntryService entryService;
//加入购物车
@ResponseBody
@RequestMapping(value = "/addToCart", method = RequestMethod.GET)
public String addToCart(String menuId, HttpSession session) {
User user = comment(session);
ShoppingCart cart = new ShoppingCart();
cart.setUserId(Integer.parseInt(user.getId()));
cart.setMenuId(Integer.parseInt(menuId));
Integer count = shoppingCartService.selectCountByCart(cart);
if (count == null || count == 0) {
cart.setCount(1);
shoppingCartService.addCart(cart);
} else {
cart.setCount(count + 1);
shoppingCartService.updateCartCount(cart);
}
return "商品成功加入购物车";
}
//加入购物车
@RequestMapping("addCart/{menuId}")
public String addCart(@PathVariable("menuId") String menuId, HttpSession session) {
User user = comment(session);
ShoppingCart cart = new ShoppingCart();
cart.setUserId(Integer.parseInt(user.getId()));
cart.setMenuId(Integer.parseInt(menuId));
Integer count = shoppingCartService.selectCountByCart(cart);
if (count == null || count == 0) {
cart.setCount(1);
shoppingCartService.addCart(cart);
} else {
cart.setCount(count + 1);
shoppingCartService.updateCartCount(cart);
}
return "redirect:/user/cart";
}
//批量删除购物车商品
@RequestMapping("delAllCart")
@ResponseBody
public String delAllCart(String menuIds, HttpSession session) {
String[] strings = null;
String string = null;
if (menuIds.contains("&")) {
strings = menuIds.split("&");
} else {
string = menuIds;
}
User user = comment(session);
if (string == null) {
for (int i = 0; i < strings.length; i++) {
ShoppingCart cart = new ShoppingCart();
cart.setUserId(Integer.parseInt(user.getId()));
cart.setMenuId(Integer.parseInt(strings[i]));
shoppingCartService.delCart(cart);
}
} else {
ShoppingCart cart = new ShoppingCart();
cart.setUserId(Integer.parseInt(user.getId()));
cart.setMenuId(Integer.parseInt(string));
shoppingCartService.delCart(cart);
}
return "删除成功";
}
//购物车商品减一
@RequestMapping("redCart/{menuId}")
public String redCart(@PathVariable("menuId") String menuId, HttpSession session) {
User user = comment(session);
ShoppingCart cart = new ShoppingCart();
cart.setUserId(Integer.parseInt(user.getId()));
cart.setMenuId(Integer.parseInt(menuId));
Integer count = shoppingCartService.selectCountByCart(cart);
if (count > 1) {
cart.setCount(count - 1);
shoppingCartService.updateCartCount(cart);
} else {
shoppingCartService.delCart(cart);
}
return "redirect:/user/cart";
}
//单个商品下单详情页面
@RequestMapping("choiceOrders")
@ResponseBody
public String choiceOrders(String menuIds, HttpSession session, Model model) {
User user = comment(session);
String[] strings = menuIds.split("&");
//判断用户是否填写地址信息
Address address = addressService.selectByUserId(user.getId());
if (address.getAddress() == null || address.getName() == null || address.getPhoneNumber() == null) {
return "地址信息未填写";
}
BigDecimal menuAllPrice = BigDecimal.ZERO;
BigDecimal menuPrice;
List<OrdersEntry> entryList = new ArrayList<>();
for (int i = 0; i < strings.length; i++) {
//购物车信息
ShoppingCart cart = new ShoppingCart();
cart.setUserId(Integer.parseInt(user.getId()));
cart.setMenuId(Integer.parseInt(strings[i]));
cart = shoppingCartService.selectCart(cart);
//订单条目类
Menu menu = menuService.selectByMenuId(Integer.parseInt(strings[i]));
OrdersEntry entry = new OrdersEntry();
entry.setCount(cart.getCount());
entry.setDishName(menu.getDishName());
entry.setPrice(menu.getPrice());
menuPrice = menu.getPrice().multiply(new BigDecimal(cart.getCount()));
entryList.add(entry);
//累加计算订单总金额
menuAllPrice = menuAllPrice.add(menuPrice);
}
//订单DTO
OrdersDto ordersDto = new OrdersDto();
ordersDto.setOrdersEntryList(entryList);
ordersDto.setUserId(Integer.parseInt(user.getId()));
ordersDto.setUserName(address.getName());
ordersDto.setTotalPrice(menuAllPrice);
ordersDto.setPhoneNumber(address.getPhoneNumber());
ordersDto.setOrdersAddress(address.getAddress());
ordersDto.setRemark(address.getRemark());
ordersDto.setOrdersState(OrdersStateEnum.ORDERS_STATE_UNPROCESSED.getText());
ordersDto.setOrdersType(OrdersTypeEnum.ORDERS_TYPE_ENTER.getText());
model.addAttribute("ordersDto", ordersDto);
session.setAttribute("choicePageSession", ordersDto);
session.setAttribute("menuIdsSession", menuIds);
return "true";
}
//单个下单,批量下单
@ResponseBody
@Transactional
@RequestMapping("toOrdersOne")
public String toOrdersOne(OrdersDto choiceDto, HttpSession session) {
//判断的地址信息是否填写
User user = comment(session);
Address address = addressService.selectByUserId(user.getId());
if (address.getAddress() == null || address.getName() == null || address.getPhoneNumber() == null) {
return "地址信息未填写";
}
//下单前获取支付密码并判断输入密码是否正确
Account account = (Account) session.getAttribute("account");
Wallet wallet = walletService.selectWalletByAccountId(account.getId());
OrdersDto dtoSession = (OrdersDto) session.getAttribute("choicePageSession");
//余额判断
if (dtoSession.getTotalPrice().compareTo(wallet.getMoney()) > 0) {
return "余额不足";
}
if (!wallet.getPayPassword().equals(choiceDto.getPayPwd())) {
return "密码错误";
}
//订单编号生成
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String ordersNumber = format.format(date).concat(dtoSession.getUserId().toString());
String menuIdsSession = (String) session.getAttribute("menuIdsSession");
String[] strings = null;
String string = null;
if (menuIdsSession.contains("&")) {
strings = menuIdsSession.split("&");
} else {
string = menuIdsSession;
}
//批量下单
if (null == string) {
for (String s : strings) {
//购物车
ShoppingCart cart = new ShoppingCart();
cart.setUserId(dtoSession.getUserId());
cart.setMenuId(Integer.parseInt(s));
cart = shoppingCartService.selectCart(cart);
//订单条目类
Menu menu = menuService.selectByMenuId(Integer.parseInt(s));
OrdersEntry entry = new OrdersEntry();
entry.setCount(cart.getCount());
entry.setDishName(menu.getDishName());
entry.setOrdersNumber(ordersNumber);
entry.setPrice(menu.getPrice());
entryService.addEntry(entry);
//订单生成后删除购物车中数据
ShoppingCart cart1 = new ShoppingCart();
cart1.setUserId(dtoSession.getUserId());
cart1.setMenuId(Integer.parseInt(s));
shoppingCartService.delCart(cart1);
//商品销量加count
menu.setSale(menu.getSale() + cart.getCount());
boolean b = menuService.updateDish(menu);
}
}
//单个下单
else {
//购物车
ShoppingCart cart = new ShoppingCart();
cart.setUserId(dtoSession.getUserId());
cart.setMenuId(Integer.parseInt(string));
cart = shoppingCartService.selectCart(cart);
//订单条目类
Menu menu = menuService.selectByMenuId(Integer.parseInt(string));
OrdersEntry entry = new OrdersEntry();
entry.setCount(cart.getCount());
entry.setDishName(menu.getDishName());
entry.setOrdersNumber(ordersNumber);
entry.setPrice(menu.getPrice());
entryService.addEntry(entry);
//订单生成后删除购物车中数据
ShoppingCart cart1 = new ShoppingCart();
cart1.setUserId(dtoSession.getUserId());
cart1.setMenuId(Integer.parseInt(string));
shoppingCartService.delCart(cart1);
//商品销量加count
menu.setSale(menu.getSale() + cart.getCount());
boolean b = menuService.updateDish(menu);
}
//订单
Orders orders = new Orders();
orders.setOrdersType(dtoSession.getOrdersType());
//进店用餐 餐桌信息绑定
if (dtoSession.getOrdersType().equals(OrdersTypeEnum.ORDERS_TYPE_ENTER.getText())) {
orders.setOrdersTable(choiceDto.getOrdersTable());
orders.setOrdersAddress(null);
String reserveDate = choiceDto.getReserveDate();
String ordersStartTime = choiceDto.getOrdersStartTime();
String ordersEndTime = choiceDto.getOrdersEndTime();
orders.setReserveDate(choiceDto.getReserveDate());
orders.setOrdersStartTime(choiceDto.getOrdersStartTime());
orders.setOrdersEndTime(choiceDto.getOrdersEndTime());
deskService.updDesk(ordersNumber,choiceDto.getOrdersTable(), dtoSession.getUserId(), TableStateEnum.STATE_TRUE.getValue(), reserveDate,ordersStartTime,ordersEndTime);
} else {
//外卖配送 地址信息
orders.setOrdersAddress(choiceDto.getOrdersAddress());
orders.setOrdersTable(null);
}
orders.setPhoneNumber(choiceDto.getPhoneNumber());
orders.setRemark(choiceDto.getRemark());
orders.setUserId(dtoSession.getUserId());
orders.setOrdersState(dtoSession.getOrdersState());
orders.setOrdersType(dtoSession.getOrdersType());
orders.setOrdersNumber(ordersNumber);
orders.setUserName(dtoSession.getUserName());
orders.setTotalPrice(dtoSession.getTotalPrice());
ordersService.addOrders(orders);
//钱包减
BigDecimal subtract = wallet.getMoney().subtract(dtoSession.getTotalPrice());
wallet.setMoney(subtract);
walletService.updateWallet(wallet);
return "下单成功";
}
//更新订单信息
@ResponseBody
@Transactional
@RequestMapping("toUpdateOrders")
public String toUpdateOrders(OrdersDto choiceDto, HttpSession session) {
//下单前获取支付密码并判断输入密码是否正确
Account account = (Account) session.getAttribute("account");
//获取订单类型
OrdersDto ordersDtoGetType = (OrdersDto)session.getAttribute("choicePageSession");
//获取修改的订单编号
String ordersNumberUpd = (String) session.getAttribute("ordersNumberUpd");
Wallet wallet = walletService.selectWalletByAccountId(account.getId());
if (!wallet.getPayPassword().equals(choiceDto.getPayPwd())) {
return "密码错误";
}
//根据订单编号,更新订单信息
Orders orders = new Orders();
orders.setOrdersNumber(ordersNumberUpd);
orders.setOrdersType(ordersDtoGetType.getOrdersType());
//获取用户id
User user = userService.selectByAccountId(Integer.parseInt(account.getId()));
//进店用餐
if (orders.getOrdersType().equals(OrdersTypeEnum.ORDERS_TYPE_ENTER.getText())){
orders.setOrdersAddress(null);
orders.setOrdersTable(choiceDto.getOrdersTable());
String reserveDate = choiceDto.getReserveDate();
String ordersStartTime =choiceDto.getOrdersStartTime();
String ordersEndTime = choiceDto.getOrdersEndTime();
orders.setReserveDate(choiceDto.getReserveDate());
orders.setOrdersStartTime(choiceDto.getOrdersStartTime());
orders.setOrdersEndTime(choiceDto.getOrdersEndTime());
deskService.updDesk(ordersNumberUpd,choiceDto.getOrdersTable(), Integer.parseInt(user.getId()), TableStateEnum.STATE_TRUE.getValue(), reserveDate,ordersStartTime,ordersEndTime);
}
//外卖配送
else{
orders.setOrdersAddress(choiceDto.getOrdersAddress());
orders.setOrdersTable(null);
}
orders.setPhoneNumber(choiceDto.getPhoneNumber());
orders.setRemark(choiceDto.getRemark());
return ordersService.updateOrdersByNumber(orders);
}
//下单 订单类型
@RequestMapping("ordersType/{type}")
public String ordersType(@PathVariable("type") Integer type, HttpSession session,Model model) {
String ordersType = "进店用餐";
if (type == 1) {
ordersType = "外卖配送";
}
OrdersDto choicePageSession = (OrdersDto) session.getAttribute("choicePageSession");
choicePageSession.setOrdersType(ordersType);
session.removeAttribute("choicePageSession");
session.setAttribute("choicePageSession", choicePageSession);
model.addAttribute("ordersDto", choicePageSession);
return "user/choicePage";
}
//订单修改 订单类型
@RequestMapping("ordersUpdType/{type}")
public String ordersUpdType(@PathVariable("type") Integer type, HttpSession session,Model model) {
String ordersType = "进店用餐";
if (type == 1) {
ordersType = "外卖配送";
}
OrdersDto choicePageSession = (OrdersDto) session.getAttribute("choicePageSession");
choicePageSession.setOrdersType(ordersType);
session.removeAttribute("choicePageSession");
session.setAttribute("choicePageSession", choicePageSession);
model.addAttribute("ordersDto", choicePageSession);
return "user/editOrdersPage";
}
@RequestMapping("zhuan")
public String zhuan(HttpSession session, Model model) {
OrdersDto choicePageSession = (OrdersDto) session.getAttribute("choicePageSession");
model.addAttribute("ordersDto", choicePageSession);
return "user/choicePage";
}
//公共方法
private User comment(HttpSession session) {
Account account = (Account) session.getAttribute("account");
return userService.selectByAccountId(Integer.parseInt(account.getId()));
}
}
系统首页:可以通过餐品类别进行筛选。同时可以看到留言板,也可以进行留言。
基本信息:可更改自己的基本信息。
购物车信息:可以查看购物车的菜品,可以进行删除、下单。
菜品下单:可以备注预约餐桌与时间。支持进店用餐和外卖配送。
订单信息:查看订单详情,支持添加商品、修改信息、取消订单。
地址管理:如需外卖配送需要填写配送地址。
我的钱包:可以进行重置与更改密码。
投诉信息:可以对商家进行投诉。
后台管理员登录页面。
用户管理:可以重置用户密码。
钱包管理:查看用户钱包剩余金额。
菜品管理:可以新增、删除、修改。
餐桌管理:支持用户进店就餐。
订单管理:分为四种订单未处理、处理中、已完成、已取消订单。
留言管理:可以选择优质留言在首页进行展示。
投诉管理:商家可看到投诉信息并进行处理。