源码获取:俺的博客首页 "资源" 里下载!
项目介绍
基于SSM的校园外卖配送系统
角色:管理员、用户、配送员
用户登录系统后,可以对个人中心,订单信息管理,订单取消管理,配送接单管理,取消配送管理,送达通知管理等功能
管理员登录系统后,可以对个人中心,用户管理,配送员管理,美食分类管理,特色美食管理,订单信息管理,订单取消管理,配送接单管理,取消配送管理,送达通知管理,系统管理等功能
配送员登录系统后,可以对个人中心,订单信息管理,配送接单管理,取消配送管理,送达通知管理等功能
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
后端:SSM(Spring+SpringMVC+Mybatis)
前端:JSP+CSS+JS+JQUERY+Layui
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
3. 将项目中db.xml配置文件中的数据库配置改为自己的配置,然后运行;
用户管理控制层:
@Controller
public class TbUserController {
@Resource
TbUserServiceImpl tbUserService;
@GetMapping("/toLogin")
public String toLogin(){
return "user/login";
}
@PostMapping("/register")
public String register(String uUsername, String uPassword, String uRole,Model model){
List<TbUser> users = tbUserService.selectAllUser();
for (TbUser temp : users){ //验证成功,直接登录
if(uUsername.equals(temp.getUUsername())){
model.addAttribute("msg","刚刚:注册失败,该用户已存在!");
return "user/login";
}
}
TbUser user = new TbUser();
user.setUUsername(uUsername);
user.setUPassword(uPassword);
user.setURole(uRole);
tbUserService.insertUser(user);
model.addAttribute("msg","刚刚:注册成功,赶快登录进行登录吧~");
return "user/login";
}
/*插入用户数据,返回字符串信息*/
@ResponseBody
@RequestMapping("/insertUserInfo")
public String insertUserInfo(String uUsername, String uPassword, String uRole){
//查询是否存在用户名了
String msg = "未知错误!";
List<TbUser> users = tbUserService.selectUserByName(uUsername);
if(users.size() == 0){
TbUser user = new TbUser();
user.setUUsername(uUsername);
user.setUPassword(uPassword);
user.setURole(uRole); //字符串转化为int
int i = tbUserService.insertUser(user);
if(i != 0){
msg = "新添用户成功!";
}
}else {
msg = "该用户名已存在,插入失败!";
}
return msg;
}
/*编辑用户信息,返回字符串信息*/
@ResponseBody
@RequestMapping("/edUserInfo")
public String edUserInfo(TbUser user){
tbUserService.updateUserByUser(user);
return "用户数据已更新!";
}
/*跳转用户信息页面 + 分页*/
@RequestMapping("/userInfo") //从1开始
public String userInfo(Model model,@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum){
List<TbUser> users = tbUserService.selectAllUser();
Page<TbUser> page = new Page<>(pageNum,5);
tbUserService.selectPage(page);
model.addAttribute("users",users);
model.addAttribute("page",page);
return "user/userInfo";
}
/*删除用户*/
@RequestMapping("/deleteUser/{uId}")
public String deleteUser(@PathVariable("uId")int uId, Model model){
tbUserService.deleteUserById(uId);
model.addAttribute("msg","删除成功!");
return "redirect:/userInfo";
}
@GetMapping("/myInfo")
public String myInfo(Principal principal,Model model){
String str = principal.getName();
List<TbUser> list = tbUserService.selectAllUser();
for(TbUser tbUser:list) {
if(tbUser.getUUsername().equals(str)){
model.addAttribute("Member",tbUser.getMember());
}
}
return "user/myInfo";
}
/*上传头像*/
@RequestMapping("/updateMyImg")
public String updateMyImg(@RequestParam(value = "updateHeadImg") MultipartFile updateHeadImg,
int uId, Model model, HttpSession session){
String imgPath = FileUpload.uploadFile(updateHeadImg);
//更新操作
TbUser user = tbUserService.selectUserById(uId);
user.setUUrl(imgPath);
tbUserService.updateUserByUser(user);
user = tbUserService.selectUserById(uId);
UpdateSession.reloadUserAuthority(session,user);
return "redirect:/myInfo";
}
/*更新我的信息*/
@RequestMapping("/updateMyInfo")
public String updateMyInfo(TbUser user, HttpSession session){
//更新操作
TbUser tbUser = tbUserService.selectUserById(user.getUId()); //保存新数据,避免被原数据覆盖
System.out.println("tbUser = " + tbUser);
user.setUUsername(tbUser.getUUsername());
user.setUPassword(tbUser.getPassword());
user.setUMoney(tbUser.getUMoney());
tbUserService.updateUserByUser(user);
user = tbUserService.selectUserById(user.getUId());
UpdateSession.reloadUserAuthority(session,user);
return "redirect:/myInfo";
}
@RequestMapping("/shenqinghuiyuan")
public String shenqinghuiyuan(Integer uId, HttpSession session,Model model){
//更新操作
//保存新数据,避免被原数据覆盖
TbUser tbUser = tbUserService.selectUserById(uId);
if(tbUser.getUMoney()>200){
tbUserService.updateMeber(uId);
model.addAttribute("Member",2);
model.addAttribute("error","申请成功,请重新登录后方可生效");
}else{
model.addAttribute("error","未满足条件");
model.addAttribute("Member",1);
}
return "user/myInfo";
}
// @GetMapping("/outLogin")
// public String outLogin(HttpSession session){
// session.removeAttribute("user");
// return "user/login";
// }
// @PostMapping("/login") 添加了安全策略不在需要手动验证,只需要提供个请求路径
// public void login(String uUsername, String uPassword, Model model, HttpSession session){
// List<TbUser> users = tbUserService.selectAllUser();
// for (TbUser temp : users){ //验证成功,直接登录
// if(uUsername.equals(temp.getUUsername()) && uPassword.equals(temp.getUPassword())){
// session.setAttribute("user",temp);
// return "redirect:/";
// }
// if(uUsername.equals(temp.getUUsername()) && !uPassword.equals(temp.getUPassword())){
// model.addAttribute("msg","刚刚:密码错误,登录失败!");
// return "user/login";
// }
// }
// model.addAttribute("msg","刚刚:该用户不存在,请重新输入!");
// return "user/login";
// }
}
订单详情管理控制层:
@Controller
public class OrderDetailController {
@Resource
OrderDetailServiceImpl orderDetailService;
@Resource
ShoppingCartServiceImpl shoppingCartService;
@Resource
MenuDetailServiceImpl menuDetailService;
@Resource
TbUserServiceImpl tbUserService;
//修改订单状态,从0到1,由商家更新
@ResponseBody
@RequestMapping("/changeStatusToOne")
public String changeStatusToOne(int odId){
OrderDetail one = orderDetailService.selectOneByOdId(odId);
one.setOdStatus(1);
orderDetailService.updateOrder(one); //更新订单
return "已接单,尽快送餐吧~";
}
//修改订单状态,从1到2,由用户更新
@ResponseBody
@RequestMapping("/changeStatusToTwo")
public String changeStatusToTwo(int odId){
OrderDetail one = orderDetailService.selectOneByOdId(odId);
one.setOdStatus(2);
orderDetailService.updateOrder(one); //更新订单
//同时更新商家的账户
TbUser adminUser = tbUserService.selectUserById(1);
int updateMoney = one.getOdTotal()+adminUser.getUMoney();
adminUser.setUMoney(updateMoney);
tbUserService.updateUserByUser(adminUser);
return "您已确认送达,钱已入商家商户,订单已完结~";
}
@RequestMapping("/orderManage")
public String orderManage(Model model,@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum){
List<OrderDetail> orders = orderDetailService.selectAll();
Collections.reverse(orders); //倒叙
Page<TbUser> page = new Page<>(pageNum,10);
orderDetailService.selectPage(page); //分页
int allCount = orders.size(); //总数
int pendingCount = 0; //待处理单数
int receivedCount = 0; //待已接单数
int finishCount = 0; //已完结
for (OrderDetail order : orders){
if(order.getOdStatus() == 0){
pendingCount += 1;
}else if(order.getOdStatus() == 1){
receivedCount += 1;
}else{
finishCount += 1;
}
}
TbUser adminUser = tbUserService.selectUserById(1);
model.addAttribute("total",adminUser.getUMoney());
model.addAttribute("page",page);
model.addAttribute("orders",orders);
model.addAttribute("allCount",allCount);
model.addAttribute("pendingCount",pendingCount);
model.addAttribute("receivedCount",receivedCount);
model.addAttribute("finishCount",finishCount);
return "menu/orderManage";
}
@RequestMapping("/myOrder")
public String myOrder(Model model,int uId){
List<OrderDetail> myOrders = orderDetailService.selectAllOrderByUId(uId);
TbUser user = tbUserService.selectUserById(uId);
model.addAttribute("myOrders",myOrders);
model.addAttribute("total",user.getUMoney());
return "user/myOrder";
}
@ResponseBody
@PostMapping("/toOrder")
public String toOrder(OrderDetail orderDetail){
TbUser user = tbUserService.selectUserById(orderDetail.getUId());
//查询当前用户的所以购物车
List<ShoppingCart> carts = shoppingCartService.selectAllByUId(orderDetail.getUId());
//获取到具体商品
String odDetail = "【";
int odTotal = 0;
for (ShoppingCart cart : carts){
odDetail += cart.getScName()+" × "+cart.getScAmount()+";"; //拼接成:米饭 × 1;格式
odTotal += cart.getScPrice()*cart.getScAmount(); //数量×价格
}
odDetail += "】";
//赋值
orderDetail.setOdDetail(odDetail);
if(user.getMember()==2){
orderDetail.setOdTotal((int)(odTotal * 0.88));
}else{
orderDetail.setOdTotal(odTotal);
}
orderDetail.setOdStatus(0);
orderDetail.setOdNo(RandomNo.getRandomNo());
//完成插入
orderDetailService.insertOrder(orderDetail);
//清空购物车 + 更新商品数据
for (ShoppingCart cart : carts){
shoppingCartService.deleteById(cart.getScId()); //删除购物车数据
MenuDetail menuDetail = menuDetailService.selectById(cart.getMdId()); //通过产品id获得产品
menuDetail.setMdAmount(menuDetail.getMdAmount()-cart.getScAmount()); //减去下单数量
menuDetailService.updateMenu(menuDetail); //更新产品数据
}
TbUser User= tbUserService.selectUserById(orderDetail.getUId()); //用户更新支付金额
System.out.println(odTotal+"=============");
System.out.println(user.getMember()+"====="+odTotal);
if(user.getMember()==1 && odTotal>200) {//当会员为1时,说明不是会员,并且支付的金额大于200
user.setMember(2);
System.out.println("进入方法后"+user.getMember());
}
user.setUMoney(user.getUMoney()+odTotal);
System.out.println(user.getMember());
tbUserService.updateUserByUser(user);
List<OrderDetail> details = orderDetailService.selectAllOrderByUId(orderDetail.getUId());
for (OrderDetail detail : details){
System.out.println("detail = " + detail.getOdCreateTime());
}
return "下单成功~";
}
}
购物车管理控制层:
@Controller
public class ShoppingCartController {
@Resource
ShoppingCartServiceImpl shoppingCartService;
@Resource
TbUserServiceImpl tbUserService;
/*去我的购物车页面*/
@RequestMapping("/shoppingCart")
public String shoppingCart(Model model,int uId){
//查询购物车的商品
List<ShoppingCart> products = shoppingCartService.selectAllByUId(uId);
int total = 0;
for (ShoppingCart cart : products){
total += cart.getScPrice()*cart.getScAmount();
}
model.addAttribute("products",products);
model.addAttribute("total",total);
TbUser tbUser = tbUserService.selectUserById(uId);
if(tbUser.getMember()==2){
int youhuitotal =(int) (total* 0.88);
model.addAttribute("youhuitotal",youhuitotal);
}
model.addAttribute("Member",tbUser.getMember());
return "user/shoppingCart";
}
@RequestMapping("/shoppingCart-plus")
public String shoppingCartPlus(int uId,int mdId){
//把数量+1
ShoppingCart one = shoppingCartService.selectOneByMdIdAndUId(mdId, uId);
one.setScAmount(one.getScAmount()+1);
shoppingCartService.updateProduct(one);
System.out.println("数量+1成功");
return "redirect:/shoppingCart?uId="+uId;
}
@RequestMapping("/shoppingCart-minus")
public String shoppingCartMinus(int uId,int mdId){
/*如果 数量== 1,直接删除*/
ShoppingCart one = shoppingCartService.selectOneByMdIdAndUId(mdId, uId);
if (one.getScAmount() == 1 ) {
//删除数据
shoppingCartService.deleteById(one.getScId());
return "redirect:/shoppingCart?uId="+uId;
}else{
//数量-1
one.setScAmount(one.getScAmount()-1);
shoppingCartService.updateProduct(one);
System.out.println("数量-1成功");
return "redirect:/shoppingCart?uId="+uId;
}
}
@ResponseBody
@RequestMapping("/addShoppingCart")
public String addShoppingCart(ShoppingCart shoppingCart){
//插入一条数据
if (shoppingCartService.selectExist(shoppingCart.getMdId(), shoppingCart.getUId()) == 0 ) {
shoppingCartService.insertProduct(shoppingCart);
return "新加入成功!";
}else{
/*如果已经存在了,直接加一*/
ShoppingCart one = shoppingCartService.selectOneByMdIdAndUId(shoppingCart.getMdId(), shoppingCart.getUId());
one.setScAmount(one.getScAmount()+1);
shoppingCartService.updateProduct(one);
return "数量加+1成功!";
}
}
}
源码获取:俺的博客首页 "资源" 里下载!