|
|
@@ -0,0 +1,96 @@
|
|
|
+package com.zxyj.controller.assessment;
|
|
|
+
|
|
|
+import com.zxyj.common.Result;
|
|
|
+import com.zxyj.entity.AssessmentOrder;
|
|
|
+import com.zxyj.entity.AssessmentAppointment;
|
|
|
+import com.zxyj.service.AssessmentOrderService;
|
|
|
+import com.zxyj.service.AssessmentAppointmentService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Tag(name = "评估订单", description = "评估订单与支付")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/assessment/order")
|
|
|
+public class AssessmentOrderController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AssessmentOrderService orderService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AssessmentAppointmentService appointmentService;
|
|
|
+
|
|
|
+ @Operation(summary = "创建评估订单")
|
|
|
+ @PostMapping("/create")
|
|
|
+ public Result<Map<String, Object>> createOrder(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> body) {
|
|
|
+ Long familyId = Long.valueOf(body.get("familyId").toString());
|
|
|
+ Long childId = body.get("childId") != null ? Long.valueOf(body.get("childId").toString()) : null;
|
|
|
+ Long guideId = Long.valueOf(body.get("guideId").toString());
|
|
|
+ Long packageId = Long.valueOf(body.get("packageId").toString());
|
|
|
+ String guideName = body.get("guideName") != null ? body.get("guideName").toString() : null;
|
|
|
+ String packageName = body.get("packageName") != null ? body.get("packageName").toString() : null;
|
|
|
+ Long totalPrice = body.get("totalPrice") != null ? Long.valueOf(body.get("totalPrice").toString()) : 0L;
|
|
|
+ Long discountAmount = body.get("discountAmount") != null ? Long.valueOf(body.get("discountAmount").toString()) : 0L;
|
|
|
+
|
|
|
+ AssessmentOrder order = orderService.createOrder(
|
|
|
+ familyId, userId, childId, guideId, packageId,
|
|
|
+ guideName, packageName, totalPrice, discountAmount);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("orderNo", order.getOrderNo());
|
|
|
+ result.put("actualPrice", order.getActualPrice());
|
|
|
+ result.put("status", order.getStatus());
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "获取订单详情")
|
|
|
+ @PostMapping("/detail")
|
|
|
+ public Result<AssessmentOrder> getOrderDetail(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> body) {
|
|
|
+ String orderNo = body.get("orderNo") != null ? body.get("orderNo").toString() : null;
|
|
|
+ if (orderNo == null) return Result.error("订单号不能为空");
|
|
|
+ AssessmentOrder order = orderService.getByOrderNo(orderNo);
|
|
|
+ if (order == null) return Result.error("订单不存在");
|
|
|
+ if (!order.getUserId().equals(userId)) return Result.error("无权查看");
|
|
|
+ return Result.success(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "我的订单列表")
|
|
|
+ @PostMapping("/my-orders")
|
|
|
+ public Result<List<AssessmentOrder>> getMyOrders(@RequestAttribute("userId") Long userId) {
|
|
|
+ List<AssessmentOrder> orders = orderService.getByUserId(userId);
|
|
|
+ return Result.success(orders);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "支付订单")
|
|
|
+ @PostMapping("/pay")
|
|
|
+ public Result<Map<String, Object>> payOrder(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> body) {
|
|
|
+ String orderNo = body.get("orderNo") != null ? body.get("orderNo").toString() : null;
|
|
|
+ String payType = body.get("payType") != null ? body.get("payType").toString() : "wechat";
|
|
|
+ if (orderNo == null) return Result.error("订单号不能为空");
|
|
|
+
|
|
|
+ boolean success = orderService.payOrder(orderNo, payType);
|
|
|
+ if (!success) return Result.error("支付失败");
|
|
|
+
|
|
|
+ // 支付成功后确认预约
|
|
|
+ AssessmentOrder order = orderService.getByOrderNo(orderNo);
|
|
|
+ if (order != null && order.getChildId() != null) {
|
|
|
+ appointmentService.confirmAppointmentByOrder(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("orderNo", orderNo);
|
|
|
+ result.put("payTime", new Date());
|
|
|
+ result.put("status", "paid");
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+}
|