Compare commits
No commits in common. "948ab55cd40d8b6cbbb50413e2ab82f937947e2f" and "4f19af093e428784b3cabedbb6e236cecc9f12f3" have entirely different histories.
948ab55cd4
...
4f19af093e
|
@ -7,7 +7,6 @@ import com.sky.result.Result;
|
||||||
import com.sky.service.OrderService;
|
import com.sky.service.OrderService;
|
||||||
import com.sky.vo.OrderPaymentVO;
|
import com.sky.vo.OrderPaymentVO;
|
||||||
import com.sky.vo.OrderSubmitVO;
|
import com.sky.vo.OrderSubmitVO;
|
||||||
import com.sky.vo.OrderVO;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -81,30 +80,4 @@ public class OrderController {
|
||||||
PageResult pageResult = orderService.pageQuery4User(page, pageSize, status);
|
PageResult pageResult = orderService.pageQuery4User(page, pageSize, status);
|
||||||
return Result.success(pageResult);
|
return Result.success(pageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询订单详情
|
|
||||||
*
|
|
||||||
* @param id 查询订单id
|
|
||||||
* @return OrderVO
|
|
||||||
*/
|
|
||||||
@ApiOperation("查询订单详情")
|
|
||||||
@GetMapping("/orderDetail/{id}")
|
|
||||||
public Result<OrderVO> orderDetail(@PathVariable Long id) {
|
|
||||||
OrderVO orderVO = orderService.detail(id);
|
|
||||||
return Result.success(orderVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消订单
|
|
||||||
*
|
|
||||||
* @param id 订单id
|
|
||||||
* @return Result<String>
|
|
||||||
*/
|
|
||||||
@ApiOperation("取消订单")
|
|
||||||
@PutMapping("/cancel/{id}")
|
|
||||||
public Result<String> cancel(@PathVariable("id") Long id) {
|
|
||||||
orderService.userCancelById(id);
|
|
||||||
return Result.success();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,4 @@ public interface OrderMapper {
|
||||||
* @return Page<Orders>
|
* @return Page<Orders>
|
||||||
*/
|
*/
|
||||||
Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
|
Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据id查询订单
|
|
||||||
*
|
|
||||||
* @param id 订单id
|
|
||||||
* @return Orders
|
|
||||||
*/
|
|
||||||
Orders useCancelById(Long id);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.sky.dto.OrdersSubmitDTO;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.vo.OrderPaymentVO;
|
import com.sky.vo.OrderPaymentVO;
|
||||||
import com.sky.vo.OrderSubmitVO;
|
import com.sky.vo.OrderSubmitVO;
|
||||||
import com.sky.vo.OrderVO;
|
|
||||||
|
|
||||||
public interface OrderService {
|
public interface OrderService {
|
||||||
/**
|
/**
|
||||||
|
@ -47,19 +46,4 @@ public interface OrderService {
|
||||||
* @return PageResult
|
* @return PageResult
|
||||||
*/
|
*/
|
||||||
PageResult pageQuery4User(int pageNum, int pageSize, Integer status);
|
PageResult pageQuery4User(int pageNum, int pageSize, Integer status);
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询订单详情
|
|
||||||
*
|
|
||||||
* @param id 查询订单id
|
|
||||||
* @return OrderVO
|
|
||||||
*/
|
|
||||||
OrderVO detail(Long id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消订单
|
|
||||||
*
|
|
||||||
* @param id 订单id
|
|
||||||
*/
|
|
||||||
void userCancelById(Long id);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import com.sky.vo.OrderPaymentVO;
|
||||||
import com.sky.vo.OrderSubmitVO;
|
import com.sky.vo.OrderSubmitVO;
|
||||||
import com.sky.vo.OrderVO;
|
import com.sky.vo.OrderVO;
|
||||||
import com.sky.websocket.WebSocketServer;
|
import com.sky.websocket.WebSocketServer;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -33,7 +32,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
|
||||||
public class OrderServiceImpl implements OrderService {
|
public class OrderServiceImpl implements OrderService {
|
||||||
@Resource
|
@Resource
|
||||||
private OrderMapper orderMapper;
|
private OrderMapper orderMapper;
|
||||||
|
@ -77,24 +75,15 @@ public class OrderServiceImpl implements OrderService {
|
||||||
|
|
||||||
// 2. 向订单中插入1条数据
|
// 2. 向订单中插入1条数据
|
||||||
Orders orders = new Orders();
|
Orders orders = new Orders();
|
||||||
String address = addressBook.getProvinceName() + addressBook.getCityName() + addressBook.getDistrictName() + addressBook.getDetail();
|
|
||||||
BeanUtils.copyProperties(ordersSubmitDTO, orders);
|
BeanUtils.copyProperties(ordersSubmitDTO, orders);
|
||||||
orders.setOrderTime(LocalDateTime.now());
|
orders.setOrderTime(LocalDateTime.now());
|
||||||
orders.setPayStatus(Orders.UN_PAID);
|
orders.setPayStatus(Orders.UN_PAID);
|
||||||
orders.setStatus(Orders.PENDING_PAYMENT);
|
orders.setStatus(Orders.PENDING_PAYMENT);
|
||||||
orders.setNumber(String.valueOf(System.currentTimeMillis()));
|
orders.setNumber(String.valueOf(System.currentTimeMillis()));
|
||||||
orders.setPhone(addressBook.getPhone());
|
orders.setPhone(addressBook.getConsignee());
|
||||||
orders.setAddress(address);
|
|
||||||
orders.setUserName(addressBook.getConsignee());
|
|
||||||
orders.setUserId(currentId);
|
orders.setUserId(currentId);
|
||||||
String sex = addressBook.getSex();// 性别
|
|
||||||
String consignee = addressBook.getConsignee().substring(0, 1);// 姓
|
|
||||||
if (sex.equals("1")) {
|
|
||||||
orders.setConsignee(consignee + "女士");
|
|
||||||
} else {
|
|
||||||
orders.setConsignee(consignee + "先生");
|
|
||||||
}
|
|
||||||
orderMapper.insert(orders);
|
orderMapper.insert(orders);
|
||||||
|
|
||||||
ArrayList<OrderDetail> orderDetailArrayList = new ArrayList<>();
|
ArrayList<OrderDetail> orderDetailArrayList = new ArrayList<>();
|
||||||
// 3. 向订单数据插入n条数据
|
// 3. 向订单数据插入n条数据
|
||||||
for (ShoppingCart cart : shoppingCartList) {
|
for (ShoppingCart cart : shoppingCartList) {
|
||||||
|
@ -218,58 +207,6 @@ public class OrderServiceImpl implements OrderService {
|
||||||
assert page != null;
|
assert page != null;
|
||||||
return new PageResult(page.getTotal(), list);
|
return new PageResult(page.getTotal(), list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询订单详情
|
|
||||||
*
|
|
||||||
* @param id 查询订单id
|
|
||||||
* @return OrderVO
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public OrderVO detail(Long id) {
|
|
||||||
// 根据id查询订单
|
|
||||||
Orders orders = orderMapper.getById(id);
|
|
||||||
// 查询该订单对应的菜品/套餐明细
|
|
||||||
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
|
|
||||||
|
|
||||||
// 将该订单及其详情封装到OrderVO并返回
|
|
||||||
OrderVO orderVO = new OrderVO();
|
|
||||||
BeanUtils.copyProperties(orders, orderVO);
|
|
||||||
orderVO.setOrderDetailList(orderDetailList);
|
|
||||||
return orderVO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消订单
|
|
||||||
*
|
|
||||||
* @param id 订单id
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void userCancelById(Long id) {
|
|
||||||
// 根据id查询订单
|
|
||||||
Orders ordersDB = orderMapper.getById(id);
|
|
||||||
|
|
||||||
// 如果查询到的订单为空
|
|
||||||
if (ordersDB == null) {
|
|
||||||
throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
// 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消
|
|
||||||
if (ordersDB.getStatus() > 2) {
|
|
||||||
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
|
|
||||||
}
|
|
||||||
Orders orders = new Orders();
|
|
||||||
orders.setId(ordersDB.getId());
|
|
||||||
// 订单处于待接单状态下取消,需要进行退款
|
|
||||||
if (ordersDB.getStatus().equals(Orders.TO_BE_CONFIRMED)) {
|
|
||||||
log.info("订单需要退款。。。。。。。");
|
|
||||||
orders.setPayStatus(Orders.REFUND);
|
|
||||||
}
|
|
||||||
// 更新订单状态、取消原因、取消时间
|
|
||||||
orders.setStatus(Orders.CANCELLED);
|
|
||||||
orders.setCancelReason("用户取消");
|
|
||||||
orders.setCancelTime(LocalDateTime.now());
|
|
||||||
orderMapper.update(orders);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,11 +95,4 @@
|
||||||
</where>
|
</where>
|
||||||
order by order_time desc
|
order by order_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 根据id查询订单 -->
|
|
||||||
<select id="useCancelById" resultType="com.sky.entity.Orders">
|
|
||||||
select *
|
|
||||||
from orders
|
|
||||||
where id = #{id};
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue