源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目分为前后台,前台为普通用户角色,后台为管理员角色;
管理员角色包含以下功能:
人员管理,修改个人信息,图片管理,图表管理,管理员登录,订单管理,配件管理等功能。
用户角色包含以下功能:
修改个人信息,提交付款,查看商品详情,查看我的订单,查看购物车,查看首页,用户登录,确认订单等功能。
环境需要
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等版本均可;
技术栈
java+Springboot+ElementUI+Vue+Mysql
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2.使用IDEA/Eclipse/MyEclipse导入项目,配置tomcat;
3. 将项目中config/jdbc.properties配置文件中的数据库配置改为自己的配置;
购物车管理控制层:
@Controller@RequestMapping("/cart")publicclassCartController {
@Autowiredprivate ICartService cartService;
@Autowiredprivate IGoodsService goodsService;
@Autowiredprivate IAddressService addressService;
@RequestMapping("addCart")@ResponseBodypublic String addToCart(Integer goodsId,Integer num,HttpServletRequest request){
HttpSessionsession= request.getSession();
Users user=(Users) session.getAttribute("user");
Cartcart= cartService.findCartByUserId(user.getUserId(), goodsId);
if(cart!=null){
cart.setCartNum(cart.getCartNum()+num);
cartService.updateCart(cart);
}else{
Goodsgoods= goodsService.findById(goodsId);
Cart c=newCart(goods, num, goods.getGoodsPrice(), user);
cartService.addGoodsToCart(c);
}
return"success";
}
@RequestMapping("findCartByUser")@ResponseBodypublic List<Cart> findCartByUser(HttpServletRequest request){
HttpSessionsession= request.getSession();
Users user=(Users) session.getAttribute("user");
List<Cart> list = cartService.findCartByUserId(user.getUserId());
return list;
}
@RequestMapping("deleteCart")@ResponseBodypublic String deleteCart(Integer cartId){
Integerrs= cartService.deleteCart(cartId);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("reduceCartNum")@ResponseBodypublic String reduceCartNum(Integer cartId){
Cartcart= cartService.findCartById(cartId);
cart.setCartNum(cart.getCartNum()-1);
Integerrs= cartService.updateCart(cart);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("addCartNum")@ResponseBodypublic String addCartNum(Integer cartId){
Cartcart= cartService.findCartById(cartId);
cart.setCartNum(cart.getCartNum()+1);
Integerrs= cartService.updateCart(cart);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("preOrder")public String preOrder(Integer[] goodslist,Model model,HttpServletRequest request){
List<Cart> cartList=newArrayList<Cart>();
for (Integer i : goodslist) {
Cartcart= cartService.findCartById(i);
cartList.add(cart);
}
model.addAttribute("cartList", cartList);
HttpSessionsession= request.getSession();
Usersuser= (Users) session.getAttribute("user");
List<Address> addrList = addressService.findAddressByUserId(user.getUserId());
model.addAttribute("addrList", addrList);
return"userview/confirm_order";
}
}
订单管理控制层:
@Controller@RequestMapping("/order")publicclassOrderController {
@Autowiredprivate ICartService cartService;
@Autowiredprivate IGoodsService goodsService;
@Autowiredprivate IOrderService orderService;
@Autowiredprivate IAddressService addressService;
@Autowiredprivate IGuessService guessService;
@RequestMapping("takeOrder")public String takeOrder(Integer[] goodslist,Integer addr,Model model,HttpServletRequest request){
List<Cart> cartList=newArrayList<Cart>();
List<OrderDetail> detailList=newArrayList<OrderDetail>();
Double totalPrice=0D;
for (Integer i : goodslist) {
Cartcart= cartService.findCartById(i);
totalPrice+=cart.getCartNum()*cart.getCartGoods().getGoodsPrice();
cartList.add(cart);
OrderDetail detail=newOrderDetail(cart.getCartGoods(), cart.getCartGoods().getGoodsPrice()*cart.getCartNum(), cart.getCartNum());
detailList.add(detail);
}
HttpSessionsession= request.getSession();
Users user=(Users) session.getAttribute("user");
Date orderDate=newDate();
Addressaddress= addressService.findAddresById(addr);
String a=address.getAddrProvince()+address.getAddrCity()+address.getAddrArea()+address.getAddrDetail();
Order order=newOrder(user, orderDate, totalPrice, 1, address.getAddrNickname(), address.getAddrPhone(), a);
order.setDetailList(detailList);
OrdertakeOrder= orderService.takeOrder(order);
for (Cart c : cartList) {
Goodsgoods= goodsService.findById(c.getCartGoods().getGoodsId());
goods.setGoodsNum(goods.getGoodsNum()-c.getCartNum());
goods.setGoodsVolume(goods.getGoodsVolume()+c.getCartNum());
goodsService.update(goods);
cartService.deleteCart(c.getCartId());
}
model.addAttribute("order",takeOrder);
List<Guess> guessList = guessService.findGuessGoodsByUserId(user.getUserId(), 4);
model.addAttribute("guessList", guessList);
return"userview/takeorder";
}
@RequestMapping("findReadPayOrder")@ResponseBodypublic List<Order> findReadyPayOrder(HttpServletRequest request){
HttpSessionsession= request.getSession();
Users user=(Users) session.getAttribute("user");
List<Order> orderList = orderService.findOrdersByUserIdAndState(user.getUserId(), 1);
return orderList;
}
@RequestMapping("findReadyToDeliverOrder")@ResponseBodypublic List<Order> findReadyToDeliverOrder(HttpServletRequest request){
HttpSessionsession= request.getSession();
Usersuser= (Users) session.getAttribute("user");
List<Order> orderList = orderService.findOrdersByUserIdAndState(user.getUserId(), 2);
return orderList;
}
@RequestMapping("findReadyToReceiveOrder")@ResponseBodypublic List<Order> findReadToReceiveOrder(HttpServletRequest request){
HttpSessionsession= request.getSession();
Usersuser= (Users) session.getAttribute("user");
List<Order> orderList = orderService.findOrdersByUserIdAndState(user.getUserId(), 3);
return orderList;
}
@RequestMapping("findReadyToEvaluateOrder")@ResponseBodypublic List<Order> findReadyToEvaluateOrder(HttpServletRequest request){
HttpSessionsession= request.getSession();
Usersuser= (Users) session.getAttribute("user");
List<Order> orderList = orderService.findOrdersByUserIdAndState(user.getUserId(), 4);
return orderList;
}
@RequestMapping("findFinishOrder")@ResponseBodypublic List<Order> findFinishOrder(HttpServletRequest request){
HttpSessionsession= request.getSession();
Usersuser= (Users) session.getAttribute("user");
List<Order> orderList = orderService.findOrdersByUserIdAndState(user.getUserId(), 5);
return orderList;
}
@RequestMapping("receiveOrder")@ResponseBodypublic String receiveOrder(String orderId){
Integerrs= orderService.receiveOrder(orderId);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("deleteOrder")@ResponseBodypublic String deleteOrder(String orderId){
Integerrs= orderService.deleteOrder(orderId);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("findOrderBySplitPage")@ResponseBodypublic JSONObject findOrderBySplitPage(Integer page,Integer limit,OrderSearchVO vo){
if(vo!=null){
System.out.println(vo.getOrderState()+"========================");
}
PageInfo<Order> info = orderService.findOrdersBySplitPage(page, limit,vo);
JSONObject obj=newJSONObject();
obj.put("msg", "");
obj.put("code", 0);
obj.put("count", info.getTotal());
obj.put("data", info.getList());
return obj;
}
@RequestMapping("updateOrder")@ResponseBodypublic String updateOrder(Order order){
Integerrs= orderService.updateOrder(order);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("deliverOrder")@ResponseBodypublic String deliverOrder(String orderId,String expressNo){
if(!expressNo.trim().equals("")){
Integerrs= orderService.deliverOrder(orderId, expressNo);
if(rs>0){
return"success";
}else{
return"fail";
}
}else{
return"fail";
}
}
@RequestMapping("findOrderById")@ResponseBodypublic Order findOrderById(String orderId){
Orderorder= orderService.findOrderById(orderId);
return order;
}
@RequestMapping("findTotalOrder")@ResponseBodypublic JSONObject findOrderTotalMoney(){
List<OrderVO> list = orderService.findTotalMoneyByMonth(6);
String[] month=newString[6];
Long[] total=newLong[6];
Integer[] sheets=newInteger[6];
for(int i=0;i<list.size();i++){
month[i]=list.get(i).getOrderMonth();
total[i]=list.get(i).getTotalMoney();
sheets[i]=list.get(i).getSheets();
}
JSONObject obj=newJSONObject();
obj.put("month", month);
obj.put("total", total);
obj.put("sheets", sheets);
return obj;
}
@RequestMapping("findToDo")@ResponseBodypublic JSONObject findToDo(){
IntegertotalOrder= orderService.findTotalOrder();
IntegertotalDediver= orderService.findTotalDeliverOrder();
JSONObject obj=newJSONObject();
obj.put("total", totalOrder);
obj.put("deliver", totalDediver);
return obj;
}
@RequestMapping("toPay")@ResponseBodypublic JSONObject toPayFor(String orderId,HttpServletResponse response){
Orderout_trade_no= orderService.findOrderById(orderId);
Integerrs= orderService.payForOrder(orderId);
if(rs>0){
System.out.println("同步通知支付成功");
}
JSONObject obj=newJSONObject();
obj.put("result", "paysuccess");
return obj;
/**
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
//设置请求参数
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
alipayRequest.setReturnUrl(AlipayConfig.return_url);
alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
Order order = orderService.findOrderById(orderId);
//商户订单号,商户网站订单系统中唯一订单号,必填
String out_trade_no=null;
//付款金额,必填
String total_amount=null;
//订单名称,必填
String subject=null;
try {
out_trade_no = new String(orderId.getBytes("ISO-8859-1"),"UTF-8");
total_amount = new String((order.getOrderPrice()+"").getBytes("ISO-8859-1"),"UTF-8");
subject = new String("我的商城");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
//商品描述,可空
List<OrderDetail> detailList = order.getDetailList();
String body = null;
for (OrderDetail o : detailList) {
body=body+o.getDetailGoods().getGoodsName()+",";
}
body=body.substring(0, body.length()-1)+"等商品";
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
+ "\"total_amount\":\""+ total_amount +"\","
+ "\"subject\":\""+ subject +"\","
+ "\"body\":\""+ body +"\","
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
//请求
try {
String result = alipayClient.pageExecute(alipayRequest).getBody();
//输出
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
out.print(result);
} catch (AlipayApiException | IOException e) {
e.printStackTrace();
}
return null;**/
}
@RequestMapping("notify_url")publicvoidnotifyUrl(HttpServletRequest request,HttpServletResponse response){
Map<String,String> params = newHashMap<String,String>();
Map<String,String[]> requestParams = request.getParameterMap();
for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
Stringname= (String) iter.next();
String[] values = (String[]) requestParams.get(name);
StringvalueStr="";
for (inti=0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i]
: valueStr + values[i] + ",";
}
//乱码解决,这段代码在出现乱码时使用try {
valueStr = newString(valueStr.getBytes("ISO-8859-1"), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
params.put(name, valueStr);
}
boolean signVerified=false;
try {
signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type);
} catch (AlipayApiException e1) {
e1.printStackTrace();
} //调用SDK验证签名//——请在这里编写您的程序(以下代码仅作参考)——/* 实际验证过程建议商户务必添加以下校验:
1、需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
4、验证app_id是否为该商户本身。
*/
PrintWriter out=null;
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
if(signVerified) {//验证成功//商户订单号
String out_trade_no="";
//交易状态
String trade_status="";
try {
out_trade_no = newString(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
//支付宝交易号Stringtrade_no=newString(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
trade_status = newString(request.getParameter("trade_status").getBytes("ISO-8859-1"),"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if(trade_status.equals("TRADE_FINISHED")||trade_status.equals("TRADE_SUCCESS")){
//判断该笔订单是否在商户网站中已经做过处理//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序//如果有做过处理,不执行商户的业务程序Integerrs= orderService.payForOrder(out_trade_no);
if(rs>0){
System.out.println("异步通知支付成功");
}
//注意://付款完成后,支付宝系统发送该交易状态通知
}
out.println("success");
}else {//验证失败
out.println("fail");
//调试用,写文本函数记录程序运行情况是否正常//String sWord = AlipaySignature.getSignCheckContentV1(params);//AlipayConfig.logResult(sWord);
}
}
@RequestMapping("return_url")public String returnUrl(String out_trade_no){
Integerrs= orderService.payForOrder(out_trade_no);
if(rs>0){
System.out.println("同步通知支付成功");
}
return"paysuccess";
}
}
商品管理控制层:
@Controller@RequestMapping("/goods")publicclassGoodsController {
@Autowiredprivate IGoodsService goodsService;
@Autowiredprivate IGuessService guessService;
@Autowiredprivate IEvaluateService evaluateService;
@RequestMapping("findAll")public String findAllGoods(Model model){
List<Goods> list = goodsService.findAll();
model.addAttribute("goodsList", list);
return"list";
}
@RequestMapping("/findGoodsDiscounts")@ResponseBodypublic JSONObject findGoodsDiscounts(){
PageInfo<Goods> info = goodsService.findGoodsDiscounts();
JSONObjectobj=newJSONObject();
obj.put("msg", "");
obj.put("code", 0);
obj.put("count", info.getTotal());
obj.put("data", info.getList());
return obj;
}
@RequestMapping("{goodsId}")public String findAllGoods(@PathVariable("goodsId")Integer goodsId,Model model){
Goodsgoods= goodsService.findById(goodsId);
List<Evaluate> evaList = evaluateService.findEvaluateByGoodsId(goodsId);
model.addAttribute("goods", goods);
model.addAttribute("evaList", evaList);
return"detail";
}
@RequestMapping("preUpdate")public String preUpdate(Integer goodsId,Model model){
Goodsgoods= goodsService.findById(goodsId);
model.addAttribute("goods", goods);
return"update";
}
@RequestMapping("findBySplitPage")@ResponseBodypublic JSONObject findBySplitPage(Integer page,Integer limit,String keyword){
PageInfo<Goods> info = goodsService.findBySplitPage(page, limit,keyword);
JSONObject obj=newJSONObject();
obj.put("msg", "");
obj.put("code", 0);
obj.put("count", info.getTotal());
obj.put("data", info.getList());
return obj;
}
@RequestMapping("findGoodsByType")@ResponseBodypublic List<Goods> findGoodsByType(Integer typeId){
List<Goods> list = goodsService.findGoodsByType(typeId);
return list;
}
@RequestMapping("detail")public String findGoodsDetail(Integer goodsId,Model model,HttpServletRequest request){
Goodsgoods= goodsService.findById(goodsId);
model.addAttribute("goods",goods);
model.addAttribute("evaList", goods.getEvaList());
HttpSessionsession= request.getSession();
Users user=(Users) session.getAttribute("user");
if(user!=null){
Guessguess= guessService.findGuessByUserId(user.getUserId(), goods.getGoodsId());
if(guess!=null){
guess.setGuessNum(guess.getGuessNum()+1);
guessService.updateGuess(guess);
}else{
Guess g=newGuess(goods, 1, -1, user);
guessService.addGuess(g);
}
}
return"userview/product_detail";
}
@RequestMapping("findHotGoods")@ResponseBodypublic List<Goods> findHotGoods(){
return goodsService.findHotGoods(4);
}
@RequestMapping("search")public ModelAndView searchGoodsByName(String keyWord){
ModelAndView mv=newModelAndView();
List<Goods> list = goodsService.findGoodsLikeName(keyWord);
mv.addObject("searchList",list);
mv.setViewName("userview/search");
return mv;
}
@RequestMapping("searchPre")@ResponseBodypublic List<Goods> searchPreGoods(String keyword){
List<Goods> list = goodsService.findGoodsLikeName(keyword);
return list;
}
@RequestMapping("delete")@ResponseBodypublic String deleteGoods(Integer goodsId){
Integerrs= goodsService.deleteGoods(goodsId);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("updateGoods")@ResponseBodypublic String updateGoods(Goods goods){
Integerrs= goodsService.update(goods);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("batchDelete")@ResponseBodypublic String batchDelete(String batchId){
Integer rs=0;
String[] id = batchId.split(",");
for (String s : id) {
IntegergoodsId= Integer.valueOf(s);
rs = goodsService.deleteGoods(goodsId);
}
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping(value="uploadImg",method={RequestMethod.POST})@ResponseBodypublic Object uploadGoodsImg(@PathVariable(value="file")MultipartFile file,HttpServletRequest request){
Stringstr= file.getOriginalFilename();
String name=UUIDUtil.getUUID()+str.substring(str.lastIndexOf("."));
String path=request.getSession().getServletContext().getRealPath("/upload")+"/"+name;
try {
file.transferTo(newFile(path));
} catch (IllegalStateException | IOException e) {
e.printStackTrace();
}
JSONObject obj=newJSONObject();
obj.put("src", name);
return obj;
}
@RequestMapping("addGoods")@ResponseBodypublic String addGoods(Goods goods){
Integerrs= goodsService.addGoods(goods);
if(rs>0){
return"success";
}else{
return"fail";
}
}
@RequestMapping("findGoodsByVolume")@ResponseBodypublic JSONObject findGoodsByVolume(){
List<Goods> goodsList = goodsService.findGoodsByVolume(5);
String[] name=newString[5];
Integer[] volume=newInteger[5];
for(int i=0;i<goodsList.size();i++){
name[i]=goodsList.get(i).getGoodsName();
volume[i]=goodsList.get(i).getGoodsVolume();
}
JSONObject obj=newJSONObject();
obj.put("name", name);
obj.put("volume", volume);
return obj;
}
@RequestMapping("chaozan")@ResponseBodypublic JSONObject chaozan(Integer goodsId,HttpServletRequest request){
HttpSessionsession= request.getSession();
Users user=(Users) session.getAttribute("user");
Integerrs= goodsService.chaozan(user.getUserId(),goodsId);
Goodsgoods= goodsService.findById(goodsId);
JSONObject obj=newJSONObject();
if(rs>0){
obj.put("goodzan", goods.getGoodsZan());
obj.put("result", "success");
}else{
obj.put("result", "fail");
}
return obj;
}
}
源码获取:俺的博客首页 "资源" 里下载!