微信小程序点餐系统的开发与实现

打印 上一主题 下一主题

主题 528|帖子 528|积分 1584

作者主页:编程千纸鹤
  作者简介:Java、前端、Pythone开发多年,做过高程,项目经理,架构师
  主要内容:Java项目开发、毕业设计开发、面试技术整理、最新技术分享
  

一,项目简介

       随着互联网技术逐渐的深入到生活,人们的生活消费习惯,已经发生很大的变化。就餐厅用餐而言,互联网技术和移动互联网技术的应用也己相关普及,比如早几年前就出现的餐厅点餐系统,就通过信息化的技术手段代替原来纸质菜单点餐的传统方式。这种方式一是可以方便顾客实现点餐叫号,二是方便商家进行人单合一的统一管理,减少了报单出错率,提升了用户的体验,所以得以大面积的应用和普及。
       而移动互联网的出现,让智能手机的赋能更大广泛,腾讯微信适时推出微信小程序,使得智能手机的用户可以通过微信进行相应的信息化管理和参与,比如目前大面积应用的小程序商城,就将商业的业态从传统的PC互联网直接植入手机移动互联网,这种轻量级的APP应用,极大的方便使用者,也给商家通过微信带了大量的流量。
     微信小程序的功能推出,极大方便了全国2亿多的微信用户,在这个生态体系上构建了一个宠大的商业帝国,而小程序开发的应用,又快速的渗透到各个行业。在餐饮行业的信息化应用,也发生了一系统变化,比如通过微信小程序实现用户自助点餐功能,这就极大的方便了用户,减少了点餐的距离限制,用户可以在餐厅打开手机微信小程序进行点餐,也可以在去餐厅的途中或者甚至在家就可以点餐,打破了时空的限制,更加的灵活方便。经过调查和实地分析,基于对微信小程序的研究,开发了这套微信小程序点餐系统,为餐饮业的信息化建设添砖加瓦。
根据上述对微信小程序点餐系统的功能性需求分析,设计出了微信小程序点餐系统的功能结构图,如下图1-1所示。
 


图1-1 系统功能结构图

     前台用户登陆小程序,采用微信账户绑定登陆实现。目前由于测试账户没开通此权限,只能用开发者的身份来进行测试进行。前台用户可以在手机小程序上浏览系统发布的餐品,实现完整的订餐流程。看中相应的餐品可以添加到购物车中,然后下单购买,并可以查看相关的订单信息。
    后台用户必须登陆方可进行相应的操作,主要进行相应的业务数据管理。
    用户管理:可以管理前端和后端的用户信息,进行相应的数据增删改查操作。
    餐品管理:可以管理点餐系统发布的餐品信息,进行相应的数据增删改查操作。
    订单管理:对前端用户的下单信息进行相应的管理操作。
    分类管理:主要实现对前端点餐显示的餐品分类管理。
    系统管理:主要可以实现对系统的相关基本信息的管理操作。
二,环境介绍

后台开发:
语言环境:Java:  jdk1.8
数据库:Mysql: mysql5.7
应用服务器:Tomcat:  tomcat8.5.31
开发工具:IDEA或eclipse
前端开发:
开发工具:微信开发者工具
开发技术:微信小程序

整体采用前后端分离开发,前后端单独测试
三,系统展示

3.1微信小程序功能模块的展示


3.1.1前台首页展示


   微信小程序点餐前端主要就是实现点餐操作,主要包含预约点餐、菜单浏览、电话订餐、客服个模块。具体操作界面展示如下图4-1所示。

图3-1 前台首页界面

 
3.1.2 前台菜单浏览模块

用户进入微信点餐系统进入浏览菜单即可查看餐厅发布的餐品信息,具体如下图3-2所示:

图3-2 菜单浏览界面


3.1.3前台用户购物车模块


    微信小程序点餐前台用户登陆系统后可以进入预约点餐模块将餐品添加到购物车。用户登陆直接绑定用户微信账户进行登陆,非常方便。添加购物车操作界面如下图3-3所示。

图3-3前台用户添加购物车操作界面

3.1.4前台用户点餐支付模块

    前台用户登陆点餐系统后,可以进入预约点餐模块将喜欢的餐品添加到购物车后提交订单并进行支付购买。完成餐品购买后并完成整个订单操作后,可以对餐品进行相关的评论。相关管理操作界面如下图3-4所示。

图3-4前台用户点餐支付界面


3.1.4前台用户个人订单管理模块

    微信小程序点餐前台用户登陆系统后可以在我的模块中个人订单管理模块中管理个人的订单信息。前端用户个人订单管理操作界面如下图3-5所示。

