123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- <?php
- namespace App\Admin\Controllers;
- use App\Services\OrderService;
- use Illuminate\Http\Request;
- use Slowlyo\OwlAdmin\Controllers\AdminController;
- /**
- * @group 后台
- * 订单管理
- *
- * @property OrderService $service
- */
- class OrderController extends AdminController
- {
- protected string $serviceName = OrderService::class;
- public function list()
- {
- $crud = $this->baseCRUD()
- ->filterTogglable(false)
- ->headerToolbar([
- $this->createButton('dialog'),
- ...$this->baseHeaderToolBar(),
- ])
- ->columns([
- amis()->TableColumn('id', 'ID')->sortable(),
- amis()->TableColumn('user_id', '用户编号'),
- amis()->TableColumn('coach_id', '技师编号'),
- amis()->TableColumn('service_id', '项目编号'),
- amis()->TableColumn('channel_id', '渠道编号'),
- amis()->TableColumn('shop_id', '店铺编号'),
- amis()->TableColumn('customer_service_id', '跟单客服编号'),
- amis()->TableColumn('order_type', '订单类型'),
- amis()->TableColumn('order_source', '订单来源'),
- amis()->TableColumn('total_amount', '订单金额'),
- amis()->TableColumn('service_amount', '项目金额'),
- amis()->TableColumn('traffic_amount', '路程金额'),
- amis()->TableColumn('service_snapshot', '项目快照'),
- amis()->TableColumn('service_time', '服务时间'),
- amis()->TableColumn('distance', '目的地距离(米)')->sortable(),
- amis()->TableColumn('latitude', '目的地纬度'),
- amis()->TableColumn('longitude', '目的地经度'),
- amis()->TableColumn('location', '目的地定位地址'),
- amis()->TableColumn('address', '目的地详细地址'),
- amis()->TableColumn('area_code', '目的地行政区划代码'),
- amis()->TableColumn('remark', '订单备注'),
- amis()->TableColumn('state', '订单状态'),
- amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
- amis()->TableColumn('updated_at', admin_trans('admin.updated_at'))->type('datetime')->sortable(),
- $this->rowActions('dialog'),
- ]);
- return $this->baseList($crud);
- }
- public function form($isEdit = false)
- {
- return $this->baseForm()->body([
- amis()->TextControl('user_id', '用户编号'),
- amis()->TextControl('coach_id', '技师编号'),
- amis()->TextControl('service_id', '项目编号'),
- amis()->TextControl('channel_id', '渠道编号'),
- amis()->TextControl('shop_id', '店铺编号'),
- amis()->TextControl('customer_service_id', '跟单客服编号'),
- amis()->TextControl('order_type', '订单类型'),
- amis()->TextControl('order_source', '订单来源'),
- amis()->TextControl('total_amount', '订单金额'),
- amis()->TextControl('service_amount', '项目金额'),
- amis()->TextControl('traffic_amount', '路程金额'),
- amis()->TextControl('service_snapshot', '项目快照'),
- amis()->TextControl('service_time', '服务时间'),
- amis()->TextControl('distance', '目的地距离(米)'),
- amis()->TextControl('latitude', '目的地纬度'),
- amis()->TextControl('longitude', '目的地经度'),
- amis()->TextControl('location', '目的地定位地址'),
- amis()->TextControl('address', '目的地详细地址'),
- amis()->TextControl('area_code', '目的地行政区划代码'),
- amis()->TextControl('remark', '订单备注'),
- amis()->TextControl('state', '订单状态'),
- ]);
- }
- public function detail()
- {
- return $this->baseDetail()->body([
- amis()->TextControl('id', 'ID')->static(),
- amis()->TextControl('user_id', '用户编号')->static(),
- amis()->TextControl('coach_id', '技师编号')->static(),
- amis()->TextControl('service_id', '项目编号')->static(),
- amis()->TextControl('channel_id', '渠道编号')->static(),
- amis()->TextControl('shop_id', '店铺编号')->static(),
- amis()->TextControl('customer_service_id', '跟单客服编号')->static(),
- amis()->TextControl('order_type', '订单类型')->static(),
- amis()->TextControl('order_source', '订单来源')->static(),
- amis()->TextControl('total_amount', '订单金额')->static(),
- amis()->TextControl('service_amount', '项目金额')->static(),
- amis()->TextControl('traffic_amount', '路程金额')->static(),
- amis()->TextControl('service_snapshot', '项目快照')->static(),
- amis()->TextControl('service_time', '服务时间')->static(),
- amis()->TextControl('distance', '目的地距离(米)')->static(),
- amis()->TextControl('latitude', '目的地纬度')->static(),
- amis()->TextControl('longitude', '目的地经度')->static(),
- amis()->TextControl('location', '目的地定位地址')->static(),
- amis()->TextControl('address', '目的地详细地址')->static(),
- amis()->TextControl('area_code', '目的地行政区划代码')->static(),
- amis()->TextControl('remark', '订单备注')->static(),
- amis()->TextControl('state', '订单状态')->static(),
- amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
- amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
- ]);
- }
- /**
- * [订单管理]更换订单技师
- *
- * @description 更换订单的服务技师
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @bodyParam order_id integer required 订单ID Example: 1
- * @bodyParam new_coach_id integer required 新技师ID Example: 2
- * @bodyParam reason string optional 更换原因 Example: 技师临时有事
- *
- * @response {
- * "code": 200,
- * "message": "更换技师成功",
- * "data": null
- * }
- */
- public function changeCoach(Request $request)
- {
- $validated = $request->validate([
- 'order_id' => 'required|integer|exists:order,id',
- 'new_coach_id' => 'required|integer|exists:coach_users,id',
- 'reason' => 'nullable|string|max:255',
- ]);
- return $this->service->changeOrderCoach($validated);
- }
- /**
- * [订单管理]指定抢单技师
- *
- * @description 为订单指定抢单技师
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @bodyParam order_id integer required 订单ID Example: 1
- * @bodyParam coach_id integer required 技师ID Example: 2
- * @bodyParam remark string optional 备注 Example: 平台指派
- *
- * @response {
- * "code": 200,
- * "message": "指定技师成功",
- * "data": null
- * }
- */
- public function assignCoach(Request $request)
- {
- $validated = $request->validate([
- 'order_id' => 'required|integer|exists:order,id',
- 'coach_id' => 'required|integer|exists:coach_users,id',
- 'remark' => 'nullable|string|max:255',
- ]);
- return $this->service->assignOrderCoach($validated);
- }
- /**
- * [订单管理]获取订单抢单技师列表
- *
- * @description 获取参与抢单的技师列表
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @urlParam order_id integer required 订单ID Example: 1
- *
- * @response {
- * "code": 200,
- * "message": "获取成功",
- * "data": [{
- * "id": 1,
- * "coach_id": 100,
- * "nickname": "技师A",
- * "avatar": "https://example.com/avatar.jpg",
- * "distance": "1.5",
- * "state": 1,
- * "created_at": "2024-03-20 10:00:00"
- * }]
- * }
- */
- public function getOrderGrabList(Request $request, $orderId)
- {
- return $this->service->getOrderGrabList($orderId);
- }
- /**
- * [订单管理]获取附近技师列表
- *
- * @description 获取订单附近的技师列表
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @urlParam orderId integer required 订单ID Example: 1
- *
- * @queryParam distance integer optional 搜索范围(米) Example: 5000
- *
- * @response {
- * "code": 200,
- * "message": "获取成功",
- * "data": [{
- * "id": 1,
- * "nickname": "技师A",
- * "avatar": "https://example.com/avatar.jpg",
- * "distance": "1.5",
- * "work_status": 1,
- * "work_status_text": "空闲",
- * "rating": "4.8",
- * "order_count": 100,
- * "created_at": "2024-03-20 10:00:00"
- * }]
- * }
- */
- public function getNearbyCoaches(Request $request, $orderId)
- {
- $validated = $request->validate([
- 'distance' => 'nullable|integer|min:1000|max:50000',
- ]);
- return $this->service->getNearbyCoaches($orderId, $validated['distance'] ?? 5000);
- }
- /**
- * [订单管理]重置订单技师
- *
- * @description 重置订单技师,将订单改为抢单模式
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @bodyParam order_id integer required 订单ID Example: 1
- * @bodyParam reason string optional 重置原因 Example: 技师无法服务
- *
- * @response {
- * "code": 200,
- * "message": "重置技师成功",
- * "data": null
- * }
- */
- public function resetCoach(Request $request)
- {
- $validated = $request->validate([
- 'order_id' => 'required|integer|exists:order,id',
- 'reason' => 'nullable|string|max:255',
- ]);
- return $this->service->resetOrderCoach($validated);
- }
- /**
- * [订单管理]临时接单
- *
- * @description 管理员代替技师接单
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @bodyParam order_id integer required 订单ID Example: 1
- * @bodyParam reason string optional 接单原因 Example: 客户要求指定技师
- *
- * @response {
- * "code": 200,
- * "message": "接单成功",
- * "data": null
- * }
- */
- public function temporaryAccept(Request $request)
- {
- $validated = $request->validate([
- 'order_id' => 'required|integer|exists:order,id',
- 'reason' => 'nullable|string|max:255',
- ]);
- return $this->service->temporaryAcceptOrder($validated);
- }
- /**
- * [订单管理]开始服务
- *
- * @description 管理员代替技师开始服务
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @bodyParam order_id integer required 订单ID Example: 1
- * @bodyParam reason string optional 原因 Example: 用户核销码无法扫描
- *
- * @response {
- * "code": 200,
- * "message": "开始服务成功",
- * "data": null
- * }
- */
- public function startService(Request $request)
- {
- $validated = $request->validate([
- 'order_id' => 'required|integer|exists:order,id',
- 'reason' => 'nullable|string|max:255',
- ]);
- return $this->service->startOrderService($validated);
- }
- /**
- * [订单管理]结束服务
- *
- * @description 管理员代替技师结束服务
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @bodyParam order_id integer required 订单ID Example: 1
- * @bodyParam reason string optional 原因 Example: 用户要求提前结束服务
- *
- * @response {
- * "code": 200,
- * "message": "结束服务成功",
- * "data": null
- * }
- */
- public function endService(Request $request)
- {
- $validated = $request->validate([
- 'order_id' => 'required|integer|exists:order,id',
- 'reason' => 'nullable|string|max:255',
- ]);
- return $this->service->endOrderService($validated);
- }
- /**
- * [订单管理]处理报警
- *
- * @description 处理技师报警事件
- *
- * @header x-xsrf-token required CSRF令牌 Example: your_csrf_token
- *
- * @bodyParam exc_record_id integer required 异常记录ID Example: 1
- * @bodyParam handle_result string required 处理结果 Example: 已电话联系技师,确认安全
- *
- * @response {
- * "code": 200,
- * "message": "处理成功",
- * "data": null
- * }
- */
- public function handleAlarm(Request $request)
- {
- $validated = $request->validate([
- 'exc_record_id' => 'required|integer|exists:order_exc_records,id',
- 'handle_result' => 'required|string|max:255',
- ]);
- return $this->service->handleOrderAlarm($validated);
- }
- }
|