OrderController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. namespace App\Http\Controllers\Coach;
  3. use Illuminate\Http\Request;
  4. use App\Traits\ResponseTrait;
  5. use App\Http\Controllers\Controller;
  6. use App\Services\Coach\OrderService;
  7. use Illuminate\Support\Facades\Auth;
  8. /**
  9. * @group 技师端
  10. *
  11. * 订单相关的API接口
  12. */
  13. class OrderController extends Controller
  14. {
  15. use ResponseTrait;
  16. protected OrderService $service;
  17. public function __construct(OrderService $service)
  18. {
  19. $this->service = $service;
  20. }
  21. /**
  22. * [订单]获取可抢订单列表
  23. *
  24. * @description 获取当前技师40公里范围内的可抢订单列表,包含订单基本信息和距离
  25. *
  26. * @authenticated
  27. *
  28. * @queryParam area_code string required 区划代码 Example: 370602
  29. * @queryParam page int 页码 Example: 1
  30. * @queryParam per_page int 每页数量 Example: 10
  31. *
  32. * @response {
  33. * "data": [
  34. * {
  35. * "id": 1,
  36. * "order_no": "202403210001",
  37. * "project_name": "精油推拿",
  38. * "project_duration": 60,
  39. * "project_price": "188.00",
  40. * "address": "山东省烟台市芝罘区幸福小区1号楼",
  41. * "distance": 2.5,
  42. * "service_time": "2024-03-21 10:00:00",
  43. * "created_at": "2024-03-21 09:30:00"
  44. * }
  45. * ],
  46. * "meta": {
  47. * "total": 100,
  48. * "per_page": 10,
  49. * "current_page": 1,
  50. * "last_page": 10
  51. * }
  52. * }
  53. */
  54. public function getGrabList(Request $request)
  55. {
  56. $params = $request->validate([
  57. 'area_code' => 'required|string',
  58. 'page' => 'nullable|integer|min:1',
  59. 'per_page' => 'nullable|integer|min:1|max:50',
  60. ]);
  61. return $this->success($this->service->getGrabList(Auth::user()->id, $params));
  62. }
  63. /**
  64. * [订单]获取订单列表
  65. *
  66. * @description 获取当前技师的订单列表,不包含已创建和已分配状态的订单
  67. *
  68. * @authenticated
  69. *
  70. * @queryParam page int 页码 Example: 1
  71. * @queryParam per_page int 每页数量 Example: 10
  72. *
  73. * @response {
  74. * "data": {
  75. * "items": [
  76. * {
  77. * "id": 1,
  78. * "order_no": "202403210001",
  79. * "project_name": "精油推拿",
  80. * "project_duration": 60,
  81. * "project_price": "188.00",
  82. * "address": "山东省烟台市芝罘区幸福小区1号楼",
  83. * "service_time": "2024-03-21 10:00:00",
  84. * "status": "completed",
  85. * "created_at": "2024-03-21 09:30:00"
  86. * }
  87. * ],
  88. * "total": 100
  89. * }
  90. * }
  91. */
  92. public function getOrderList(Request $request)
  93. {
  94. $params = $request->validate([
  95. 'page' => 'nullable|integer|min:1',
  96. 'per_page' => 'nullable|integer|min:1|max:50',
  97. ]);
  98. return $this->success($this->service->getOrderList(Auth::user()->id, $params));
  99. }
  100. /**
  101. * [订单]抢单
  102. *
  103. * @description 技师抢取指定订单
  104. *
  105. * @authenticated
  106. *
  107. * @urlParam order_id integer required 订单ID Example: 1
  108. *
  109. * @response {
  110. * "message": "抢单成功",
  111. * "order_id": 1
  112. * }
  113. * @response 400 {
  114. * "message": "订单状态异常,无法抢单"
  115. * }
  116. * @response 400 {
  117. * "message": "订单超出服务范围"
  118. * }
  119. * @response 400 {
  120. * "message": "未开通该项目服务资格"
  121. * }
  122. */
  123. public function grabOrder(int $order_id)
  124. {
  125. return $this->success($this->service->grabOrder(Auth::user()->id, $order_id));
  126. }
  127. /**
  128. * [订单]接单
  129. *
  130. * @description 技师接受已分配的订单
  131. *
  132. * @authenticated
  133. *
  134. * @urlParam order_id integer required 订单ID Example: 1
  135. *
  136. * @response {
  137. * "message": "接单成功",
  138. * "order_id": 1,
  139. * "order_no": "202403210001"
  140. * }
  141. * @response 400 {
  142. * "message": "订单状态异常,无法接单"
  143. * }
  144. * @response 403 {
  145. * "message": "该订单未分配给您"
  146. * }
  147. */
  148. public function acceptOrder(int $order_id)
  149. {
  150. return $this->success($this->service->acceptOrder(Auth::user()->id, $order_id));
  151. }
  152. /**
  153. * [订单]拒单
  154. *
  155. * @description 技师拒绝已分配的订单
  156. *
  157. * @authenticated
  158. *
  159. * @urlParam order_id integer required 订单ID Example: 1
  160. *
  161. * @bodyParam reason string required 拒单原因(8-200个字符) Example: 距离太远,无法服务
  162. *
  163. * @response {
  164. * "message": "拒单成功",
  165. * "order_id": 1,
  166. * "order_no": "202403210001"
  167. * }
  168. * @response 400 {
  169. * "message": "订单状态异常,无法拒单"
  170. * }
  171. * @response 403 {
  172. * "message": "该订单未分配给您"
  173. * }
  174. */
  175. public function rejectOrder(Request $request, int $order_id)
  176. {
  177. $data = $request->validate([
  178. 'reason' => 'required|string|min:8|max:200',
  179. ]);
  180. return $this->success($this->service->rejectOrder(Auth::user()->id, $order_id, $data['reason']));
  181. }
  182. /**
  183. * [订单]出发
  184. *
  185. * @description 技师确认出发前往服务地点
  186. *
  187. * @authenticated
  188. *
  189. * @urlParam order_id integer required 订单ID Example: 1
  190. *
  191. * @response {
  192. * "message": "已确认出发",
  193. * "order_id": 1,
  194. * "order_no": "202403210001",
  195. * "departed_at": "2024-03-21 10:00:00"
  196. * }
  197. * @response 400 {
  198. * "message": "订单状态异常,无法确认出发"
  199. * }
  200. * @response 403 {
  201. * "message": "该订单未分配给您"
  202. * }
  203. */
  204. public function depart(int $order_id)
  205. {
  206. return $this->success($this->service->depart(Auth::user()->id, $order_id));
  207. }
  208. /**
  209. * [订单]到达
  210. *
  211. * @description 技师确认已到达服务地点
  212. *
  213. * @authenticated
  214. *
  215. * @urlParam order_id integer required 订单ID Example: 1
  216. *
  217. * @response {
  218. * "message": "已确认到达",
  219. * "order_id": 1,
  220. * "order_no": "202403210001",
  221. * "arrived_at": "2024-03-21 10:30:00"
  222. * }
  223. * @response 400 {
  224. * "message": "订单状态异常,无法确认到达"
  225. * }
  226. * @response 403 {
  227. * "message": "该订单未分配给您"
  228. * }
  229. */
  230. public function arrive(int $order_id)
  231. {
  232. return $this->success($this->service->arrive(Auth::user()->id, $order_id));
  233. }
  234. /**
  235. * [订单]开始服务
  236. *
  237. * @description 技师扫描客户二维码开始服务
  238. *
  239. * @bodyParam order_id integer required 订单ID Example: 1
  240. * @bodyParam qr_code string required 二维码内容 Example: order_1_1677123456_abcdef
  241. *
  242. * @response {
  243. * "status": true,
  244. * "message": "开始服务成功",
  245. * "data": {
  246. * "order_id": 1,
  247. * "state": "serving",
  248. * "service_start_time": "2024-01-01 12:00:00"
  249. * }
  250. * }
  251. */
  252. public function startService(Request $request)
  253. {
  254. $validated = $request->validate([
  255. 'order_id' => 'required|integer',
  256. 'qr_code' => 'required|string',
  257. ]);
  258. return $this->success(
  259. $this->service->startService(
  260. Auth::user()->id,
  261. $validated['order_id'],
  262. $validated['qr_code']
  263. )
  264. );
  265. }
  266. /**
  267. * [订单]撤离
  268. *
  269. * @description 技师确认已完成服务并撤离服务地点
  270. *
  271. * @authenticated
  272. *
  273. * @urlParam order_id integer required 订单ID Example: 1
  274. *
  275. * @response {
  276. * "status": true,
  277. * "message": "撤离成功",
  278. * "data": {
  279. * "order_id": 1,
  280. * "state": "completed",
  281. * "leave_time": "2024-03-21 12:30:00"
  282. * }
  283. * }
  284. * @response 400 {
  285. * "message": "订单状态异常,无法确认撤离"
  286. * }
  287. * @response 403 {
  288. * "message": "该订单未分配给您"
  289. * }
  290. */
  291. public function leave(int $order_id)
  292. {
  293. return $this->success($this->service->leave(Auth::user()->id, $order_id));
  294. }
  295. /**
  296. * [订单]订单设置
  297. *
  298. * @return JsonResponse
  299. *
  300. * @description 更新技师的订单相关设置,如服务距离等
  301. *
  302. * @bodyParam distance float 服务距离(公里) Example: 10
  303. *
  304. * @response {
  305. * "message": "订单设置更新成功",
  306. * "coach_id": 1,
  307. * "settings": {
  308. * "distance": 10
  309. * }
  310. * }
  311. */
  312. public function setOrder(Request $request)
  313. {
  314. $data = $request->validate([
  315. 'distance' => 'nullable|numeric|min:0',
  316. ]);
  317. return $this->success(
  318. $this->service->setOrder(Auth::user()->id, $data)
  319. );
  320. }
  321. /**
  322. * [订单]获取订单设置
  323. *
  324. * @description 获取技师的订单相关设置,如服务距离等
  325. *
  326. * @authenticated 需要技师身份认证
  327. *
  328. * @response 200 {
  329. * "status": true,
  330. * "message": "获取成功",
  331. * "data": {
  332. * "distance": 10, // 服务距离(公里)
  333. * "distance_max": 40, // 最大服务距离(公里)
  334. * "distance_min": 1 // 最小服务距离(公里)
  335. * }
  336. * }
  337. */
  338. public function getOrderSettings()
  339. {
  340. return $this->success(
  341. $this->service->getOrderSettings(Auth::user()->coach)
  342. );
  343. }
  344. }