目录
- 一、商家端订单管理模块
- 1、查看历史订单
- 2、查询订单详情
- 3、取消订单
- 4、再来一单
- 5、代码开发
- 6、测试
- 二、用户端历史订单模块
- 1、订单搜索
- 2、各个状态的订单数量统计
- 3、查询订单详情
- 4、接单
- 5、拒单
- 6、取消订单
- 7、派送订单
- 8、完成订单
- 9、代码开发
- 10、测试
- 三、校验收货地址是否超出配送范围
一、商家端订单管理模块
商家端订单管理模块:
- 订单搜索
- 各个状态的订单数量统计
- 查询订单详情
- 接单
- 拒单
- 取消订单
- 派送订单
- 完成订单
1、查看历史订单
业务规则
- 分页查询历史订单
- 可以根据订单状态查询
- 展示订单数据时,需要展示的数据包括:下单时间、订单状态、订单金额、订单明细(商品名称、图片)
接口设计
2、查询订单详情
接口设计:
3、取消订单
业务规则:
- 待支付和待接单状态下,用户可直接取消订单
- 商家已接单状态下,用户取消订单需电话沟通商家
- 派送中状态下,用户取消订单需电话沟通商家
- 如果在待接单状态下取消订单,需要给用户退款
- 取消订单后需要将订单状态修改为“已取消”
接口设计:
4、再来一单
5、代码开发
OrderController:
package com.sky.controller.user;import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "用户端订单相关接口")
public class OrderController {@Autowiredprivate OrderService orderService;/*** 用户下单* @param ordersSubmitDTO* @return*/@PostMapping("/submit")@ApiOperation("用户下单")public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);return Result.success(orderSubmitVO);}/*** 历史订单查询* @param page* @param pageSize* @param status* @return*/@GetMapping("/historyOrders")@ApiOperation("历史订单查询")public Result<PageResult> page(int page, int pageSize, Integer status){PageResult pageResult = orderService.pageQueryUser(page, pageSize, status);return Result.success(pageResult);}/*** 查看订单详情* @param id* @return*/@GetMapping("/orderDetail/{id}")@ApiOperation("查询订单详情")public Result<OrderVO> details(@PathVariable("id") Long id){OrderVO orderVO = orderService.details(id);return Result.success(orderVO);}/*** 取消订单* @param id* @return*/@PutMapping("cancel/{id}")@ApiOperation("取消订单")public Result cancel(@PathVariable("id") Long id){orderService.cancelById(id);return Result.success();}/*** 再来一单* @param id* @return*/@PostMapping("/repetition/{id}")@ApiOperation("再来一单")public Result repetition(@PathVariable("id") Long id){orderService.repetitionById(id);return Result.success();}/*** 客户催单* @param id* @return*/@GetMapping("/reminder/{id}")@ApiOperation("客户催单")public Result reminder(@PathVariable("id") Long id){orderService.reminder(id);return Result.success();}
}
OrderService:
package com.sky.service;import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;public interface OrderService {/*** 添加订单* @param ordersSubmitDTO* @return*/OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO);/*** 客户催单* @param id*/void reminder(Long id);/*** 订单分页查询* @param page* @param pageSize* @param status* @return*/PageResult pageQueryUser(int page, int pageSize, Integer status);/*** 查询订单详情* @param id* @return*/OrderVO details(Long id);/*** 取消订单* @param id*/void cancelById(Long id);/*** 再来一单* @param id*/void repetitionById(Long id);
}
OrderServiceImpl
package com.sky.service.impl;import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant;
import com.sky.context.BaseContext;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.AddressBook;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.entity.ShoppingCart;
import com.sky.exception.AddressBookBusinessException;
import com.sky.exception.OrderBusinessException;
import com.sky.exception.ShoppingCartBusinessException;
import com.sky.mapper.AddressBookMapper;
import com.sky.mapper.OrderDetailMapper;
import com.sky.mapper.OrderMapper;
import com.sky.mapper.ShoppingCartMapper;
import com.sky.result.PageResult;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.websocket.WebSocketServer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;@Service
public class OrderServiceImpl implements OrderService {@Autowiredprivate OrderMapper orderMapper;@Autowiredprivate OrderDetailMapper orderDetailMapper;@Autowiredprivate AddressBookMapper addressBookMapper;@Autowiredprivate ShoppingCartMapper shoppingCartMapper;@Autowiredprivate WebSocketServer webSocketServer;/*** 用户下单* @param ordersSubmitDTO* @return*/@Transactionalpublic OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO) {//处理各种异常(地址为空,购物车为空)AddressBook addressBook = addressBookMapper.getById(ordersSubmitDTO.getAddressBookId());if(addressBook == null){//抛出业务异常throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);}Long userId = BaseContext.getCurrentId();ShoppingCart shoppingCart = new ShoppingCart();shoppingCart.setUserId(userId);List<ShoppingCart> shoppingCartList = shoppingCartMapper.list(shoppingCart);if(shoppingCartList == null || shoppingCartList.size() == 0){//抛出异常throw new ShoppingCartBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);}//向订单表插入一条数据Orders order = new Orders();BeanUtils.copyProperties(ordersSubmitDTO, order);order.setOrderTime(LocalDateTime.now());order.setPayStatus(Orders.UN_PAID);order.setStatus(Orders.PENDING_PAYMENT);order.setNumber(String.valueOf(System.currentTimeMillis()));order.setPhone(addressBook.getPhone());order.setUserId(userId);orderMapper.insert(order);//向订单明细表插入n条数据List<OrderDetail> orderDetailList = new ArrayList<>();shoppingCartList.forEach(cart -> {OrderDetail orderDetail = new OrderDetail();BeanUtils.copyProperties(cart, orderDetail);orderDetail.setOrderId(order.getId());orderDetailList.add(orderDetail);});orderDetailMapper.insertBactch(orderDetailList);//清空用户购物车数据shoppingCartMapper.deleteByUserId(userId);//封装VO返回结果Map map = new HashMap();map.put("type", 1);//1表示来单提醒 2表示客户催单map.put("orderId", order.getId());map.put("content", "订单号:" + order.getNumber());String json = JSON.toJSONString(map);webSocketServer.sendToAllClient(json);return OrderSubmitVO.builder().id(order.getId()).orderTime(order.getOrderTime()).orderNumber(order.getNumber()).orderAmount(order.getAmount()).build();}/*** 客户催单* @param id*/@Overridepublic void reminder(Long id) {//根据id查询是否有订单Orders ordersDB = orderMapper.getById(id);if(ordersDB == null){throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);}Map map = new HashMap();map.put("type", 1);//1表示来单提醒 2表示客户催单map.put("orderId", id);map.put("content", "订单号:" + ordersDB.getNumber());//通过websocket向客户端浏览器推送消息webSocketServer.sendToAllClient(JSON.toJSONString(map));}/*** 订单分页查询* @param pageNum* @param pageSize* @param status* @return*/@Overridepublic PageResult pageQueryUser(int pageNum, int pageSize, Integer status) {// 设置分页PageHelper.startPage(pageNum, pageSize);OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();ordersPageQueryDTO.setUserId(BaseContext.getCurrentId());ordersPageQueryDTO.setStatus(status);// 分页条件查询Page<Orders> page = orderMapper.pageQuery(ordersPageQueryDTO);List<OrderVO> list = new ArrayList();// 查询出订单明细,并封装入OrderVO进行响应if (page != null && page.getTotal() > 0) {for (Orders orders : page) {Long orderId = orders.getId();// 订单id// 查询订单明细List<OrderDetail> orderDetails = orderDetailMapper.getByOrderId(orderId);OrderVO orderVO = new OrderVO();BeanUtils.copyProperties(orders, orderVO);orderVO.setOrderDetailList(orderDetails);list.add(orderVO);}}return new PageResult(page.getTotal(), list);}/*** 查询订单详情* @param id* @return*/@Overridepublic OrderVO details(Long id) {//根据id查询订单Orders order = orderMapper.getById(id);//查询订单菜品详情List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(id);//封装为orderVO返回OrderVO orderVO = new OrderVO();BeanUtils.copyProperties(order, orderVO);orderVO.setOrderDetailList(orderDetailList);return orderVO;}@Overridepublic void cancelById(Long id) {//根据id查询菜单Orders order = orderMapper.getById(id);if(order == null){throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);}//订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消if (order.getStatus() > 2) {throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);}Orders orders = new Orders();orders.setId(order.getId());//订单处于待接单状态下取消,需要退款//这里由于没做支付功能,所以当订单状态为1 2 时都默认取消//更新订单状态,取消原因,取消时间orders.setStatus(Orders.CANCELLED);orders.setCancelReason("用户取消");orders.setCancelTime(LocalDateTime.now());orderMapper.update(orders);}/*** 再来一单* @param id*/@Overridepublic void repetitionById(Long id) {//再来一单:需要把订单中的数据重新回显到购物车,用户再点击购买结算Long userId = BaseContext.getCurrentId();//根据订单id查询订单的详情菜品List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(id);// 将订单详情对象转换为购物车对象List<ShoppingCart> shoppingCartList = orderDetailList.stream().map(x -> {ShoppingCart shoppingCart = new ShoppingCart();//将原订单中的菜品信息放入购物车BeanUtils.copyProperties(x, shoppingCart, "id");shoppingCart.setUserId(userId);shoppingCart.setCreateTime(LocalDateTime.now());return shoppingCart;}).collect(Collectors.toList());//购物车数据批量插入shoppingCartMapper.insertBatch(shoppingCartList);}
}
OrderMapper:
package com.sky.mapper;import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;import java.time.LocalDateTime;
import java.util.List;@Mapper
public interface OrderMapper {/*** 像订单表中插入数据* @param order*/void insert(Orders order);/*** 根据订单状态下单时间查询订单* @param status* @param orderTime* @return*/@Select("select * from orders where status = #{status} and order_time < #{orderTime}")List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);/*** 根据id查询订单* @param id* @return*/@Select("select * from orders where id = #{id}")Orders getById(Long id);/*** 分页条件查询并按下单时间排序* @param ordersPageQueryDTO*/Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);/*** 跟新订单* @param orders*/void update(Orders orders);
}
OrderMapper.XML:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.OrderMapper"><insert id="insert" parameterType="Orders" useGeneratedKeys="true" keyProperty="id">insert into orders(number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark,phone, address, consignee, estimated_delivery_time, delivery_status, pack_amount, tableware_number,tableware_status)values (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod},#{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{consignee},#{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})</insert><update id="update" parameterType="com.sky.entity.Orders">update orders<set><if test="cancelReason != null and cancelReason!='' ">cancel_reason=#{cancelReason},</if><if test="rejectionReason != null and rejectionReason!='' ">rejection_reason=#{rejectionReason},</if><if test="cancelTime != null">cancel_time=#{cancelTime},</if><if test="payStatus != null">pay_status=#{payStatus},</if><if test="payMethod != null">pay_method=#{payMethod},</if><if test="checkoutTime != null">checkout_time=#{checkoutTime},</if><if test="status != null">status = #{status},</if><if test="deliveryTime != null">delivery_time = #{deliveryTime}</if></set>where id = #{id}</update><select id="pageQuery" resultType="Orders">select * from orders<where><if test="number != null and number!=''">and number like concat('%',#{number},'%')</if><if test="phone != null and phone!=''">and phone like concat('%',#{phone},'%')</if><if test="userId != null">and user_id = #{userId}</if><if test="status != null">and status = #{status}</if><if test="beginTime != null">and order_time >= #{beginTime}</if><if test="endTime != null">and order_time <= #{endTime}</if></where>order by order_time desc</select>
</mapper>
OrderDetailMapper.XML:
package com.sky.mapper;import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;import java.util.List;@Mapper
public interface OrderDetailMapper {/*** 批量插入订单明显* @param orderDetailList*/void insertBactch(List<OrderDetail> orderDetailList);/*** 根据订单id查询订单明细* @param orderId* @return*/@Select("select * from order_detail where order_id = #{orderId}")List<OrderDetail> getByOrderId(Long orderId);
}
6、测试
点击查看订单,可以看到下面都已经回显出了套餐
点击历史订单
查看订单详情
点击再来一单,跳转到购物车页面,并且购物车有相同的订单
点击取消订单
可以看到订单取消
对应状态修改
二、用户端历史订单模块
用户端历史订单模块:
- 查询历史订单
- 查询订单详情
- 取消订单
- 再来一单
1、订单搜索
业务规则:
- 输入订单号/手机号进行搜索,支持模糊搜索
- 根据订单状态进行筛选
- 下单时间进行时间筛选
- 搜索内容为空,提示未找到相关订单
- 搜索结果页,展示包含搜索关键词的内容
- 分页展示搜索到的订单数据
接口设计:
2、各个状态的订单数量统计
接口设计:
DTO设计:
3、查询订单详情
业务规则:
- 订单详情页面需要展示订单基本信息(状态、订单号、下单时间、收货人、电话、收货地址、金额等)
- 订单详情页面需要展示订单明细数据(商品名称、数量、单价)
4、接单
业务规则:
- 商家接单其实就是将订单的状态修改为“已接单”
DTO:
5、拒单
业务规则:
- 商家拒单其实就是将订单状态修改为“已取消”
- 只有订单处于“待接单”状态时可以执行拒单操作
- 商家拒单时需要指定拒单原因
- 商家拒单时,如果用户已经完成了支付,需要为用户退款
6、取消订单
业务规则:
- 取消订单其实就是将订单状态修改为“已取消”
- 商家取消订单时需要指定取消原因
- 商家取消订单时,如果用户已经完成了支付,需要为用户退款
7、派送订单
业务规则:
- 派送订单其实就是将订单状态修改为“派送中”
- 只有状态为“待派送”的订单可以执行派送订单操作
8、完成订单
业务规则:
- 完成订单其实就是将订单状态修改为“已完成”
- 只有状态为“派送中”的订单可以执行订单完成操作
9、代码开发
OrderController:在admin下创建
package com.sky.controller.admin;import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api("订单管理接口")
public class OrderController {@Autowiredprivate OrderService orderService;/*** 订单搜索* @param ordersPageQueryDTO* @return*/@GetMapping("/conditionSearch")@ApiOperation("订单搜索")public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);return Result.success(pageResult);}/*** 各个状态的订单数量统计* @return*/@GetMapping("/statistics")@ApiOperation("各个状态的订单数量查询")public Result<OrderStatisticsVO> statistics(){OrderStatisticsVO orderStatisticsVO = orderService.statistics();return Result.success(orderStatisticsVO);}/*** 查询订单详情* @param id* @return*/@GetMapping("/details/{id}")@ApiOperation("订单详情")public Result<OrderVO> details(@PathVariable("id") Long id){OrderVO orderVO = orderService.details(id);return Result.success(orderVO);}/*** 接单* @param ordersConfirmDTO* @return*/@PutMapping("/confirm")@ApiOperation("接单")public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){orderService.confirm(ordersConfirmDTO);return Result.success();}/*** 拒单* @param ordersRejectionDTO* @return* @throws Exception*/@PutMapping("/rejection")@ApiOperation("拒单")public Result rejection (@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception{orderService.rejection(ordersRejectionDTO);return Result.success();}/*** 取消订单** @return*/@PutMapping("/cancel")@ApiOperation("取消订单")public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {orderService.cancel(ordersCancelDTO);return Result.success();}/*** 派送订单** @return*/@PutMapping("/delivery/{id}")@ApiOperation("派送订单")public Result delivery(@PathVariable("id") Long id) {orderService.delivery(id);return Result.success();}/*** 完成订单** @return*/@PutMapping("/complete/{id}")@ApiOperation("完成订单")public Result complete(@PathVariable("id") Long id) {orderService.complete(id);return Result.success();}
}
OrderService:
/*** 订单搜索* @param ordersPageQueryDTO* @return*/PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);/*** 统计各个状态的订单数量* @return*/OrderStatisticsVO statistics();/*** 接单* @param ordersConfirmDTO*/void confirm(OrdersConfirmDTO ordersConfirmDTO);/*** 拒单* @param ordersRejectionDTO*/void rejection(OrdersRejectionDTO ordersRejectionDTO);/*** 取消订单* @param ordersCancelDTO*/void cancel(OrdersCancelDTO ordersCancelDTO);/*** 派送订单* @param id*/void delivery(Long id);/*** 完成订单* @param id*/void complete(Long id);
OrderServiceImpl:
/*** 订单搜索* @param ordersPageQueryDTO* @return*/@Overridepublic PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {PageHelper.startPage(ordersPageQueryDTO.getPage(),ordersPageQueryDTO.getPageSize());Page<Orders> page = orderMapper.pageQuery(ordersPageQueryDTO);// 部分订单状态,需要额外返回订单菜品信息,将Orders转化为OrderVOList<OrderVO> orderVOList = getOrderVOList(page);return new PageResult(page.getTotal(), orderVOList);}private List<OrderVO> getOrderVOList(Page<Orders> page) {// 需要返回订单菜品信息,自定义OrderVO响应结果List<OrderVO> orderVOList = new ArrayList<>();List<Orders> ordersList = page.getResult();if (!CollectionUtils.isEmpty(ordersList)) {for (Orders orders : ordersList) {// 将共同字段复制到OrderVOOrderVO orderVO = new OrderVO();BeanUtils.copyProperties(orders, orderVO);String orderDishes = getOrderDishesStr(orders);// 将订单菜品信息封装到orderVO中,并添加到orderVOListorderVO.setOrderDishes(orderDishes);orderVOList.add(orderVO);}}return orderVOList;}/*** 根据订单id获取菜品信息字符串** @param orders* @return*/private String getOrderDishesStr(Orders orders) {// 查询订单菜品详情信息(订单中的菜品和数量)List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());// 将每一条订单菜品信息拼接为字符串(格式:宫保鸡丁*3;)List<String> orderDishList = orderDetailList.stream().map(x -> {String orderDish = x.getName() + "*" + x.getNumber() + ";";return orderDish;}).collect(Collectors.toList());// 将该订单对应的所有菜品信息拼接在一起return String.join("", orderDishList);}/*** 各个状态的订单数量* @return*/@Overridepublic OrderStatisticsVO statistics() {//根据状态,查询订单Integer toBeConfirmed = orderMapper.countStatus(Orders.TO_BE_CONFIRMED);Integer confirmed = orderMapper.countStatus(Orders.CONFIRMED);Integer deliveryInProgress = orderMapper.countStatus(Orders.DELIVERY_IN_PROGRESS);// 将查询出的数据封装到orderStatisticsVO中响应OrderStatisticsVO orderStatisticsVO = new OrderStatisticsVO();orderStatisticsVO.setToBeConfirmed(toBeConfirmed);orderStatisticsVO.setConfirmed(confirmed);orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);return orderStatisticsVO;}/*** 接单* @param ordersConfirmDTO*/@Overridepublic void confirm(OrdersConfirmDTO ordersConfirmDTO) {Orders orders = Orders.builder().id(ordersConfirmDTO.getId()).status(Orders.CONFIRMED).build();orderMapper.update(orders);}/*** 拒单* @param ordersRejectionDTO*/@Overridepublic void rejection(OrdersRejectionDTO ordersRejectionDTO) {// 根据id查询订单Orders ordersDB = orderMapper.getById(ordersRejectionDTO.getId());// 订单只有存在且状态为2(待接单)才可以拒单if (ordersDB == null || !ordersDB.getStatus().equals(Orders.TO_BE_CONFIRMED)) {throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);}Orders orders = Orders.builder().id(ordersRejectionDTO.getId()).status(Orders.CANCELLED).rejectionReason(ordersRejectionDTO.getRejectionReason()).cancelTime(LocalDateTime.now()).build();orderMapper.update(orders);}/*** 取消订单** @param ordersCancelDTO*/public void cancel(OrdersCancelDTO ordersCancelDTO){// 管理端取消订单需要退款,根据订单id更新订单状态、取消原因、取消时间Orders orders = new Orders();orders.setId(ordersCancelDTO.getId());orders.setStatus(Orders.CANCELLED);orders.setCancelReason(ordersCancelDTO.getCancelReason());orders.setCancelTime(LocalDateTime.now());orderMapper.update(orders);}/*** 派送订单** @param id*/public void delivery(Long id) {// 根据id查询订单Orders ordersDB = orderMapper.getById(id);// 校验订单是否存在,并且状态为3if (ordersDB == null || !ordersDB.getStatus().equals(Orders.CONFIRMED)) {throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);}Orders orders = new Orders();orders.setId(ordersDB.getId());// 更新订单状态,状态转为派送中orders.setStatus(Orders.DELIVERY_IN_PROGRESS);orderMapper.update(orders);}/*** 完成订单** @param id*/public void complete(Long id) {// 根据id查询订单Orders ordersDB = orderMapper.getById(id);// 校验订单是否存在,并且状态为4if (ordersDB == null || !ordersDB.getStatus().equals(Orders.DELIVERY_IN_PROGRESS)) {throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);}Orders orders = new Orders();orders.setId(ordersDB.getId());// 更新订单状态,状态转为完成orders.setStatus(Orders.COMPLETED);orders.setDeliveryTime(LocalDateTime.now());orderMapper.update(orders);}
OrderMapper:
/*** 根据状态查询* @param status* @return*/@Select("select count(id) from orders where status = #{status}")Integer countStatus(Integer status);
10、测试
进入管理端页面可以看到,当前订单信息
为了方便测试,我们多添加几个订单,并在数据库中修改订单状态,改为支付完成
接两个单
拒绝一个订单
订单取消
点击查看订单详情
点击派送订单
点击完成订单
三、校验收货地址是否超出配送范围
登录百度地图开发平台: https://lbsyun.baidu.com/
点击进入工作台
淦 没通过审核 做不了