Repository navigation
feat(R): 建單前車資預估報價 API(懸而未決 #1) - #44
Merged
Merged
Conversation
POST /api/customer/rides/estimate(customer JWT,純唯讀、不建單、不寫 DB):
以全程規劃路線(起點→各停靠點→終點,含繞路)試算車資,讓乘客建單前就看到
預估,不必到行程結束才知道多少錢。多停靠點行程放大了「先搭後知價」的痛點,
這是本題主因。是預估不是定價——計費仍在完成時依實際行駛路線定格。
- service.EstimateService{osrm, fees}:與完成計費共用同一份 FeeSettings.Quote,
預估與實收落在同一套費率規則,差異只來自「規劃路線 vs 實際行駛路線」。
- 距離走既有 osrm.RouteVia(與 N5 計費同一支多點 API);OSRM 掛掉時內部退回
逐段 haversine,故預估永遠算得出近似值,不因路網引擎不可用就卡住乘客。
- 沿用 validateStops/座標驗證,不另造一套。目的地座標必填(沒終點無法路由);
車種選填(寵物車含清潔費)。多停靠點時全部站入路線(預估階段沒人被跳過)。
- 白名單輸出:fare/cleaning_fee/total/distance/duration——不回 commission/
driver_net 等內部費率(比照 FeeSettings.CustomerJSON)。
- 錯誤:座標/車種/停靠點填錯→400(沿用 createStatusForErr);未就緒→503。
驗收:service 8 案+handler 2 案綁定/授權邊界皆綠;全 repo go test ./... 無 FAIL。
尚未做:docker live E2E 對帳「預估 vs 完成實收」差異合理。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
不繞路時實收=預估(共用 FeeSettings.Quote+同一 OSRM 路線):單點 6811m 預估 22100=完成 22100;寵物車(清潔費 20%)預估 22100+4400=完成 22100+4400; App 建單 ride #24 完成卡 NT$94=同座標預估 NT$94。繞路時走 N5 max(軌跡,路線)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
App 端「懸而未決 #1」拍板:投資一支報價 API,讓乘客在建單前看到預估車資,不必到行程結束才知道多少錢。多停靠點行程(N5「車資=全程實際路線含繞路」)放大了「先搭後知價」的痛點,這是本題主因。是預估不是定價:計費仍在完成時依實際行駛路線定格。
改了什麼
POST /api/customer/rides/estimate(customer JWT,純唯讀、不建單、不寫 DB)。service.EstimateService{osrm, fees}:以全程規劃路線(起點→各停靠點→終點,含繞路)算里程,與完成計費共用同一份FeeSettings.Quote——預估與實收落在同一套費率規則,差異只來自「規劃路線 vs 實際行駛路線」。osrm.RouteVia(與 N5 計費同一支多點 API);OSRM 掛掉時內部退回逐段 haversine,故預估永遠算得出近似值,不因路網引擎不可用就卡住乘客。validateStops/座標驗證,不另造一套。目的地座標必填(沒終點無法路由);車種選填(寵物車含清潔費)。多停靠點時全部站入路線(預估階段沒人被跳過,與計費排除已跳過站刻意不同)。fare_cents/cleaning_fee_cents/total_cents/distance_m/duration_sec——不回commission/driver_net等內部費率。createStatusForErr);未就緒→503。驗收
internal/service/estimate_test.go8 案(單點/多停靠點全程入路線/寵物清潔費/缺目的地 400/非法車種/min_fare 下限/未成對停靠點/未就緒)。internal/handler/estimate_test.go2 案(授權 401/403、綁定 400、未就緒 503)。go test ./...無 FAIL。App 端對應 PR:thothawei/fleet-app 的
claude/next-todo-item-9b501a。🤖 Generated with Claude Code