123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509 |
- <?php
- namespace App\Http\Controllers\Client;
- use App\Enums\OrderType;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use App\Services\Client\OrderService;
- /**
- * @group 用户端
- *
- * 订单相关的API接口
- */
- class OrderController extends Controller
- {
- protected OrderService $service;
- public function __construct(OrderService $service)
- {
- $this->service = $service;
- }
- /**
- * [订单]订单初始化
- *
- * 初始化订单
- *
- * @authenticated
- *
- * @bodyParam coach_id int required 技师ID. Example: 6
- * @bodyParam area_code string required 区划代码. Example: 370602
- * @bodyParam project_id int required 项目ID. Example: 1
- * @bodyParam latitude int 纬度. Example: 37.4219983
- * @bodyParam longitude int 经度. Example: 122.1347344
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function initialize(Request $request)
- {
- $data = $request->only(['coach_id', 'area_code', 'project_id', 'latitude', 'longitude']);
- return $this->success($this->service->initialize(Auth::user()->id, $data));
- }
- /**
- * [订单]创建订单
- *
- * 创建订单
- *
- * @authenticated
- *
- * @bodyParam project_id int required 项目ID. Example: 1
- * @bodyParam address_id int required 地址ID. Example: 1
- * @bodyParam coach_id int required 技师ID. Example: 6
- * @bodyParam use_balance boolean 使用余额. Example: false
- * @bodyParam service_time datetime required 服务时间. Example: 2024-01-01 10:00:00
- * @bodyParam order_id int 订单ID. Example: null
- * @bodyParam payment_type number required 支付类型. Example: 1 (1:余额,2:微信,3:支付宝)
- * @bodyParam order_type int required 订单类型. Example: 1
- * @bodyParam distance float 距离. Example: 10
- * @bodyParam remark string 订单备注. Example: 请准时到达
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function create(Request $request)
- {
- $data = $request->only([
- 'project_id',
- 'address_id',
- 'coach_id',
- 'use_balance',
- 'order_id',
- 'service_time',
- 'payment_type',
- 'order_type',
- 'distance',
- 'remark'
- ]);
- return $this->success($this->service->createOrder(Auth::user()->id, $data));
- }
- /**
- * [订单]结束订单
- *
- * 结束订单
- *
- * @authenticated
- *
- * @bodyParam order_id int required 订单ID. Example: 1
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function finish(Request $request)
- {
- $userId = Auth::user()->id;
- $orderId = $request->input('order_id');
- return $this->success($this->service->finishOrder($userId, $orderId));
- }
- /**
- * [订单]确认技师离开
- *
- * 确认技师离开
- *
- * @authenticated
- *
- * @bodyParam order_id int required 订单ID. Example: 123
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function confirmLeave(Request $request)
- {
- $userId = Auth::user()->id;
- $orderId = $request->input('order_id');
- return $this->success($this->service->confirmLeave($userId, $orderId));
- }
- /**
- * [订单]取消订单
- *
- * 取消订单
- *
- * @authenticated
- *
- * @bodyParam order_id int required 订单ID. Example: 123
- * @bodyParam reason string required 取消原因. Example: 123
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function cancel(Request $request)
- {
- $userId = Auth::user()->id;
- $orderId = $request->input('order_id');
- $reason = $request->input('reason');
- return $this->success($this->service->cancelOrder($userId, $orderId, $reason));
- }
- /**
- * [订单]获取订单列表
- *
- * 获取订单列表
- *
- * @authenticated
- *
- * @queryParam tab int 订单标签页 Example: 0
- * 标签页说明:
- * 0: 全部订单
- * 1: 待付款 (状态: 1,16)
- * 2: 进行中 (状态: 2,3,4,5,6,7,8,9,10)
- * 3: 已完成 (状态: 12)
- * 4: 待评价 (状态: 11)
- * 5: 已取消 (状态: 13,14,15,17,18)
- *
- * @response {
- * "status": "success",
- * "data": []
- * }
- */
- public function list(Request $request)
- {
- $tab = $request->input('tab', 0);
- return $this->success($this->service->getOrderList(Auth::user()->id, $tab));
- }
- /**
- * [订单]获取订单详情
- *
- * 获取订单详情
- *
- * @authenticated
- *
- * @urlParam id required 订单ID. Example: 6
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function detail($id)
- {
- return $this->success($this->service->getOrderDetail(Auth::user()->id, $id));
- }
- /**
- * [订单]订单退款
- *
- * 订单退款
- *
- * @authenticated
- *
- * @urlParam id required 订单ID. Example: 1
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function refund($id)
- {
- return $this->success($this->service->refundOrder($id));
- }
- /**
- * [订单]获取代理商配置
- *
- * 获取代理商配置
- *
- * @authenticated
- *
- * @bodyParam agent_id int required 代理商ID. Example: 1
- *
- * @response {
- * "min_distance": 0,
- * "min_fee": 0,
- * "per_km_fee": 0
- * }
- */
- public function getAgentConfig(Request $request)
- {
- $agentId = $request->input('agent_id');
- return $this->success($this->service->getAgentConfig($agentId));
- }
- /**
- * [订单]获取技师配置
- *
- * 获取技师配置
- *
- * @authenticated
- *
- * @bodyParam coach_id int required 技师ID. Example: 1
- *
- * @response {
- * "delivery_fee_type": "round_trip",
- * "charge_delivery_fee": true
- * }
- */
- public function getCoachConfig(Request $request)
- {
- $coachId = $request->input('coach_id');
- return $this->success($this->service->getCoachConfig($coachId));
- }
- /**
- * [订单]计算订单金额
- *
- * 计算订单金额
- *
- * @authenticated
- *
- * @bodyParam address_id int required 地址ID. Example: 1
- * @bodyParam coach_id int required 技师ID. Example: 1
- * @bodyParam project_id int required 项目ID. Example: 1
- * @bodyParam agent_id int 代理商ID. Example: 1
- * @bodyParam use_balance boolean 使用余额. Example: 0
- * @bodyParam distance float 距离. Example: 0
- *
- * @response {
- * "total_amount": 0,
- * "balance_amount": 0,
- * "pay_amount": 0,
- * "coupon_amount": 0,
- * "tip_amount": 0,
- * "project_amount": 0,
- * "delivery_fee": 0
- * }
- */
- public function calculateOrderAmount(Request $request)
- {
- $userId = Auth::user()->id;
- $addressId = $request->input('address_id');
- $coachId = $request->input('coach_id');
- $projectId = $request->input('project_id');
- $agentId = $request->input('agent_id');
- $useBalance = $request->input('use_balance', 0);
- $distance = $request->input('distance', 0);
- return $this->success($this->service->calculateOrderAmount($userId, $addressId, $coachId, $projectId, $agentId, $useBalance, $distance));
- }
- /**
- * [订单]加钟
- *
- * 加钟
- *
- * @authenticated
- *
- * @bodyParam project_id int required 项目ID. Example: 1
- * @bodyParam use_balance boolean 使用余额. Example: false
- * @bodyParam order_id int 订单ID. Example: 15
- * @bodyParam payment_type number 支付类型. Example: 1 (1:余额,2:微信,3:支付宝)
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function addTime(Request $request)
- {
- $data = $request->only(['project_id', 'use_balance', 'order_id', 'payment_type']);
- $data['order_type'] = OrderType::OVERTIME->value;
- return $this->success($this->service->createOrder(Auth::user()->id, $data));
- }
- /**
- * [订单]指定技师
- *
- * @authenticated
- *
- * @bodyParam coach_id int required 技师ID. Example: 1
- * @bodyParam order_id int required 订单ID. Example: 1
- *
- * @response {
- * "status": "success",
- * "data": {}
- * }
- */
- public function assignCoach(Request $request)
- {
- $userId = Auth::user()->id;
- $coachId = $request->input('coach_id');
- $orderId = $request->input('order_id');
- $payment_type = $request->input('payment_type');
- $distance = $request->input('distance');
- return $this->success($this->service->assignCoach($userId, $orderId, $coachId, $payment_type, $distance));
- }
- /**
- * [订单]获取抢单列表
- *
- * 获取抢单列表
- *
- * @queryParam order_id int required 订单ID. Example: 7
- *
- * @response {
- * "data": [
- * {
- * "id": 1,
- * "coach_id": 1,
- * "nickname": "技师昵称",
- * "avatar": "头像地址",
- * "created_at": "2024-03-21 10:00:00"
- * }
- * ]
- * }
- */
- public function getOrderGrabList(Request $request)
- {
- $orderId = $request->input('order_id');
- return $this->success($this->service->getOrderGrabList($orderId));
- }
- /**
- * [订单]生成核销码
- *
- * 生成订单核销码,用于技师扫码开始服务
- *
- * @authenticated
- *
- * @urlParam id required 订单ID. Example: 1
- *
- * @response {
- * "qr_code": "order_123_1679876543_abcdef123456",
- * "expired_at": "2024-03-27 10:30:00"
- * }
- */
- public function generateCode($id)
- {
- return $this->success($this->service->generateVerificationCode(Auth::user()->id, $id));
- }
- /**
- * [订单]订单评价
- *
- * 用户评价订单
- *
- * @authenticated
- *
- * @bodyParam order_id int required 订单ID
- * @bodyParam service_score decimal 服务评分(1-5分,支持一位小数) Example: 4.5
- * @bodyParam appearance_score decimal 形象评分(1-5分,支持一位小数) Example: 4.5
- * @bodyParam attitude_score decimal 态度评分(1-5分,支持一位小数) Example: 4.5
- * @bodyParam professional_score decimal 专业评分(1-5分,支持一位小数) Example: 4.5
- * @bodyParam tags array 评价标签ID数组 Example: [1,2,3]
- * @bodyParam content string 评价内容 Example: 服务很专业,技师态度很好
- * @bodyParam images array 评价图片数组 Example: ["path/to/image1.jpg", "path/to/image2.jpg"]
- *
- * @response 200 {
- * "code": 200,
- * "message": "评价成功",
- * "data": null
- * }
- * @response 400 {
- * "code": 400,
- * "message": "订单不存在",
- * "data": null
- * }
- * @response 422 {
- * "code": 422,
- * "message": "评分必须在1-5分之间",
- * "data": null
- * }
- *
- * @throws \Exception
- */
- public function rate(Request $request)
- {
- $validated = $request->validate([
- 'order_id' => 'required|integer',
- 'service_score' => 'nullable|numeric|min:1|max:5',
- 'appearance_score' => 'nullable|numeric|min:1|max:5',
- 'attitude_score' => 'nullable|numeric|min:1|max:5',
- 'professional_score' => 'nullable|numeric|min:1|max:5',
- 'tags' => 'nullable|array',
- 'tags.*' => 'integer|exists:order_comment_tags,id',
- 'content' => 'nullable|string|max:1000',
- 'images' => 'nullable|array',
- 'images.*' => 'string'
- ]);
- $this->service->rateOrder(Auth::user()->id, $validated);
- return $this->success(null, '评价成功');
- }
- /**
- * [订单]获取评价标签列表
- *
- * 获取所有可用的评价标签列表,用于用户评价时选择
- *
- * @authenticated
- *
- * @response {
- * "data": [
- * {
- * "id": 1,
- * "tag_name": "打扫干净"
- * },
- * {
- * "id": 2,
- * "tag_name": "工装规范"
- * },
- * {
- * "id": 3,
- * "tag_name": "态度端正"
- * }
- * ]
- * }
- */
- public function commentTags()
- {
- return $this->success($this->service->getCommentTags());
- }
- /**
- * [订单]删除订单
- *
- * 用户删除订单,删除后订单将不在列表中显示
- *
- * @authenticated
- *
- * @urlParam id required 订单ID. Example: 1
- *
- * @response {
- * "status": "success",
- * "message": "订单删除成功",
- * "data": null
- * }
- *
- * @response 404 {
- * "message": "订单不存在"
- * }
- *
- * @response 422 {
- * "message": "当前订单状态不允许删除"
- * }
- */
- public function delete($id)
- {
- return $this->success($this->service->deleteOrder(Auth::user()->id, $id));
- }
- }
|