图3-5前台用户个人订单管理操作界面

3.2后台功能模块的展示


3.2.1用户登录功能


    微信小程序点餐后台用户如果想要对餐厅的相关信息进行管理操作,首先要登录系统,才可展开相关的操作。输入手机号和密码后用户登陆界面如下图3-6所示。

图3-6用户登录操作界面


3.2.2用户管理功能


    微信小程序点餐系统管理员用户登陆系统后,可以进入用户管理菜单进行相应的管理员用户信息管理。用户管理操作界面如下图3-7、3-8所示:

图3-7后台用户管理功能界面图


图3-8后台用户新增界面图

3.2.3 后台餐品管理操作UI


    微信小程序点餐管理员用户登陆系统后,可以进入餐品管理菜单进行相应的餐品信息管理。其中主要包含餐品的添加、修改、查询、下架操作等,添加餐品时可以指定餐品的图片进行展示。餐品信息管理操作界面如下图3-9、3-10所示。


图3-9后台餐品管理功能UI界面


图3-10后台餐品新增功能UI界面


3.2.4 后台餐品订单管理操作UI


    微信小程序点餐系统管理员用户登陆系统后,可以进入餐品订单管理菜单进行相应的餐品订单信息管理。其中主要包含餐品订单的查询、订单明细的查看等,添加餐品时可以上传餐品的图片进行展示。订单信息管理操作界面如下图3-11、3-12所示。


图3-11后台订单管理功能UI界面



图3-12后台订单详情查看功能UI界面


四,核心代码展示

  1. package com.imooc.controller;
  2. import com.imooc.constant.CookieConstant;
  3. import com.imooc.constant.RedisConstant;
  4. import com.imooc.dataobject.SellerInfo;
  5. import com.imooc.enums.ResultEnum;
  6. import com.imooc.exception.SellException;
  7. import com.imooc.form.SellerForm;
  8. import com.imooc.repository.SellerInfoRepository;
  9. import com.imooc.utils.CookieUtil;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.validation.BindingResult;
  13. import org.springframework.web.bind.annotation.GetMapping;
  14. import org.springframework.web.bind.annotation.PostMapping;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import org.springframework.web.servlet.ModelAndView;
  19. import java.util.List;
  20. import java.util.Map;
  21. import java.util.UUID;
  22. import javax.servlet.http.Cookie;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.validation.Valid;
  26. import lombok.extern.slf4j.Slf4j;
  27. @RestController
  28. @RequestMapping("/admin")
  29. @Slf4j
  30. public class AdminUserController {
  31.     @Autowired
  32.     SellerInfoRepository repository;
  33.     /**
  34.      * 后台用户登陆操作
  35.      * @param phone
  36.      * @param password
  37.      * @param response
  38.      * @return
  39.      */
  40.     @GetMapping("/loginAdmin")
  41.     public String loginAdmin(@RequestParam("phone") String phone,
  42.                              @RequestParam("password") String password,
  43.                              HttpServletResponse response) {
  44.         SellerInfo sellerInfo = repository.findByPhone(phone);
  45.         log.info("商家信息={}", sellerInfo);
  46.         if (sellerInfo != null && sellerInfo.getPassword().equals(password)) {
  47.             String token = UUID.randomUUID().toString();
  48.             log.info("登录成功的token={}", token);
  49.             Integer expire = RedisConstant.EXPIRE;
  50.             //3. 设置token至cookie
  51.             CookieUtil.set(response, CookieConstant.TOKEN, token, expire);
  52.             return "登录成功";
  53.         } else {
  54.             throw new SellException(ResultEnum.LOGIN_FAIL);
  55.         }
  56.     }
  57.     @GetMapping("/logout")
  58.     public ModelAndView logout(HttpServletRequest request,
  59.                                HttpServletResponse response,
  60.                                Map<String, Object> map) {
  61.         //1. 从cookie里查询
  62.         Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN);
  63.         if (cookie != null) {
  64.             //2. 清除cookie
  65.             CookieUtil.set(response, CookieConstant.TOKEN, null, 0);
  66.         }
  67.         map.put("msg", ResultEnum.LOGOUT_SUCCESS.getMessage());
  68.         map.put("url", "/sell/seller/order/list");
  69.         return new ModelAndView("common/success", map);
  70.     }
  71.     /*
  72.      * 页面相关
  73.      * */
  74.     @GetMapping("/list")
  75.     public ModelAndView list(Map<String, Object> map) {
  76.         List<SellerInfo> categoryList = repository.findAll();
  77.         map.put("categoryList", categoryList);
  78.         return new ModelAndView("admin/list", map);
  79.     }
  80.     @GetMapping("/index")
  81.     public ModelAndView index(@RequestParam(value = "sellerId", required = false) Integer sellerId,
  82.                               Map<String, Object> map) {
  83.         SellerInfo sellerInfo = repository.findBySellerId(sellerId);
  84.         map.put("category", sellerInfo);
  85.         return new ModelAndView("admin/index", map);
  86.     }
  87.     /**
  88.      * 保存/更新
  89.      */
  90.     @PostMapping("/save")
  91.     public ModelAndView save(@Valid SellerForm form,
  92.                              BindingResult bindingResult,
  93.                              Map<String, Object> map) {
  94.         log.info("SellerForm={}", form);
  95.         if (bindingResult.hasErrors()) {
  96.             map.put("msg", bindingResult.getFieldError().getDefaultMessage());
  97.             map.put("url", "/sell/admin/index");
  98.             return new ModelAndView("common/error", map);
  99.         }
  100.         SellerInfo sellerInfo = new SellerInfo();
  101.         try {
  102.             if (form.getSellerId() != null) {
  103.                 sellerInfo = repository.findBySellerId(form.getSellerId());
  104.             }
  105.             BeanUtils.copyProperties(form, sellerInfo);
  106.             repository.save(sellerInfo);
  107.         } catch (SellException e) {
  108.             map.put("msg", e.getMessage());
  109.             map.put("url", "/sell/admin/index");
  110.             return new ModelAndView("common/error", map);
  111.         }
  112.         map.put("url", "/sell/admin/list");
  113.         return new ModelAndView("common/success", map);
  114.     }
  115. }
