소스 검색

chore: auto bump version and changelog [skip ci]

iwt 1 주 전
부모
커밋
f7bc6c6e5a
3개의 변경된 파일165개의 추가작업 그리고 3개의 파일을 삭제
  1. 162 0
      cfc-backend/src/main/java/com/etotem/cfc/service/ProductOrderService.java
  2. 1 1
      cfc-web/.last_build_commit
  3. 2 2
      cfc-web/package-lock.json

+ 162 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/ProductOrderService.java

@@ -1335,4 +1335,166 @@ public class ProductOrderService {
         }
         return code.toString();
     }
+
+    /**
+     * 供应商审核修改订单(仅 pending 状态)
+     * 支持:修改单价/总价、修改配送方式、添加临时优惠券、添加赠品
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public Result<Map<String, Object>> reviewUpdate(Map<String, Object> params, Long userId) {
+        String orderNo = (String) params.get("orderNo");
+        if (orderNo == null || orderNo.isEmpty()) {
+            return Result.error("订单号不能为空");
+        }
+
+        ProductOrder order = orderMapper.selectOne(
+            new LambdaQueryWrapper<ProductOrder>().eq(ProductOrder::getOrderNo, orderNo));
+        if (order == null) {
+            return Result.error("订单不存在");
+        }
+        if (!"pending".equals(order.getStatus())) {
+            return Result.error("仅待支付订单可审核修改");
+        }
+
+        // 权限校验:供应商必须是该订单商品的 vendorId
+        Product product = productMapper.selectById(order.getProductId());
+        if (product == null || product.getVendorId() == null || !product.getVendorId().equals(userId)) {
+            return Result.error("无权操作此订单");
+        }
+
+        boolean hasChange = false;
+        StringBuilder changeLog = new StringBuilder();
+
+        // ===== 1. 修改价格 =====
+        Integer newUnitPrice = params.get("unitPrice") != null ? ((Number) params.get("unitPrice")).intValue() : null;
+        if (newUnitPrice != null && newUnitPrice >= 0) {
+            int oldPrice = order.getUnitPrice() != null ? order.getUnitPrice() : 0;
+            int oldTotal = order.getTotalAmount() != null ? order.getTotalAmount() : 0;
+            order.setUnitPrice(newUnitPrice);
+            int newTotal = newUnitPrice * (order.getQuantity() != null ? order.getQuantity() : 1);
+            order.setTotalAmount(newTotal);
+            int pointsCost = order.getPointsCost() != null ? order.getPointsCost() : 0;
+            int moneyAmount = newTotal - pointsCost - (order.getDiscountAmount() != null ? order.getDiscountAmount() : 0);
+            order.setMoneyAmount(Math.max(moneyAmount, 0));
+            hasChange = true;
+            if (oldTotal != newTotal) {
+                changeLog.append(String.format("价格:%d元 → %d元", oldTotal / 100, newTotal / 100));
+            }
+        }
+
+        // ===== 2. 修改配送方式 =====
+        Integer newDeliveryMethod = params.get("deliveryMethod") != null ? ((Number) params.get("deliveryMethod")).intValue() : null;
+        if (newDeliveryMethod != null) {
+            Integer productMethod = product.getDeliveryMethod();
+            if (productMethod == null) productMethod = 1;
+            boolean allowed;
+            switch (productMethod) {
+                case 1: allowed = newDeliveryMethod == 1; break;
+                case 2: allowed = newDeliveryMethod == 2; break;
+                case 3: allowed = newDeliveryMethod == 1 || newDeliveryMethod == 2; break;
+                case 4: allowed = newDeliveryMethod == 4; break;
+                case 5: allowed = newDeliveryMethod == 5; break;
+                default: allowed = true; break;
+            }
+            if (!allowed) {
+                return Result.error("该商品不支持此配送方式");
+            }
+            if (newDeliveryMethod.equals(order.getDeliveryMethod())) {
+                // 未变更,跳过
+            } else {
+                int oldMethod = order.getDeliveryMethod() != null ? order.getDeliveryMethod() : 1;
+                order.setDeliveryMethod(newDeliveryMethod);
+                hasChange = true;
+                changeLog.append(String.format("配送方式:%d → %d", oldMethod, newDeliveryMethod));
+            }
+        }
+
+        // ===== 3. 添加临时优惠券 =====
+        Integer couponValue = params.get("couponValue") != null ? ((Number) params.get("couponValue")).intValue() : null;
+        Long existingCouponId = order.getCouponId();
+        if (couponValue != null && couponValue > 0 && existingCouponId == null) {
+            Coupon tempCoupon = new Coupon();
+            tempCoupon.setName("供应商临时券-" + orderNo);
+            tempCoupon.setType("ONE_TIME");
+            tempCoupon.setValue(couponValue);
+            tempCoupon.setMinSpend(0);
+            tempCoupon.setDiscountRate(null);
+            tempCoupon.setProductId(order.getProductId());
+            tempCoupon.setStatus("ACTIVE");
+            tempCoupon.setValidFrom(new Date());
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(order.getCancelAt() != null ? order.getCancelAt() : new Date());
+            cal.add(Calendar.DAY_OF_MONTH, 7);
+            tempCoupon.setValidUntil(cal.getTime());
+            couponMapper.insert(tempCoupon);
+            order.setCouponId(tempCoupon.getId());
+            order.setDiscountAmount(couponValue);
+            int pointsCost = order.getPointsCost() != null ? order.getPointsCost() : 0;
+            int moneyAmount = order.getTotalAmount() - pointsCost - couponValue;
+            order.setMoneyAmount(Math.max(moneyAmount, 0));
+            // Grant to buyer's family
+            if (order.getFamilyId() != null) {
+                FamilyCoupon fc = new FamilyCoupon();
+                fc.setFamilyId(order.getFamilyId());
+                fc.setCouponId(tempCoupon.getId());
+                fc.setStatus("AVAILABLE");
+                fc.setReceivedAt(new Date());
+                fc.setOrderId(order.getId());
+                familyCouponMapper.insert(fc);
+            }
+            hasChange = true;
+            changeLog.append(String.format("新增优惠券:减免%d元", couponValue / 100));
+        }
+
+        // ===== 4. 添加赠品 =====
+        List<Map<String, Object>> giftItems = (List<Map<String, Object>>) params.get("giftItems");
+        if (giftItems != null && !giftItems.isEmpty()) {
+            for (Map<String, Object> gift : giftItems) {
+                Long giftProductId = gift.get("giftProductId") != null ? ((Number) gift.get("giftProductId")).longValue() : null;
+                String giftProductName = (String) gift.get("giftProductName");
+                String giftProductImage = (String) gift.get("giftProductImage");
+                Integer quantity = gift.get("quantity") != null ? ((Number) gift.get("quantity")).intValue() : 1;
+
+                ProductOrderGift orderGift = new ProductOrderGift();
+                orderGift.setOrderId(order.getId());
+                orderGift.setOrderNo(order.getOrderNo());
+                orderGift.setGiftType("product");
+                orderGift.setGiftProductId(giftProductId);
+                orderGift.setGiftProductName(giftProductName);
+                orderGift.setGiftProductImage(giftProductImage);
+                orderGift.setCfValue(0);
+                orderGift.setQuantity(quantity);
+                orderGift.setFulfilled(0);
+                orderGift.setCreatedAt(new Date());
+                productOrderGiftMapper.insert(orderGift);
+
+                hasChange = true;
+                changeLog.append(String.format("新增赠品:%s x%d",
+                    giftProductName != null ? giftProductName : "赠品", quantity));
+            }
+        }
+
+        // ===== 5. 更新备注 =====
+        String remark = (String) params.get("remark");
+        if (remark != null && !remark.isEmpty()) {
+            if (order.getRemark() != null && !order.getRemark().isEmpty()) {
+                order.setRemark(order.getRemark() + " | " + remark);
+            } else {
+                order.setRemark(remark);
+            }
+        } else if (hasChange) {
+            order.setRemark("供应商审核修改: " + changeLog.toString());
+        }
+
+        // ===== 6. 更新订单时间 =====
+        order.setUpdatedAt(new Date());
+        orderMapper.updateById(order);
+
+        // ===== 7. 组装返回 =====
+        ProductOrderDTO dto = ProductOrderDTO.from(order);
+        Map<String, Object> result = new HashMap<>();
+        result.put("order", dto);
+        result.put("changeLog", changeLog.toString());
+        return Result.success(result);
+    }
 }

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-494f64d351f2aed3b5800fcda547decbfdfdb69e
+b9af694815111bfd98502e453e9578ae87be6f7e

+ 2 - 2
cfc-web/package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "cfc-web",
-  "version": "1.0.1381",
+  "version": "1.0.1382",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "cfc-web",
-      "version": "1.0.1381",
+      "version": "1.0.1382",
       "dependencies": {
         "@wangeditor/editor": "^5.1.23",
         "@wangeditor/editor-for-vue": "^1.0.2",