(全新)基于springboot,vue网上商城定制版v3.0
本人原创作品,用户前台、系统管理员后台项目完整,无任何bug。
每行代码都是本人自己写,我在代码上面都写有详细注释,不懂任何问题都可以咨询
开发工具:IDEA
服务器:Tomcat9.0, jdk1.8
项目构建:maven
数据库:mysql5.7
系统分前后台,采用前后端分离
前端技术:vue (vue cli,vue-router,vuex全家桶),elementUI等框架实现
服务端技术:springboot,mybatis-plus
随着计算机技术的发展和网络人口的增加,网络世界也越来越广博,越来越丰富,网上商城已经成为网上购物的一股潮流。互联网已日益成为收集提供信息的最佳渠道并逐步进入传统的流通流域,互联网的跨地域性和可交互性使其在与传统媒体行业和传统贸易行业的竞争中是具有不可抗拒的优势。人们对于互联网技术的要求已不单单是浏览一下网站网页,收发电子邮件,日益忙碌的人们开始追求足不出户就能买到心仪的商品,是越来越多的上网爱好者实现购物的一种方式。对于企业来讲,无论是企业之间(B to B),还是企业和客户之间(B to C)的交易,如果能够实现网上交易将大大提高交易速度节约成本。但是对网络的及时、一对一、跨时间、 跨空间等特性,并没有充分加以利用。在这种形势下,传统的依靠管理人员人工工作传递信息和数据的管理方式就无法满足企业日益增长的业务需求了。因而开发了这样一个具有前后台的网上商城系统,以满足购物者和企业的需求。
前台截图:
后台截图:
![在这里插入图片描述](https://img-blog.csdnimg.cn/914968fd2e5e44a1b8e3169bf41abbaf.png#pic_center
package com.ping.controller;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.ping.dto.MonthStatisticsDto;
import com.ping.enums.OrderStatusEnum;
import com.ping.pojo.Order;
import com.ping.pojo.Product;
import com.ping.pojo.RespBean;
import com.ping.service.IOrderService;
import com.ping.service.IProductService;
import com.ping.utils.PublicUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 前端控制器
* </p>
*
* @author IT教程资源
* @since 2022-07-03
*/
@RestController
@RequestMapping("/home")
public class HomeController {
@Autowired
private IOrderService iOrderService;
@Autowired
private IProductService iProductService;
/**
* @author lyp 2022/7/29 14:58
* 首页统计查询
*/
@ApiOperation("查询首页统计信息")
@GetMapping("/getHomeInfo")
public RespBean getHomeInfo(){
Map<String,Object> resultMap=new HashMap<>();
//1.查询所有订单
int allCount = iOrderService.count();
//总订单量
resultMap.put("totalOrderCount",allCount);
//2.待付款订单量
QueryWrapper<Order> orderQueryWrapper1=new QueryWrapper<>();
orderQueryWrapper1.eq("status", OrderStatusEnum.NO_PAYMENT.getValue());
int noPaymentCount = iOrderService.count(orderQueryWrapper1);
resultMap.put("noPaymentCount",noPaymentCount);
//2.待发货订单量
QueryWrapper<Order> orderQueryWrapper2=new QueryWrapper<>();
orderQueryWrapper2.eq("status", OrderStatusEnum.NO_DELIVERY.getValue());
int noDeliveryCount = iOrderService.count(orderQueryWrapper2);
resultMap.put("noDeliveryCount",noDeliveryCount);
//3.待收货订单量
QueryWrapper<Order> orderQueryWrapper3=new QueryWrapper<>();
orderQueryWrapper3.eq("status", OrderStatusEnum.NO_RECEIVE.getValue());
int noReceiveCount = iOrderService.count(orderQueryWrapper3);
resultMap.put("noReceiveCount",noReceiveCount);
//4.待评价订单量
QueryWrapper<Order> orderQueryWrapper4=new QueryWrapper<>();
orderQueryWrapper4.eq("status", OrderStatusEnum.NO_EVALUATION.getValue());
int noEvaluationCount = iOrderService.count(orderQueryWrapper4);
resultMap.put("noEvaluationCount",noEvaluationCount);
//5.已完成订单量
QueryWrapper<Order> orderQueryWrapper5=new QueryWrapper<>();
orderQueryWrapper5.eq("status", OrderStatusEnum.FINISHED.getValue());
int finishedCount = iOrderService.count(orderQueryWrapper5);
resultMap.put("finishedCount",finishedCount);
//6.查询商品销量
List<Product> productList = iProductService.list();
List<Product> products=null;
if(productList!=null && !productList.isEmpty()){
products = productList.stream().sorted(Comparator.comparing(Product::getVolume).reversed()).limit(5).collect(Collectors.toList());
}
resultMap.put("productSaleStatistics",products);
//7.前6个月订单量统计
List<String> sixMonth = PublicUtil.getFourMonth(DateUtil.format(new Date(), "yyyy-MM"));
String dayStr = sixMonth.get(0);
List<MonthStatisticsDto> list = iOrderService.selectRecentMonthTran(dayStr);
//补全数据库中不存在的日期,数为0
List<MonthStatisticsDto> orderSaleStatistics = Lists.newArrayList();
boolean flag;
for (int i=0;i<sixMonth.size();i++){
flag=false;
for(MonthStatisticsDto monthStatisticsDto : list){
String date = monthStatisticsDto.getMonth();
if(date.equalsIgnoreCase(sixMonth.get(i))){
orderSaleStatistics.add(monthStatisticsDto);
flag=true;
break;
}
}
//如果都没有找到
if(!flag){
MonthStatisticsDto monthDto=new MonthStatisticsDto();
monthDto.setCount(0);
monthDto.setMonth(sixMonth.get(i));
orderSaleStatistics.add(monthDto);
}
}
resultMap.put("orderSaleStatistics",orderSaleStatistics);
return RespBean.success(resultMap);
}
}
package com.ping.controller;
import com.ping.pojo.Admin;
import com.ping.pojo.AdminLoginParam;
import com.ping.pojo.RespBean;
import com.ping.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.Map;
@RestController
@Api(tags = "LoginController")
public class LoginController {
@Autowired
private IAdminService adminService;
@ApiOperation(value = "登录之后返回token")
@RequestMapping("/login")
public RespBean login(@RequestBody AdminLoginParam adminLoginParam, HttpServletRequest request){
return adminService.login(adminLoginParam.getUsername(),adminLoginParam.getPassword(),adminLoginParam.getCode(),request);
}
@ApiOperation("获取当前登录用户的信息")
@RequestMapping("/adminInfo")
public Admin getAdminInfo(Principal principal){
if(null==principal){
return null;
}
String userName = principal.getName();
Admin admin=adminService.getAdminByUserName(userName);
admin.setPassword(null);//安全考虑
admin.setRoles(adminService.getRoles(admin.getId()));
return admin;
}
@ApiOperation(value = "退出登录")
@RequestMapping("/logout")
public RespBean logout(){
return RespBean.success("注销成功");
}
@ApiOperation(value = "检查原密码是否正确")
@GetMapping("/checkPassword")
public RespBean checkPassword(String oldpassword,Principal principal){
if(null==principal){
return null;
}
String userName = principal.getName();
Admin admin=adminService.getAdminByUserName(userName);
BCryptPasswordEncoder encoder=new BCryptPasswordEncoder();
//判断旧密码是否正确
if(encoder.matches(oldpassword,admin.getPassword())){
return RespBean.success("原密码正确");
}
return RespBean.error("原密码错误");
}
@ApiOperation("更新密码")
@PutMapping("/updatePassword")
public RespBean updatePassword(@RequestBody Map<String,Object> passwordInfo,Principal principal){
//原密码
String oldpassword = (String) passwordInfo.get("oldpassword");
//新密码
String password = (String) passwordInfo.get("password");
if(null==principal){
return null;
}
String userName = principal.getName();
Admin admin=adminService.getAdminByUserName(userName);
BCryptPasswordEncoder encoder=new BCryptPasswordEncoder();
//判断旧密码是否正确
if(!encoder.matches(oldpassword,admin.getPassword())){
return RespBean.error("原密码错误");
}
return adminService.updatePassword(password,admin);
}
@ApiOperation(value = "检查账号是否可用")
@GetMapping("/checkUsername")
public RespBean checkUsername(String username){
Admin admin=adminService.getAdminByUserName(username);
if(admin!=null){
return RespBean.error("账号已存在");
}
return RespBean.success("账号可用");
}
}
package com.ping.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ping.dto.OrderDetailsDto;
import com.ping.dto.OrderDto;
import com.ping.dto.query.OrderQueryDto;
import com.ping.enums.OrderStatusEnum;
import com.ping.enums.PaymentStatusEnum;
import com.ping.mapper.*;
import com.ping.pojo.*;
import com.ping.service.IOrderService;
import com.ping.utils.OrderUtil;
import com.ping.utils.PageUtil;
import com.ping.utils.UserUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author IT教程资源
* @since 2022-07-03
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
@Autowired
private OrderMapper orderMapper;
@Autowired
private OrderDetailsMapper orderDetailsMapper;
@Autowired
private DeliveryAddressMapper deliveryAddressMapper;
@Autowired
private ShoppingCartMapper shoppingCartMapper;
@Autowired
private ProductMapper productMapper;
@Override
public void saveOrder(User user, OrderDto orderDto) {
//生成订单号
String orderNo = OrderUtil.getOrderNo();
orderDto.setOrderNo(orderNo);
//step1.封装订单明细
List<OrderDetailsDto> orderDetailsDtoList = orderDto.getOrderDetailsDtoList();
if(orderDetailsDtoList!=null && !orderDetailsDtoList.isEmpty()){
//批量保存订单明细
orderDetailsDtoList.forEach(orderDetailsDto -> {
OrderDetails orderDetails=new OrderDetails();
BeanUtils.copyProperties(orderDetailsDto,orderDetails);
orderDetails.setOrderNo(orderNo);
orderDetailsMapper.insert(orderDetails);
});
}else {
throw new RuntimeException("订单明细不存在异常");
}
//step2.封装订单
Order order=new Order();
BeanUtils.copyProperties(orderDto,order);
//查询收货地址信息
DeliveryAddress deliveryAddress = deliveryAddressMapper.selectById(orderDto.getDeliveryAddress().getId());
if(deliveryAddress==null){
throw new RuntimeException("收货地址不存在异常");
}
//订单号
order.setOrderNo(orderNo);
//收货人姓名
order.setConsigneeName(deliveryAddress.getName());
//收货人电话
order.setConsigneePhone(deliveryAddress.getPhone());
//收货人地址:省市区+详细地址
order.setConsigneeAddress(deliveryAddress.getProvince()+deliveryAddress.getCity()+deliveryAddress.getDistrict()+deliveryAddress.getAddress());
//订单状态-待付款
if(1==order.getPaymentType()) {
//货到付款,待发货
order.setStatus(OrderStatusEnum.NO_DELIVERY.getValue());
}else {
//在线支付,待付款
order.setStatus(OrderStatusEnum.NO_PAYMENT.getValue());
}
//所属用户
order.setUserId(user.getId());
//支付状态
order.setPaymentStatus(PaymentStatusEnum.NO_PAYMENT.getValue());
//保存订单
orderMapper.insert(order);
//step3.清空购物车
List<Integer> cartIds=new ArrayList<>();
orderDto.getOrderDetailsDtoList().forEach(orderDetailsDto -> {
cartIds.add(orderDetailsDto.getShoppingCart().getId());
});
//批量删除购物车
shoppingCartMapper.deleteBatchIds(cartIds);
//step4.修改商品已售
orderDto.getOrderDetailsDtoList().forEach(orderDetailsDto -> {
productMapper.updateProductStockAndVolumeById(orderDetailsDto.getBuyCount(),orderDetailsDto.getProductId());
});
}
@Override
public RespPageBean getOrderPage(OrderQueryDto queryDto) {
User currentUser = UserUtils.getCurrentUser();
queryDto.setUserId(currentUser.getId());
//多表查询自定义分页
int count = orderMapper.countByTotal(queryDto);
PageUtil page = new PageUtil(queryDto.getCurrentPage(), queryDto.getPageSize(), count);
List<OrderDto> list= orderMapper.findByPage(page,queryDto);
RespPageBean respPageBean=new RespPageBean((long) count,list);
return respPageBean;
}
}