复制代码
  1. package com.imooc.controller;
  2. import com.imooc.VO.ResultVO;
  3. import com.imooc.converter.OrderForm2OrderDTOConverter;
  4. import com.imooc.dto.OrderDTO;
  5. import com.imooc.enums.ResultEnum;
  6. import com.imooc.exception.SellException;
  7. import com.imooc.form.OrderForm;
  8. import com.imooc.service.BuyerService;
  9. import com.imooc.service.OrderService;
  10. import com.imooc.utils.ResultVOUtil;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.util.CollectionUtils;
  13. import org.springframework.util.StringUtils;
  14. import org.springframework.validation.BindingResult;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. import javax.validation.Valid;
  24. import lombok.extern.slf4j.Slf4j;
  25. /**
  26. * Created by znz
  27. */
  28. @RestController
  29. @RequestMapping("/buyer/order")
  30. @Slf4j
  31. public class BuyerOrderController {
  32.     @Autowired
  33.     private OrderService orderService;
  34.     @Autowired
  35.     private BuyerService buyerService;
  36.     //创建订单
  37.     @PostMapping("/create")
  38.     public ResultVO<Map<String, String>> create(@Valid OrderForm orderForm,
  39.                                                 BindingResult bindingResult) {
  40.         if (bindingResult.hasErrors()) {
  41.             log.error("【创建订单】参数不正确, orderForm={}", orderForm);
  42.             throw new SellException(ResultEnum.PARAM_ERROR.getCode(),
  43.                     bindingResult.getFieldError().getDefaultMessage());
  44.         }
  45.         OrderDTO orderDTO = OrderForm2OrderDTOConverter.convert(orderForm);
  46.         if (CollectionUtils.isEmpty(orderDTO.getOrderDetailList())) {
  47.             log.error("【创建订单】购物车不能为空");
  48.             throw new SellException(ResultEnum.CART_EMPTY);
  49.         }
  50.         OrderDTO createResult = orderService.create(orderDTO);
  51.         Map<String, String> map = new HashMap<>();
  52.         map.put("orderId", createResult.getOrderId());
  53.         return ResultVOUtil.success(map);
  54.     }
  55.     //订单列表
  56.     @GetMapping("/listByStatus")
  57.     public ResultVO<List<OrderDTO>> listByStatus(@RequestParam("openid") String openid,
  58.                                                  @RequestParam(value = "orderStatus", defaultValue = "0") Integer orderStatus) {
  59.         if (StringUtils.isEmpty(openid)) {
  60.             log.error("【查询订单列表】openid为空");
  61.             throw new SellException(ResultEnum.PARAM_ERROR);
  62.         }
  63.         List<OrderDTO> orderList = buyerService.findOrderList(openid, orderStatus);
  64.         return ResultVOUtil.success(orderList);
  65.     }
  66.     //订单详情
  67.     @GetMapping("/detail")
  68.     public ResultVO<OrderDTO> detail(@RequestParam("openid") String openid,
  69.                                      @RequestParam("orderId") String orderId) {
  70.         OrderDTO orderDTO = buyerService.findOrderOne(openid, orderId);
  71.         return ResultVOUtil.success(orderDTO);
  72.     }
  73.     //确认收货
  74.     @PostMapping("/sure")
  75.     public ResultVO sure(@RequestParam("openid") String openid,
  76.                            @RequestParam("orderId") String orderId) {
  77.         buyerService.cancelOrder(openid, orderId);
  78.         return ResultVOUtil.success();
  79.     }
  80.     //取消订单
  81.     @PostMapping("/cancel")
  82.     public ResultVO cancel(@RequestParam("openid") String openid,
  83.                            @RequestParam("orderId") String orderId) {
  84.         buyerService.cancelOrder(openid, orderId);
  85.         return ResultVOUtil.success();
  86.     }
  87. }
