logic = new DeviceLogic(); parent::__construct(); } #[Permission('我的设备列表', 'core:device:index')] public function index(Request $request): Response { return $this->success($this->logic->indexList($this->filters($request))); } #[Permission('下级设备列表', 'core:device:subordinate:index')] public function subordinateIndex(Request $request): Response { return $this->success($this->logic->subordinateIndexList($this->filters($request))); } #[Permission('导出我的设备', 'core:device:export')] public function export(Request $request): Response { return $this->logic->export($this->filters($request)); } #[Permission('设备管理详情', 'core:device:read')] public function read(Request $request): Response { return $this->success($this->logic->readDevice((int) $request->input('id', 0))); } #[Permission('下级设备归属详情', 'core:device:subordinate:read')] public function subordinateRead(Request $request): Response { return $this->success($this->logic->readDevice((int) $request->input('id', 0), true)); } #[Permission('设备供电/断电', 'core:device:power')] public function power(Request $request): Response { $data = $request->post(); $action = trim((string) ($data['action'] ?? '')); if (!in_array($action, ['on', 'off'], true)) { return $this->fail('请选择设备供电或设备断电操作'); } return $this->success( $this->logic->switchPower((int) ($data['id'] ?? 0), $action), $action === 'on' ? '设备供电指令已下发' : '设备断电指令已下发' ); } #[Permission('下级设备供电/断电', 'core:device:subordinate:power')] public function subordinatePower(Request $request): Response { $data = $request->post(); $action = trim((string) ($data['action'] ?? '')); if (!in_array($action, ['on', 'off'], true)) { return $this->fail('请选择设备供电或设备断电操作'); } return $this->success( $this->logic->switchPower((int) ($data['id'] ?? 0), $action, true), $action === 'on' ? '设备供电指令已下发' : '设备断电指令已下发' ); } #[Permission('从设备页解绑商户', 'core:device:unbind')] public function unbind(Request $request): Response { $this->logic->unbindDevice((int) $request->post('id', 0)); return $this->success([], '设备解绑成功'); } #[Permission('下级设备解绑商户', 'core:device:subordinate:unbind')] public function subordinateUnbind(Request $request): Response { $this->logic->unbindDevice((int) $request->post('id', 0), true); return $this->success([], '设备解绑成功'); } private function filters(Request $request): array { return $request->more([ ['category', 'all'], ['device_state', ''], ['merchant', ''], ['qr_code', ''], ['device_sn', ''], ['goods_type', ''], ['signal', ''], ]); } }