package com.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.entity.*;
import com.github.pagehelper.PageInfo;
import com.service.IAddressService;
import com.service.ICartService;
import com.service.IGoodsService;
import com.service.IOrderService;
import com.util.OrderSearchVO;
import com.util.OrderVO;
import com.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import sun.awt.image.IntegerComponentRaster;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/order")
public class OrderController {
@Autowired
private IOrderService orderService;
@Autowired
private IAddressService addressService;
@Autowired
private ICartService cartService;
@Autowired
private IGoodsService goodsService;
/**
* 下单 判断库存
* @author: wxj
* @param addr
* @param goodslist
* @param request
* @return
*/
@RequestMapping("takeOrder")
public String takeOrder(Integer addr, Integer [] goodslist, RedirectAttributes redirectAttributes, HttpServletRequest request){
HttpSession session = request.getSession();
int flag = 1;
for(Integer id : goodslist){
Cart cart = cartService.findCartById(id);
if(cart.getCart_goods().getGoods_num() < cart.getCart_num()){
flag = 0;
}
}
//刷新页面清除session
if(flag == 0){
redirectAttributes.addFlashAttribute("errmsg","库存不足,购买失败!");
return "redirect:/cart/confirm_order";
}else{
double totalPrice = 0.0;
List<OrderDetail> detailList = new ArrayList<OrderDetail>();
for(Integer id : goodslist){
Cart cart = cartService.findCartById(id);
totalPrice += cart.getCart_price() * cart.getCart_num();
OrderDetail detail = new OrderDetail(cart.getCart_goods(), cart.getCart_price(), cart.getCart_num());
detailList.add(detail);
goodsService.reduceGoodsVolume(cart.getCart_num(),cart.getCart_goods().getGoods_id());
cartService.deleteCart(cart.getCart_id());
if(goodsService.findGoodsById(cart.getCart_goods().getGoods_id()).getGoods_num() == 0){
goodsService.outOfStock(cart.getCart_goods().getGoods_id());
}
}
Address address = addressService.findAddressById(addr);
String order_address = address.getAddr_province() + address.getAddr_city() + address.getAddr_area() + address.getAddr_detail();
Users user = (Users)session.getAttribute("user");
Order preOrder = new Order(user, Time.getDate(),totalPrice,1,address.getAddr_nickname(),address.getAddr_phone(),order_address);
preOrder.setDetailList(detailList);
Order order = orderService.takeOrder(preOrder);
session.setAttribute("order",order);
return "redirect:/order/toOrder";
}
}
@RequestMapping("toOrder")
public String toOrder(HttpSession session,Model model){
model.addAttribute("order",session.getAttribute("order"));
session.removeAttribute("cartList");
session.removeAttribute("addressList");
return "user/takeorder";
}
@RequestMapping("payForOrder")
@ResponseBody
public String payForOrder(String orderId){
Integer rs = orderService.payForOrder(orderId);
if(rs > 0){
return "success";
}else {
return "fail";
}
}
@RequestMapping("findOrderByUserAndState")
@ResponseBody
public List<Order> findOrderByUserAndState(Integer state,HttpServletRequest request){
HttpSession session = request.getSession();
Users user = (Users)session.getAttribute("user");
List<Order> list = orderService.findOrdersByUserAndState(user.getUser_id(),state);
return list;
}
@RequestMapping("receiveOrder")
@ResponseBody
public String receiveOrder(String order_id){
Integer rs = orderService.receiveOrder(order_id);
if(rs > 0){
return "success";
}else {
return "fail";
}
}
@RequestMapping("deleteOrder")
@ResponseBody
public String deleteOrder(String order_id){
Integer rs = orderService.deleteOrder(order_id);
if(rs > 0){
return "success";
}else {
return "fail";
}
}
@RequestMapping("findOrderById")
@ResponseBody
public Order findOrderById(String order_id){
return orderService.findOrderById(order_id);
}
@RequestMapping("updateOrder")
@ResponseBody
public String updateOrder(Order order){
Integer rs = orderService.updateOrder(order);
if(rs > 0){
return "success";
}else {
return "fail";
}
}
@RequestMapping("findOrderBySplitPage")
@ResponseBody
public JSONObject findOrderBySplitPage(@RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "limit",defaultValue = "10") Integer limit, OrderSearchVO vo){
PageInfo<Order> info = orderService.findOrderBySplitPage(page, limit, vo);
JSONObject obj = new JSONObject();
obj.put("msg","");
obj.put("code",0);
obj.put("count",info.getTotal());
obj.put("data",info.getList());
return obj;
}
@RequestMapping("deliverOrder")
@ResponseBody
public String deliverOrder(String order_id,String express_no){
Integer rs = orderService.deliverOrder(order_id, express_no);
if(rs > 0){
return "success";
}else {
return "fail";
}
}
@RequestMapping("findTotalOrder")
@ResponseBody
public JSONObject findTotalOrder(Integer limit){
List<OrderVO> list = orderService.findTotalMoneyByMonth(limit);
ArrayList<String> month = new ArrayList<String>();
ArrayList<Integer> sheets = new ArrayList<Integer>();
ArrayList<Long> total = new ArrayList<Long>();
for(OrderVO vo : list){
month.add(vo.getOrderMonth());
sheets.add(vo.getSheets());
total.add(vo.getTotalMoney());
}
JSONObject obj = new JSONObject();
obj.put("month",month);
obj.put("sheets",sheets);
obj.put("total",total);
return obj;
}
@RequestMapping("findEvent")
@ResponseBody
public JSONObject findEvent(){
Integer total = orderService.findTotalOrder();
Integer deliver = orderService.findTotalDeliverOrder();
JSONObject obj = new JSONObject();
obj.put("total",total);
obj.put("delever",deliver);
return obj;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于SSM实现的网上手机商城设计与实现源码+项目说明.zip 功能: 前台 登录、注册、注销 查看商品、商品评论、热销商品 收藏、取消收藏商品 加入购物车 购物车增、删、改、查 购买商品、确认收货、删除已完成订单 评价已确认收货的商品,带评分和多图片上传 修改个人资料、修改头像 用户中心: 收藏中心:取消收藏、加入购物车 订单中心:根据订单状态查看订单:待付款、待发货、待收货、待评价、完成 地址管理:收货地址的增、删、改、查 账号安全:修改密码 后台 主页:利用Echarts图标展示商品分类销量排行、统计销售额及订单量、待办事件、手机销量排行 待办事件: 总订单量、待发货量 商品分类销量排行: 显示不同类型手机的销量 销售额及订单量趋势: 根据月份统计销售额及订单量 手机销量排行: 显示销量排行前十的手机及其销量 商品管理:商品的增、删、改、查,按名称搜索商品、批量删除 订单管理:查看所有订单、删除、修改订单信息、发货、条件查询(订单日期、状态) 用户管理:用户的查看、删除、修改、禁用、搜索 轮播图管理:前台首页轮播图的增、删、改、查、禁用 评论管理:评论的查看、删除、关键词搜索
资源推荐
资源详情
资源评论
收起资源包目录
基于SSM实现的网上手机商城设计与实现源码+项目说明.zip (889个子文件)
OrderController.class 10KB
OrderController.class 10KB
GoodsController.class 8KB
GoodsController.class 8KB
UserController.class 7KB
UserController.class 7KB
EvaluateController.class 7KB
EvaluateController.class 7KB
OrderServiceImp.class 6KB
OrderServiceImp.class 6KB
GoodsServiceImp.class 6KB
GoodsServiceImp.class 6KB
AdminController.class 6KB
AdminController.class 6KB
BannerController.class 5KB
BannerController.class 5KB
CartController.class 5KB
CartController.class 5KB
Order.class 4KB
Order.class 4KB
AddressController.class 4KB
AddressController.class 4KB
Goods.class 4KB
Goods.class 4KB
Evaluate.class 4KB
Evaluate.class 4KB
EvaluateServiceImp.class 4KB
EvaluateServiceImp.class 4KB
GoodsTypeController.class 4KB
GoodsTypeController.class 4KB
GoodsTypeServiceImp.class 4KB
GoodsTypeServiceImp.class 4KB
AdminServiceImp.class 3KB
AdminServiceImp.class 3KB
UserServiceImp.class 3KB
UserServiceImp.class 3KB
GuessController.class 3KB
GuessController.class 3KB
BannerServiceImp.class 3KB
BannerServiceImp.class 3KB
Address.class 3KB
Address.class 3KB
AddressServiceImp.class 3KB
AddressServiceImp.class 3KB
ProCityAreaServiceImp.class 3KB
ProCityAreaServiceImp.class 3KB
GoodsListener.class 3KB
GoodsListener.class 3KB
Funs.class 3KB
Funs.class 3KB
ViewController.class 2KB
ViewController.class 2KB
Admins.class 2KB
Admins.class 2KB
Users.class 2KB
Users.class 2KB
AdminLoginInteceptor.class 2KB
AdminLoginInteceptor.class 2KB
UserLoginInterceptor.class 2KB
UserLoginInterceptor.class 2KB
RedisEvaluateServiceImp.class 2KB
RedisEvaluateServiceImp.class 2KB
OrderDetail.class 2KB
OrderDetail.class 2KB
CartServiceImp.class 2KB
CartServiceImp.class 2KB
Cart.class 2KB
Cart.class 2KB
Guess.class 2KB
Guess.class 2KB
GuessServiceImp.class 2KB
GuessServiceImp.class 2KB
Role.class 2KB
Role.class 2KB
Banner.class 2KB
Banner.class 2KB
GoodsType.class 2KB
GoodsType.class 2KB
OrderSearchVO.class 2KB
OrderSearchVO.class 2KB
BannerListener.class 1KB
BannerListener.class 1KB
OrderMapper.class 1KB
OrderMapper.class 1KB
ProCityAreaController.class 1KB
ProCityAreaController.class 1KB
MD5Util.class 1KB
MD5Util.class 1KB
Evaimg.class 1KB
Evaimg.class 1KB
GoodsMapper.class 1KB
GoodsMapper.class 1KB
IGoodsService.class 1KB
IGoodsService.class 1KB
IOrderService.class 1KB
IOrderService.class 1KB
MemoryServiceImp.class 1KB
MemoryServiceImp.class 1KB
Cities.class 1KB
Cities.class 1KB
共 889 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
- sacnf改不过来呀2023-12-26资源质量不错,和资源描述一致,内容详细,对我很有用。
onnx
- 粉丝: 9489
- 资源: 5595
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C#ASP.NET工程项目管理源码带文档数据库 SQL2008源码类型 WebForm
- 20210203047_卢诗贝_大数据1班.rar
- GL《装成偏执狂攻略清冷师尊翻车后》作者:酸辣离蒿.txt
- C#会员管理系统源码带短信平台数据库 SQL2008源码类型 WebForm
- 企业创新数据90-23年.dta
- AI一键扣图,一键去背景
- C++线程池、C++11标准库线程制作的线程池
- 同城定位付费进群完整源码+对接支付/详细教程/可用无问题
- C#CS框架小区物业管理系统源码数据库 Access源码类型 WinForm
- Alibaba-Dragonwell-Extended-21.0.5.0.5.9-x64-windows.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功