CommonController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Client\CommonService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * @group 用户端-公共管理
  8. *
  9. * 公共相关的API接口
  10. */
  11. class CommonController extends Controller
  12. {
  13. protected CommonService $service;
  14. public function __construct(CommonService $service)
  15. {
  16. $this->service = $service;
  17. }
  18. /**
  19. * 获取代理商配置
  20. *
  21. * 获取指定代理商的配置信息
  22. *
  23. * @authenticated
  24. *
  25. * @bodyParam agent_id int required 代理商ID. Example: 1
  26. *
  27. * @response {
  28. * "min_distance": 0,
  29. * "min_fee": 0,
  30. * "per_km_fee": 0
  31. * }
  32. */
  33. public function getConfig(Request $request)
  34. {
  35. $agentId = $request->input('agent_id');
  36. return $this->service->getAgentConfig($agentId);
  37. }
  38. /**
  39. * 获取技师配置
  40. *
  41. * 获取指定技师的配置信息
  42. *
  43. * @authenticated
  44. *
  45. * @bodyParam coach_id int required 技师ID. Example: 1
  46. *
  47. * @response {
  48. * "delivery_fee_type": "round_trip",
  49. * "charge_delivery_fee": true
  50. * }
  51. */
  52. public function getCoachConfig(Request $request)
  53. {
  54. $coachId = $request->input('coach_id');
  55. return $this->service->getCoachConfig($coachId);
  56. }
  57. /**
  58. * 计算路费金额
  59. *
  60. * 根据距离和其他参数计算路费
  61. *
  62. * @authenticated
  63. *
  64. * @bodyParam coach_id int required 技师ID. Example: 1
  65. * @bodyParam agent_id int 可选 代理商ID. Example: 1
  66. * @bodyParam distance float required 距离. Example: 10.5
  67. * @bodyParam latitude float 纬度. Example: 34.0522
  68. * @bodyParam longitude float 经度. Example: -118.2437
  69. *
  70. * @response {
  71. * "fee": 15.75
  72. * }
  73. */
  74. public function calculateDeliveryFee(Request $request)
  75. {
  76. $coachId = $request->input('coach_id');
  77. $agentId = $request->input('agent_id');
  78. $distance = $request->input('distance');
  79. $latitude = $request->input('latitude');
  80. $longitude = $request->input('longitude');
  81. if ($agentId) {
  82. return $this->service->calculateDeliveryFee($coachId, $agentId, $distance);
  83. } else {
  84. return $this->service->calculateDeliveryFeeByLocation($coachId, $latitude, $longitude, $distance);
  85. }
  86. }
  87. }