getItemId(); $instanceId = $data->getItemInstanceId(); $selectIds = $data->getSelectIds()->getIterator()->getArrayCopy(); $userId = $this->user_id; // 验证参数 if ($itemId <= 0) { throw new LogicException("宝箱ID无效"); } // 调用宝箱开启服务 $result = ChestService::openChest($userId, $itemId, $instanceId, [ 'select_ids' => $selectIds, 'source_type' => 'app_open_box', 'device_info' => request()->userAgent(), 'ip_address' => request()->ip(), ]); if (!$result) { throw new LogicException("开启宝箱失败,请检查宝箱是否存在或是否可开启"); } // 设置响应状态 $this->response->setCode(0); $this->response->setMsg('开启宝箱成功'); Log::info('用户开启宝箱成功', [ 'user_id' => $userId, 'item_id' => $itemId, 'instance_id' => $instanceId, 'select_ids' => $selectIds, 'result' => $result ]); } catch (LogicException $e) { // 设置错误响应 $this->response->setCode(400); $this->response->setMsg($e->getMessage()); Log::warning('用户开启宝箱失败', [ 'user_id' => $this->user_id, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); } catch (\Exception $e) { // 设置错误响应 $this->response->setCode(500); $this->response->setMsg('系统错误,请稍后再试'); Log::error('开启宝箱操作异常', [ 'user_id' => $this->user_id, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); } return $response; } }