|
|
@@ -0,0 +1,171 @@
|
|
|
+package org.dromara.order.pc.controller;
|
|
|
+
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.log.annotation.Log;
|
|
|
+import org.dromara.common.log.enums.BusinessType;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.common.web.core.BaseController;
|
|
|
+import org.dromara.order.domain.bo.OrderMainBo;
|
|
|
+import org.dromara.order.domain.vo.OrderMainVo;
|
|
|
+import org.dromara.order.domain.vo.OrderProductVo;
|
|
|
+import org.dromara.order.domain.vo.OrderStatusStats;
|
|
|
+import org.dromara.order.service.IOrderMainService;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import jakarta.validation.constraints.NotNull;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * PC端 - 订单管理
|
|
|
+ * 前端访问路由地址为:/pc/enterprise/order
|
|
|
+ *
|
|
|
+ * @author Claude
|
|
|
+ * @date 2026-01-28
|
|
|
+ */
|
|
|
+@Validated
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RestController
|
|
|
+@RequestMapping("/pc/enterprise/order")
|
|
|
+public class PcOrderController extends BaseController {
|
|
|
+
|
|
|
+ private final IOrderMainService orderMainService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前企业的订单列表
|
|
|
+ * PC端用户只能查询自己企业的订单
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ public TableDataInfo<OrderMainVo> list(OrderMainBo bo, PageQuery pageQuery) {
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+ // 强制设置企业ID,防止越权访问
|
|
|
+ bo.setCustomerId(customerId);
|
|
|
+
|
|
|
+ return orderMainService.queryPageList(bo, pageQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前企业的订单状态统计
|
|
|
+ * 返回各状态订单数量
|
|
|
+ */
|
|
|
+ @GetMapping("/statusStats")
|
|
|
+ public R<OrderStatusStats> getStatusStats() {
|
|
|
+ return R.ok(orderMainService.queryOrderStatusStats());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单详细信息
|
|
|
+ * PC端用户只能查询自己企业的订单
|
|
|
+ *
|
|
|
+ * @param id 订单主键
|
|
|
+ */
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public R<OrderMainVo> getInfo(@NotNull(message = "主键不能为空")
|
|
|
+ @PathVariable("id") Long id) {
|
|
|
+ // 查询订单信息
|
|
|
+ OrderMainVo vo = orderMainService.queryById(id);
|
|
|
+
|
|
|
+ // 验证订单是否属于当前用户的企业
|
|
|
+ if (vo != null) {
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+ if (!customerId.equals(vo.getCustomerId())) {
|
|
|
+ return R.fail("无权访问该订单");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据订单ID查询订单商品明细
|
|
|
+ * PC端用户只能查询自己企业的订单商品
|
|
|
+ *
|
|
|
+ * @param orderIds 订单ID列表
|
|
|
+ */
|
|
|
+ @GetMapping("/products")
|
|
|
+ public TableDataInfo<OrderProductVo> getOrderProducts(@RequestParam("orderIds") List<Long> orderIds) {
|
|
|
+ if (orderIds == null || orderIds.isEmpty()) {
|
|
|
+ throw new IllegalArgumentException("订单ID列表不能为空");
|
|
|
+ }
|
|
|
+ if (orderIds.size() > 1000) {
|
|
|
+ throw new IllegalArgumentException("订单ID数量不能超过1000个");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+
|
|
|
+ // 验证所有订单是否都属于当前用户的企业
|
|
|
+ for (Long orderId : orderIds) {
|
|
|
+ OrderMainVo order = orderMainService.queryById(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ throw new IllegalArgumentException("订单ID " + orderId + " 不存在");
|
|
|
+ }
|
|
|
+ if (!customerId.equals(order.getCustomerId())) {
|
|
|
+ throw new IllegalArgumentException("无权访问订单ID " + orderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> uniqueOrderIds = new HashSet<>(orderIds);
|
|
|
+ return orderMainService.getCustomerOrderProductList(uniqueOrderIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消订单
|
|
|
+ * PC端用户只能取消自己企业的订单
|
|
|
+ *
|
|
|
+ * @param bo 订单业务对象
|
|
|
+ */
|
|
|
+ @Log(title = "PC端-订单管理", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping("/cancel")
|
|
|
+ public R<Void> cancelOrder(@RequestBody OrderMainBo bo) {
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+
|
|
|
+ // 验证订单是否属于当前用户的企业
|
|
|
+ OrderMainVo existingOrder = orderMainService.queryById(bo.getId());
|
|
|
+ if (existingOrder == null) {
|
|
|
+ return R.fail("订单不存在");
|
|
|
+ }
|
|
|
+ if (!customerId.equals(existingOrder.getCustomerId())) {
|
|
|
+ return R.fail("无权取消该订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 强制设置企业ID
|
|
|
+ bo.setCustomerId(customerId);
|
|
|
+
|
|
|
+ return toAjax(orderMainService.updateStatus(bo));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核订单
|
|
|
+ * PC端企业客户审核自己企业的订单
|
|
|
+ *
|
|
|
+ * @param bo 订单业务对象
|
|
|
+ */
|
|
|
+ @Log(title = "PC端-订单审核", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping("/checkStatus")
|
|
|
+ public R<Void> checkStatus(@RequestBody OrderMainBo bo) {
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+
|
|
|
+ // 验证订单是否属于当前用户的企业
|
|
|
+ OrderMainVo existingOrder = orderMainService.queryById(bo.getId());
|
|
|
+ if (existingOrder == null) {
|
|
|
+ return R.fail("订单不存在");
|
|
|
+ }
|
|
|
+ if (!customerId.equals(existingOrder.getCustomerId())) {
|
|
|
+ return R.fail("无权审核该订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 强制设置企业ID
|
|
|
+ bo.setCustomerId(customerId);
|
|
|
+
|
|
|
+ return toAjax(orderMainService.updateCheckStatus(bo));
|
|
|
+ }
|
|
|
+}
|