复制代码


  1. package com.imooc.controller;
  2. import com.imooc.VO.ResultVO;
  3. import com.imooc.dataobject.Comment;
  4. import com.imooc.dataobject.OrderMaster;
  5. import com.imooc.dto.OrderDTO;
  6. import com.imooc.enums.OrderStatusEnum;
  7. import com.imooc.enums.ResultEnum;
  8. import com.imooc.exception.SellException;
  9. import com.imooc.repository.CommentRepository;
  10. import com.imooc.repository.OrderMasterRepository;
  11. import com.imooc.service.OrderService;
  12. import com.imooc.utils.ResultVOUtil;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.util.StringUtils;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.util.List;
  21. /**
  22. * desc:评论相关
  23. */
  24. @RestController
  25. public class CommentController {
  26.     @Autowired
  27.     private CommentRepository repository;
  28.     @Autowired
  29.     private OrderService orderService;
  30.     @Autowired
  31.     private OrderMasterRepository masterRepository;
  32.     //订单详情
  33.     @PostMapping("/comment")
  34.     public ResultVO<Comment> detail(@RequestParam("openid") String openid,
  35.                                     @RequestParam("orderId") String orderId,
  36.                                     @RequestParam("name") String name,
  37.                                     @RequestParam("avatarUrl") String avatarUrl,
  38.                                     @RequestParam("content") String content) {
  39.         if (StringUtils.isEmpty(openid) || StringUtils.isEmpty(orderId)) {
  40.             throw new SellException(ResultEnum.PARAM_ERROR);
  41.         }
  42.         //提交评论
  43.         Comment comment = new Comment();
  44.         comment.setName(name);
  45.         comment.setAvatarUrl(avatarUrl);
  46.         comment.setOpenid(openid);
  47.         comment.setContent(content);
  48.         Comment save = repository.save(comment);
  49.         //修改订单状态
  50.         OrderDTO orderDTO = orderService.findOne(orderId);
  51.         orderDTO.setOrderStatus(OrderStatusEnum.COMMENT.getCode());
  52.         OrderMaster orderMaster = new OrderMaster();
  53.         BeanUtils.copyProperties(orderDTO, orderMaster);
  54.         OrderMaster updateResult = masterRepository.save(orderMaster);
  55.         return ResultVOUtil.success(save);
  56.     }
  57.     //所有评论
  58.     @GetMapping("/commentList")
  59.     public ResultVO<List<Comment>> commentList() {
  60.         List<Comment> all = repository.findAll();
  61.         return ResultVOUtil.success(all);
  62.     }
  63.     //单个用户的所有评论
  64.     @GetMapping("/userCommentList")
  65.     public ResultVO<List<Comment>> userCommentList(@RequestParam("openid") String openid) {
  66.         List<Comment> all = repository.findAllByOpenid(openid);
  67.         return ResultVOUtil.success(all);
  68.     }
  69. }
复制代码
五,项目总结

    微信小程序点餐系统的使用者主要包含两种用户角色,其一是管理员角色,其二是前台用户角色,这两个角色的具体功能如下:
    管理员角色:管理员登录微信小程序点餐系统后台管理后可以进行相应的管理操作,主要包含:用户管理、餐品管理、订单管理、分类管理等操作;
     前台用户角色:前台用户登录微信小程序点餐系统后可以进行餐品浏览、添加购物车、在线点餐、个人订单管理等操作。
     系统整体功能完整,根据微信小程序点餐系统需求分析,进行了微信小程序点餐系统概要设计,并在此基础上进行详细设计。完成了整个项目的详细设计后,就开始了项目的编码阶段。

来源:https://blog.csdn.net/BS009/article/details/124996625
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

老婆出轨

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表