本系统功能包括:
一: 商品模块:商品添加、规格设置,商品上下架等
二:订单模块:下单、购物车、支付,发货、收货、评 价、退款等
三:用户模块:登陆、注册、会员卡、充值等
四:其他等
环境配置: 1.1 springframework4.3.7.RELEASE 1.2 mybatis3.1.0s MyBatis-Plus 3.1.0 1.3 shirol.3.2 1.4 servlet3.1.0 1.5 druid1.0.28 1.6 weixin-java-mp3.2.0 1.7 MybatisPlus3.1.0 1.8 lombok等等。
项目技术: 2.1 Vue2.5.1 2.2 iview 2.3 layer3.0.3 2.4 jquery2.2.4 2.5 bootstrap3.3.7等等。
/** * @description 用户相关业务 */ @RestController @CrossOrigin public class UserController { final RoleService roleService; final UserService userService; final UserRoleService userRoleService; final VipService vipService; public UserController(UserService userService, RoleService roleService,VipService vipService, UserRoleService userRoleService) { this.userService = userService; this.roleService = roleService; this.userRoleService = userRoleService; this.vipService = vipService; } /*根据id查询用户*/ @RequestMapping(value = "/user/findById") private CommonResult findById(Integer id) { User user = userService.selectById(id); if(user!=null){ return CommonResult.success("查询成功",user); }else{ return CommonResult.error("查询失败"); } } /*根据帐号查询用户*/ @RequestMapping(value = "/user/findByKey") private CommonResult findByKey(String key) { User user = userService.selectByKey(key); if(user!=null){ return CommonResult.success("查询成功",user); }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") private CommonResult findCount() { Integer count = userService.selectCount(); if(count!=null){ if(count!=0){ return CommonResult.success("查询成功",count); }else{ return CommonResult.error("查询失败"); } }else{ return CommonResult.error("查询失败"); } } //通过用户帐号去查询用户的id @RequestMapping(value = "/user/findIdByKey") private CommonResult findIdByKey(String key) { Integer id = userService.selectIdByKey(key); if(id!=null){ if(id!=0){ return CommonResult.success("查询成功","id: "+id); }else{ return CommonResult.error("未查询到"); } }else{ return CommonResult.error("查询失败"); } } //删除用户 @RequestMapping(value = "/user/delete") private CommonResult delete(Integer userId) { if(userService.deleteById(userId)){ return CommonResult.success("删除成功",userId); }else{ return CommonResult.error("删除失败"); } } @RequestMapping(value = "/user/author") private CommonResult author(Integer userId,@RequestParam List<Integer> roleId) { System.out.println(userId); System.out.println(roleId); if(userId!=null && roleId!=null && roleId.size()!=0){ if(userRoleService.deleteById(userId)){ UserRole userRole = new UserRole(); userRole.setUserId(userId); for (Integer id : roleId) { userRole.setRoleId(id); userRoleService.insertData(userRole); } } return CommonResult.success("授权成功"); }else{ return CommonResult.error("角色授权数据不完整!"); } } /*查询所有VIP用户*/ @RequestMapping(value = "/vip/findAllVip") private CommonResult findAllVip() { List<Vip> vips = vipService.selectAll(); if(vips!=null){ return CommonResult.success("查询成功",vips); }else{ 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("vip信息插入失败"); } } //更新vip信息 @RequestMapping(value = "/vip/updateVip") private CommonResult updateVip(Vip vip) { if(vipService.updateById(vip)){ return CommonResult.success("vip信息更新成功",vip); }else{ return CommonResult.error("vip信息更新失败"); } } //删除vip信息 @RequestMapping(value = "/vip/deleteVip") private CommonResult deleteVip(Integer vipId) { if(vipService.deleteById(vipId)){ return CommonResult.success("删除成功",vipId); }else{ return CommonResult.error("删除失败"); } } }
/** * @description 订单相关业务 */ @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("订单数量查询失败"); } } @RequestMapping(value = "/order/add") private CommonResult addOrder(Order order) { if(order!=null){ if(order.getProductNo().contains("Vip")){ if(orderService.insertData(order)){ return CommonResult.success("创建订单成功",order); }else{ return CommonResult.error("创建订单失败"); } }else{ 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)){ redisTemplate.opsForValue().set(order.getOrderNo(),order.getOrderNo(),24, TimeUnit.HOURS); return CommonResult.success("创建订单成功",order); }else{ return CommonResult.error("创建订单失败"); } }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 = "/order/update") private CommonResult updateOrder(Order order) { if(orderService.updateById(order)){ return CommonResult.success("修改订单成功",order); }else{ return CommonResult.error("修改订单失败"); } } @RequestMapping(value = "/order/delete") private CommonResult deleteOrder(Integer orderId) { if(orderService.deleteById(orderId)){ return CommonResult.success("删除订单成功","订单id:"+orderId); }else{ return CommonResult.error("删除订单失败"); } } @RequestMapping(value = "/order/receipt") private CommonResult updateOrder(Integer orderId) { Order order = new Order(); order.setOrderId(orderId); order.setOrderState("已收货"); if(orderService.updateById(order)){ return CommonResult.success("商品收货成功",order); }else{ return CommonResult.error("商品收货失败"); } } @RequestMapping(value = "/orderDetail/orderInfo") private CommonResult orderInfo(String orderNo) { ArrayList<Object> resultList = new ArrayList<>(); Order order = orderService.selectByKey(orderNo); Logistics logistics = logisticsService.selectOrderNo(orderNo); if(order!=null){ resultList.add(order); } if(logistics!=null){ resultList.add(logistics); } if(resultList.size()!=0){ return CommonResult.success("订单详情查询成功",resultList); }else{ return CommonResult.error("订单详情查询失败"); } } }
/** * @description 购物车业务类 */ @RestController @CrossOrigin public class ShoppingCartController { final ShoppingCartService shoppingCartService; public ShoppingCartController(ShoppingCartService shoppingCartService){ this.shoppingCartService = shoppingCartService; } /*商品类别*/ @RequestMapping(value = "/shoppingCart/add") private CommonResult addShoppingCart(ShoppingCart shoppingCart) { if(shoppingCartService.insertData(shoppingCart)){ return CommonResult.success("购物车添加成功",shoppingCart); }else{ return CommonResult.error("购物车添加失败"); } } @RequestMapping(value = "/shoppingCart/update") private CommonResult updateShoppingCart(ShoppingCart shoppingCart) { if(shoppingCartService.updateById(shoppingCart)){ return CommonResult.success("购物车修改成功",shoppingCart); }else{ return CommonResult.error("购物车修改失败"); } } @RequestMapping(value = "/shoppingCart/deleteById") private CommonResult deleteShoppingCart(Integer cartId) { if(shoppingCartService.deleteById(cartId)){ return CommonResult.success("购物车删除成功","cartId: "+cartId); }else{ return CommonResult.error("购物车删除失败"); } } @RequestMapping(value = "/shoppingCart/deleteByUser") private CommonResult deleteByUser(String accountNumber) { if(shoppingCartService.deleteByUser(accountNumber)){ return CommonResult.success("购物车删除成功","accountNumber: "+accountNumber); }else{ 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("购物车查询失败"); } } }