OrderController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Enums\OrderType;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\Client\OrderService;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Auth;
  8. /**
  9. * @group 用户端
  10. *
  11. * 订单相关的API接口
  12. */
  13. class OrderController extends Controller
  14. {
  15. protected OrderService $service;
  16. public function __construct(OrderService $service)
  17. {
  18. $this->service = $service;
  19. }
  20. /**
  21. * [订单]订单初始化
  22. *
  23. * 初始化订单
  24. *
  25. * @authenticated
  26. *
  27. * @bodyParam coach_id int required 技师ID. Example: 6
  28. * @bodyParam area_code string required 区划代码. Example: 370602
  29. * @bodyParam project_id int required 项目ID. Example: 1
  30. * @bodyParam latitude int 纬度. Example: 37.4219983
  31. * @bodyParam longitude int 经度. Example: 122.1347344
  32. *
  33. * @response {
  34. * "status": "success",
  35. * "data": {}
  36. * }
  37. */
  38. public function initialize(Request $request)
  39. {
  40. $data = $request->only(['coach_id', 'area_code', 'project_id', 'latitude', 'longitude']);
  41. return $this->service->initialize(Auth::user()->id, $data);
  42. }
  43. /**
  44. * [订单]创建订单
  45. *
  46. * 创建订单
  47. *
  48. * @authenticated
  49. *
  50. * @bodyParam project_id int required 项目ID. Example: 1
  51. * @bodyParam address_id int required 地址ID. Example: 1
  52. * @bodyParam coach_id int required 技师ID. Example: 6
  53. * @bodyParam use_balance boolean 使用余额. Example: false
  54. * @bodyParam service_time datetime required 服务时间. Example: 2024-01-01 10:00:00
  55. * @bodyParam order_id int 订单ID. Example: null
  56. * @bodyParam payment_type number required 支付类型. Example: 1 (1:余额,2:微信,3:支付宝)
  57. * @bodyParam order_type int required 订单类型. Example: 1
  58. *
  59. * @response {
  60. * "status": "success",
  61. * "data": {}
  62. * }
  63. */
  64. public function create(Request $request)
  65. {
  66. $data = $request->only(['project_id', 'address_id', 'coach_id', 'use_balance', 'order_id', 'service_time', 'payment_type', 'order_type']);
  67. return $this->service->createOrder(Auth::user()->id, $data);
  68. }
  69. /**
  70. * [订单]结束订单
  71. *
  72. * 结束订单
  73. *
  74. * @authenticated
  75. *
  76. * @bodyParam order_id int required 订单ID. Example: 1
  77. *
  78. * @response {
  79. * "status": "success",
  80. * "data": {}
  81. * }
  82. */
  83. public function finish(Request $request)
  84. {
  85. $userId = Auth::user()->id;
  86. $orderId = $request->input('order_id');
  87. return $this->service->finishOrder($userId, $orderId);
  88. }
  89. /**
  90. * [订单]确认技师离开
  91. *
  92. * 确认技师离开
  93. *
  94. * @authenticated
  95. *
  96. * @bodyParam order_id int required 订单ID. Example: 123
  97. *
  98. * @response {
  99. * "status": "success",
  100. * "data": {}
  101. * }
  102. */
  103. public function confirmLeave(Request $request)
  104. {
  105. $userId = Auth::user()->id;
  106. $orderId = $request->input('order_id');
  107. return $this->service->confirmLeave($userId, $orderId);
  108. }
  109. /**
  110. * [订单]取消订单
  111. *
  112. * 取消订单
  113. *
  114. * @authenticated
  115. *
  116. * @bodyParam order_id int required 订单ID. Example: 123
  117. *
  118. * @response {
  119. * "status": "success",
  120. * "data": {}
  121. * }
  122. */
  123. public function cancel(Request $request)
  124. {
  125. $userId = Auth::user()->id;
  126. $orderId = $request->input('order_id');
  127. return $this->service->cancelOrder($userId, $orderId);
  128. }
  129. /**
  130. * [订单]获取订单列表
  131. *
  132. * 获取订单列表
  133. *
  134. * @authenticated
  135. *
  136. * @response {
  137. * "status": "success",
  138. * "data": []
  139. * }
  140. */
  141. public function list()
  142. {
  143. return $this->service->getOrderList(Auth::user()->id);
  144. }
  145. /**
  146. * [订单]获取订单详情
  147. *
  148. * 获取订单详情
  149. *
  150. * @authenticated
  151. *
  152. * @urlParam id required 订单ID. Example: 6
  153. *
  154. * @response {
  155. * "status": "success",
  156. * "data": {}
  157. * }
  158. */
  159. public function detail($id)
  160. {
  161. return $this->service->getOrderDetail(Auth::user()->id, $id);
  162. }
  163. /**
  164. * [订单]订单退款
  165. *
  166. * 订单退款
  167. *
  168. * @authenticated
  169. *
  170. * @urlParam id required 订单ID. Example: 1
  171. *
  172. * @response {
  173. * "status": "success",
  174. * "data": {}
  175. * }
  176. */
  177. public function refund($id)
  178. {
  179. return $this->service->refundOrder($id);
  180. }
  181. /**
  182. * [订单]获取代理商配置
  183. *
  184. * 获取代理商配置
  185. *
  186. * @authenticated
  187. *
  188. * @bodyParam agent_id int required 代理商ID. Example: 1
  189. *
  190. * @response {
  191. * "min_distance": 0,
  192. * "min_fee": 0,
  193. * "per_km_fee": 0
  194. * }
  195. */
  196. public function getAgentConfig(Request $request)
  197. {
  198. $agentId = $request->input('agent_id');
  199. return $this->service->getAgentConfig($agentId);
  200. }
  201. /**
  202. * [订单]获取技师配置
  203. *
  204. * 获取技师配置
  205. *
  206. * @authenticated
  207. *
  208. * @bodyParam coach_id int required 技师ID. Example: 1
  209. *
  210. * @response {
  211. * "delivery_fee_type": "round_trip",
  212. * "charge_delivery_fee": true
  213. * }
  214. */
  215. public function getCoachConfig(Request $request)
  216. {
  217. $coachId = $request->input('coach_id');
  218. return $this->service->getCoachConfig($coachId);
  219. }
  220. /**
  221. * [订单]计算订单金额
  222. *
  223. * 计算订单金额
  224. *
  225. * @authenticated
  226. *
  227. * @bodyParam address_id int required 地址ID. Example: 1
  228. * @bodyParam coach_id int required 技师ID. Example: 1
  229. * @bodyParam project_id int required 项目ID. Example: 1
  230. * @bodyParam agent_id int 代理商ID. Example: 1
  231. * @bodyParam use_balance boolean 使用余额. Example: 0
  232. * @bodyParam distance float 距离. Example: 0
  233. *
  234. * @response {
  235. * "total_amount": 0,
  236. * "balance_amount": 0,
  237. * "pay_amount": 0,
  238. * "coupon_amount": 0,
  239. * "tip_amount": 0,
  240. * "project_amount": 0,
  241. * "delivery_fee": 0
  242. * }
  243. */
  244. public function calculateOrderAmount(Request $request)
  245. {
  246. $userId = Auth::user()->id;
  247. $addressId = $request->input('address_id');
  248. $coachId = $request->input('coach_id');
  249. $projectId = $request->input('project_id');
  250. $agentId = $request->input('agent_id');
  251. $useBalance = $request->input('use_balance', 0);
  252. $distance = $request->input('distance', 0);
  253. return $this->service->calculateOrderAmount($userId, $addressId, $coachId, $projectId, $agentId, $useBalance, $distance);
  254. }
  255. /**
  256. * [订单]加钟
  257. *
  258. * 加钟
  259. *
  260. * @authenticated
  261. *
  262. * @bodyParam project_id int required 项目ID. Example: 1
  263. * @bodyParam use_balance boolean 使用余额. Example: false
  264. * @bodyParam order_id int 订单ID. Example: 15
  265. * @bodyParam payment_type number 支付类型. Example: 1 (1:余额,2:微信,3:支付宝)
  266. *
  267. * @response {
  268. * "status": "success",
  269. * "data": {}
  270. * }
  271. */
  272. public function addTime(Request $request)
  273. {
  274. $data = $request->only(['project_id', 'use_balance', 'order_id', 'payment_type']);
  275. $data['order_type'] = OrderType::OVERTIME->value;
  276. return $this->service->createOrder(Auth::user()->id, $data);
  277. }
  278. /**
  279. * [订单]指定技师
  280. *
  281. * @authenticated
  282. *
  283. * @bodyParam coach_id int required 技师ID. Example: 1
  284. * @bodyParam order_id int required 订单ID. Example: 1
  285. *
  286. * @response {
  287. * "status": "success",
  288. * "data": {}
  289. * }
  290. */
  291. public function assignCoach(Request $request)
  292. {
  293. $userId = Auth::user()->id;
  294. $coachId = $request->input('coach_id');
  295. $orderId = $request->input('order_id');
  296. return $this->service->assignCoach($userId, $orderId, $coachId);
  297. }
  298. /**
  299. * [订单]获取抢单列表
  300. *
  301. * 获取抢单列表
  302. *
  303. * @queryParam order_id int required 订单ID. Example: 7
  304. *
  305. * @response {
  306. * "data": [
  307. * {
  308. * "id": 1,
  309. * "coach_id": 1,
  310. * "nickname": "技师昵称",
  311. * "avatar": "头像地址",
  312. * "created_at": "2024-03-21 10:00:00"
  313. * }
  314. * ]
  315. * }
  316. */
  317. public function getOrderGrabList(Request $request)
  318. {
  319. $orderId = $request->input('order_id');
  320. return $this->service->getOrderGrabList($orderId);
  321. }
  322. /**
  323. * [订单]生成核销码
  324. *
  325. * 生成订单核销码,用于技师扫码开始服务
  326. *
  327. * @authenticated
  328. *
  329. * @urlParam id required 订单ID. Example: 1
  330. *
  331. * @response {
  332. * "qr_code": "order_123_1679876543_abcdef123456",
  333. * "expired_at": "2024-03-27 10:30:00"
  334. * }
  335. */
  336. public function generateCode($id)
  337. {
  338. return $this->service->generateVerificationCode(Auth::user()->id, $id);
  339. }
  340. }