赞
踩
基于javaweb+mysql的springboot前后端分离网上手机商城平台系统设计和实现(java+vue+redis+springboot+mysql+ssm)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot前后端分离网上手机商城平台系统设计和实现(java+vue+redis+springboot+mysql+ssm)
主要模块设计如下: 前后端主要技术:Java springboot springMVC mybatis mysql vue jquery node.js redis
用户注册和登录功能:。
用户信息的管理以及角色的管理、不同用户角色具有不同的功能权限操作。
商品的操作、包括商品列表信息、商品的分离、商品的详情、品牌和规格等操作。
购物车的管理操作:
订单管理操作:
6)用户退货管理
7)手机商品类型的管理
8)手机商品信息的预览、查看、搜索
9)修改密码、退出登录等功能
*/ @RestController @CrossOrigin public class OrderController { final OrderService orderService; final ProductService productService; final LogisticsService logisticsService; final RedisTemplate<String,String> redisTemplate; public OrderController(RedisTemplate<String,String> redisTemplate,OrderService orderService,LogisticsService logisticsService,ProductService productService) { this.orderService = orderService; this.productService = productService; this.logisticsService = logisticsService; this.redisTemplate = redisTemplate; } @RequestMapping(value = "/order/findById") private CommonResult findOrderById(Integer orderId) { Order order= orderService.selectById(orderId); if(orderId!=null){ return CommonResult.success("订单信息查询成功",order); }else{ return CommonResult.error("订单信息查询失败"); } } @RequestMapping(value = "/order/findOrderInfo") private CommonResult findOrderInfo(String userAccount) { List<Map<String, Object>> orderMap = orderService.selectAllOrder(userAccount); if(orderMap!=null){ return CommonResult.success("订单信息查询成功",orderMap); }else{ return CommonResult.error("订单信息查询失败"); } } @RequestMapping(value = "/order/findAll") private CommonResult findAllOrder() { List<Order> orders = orderService.selectAll(); System.out.println(orders); if(orders!=null){ return CommonResult.success("订单信息查询成功",orders); }else{ return CommonResult.error("订单信息查询失败"); } } @RequestMapping(value = "/order/findCount") private CommonResult findCount() { Integer count = orderService.selectCount(); if(count!=null){ return CommonResult.success("订单数量查询成功",count); }else{ return CommonResult.error("订单数量查询失败");
String authorization = (String) subject.getSession().getId(); User user; if (username.contains("@")) { //包含@符号,代表用户通过邮箱帐号登录 user = userService.selectByKey(username); } else { //不包含@符号,代表用户通过手机号登录 user = userService.selectByPhone(username); } info.put("user", user); //存放用户信息 //更新最后登录时间 user.setLoginTime(new Date()); userService.updateById(user); //存放sessionId, 即 token info.put("sessionId", authorization); List<Role> roles = roleService.selectAll(); List<String> rs = new ArrayList<>(); // rs 存放的是role的名称 List<String> rsInfo = new ArrayList<>(); //rsInfo 存放role的描述 for (Role role : roles) { rs.add(role.getRoleName()); rsInfo.add(role.getRoleName()); } boolean[] booleans = subject.hasRoles(rs); for (int i = booleans.length - 1; i >= 0; i--) { if (!booleans[i]) { rs.remove(i); rsInfo.remove(i); } } info.put("role", rs); info.put("roleInfo", rsInfo); return CommonResult.success("登录成功", info); }catch (LockedAccountException e){ return CommonResult.error("您的帐号存在异常行为,已被封停(请联系工作人员)"); } catch (IncorrectCredentialsException e) { return CommonResult.error("密码错误,请重新输入"); } catch (AuthenticationException e) { return CommonResult.error("该用户不存在"); } } /** * 退出登录操作 * @param key 用户登录的帐号 * @param session 前端存储的session(token)
final UserRoleService userRoleService; public UserRoleController(UserRoleService userRoleService) { this.userRoleService = userRoleService; } /*根据id查询用户*/ @RequestMapping(value = "/userRole/findById") private CommonResult findById(Integer userId) { List<UserRole> userRoles = userRoleService.selectByUserId(userId); if(userRoles!=null){ return CommonResult.success("查询成功",userRoles); }else{ return CommonResult.error("查询失败"); } } @RequestMapping(value = "/userRole/findRoleById") private CommonResult findRoleById(Integer userId) { List<Map<String, Object>> maps = userRoleService.selectRoleByUserId(userId); if(maps!=null){ return CommonResult.success("查询成功",maps); }else{ return CommonResult.error("查询失败"); } } /*查询所有用户*/ @RequestMapping(value = "/userRole/findAll") private CommonResult findAll() { List<UserRole> userRoles = userRoleService.selectAll(); if(userRoles!=null){ return CommonResult.success("查询成功",userRoles); }else{ return CommonResult.error("查询失败"); } } /*查询所有用户*/ @RequestMapping(value = "/userRole/existsRole") private CommonResult existsRole(Integer roleId) { Boolean isExist = userRoleService.existsRole(roleId); if(isExist!=null){ return CommonResult.success("查询成功",isExist); }else{ return CommonResult.error("查询失败"); } }
return CommonResult.success("查询成功",isExist); }else{ return CommonResult.error("查询失败"); } } @RequestMapping(value = "/product/findAll") private CommonResult findAll() { List<Product> products = productService.selectAll(); if(products!=null){ return CommonResult.success("全部商品信息查询成功",products); }else{ return CommonResult.error("全部商品信息查询失败"); } } @RequestMapping(value = "/product/findAllSale") private CommonResult findAllSale() { List<Product> products = productService.selectAllSale(); if(products!=null){ return CommonResult.success("全部商品信息查询成功",products); }else{ return CommonResult.error("全部商品信息查询失败"); } } @RequestMapping(value = "/product/findAllLikeName") private CommonResult findAllLikeName(String keyWord) { List<Product> products = productService.selectAllLikeName(keyWord); if(products!=null){ return CommonResult.success("全部商品信息查询成功",products); }else{ return CommonResult.error("全部商品信息查询失败"); } } @RequestMapping(value = "/product/findAllLikeType") private CommonResult findAllLikeType(String keyWord) { List<Product> products = productService.selectAllLikeType(keyWord); if(products!=null){ return CommonResult.success("全部商品信息查询成功",products); }else{ return CommonResult.error("全部商品信息查询失败"); } } @RequestMapping(value = "/product/findAllLikeBrand") private CommonResult findAllLikeBrand(String keyWord) { List<Product> products = productService.selectAllLikeBrand(keyWord); if(products!=null){ return CommonResult.success("全部商品信息查询成功",products); }else{ return CommonResult.error("全部商品信息查询失败"); }
return CommonResult.error("退出失败,未找到用户帐号"); } //权限不够时,将转到此请求上来 @RequestMapping("/notRole") private CommonResult notRole(){ return new CommonResult(403,"暂无权限!"); } /*判断key是否存在 目前用于判断邮箱是否被注册过*/ @RequestMapping(value = "/allow/existUser") private CommonResult existUser(String accountNumber) { Boolean isExist = userService.existsWithPrimaryKey(accountNumber); if(isExist!=null){ return CommonResult.success("查询成功",isExist); }else{ return CommonResult.error("查询失败"); } } /*判断手机号phone是否存在 目前被用于绑定手机号时,确认手机号已被绑定*/ @RequestMapping(value = "/allow/existPhone") private CommonResult existPhone(String telephone) { Boolean isExist = userService.existsWithPrimaryPhone(telephone); if(isExist!=null){ return CommonResult.success("手机号查询成功",isExist); }else{ return CommonResult.error("手机号查询失败"); } } public static void main(String[] args) { System.out.println("23"); SimpleHash md5 = new SimpleHash("MD5", "admin", ByteSource.Util.bytes("1325554003@qq.com"), 2); System.out.println(md5.toHex()); } /*重置密码、找回密码*/ @RequestMapping(value = "/allow/resetpwd") private CommonResult resetPwd(String accountNumber,String password) { if(accountNumber!=null && password!=null){ // SimpleHash md5 = new SimpleHash("MD5", password, ByteSource.Util.bytes(accountNumber), 2); // password=md5.toHex(); Integer id = userService.selectIdByKey(accountNumber); User user = new User(); user.setUserId(id); user.setPassword(password); if(userService.updateById(user)){ return CommonResult.success("重置密码成功",user); }else{ return CommonResult.error("重置密码失败"); } } return CommonResult.error("用户数据不存在");
return CommonResult.error("购物车删除失败"); } } @RequestMapping(value = "/shoppingCart/findAll") private CommonResult findAllShoppingCart(String accountNumber) { List<Map<String, Object>> shoppingInfo = shoppingCartService.selectAll(accountNumber); if(shoppingInfo!=null){ return CommonResult.success("购物车查询成功",shoppingInfo); }else{ return CommonResult.error("购物车查询失败"); } } @RequestMapping(value = "/shoppingCart/findById") private CommonResult findById(Integer cartId) { ShoppingCart shoppingCart = shoppingCartService.selectById(cartId); if(shoppingCart!=null){ return CommonResult.success("购物车查询成功",shoppingCart); }else{ return CommonResult.error("购物车查询失败"); } } } /** * @email qiudb.top@aliyun.com * @description 用户授权类
public ReturnProductController(ProductService productService,OrderService orderService,ReturnReasonService returnReasonService,ReturnGoodsService returnGoodsService,LogisticsService logisticsService){ this.returnReasonService = returnReasonService; this.returnGoodsService = returnGoodsService; this.logisticsService = logisticsService; this.orderService = orderService; this.productService = productService; } /*退货原因*/ @RequestMapping(value = "/returnReason/findReasonById") private CommonResult findReasonById(Integer reasonId) { ReturnReason returnReason = returnReasonService.selectById(reasonId); if(returnReason!=null){ return CommonResult.success("退货原因查询成功",returnReason); }else{ return CommonResult.error("退货原因查询失败"); } } /*查询全部退货原因*/ @RequestMapping(value = "/returnReason/findAllReason") private CommonResult findAllReason() { List<ReturnReason> returnReasons = returnReasonService.selectAll(); if(returnReasons!=null){ return CommonResult.success("退货原因查询成功",returnReasons); }else{ return CommonResult.error("退货原因查询失败"); } } /*查询全部退货原因名称*/ @RequestMapping(value = "/returnReason/findReasonName") private CommonResult findReasonName() { List<String> names = returnReasonService.selectAllName(); if(names!=null){ return CommonResult.success("退货原因查询成功",names); }else{ return CommonResult.error("退货原因查询失败"); } } /*查询退货原因是否存在*/ @RequestMapping(value = "/returnReason/existReasonName") private CommonResult existReasonName(Integer reasonId,String reasonName) { Boolean isExist = returnReasonService.existsWithReasonName(reasonId,reasonName); if(isExist!=null){
if(returnReason!=null){ return CommonResult.success("退货原因查询成功",returnReason); }else{ return CommonResult.error("退货原因查询失败"); } } /*查询全部退货原因*/ @RequestMapping(value = "/returnReason/findAllReason") private CommonResult findAllReason() { List<ReturnReason> returnReasons = returnReasonService.selectAll(); if(returnReasons!=null){ return CommonResult.success("退货原因查询成功",returnReasons); }else{ return CommonResult.error("退货原因查询失败"); } } /*查询全部退货原因名称*/ @RequestMapping(value = "/returnReason/findReasonName") private CommonResult findReasonName() { List<String> names = returnReasonService.selectAllName(); if(names!=null){ return CommonResult.success("退货原因查询成功",names); }else{ return CommonResult.error("退货原因查询失败"); } } /*查询退货原因是否存在*/ @RequestMapping(value = "/returnReason/existReasonName") private CommonResult existReasonName(Integer reasonId,String reasonName) { Boolean isExist = returnReasonService.existsWithReasonName(reasonId,reasonName); if(isExist!=null){ return CommonResult.success("查询成功",isExist); }else{ return CommonResult.error("查询失败"); } } @RequestMapping(value = "/returnReason/addReason") private CommonResult addReason(ReturnReason returnReason) { if(returnReason!=null){ if(returnReasonService.insertData(returnReason)){ return CommonResult.success("添加成功",returnReason); }else{ return CommonResult.error("添加失败");
return CommonResult.error("查询失败"); } } /*查询VIP用户信息根据id*/ @RequestMapping(value = "/vip/findVipById") private CommonResult findVipById(Integer vipId) { Vip vip = vipService.selectById(vipId); if(vip!=null){ return CommonResult.success("查询成功",vip); }else{ return CommonResult.error("查询失败"); } } /*查询VIP用户信息根据id*/ @RequestMapping(value = "/vip/findVipByKey") private CommonResult findVipByKey(String accountNumber) { Vip vip = vipService.selectByKey(accountNumber); if(vip!=null){ return CommonResult.success("查询成功",vip); }else{ return CommonResult.error("查询失败"); } } /*判断用户信息是否存在*/ @RequestMapping(value = "/vip/existsVip") private CommonResult existsVip(String accountNumber) { Boolean isExist = vipService.existsVip(accountNumber); if(isExist!=null){ return CommonResult.success("查询成功",isExist); }else{ return CommonResult.error("查询失败"); } } //创建vip信息 @RequestMapping(value = "/vip/addVip") private CommonResult addVip(Vip vip) { Date date = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(date);//设置起时间 cal.add(Calendar.YEAR, 1);//增加一年 vip.setOverdueTime(cal.getTime()); if(vipService.insertData(vip)){ return CommonResult.success("vip信息插入成功",vip);
}else{ return CommonResult.error("查询失败"); } } /*查询所有用户*/ @RequestMapping(value = "/user/findAll") private CommonResult findAll() { List<User> users = userService.selectAll(); if(users!=null){ return CommonResult.success("查询成功",users); }else{ return CommonResult.error("查询失败"); } } /*判断某个用户是否还存在*/ @RequestMapping(value = "/user/existKey") private CommonResult existKey(String key) { Boolean isExist = userService.existsWithPrimaryKey(key); if(isExist!=null){ return CommonResult.success("查询成功",isExist); }else{ return CommonResult.error("查询失败"); } } /*查询用户状态*/ @RequestMapping(value = "/user/userState") private CommonResult userState(String accountNumber) { Boolean state = userService.selectUserState(accountNumber); if(state!=null){ return CommonResult.success("查询成功",state); }else{ return CommonResult.error("查询失败"); } } /*查询用户记录的总条数*/ @RequestMapping(value = "/user/count")
returnGoods.setReturnState("允许退货"); returnGoods.setDealTime(new Date()); returnGoods.setOperatorNumber(operatorNumber); returnGoods.setOperatorName(operatorName); String orderNo = returnGoods.getOrderNo(); Integer orderId = orderService.selectIdByKey(orderNo); Order order = new Order(); order.setOrderId(orderId); order.setReturnState(true); order.setOrderState("已退货"); Logistics logistics = logisticsService.selectOrderNo(orderNo); if(logistics!=null){ logisticsService.deleteById(logistics.getLogisticId()); } if(orderService.updateById(order)){ if(returnGoodsService.updateById(returnGoods)){ return CommonResult.success("更新成功",returnGoods); }else{ return CommonResult.error("更新失败"); } }else{ return CommonResult.error("更新失败"); } } return CommonResult.error("商品退货数据不存在"); } /*买家快递寄回*/ @RequestMapping(value = "/returnGoods/sendBack") private CommonResult sendBack(Integer returnId) { if(returnId!=null){ ReturnGoods returnGoods = new ReturnGoods(); returnGoods.setReturnId(returnId); returnGoods.setReturnState("待收货"); returnGoods.setDealTime(new Date()); if(returnGoodsService.updateById(returnGoods)){ return CommonResult.success("更新成功",returnGoods); }else{ return CommonResult.error("更新失败"); } } return CommonResult.error("商品退货数据不完整"); } /*商家收到寄回的商品*/ @RequestMapping(value = "/returnGoods/receipt") private CommonResult receipt(Integer returnId) { if(returnId!=null){ ReturnGoods returnGoods = new ReturnGoods(); returnGoods.setReturnId(returnId); returnGoods.setReturnState("退货完成"); returnGoods.setDealTime(new Date());
return CommonResult.success("添加成功",userRole); }else{ return CommonResult.error("添加失败"); } } return CommonResult.error("用户数据不存在"); } @RequestMapping(value = "/userRole/delete") private CommonResult delete(Integer userId) { Boolean bool = userRoleService.deleteById(userId); System.out.println(bool); if(bool){ return CommonResult.success("删除成功",userId); }else{ return CommonResult.error("删除失败"); } } } /** * @email qiudb.top@aliyun.com * @description 数据分析,商品数量,订单数量等分析业务 */ @CrossOrigin @RestController public class OverViewController { final OrderService orderService; final ProductService productService; final ReturnGoodsService returnGoodsService; public OverViewController(OrderService orderService,ProductService productService,ReturnGoodsService returnGoodsService) { this.orderService = orderService; this.productService = productService; this.returnGoodsService = returnGoodsService; }
} }else{ return CommonResult.error("更新失败"); } } return CommonResult.error("商品退款数据不存在"); } /*拒绝买家退款申请*/ @RequestMapping(value = "/returnGoods/rejectRefund") private CommonResult rejectRefund(Integer returnId,String operatorNumber,String operatorName) { if(returnId!=null){ ReturnGoods returnGoods = returnGoodsService.selectById(returnId); returnGoods.setReturnState("拒绝退款"); returnGoods.setDealTime(new Date()); returnGoods.setOperatorNumber(operatorNumber); returnGoods.setOperatorName(operatorName); String orderNo = returnGoods.getOrderNo(); Integer orderId = orderService.selectIdByKey(orderNo); Order order = new Order(); order.setOrderId(orderId); order.setOrderState("待发货"); if(orderService.updateById(order)){ if(returnGoodsService.updateById(returnGoods)){ return CommonResult.success("更新成功",returnGoods); }else{ return CommonResult.error("更新失败"); } }else { return CommonResult.error("更新失败"); } } return CommonResult.error("商品退款数据不存在"); } /*同意买家退货*/ @RequestMapping(value = "/returnGoods/dealWithReturn") private CommonResult dealWithReturn(Integer returnId,String operatorNumber,String operatorName) { if(returnId!=null){
this.redisTemplate = redisTemplate; this.hostAddress= PropertiesUtil.getServerHost() +":"+PropertiesUtil.getPort(); } @RequestMapping("/") private String index(){ return "index.html"; } /* https://qiustudy.utools.club/alipay/create?orderNo=10060&orderName=花卷商城-华为手机支付订单&payPrice=4000 */ @ResponseBody @PostMapping(value = "/create", produces = "text/html;charset=utf-8") public void create(@RequestParam("orderNo") String orderNo, @RequestParam("orderName") String orderName, @RequestParam("payPrice") String payPrice ,HttpServletResponse response) { //发起支付 // return alipayService.create(orderNo, orderName, payPrice); //跳过支付宝支付过程 try{ //String tradeNo =map.get("out_trade_no"); String tradeNo =orderNo; if(tradeNo.contains("Vip")){ Integer orderId = orderService.selectIdByKey(tradeNo); Order order = new Order(); order.setOrderId(orderId); order.setOrderState("开通成功"); String serialNumber = redisTemplate.opsForValue().get(tradeNo); if(serialNumber !=null){ response.sendRedirect("http://"+hostAddress+"/?#/personalCenter?serialNumber="+serialNumber); redisTemplate.delete(tradeNo); }else{ response.sendRedirect("http://"+hostAddress+"/?#/personalCenter?serialNumber="+"ERROR"); } orderService.updateById(order); }else{ String Str = redisTemplate.opsForValue().get(tradeNo); redisTemplate.delete(tradeNo); assert Str != null; String[] ordersNo = Str.split(","); System.out.println(Arrays.toString(ordersNo)); for (String orderNo1 : ordersNo) { Integer orderId = orderService.selectIdByKey(orderNo1); Order order = new Order(); order.setOrderId(orderId);
}else{ return CommonResult.error("创建订单失败"); } }else{ return CommonResult.error("商品库存不足"); } } }else{ return CommonResult.error("订单数据不完整"); } } @RequestMapping(value = "/order/cartOrder") private CommonResult cartOrder(String orderNo,String ordersInfo) { JSONArray jsonArray = JSON.parseArray(ordersInfo); List<Order> orders = JSONObject.parseArray(jsonArray.toJSONString(), Order.class); if(orders!=null){ ArrayList<String> orderInfo = new ArrayList<>(); ArrayList<String> productInfo = new ArrayList<>(); for (Order order : orders) { Product product = productService.selectByKey(order.getProductNo()); Integer productStock = product.getProductStock(); Integer payAmount = order.getPayAmount(); boolean isOk =productStock >= payAmount; if(isOk){ Product newProduct = new Product(); newProduct.setProductId(product.getProductId()); int newStock = productStock - payAmount; newProduct.setProductStock(newStock); newProduct.setIsStockOut(newStock<product.getLowestStock()); // 如果库存小于等于0,自动下架 newProduct.setIsSale(newStock>0); if(productService.updateById(newProduct)){ if(orderService.insertData(order)){ orderInfo.add(order.getOrderNo()); productInfo.add(order.getProductNo()); } } } } if(orderInfo.size()!=0){ String orderNoInfo = StringUtils.join(orderInfo, ","); String productNoInfo = StringUtils.join(productInfo, ","); redisTemplate.opsForValue().set(orderNo,orderNoInfo,24, TimeUnit.HOURS); return CommonResult.success("创建订单成功",productNoInfo); }else{ return CommonResult.success("创建订单失败"); } }else{ return CommonResult.error("订单数据不完整"); }
@RequestMapping(value = "/productReview/findAll") private CommonResult findAllProductReview(String productNo) { List<Map<String, Object>> productReviewInfo = ProductReviewService.selectAll(productNo); if(productReviewInfo!=null){ return CommonResult.success("商品评论查询成功",productReviewInfo); }else{ return CommonResult.error("商品评论查询失败"); } } @RequestMapping(value = "/productReview/findById") private CommonResult findById(Integer reviewId) { ProductReview productReview = ProductReviewService.selectById(reviewId); if(productReview!=null){ return CommonResult.success("商品评论查询成功",productReview); }else{ return CommonResult.error("商品评论查询失败"); } } } /** * @email qiudb.top@aliyun.com * @description 购物车业务类 */ @RestController @CrossOrigin public class ShoppingCartController { final ShoppingCartService shoppingCartService; public ShoppingCartController(ShoppingCartService shoppingCartService){ this.shoppingCartService = shoppingCartService; }
/*查询全部供应商名称*/ @RequestMapping(value = "/supplier/findAllName") private CommonResult findAllName() { List<String> names = supplierService.selectAllName(); if(names!=null){ return CommonResult.success("供货商名称查询成功",names); }else{ return CommonResult.error("供货商名称查询失败"); } } /*查询供应商是否存在*/ @RequestMapping(value = "/supplier/existSupplier") private CommonResult existSupplier(Integer supplierId,String supplierName) { Boolean isExist = supplierService.existsWithSupplierName(supplierId,supplierName); if(isExist!=null){ return CommonResult.success("查询成功",isExist); }else{ return CommonResult.error("查询失败"); } } /*添加供应商*/ @RequestMapping(value = "/supplier/addSupplier") private CommonResult addSupplier(Supplier supplier) { if(supplier!=null){ if(supplierService.insertData(supplier)){ return CommonResult.success("添加成功",supplier); }else{ return CommonResult.error("添加失败"); } } return CommonResult.error("供应商数据不存在"); } /*修改供应商*/ @RequestMapping(value = "/supplier/updateSupplier") private CommonResult updateSupplier(Supplier supplier) { if(supplier!=null){ if(supplierService.updateById(supplier)){ return CommonResult.success("更新成功",supplier); }else{ return CommonResult.error("更新失败"); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。