DeliveryFeeController.java 1.33 KB
package com.diligrp.rider.controller;

import com.diligrp.rider.common.result.Result;
import com.diligrp.rider.dto.DeliveryFeeCalcDTO;
import com.diligrp.rider.service.DeliveryFeeService;
import com.diligrp.rider.vo.DeliveryFeeResultVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 配送费计算接口(对内中台核心接口)
 * 电商系统下单前调用此接口获取配送费
 */
@RestController
@RequestMapping("/api/delivery/fee")
@RequiredArgsConstructor
public class DeliveryFeeController {

    private final DeliveryFeeService deliveryFeeService;

    /**
     * 计算配送费
     * 入参:cityId, orderType, startLng, startLat, endLng, endLat, weight, serviceTime
     * 出参:各项费用明细 + 总费用 + 预计送达时间
     */
    @PostMapping("/calc")
    public Result<DeliveryFeeResultVO> calc(@Valid @RequestBody DeliveryFeeCalcDTO dto) {
        return Result.success(deliveryFeeService.calcFee(dto));
    }

    /**
     * 检查城市是否开通某服务
     * orderType: 1=帮我送 2=帮我取 6=外卖配送
     */
    @GetMapping("/check")
    public Result<Boolean> check(@RequestParam Long cityId, @RequestParam int orderType) {
        return Result.success(deliveryFeeService.isServiceEnabled(cityId, orderType));
    }
}