sky-take-out/sky-server/src/main/java/com/sky/controller/user/OrderController.java

111 lines
3.2 KiB
Java

package com.sky.controller.user;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "用户端订单相关接口")
@Slf4j
public class OrderController {
@Resource
private OrderService orderService;
/**
* 用户下单
*
* @param ordersSubmitDTO 订单请求数据
* @return Result<OrderSubmitVO>
*/
@ApiOperation("用户下单")
@PostMapping("/submit")
public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
log.info("用户下单:{}", ordersSubmitDTO);
OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
return Result.success(orderSubmitVO);
}
/**
* 订单支付
*
* @param ordersPaymentDTO OrdersPaymentDTO
* @return Result<OrderPaymentVO>
*/
@PutMapping("/payment")
@ApiOperation("订单支付")
public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
log.info("订单支付:{}", ordersPaymentDTO);
OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
// TODO 跳过微信支付
orderService.paySuccess(ordersPaymentDTO.getOrderNumber());
log.info("生成预支付交易单:{}", orderPaymentVO);
return Result.success(orderPaymentVO);
}
/**
* 客户催单
*
* @param id Long
* @return Result<String>
*/
@ApiOperation("客户催单")
@GetMapping("/reminder/{id}")
public Result<String> reminder(@PathVariable("id") Long id) {
orderService.reminder(id);
return Result.success();
}
/**
* 历史订单查询
*
* @param page 当前页
* @param pageSize 每页显示条数
* @param status 状态
* @return PageResult
*/
@ApiOperation("历史订单查询")
@GetMapping("/historyOrders")
public Result<PageResult> page(int page, int pageSize, Integer status) {
PageResult pageResult = orderService.pageQuery4User(page, pageSize, status);
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();
}
}