2025-03-25 18:03:57 +08:00
|
|
|
package com.ruoyi.web.app;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
2025-03-26 18:05:24 +08:00
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
2025-03-25 18:03:57 +08:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import com.ruoyi.bst.order.domain.OrderQuery;
|
|
|
|
import com.ruoyi.bst.order.domain.OrderVO;
|
|
|
|
import com.ruoyi.bst.order.domain.dto.OrderCalcPrePriceDTO;
|
|
|
|
import com.ruoyi.bst.order.domain.dto.OrderCreateDTO;
|
2025-03-26 18:05:24 +08:00
|
|
|
import com.ruoyi.bst.order.domain.dto.OrderPayDTO;
|
2025-03-25 18:03:57 +08:00
|
|
|
import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO;
|
|
|
|
import com.ruoyi.bst.order.service.OrderConverter;
|
|
|
|
import com.ruoyi.bst.order.service.OrderService;
|
2025-03-26 18:05:24 +08:00
|
|
|
import com.ruoyi.bst.order.service.OrderValidator;
|
2025-03-25 18:03:57 +08:00
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
2025-03-26 18:05:24 +08:00
|
|
|
import com.ruoyi.common.utils.ServiceUtil;
|
2025-03-25 18:03:57 +08:00
|
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/app/order")
|
|
|
|
public class AppOrderController extends BaseController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private OrderService orderService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private OrderConverter orderConverter;
|
|
|
|
|
2025-03-26 18:05:24 +08:00
|
|
|
@Autowired
|
|
|
|
private OrderValidator orderValidator;
|
|
|
|
|
2025-03-25 18:03:57 +08:00
|
|
|
@ApiOperation("获取我的订单列表")
|
|
|
|
@GetMapping("/mineList")
|
|
|
|
public TableDataInfo getMineList(OrderQuery query) {
|
|
|
|
query.setUserId(getUserId());
|
|
|
|
startPage();
|
|
|
|
List<OrderVO> list = orderService.selectOrderList(query);
|
|
|
|
return getDataTable(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("获取我的订单详情")
|
|
|
|
@GetMapping("/mineDetail")
|
|
|
|
public AjaxResult getMineDetail(Long id) {
|
|
|
|
OrderQuery query = new OrderQuery();
|
|
|
|
query.setId(id);
|
|
|
|
query.setUserId(getUserId());
|
|
|
|
return success(orderService.selectOne(query));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("支付前计算订单价格")
|
|
|
|
@GetMapping("/calculatePrice")
|
|
|
|
public AjaxResult calculatePrice(@RequestBody @Validated OrderCalcPrePriceDTO dto) {
|
|
|
|
OrderPrePriceVO vo = orderConverter.toOrderPrePriceVO(dto);
|
|
|
|
if (vo == null) {
|
|
|
|
return error("计算价格失败,请检查");
|
|
|
|
}
|
|
|
|
return success(vo);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("下单")
|
|
|
|
@PostMapping
|
|
|
|
public AjaxResult createOrder(@RequestBody @Validated OrderCreateDTO dto) {
|
|
|
|
dto.setUserId(getUserId());
|
|
|
|
return success(orderService.createOrder(dto));
|
|
|
|
}
|
2025-03-26 18:05:24 +08:00
|
|
|
|
|
|
|
@ApiOperation("支付")
|
|
|
|
@PostMapping("/pay")
|
|
|
|
public AjaxResult pay(@RequestBody @Validated OrderPayDTO dto) {
|
|
|
|
// 查询订单
|
|
|
|
OrderVO order = orderService.selectOrderByNo(dto.getNo());
|
|
|
|
ServiceUtil.assertion(!orderValidator.canPay(order, getUserId()), "您无权支付ID为%s的订单", order.getId());
|
|
|
|
|
|
|
|
return success(orderService.pay(order, dto.getAppId(), dto.getChannelId()));
|
|
|
|
}
|
2025-03-25 18:03:57 +08:00
|
|
|
|
|
|
|
}
|