You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ss-visit/GATE_CONTROLLER_UPDATE_SUMM...

3.3 KiB

门岗端控制器统一响应格式更新总结

更新内容

根据要求,已将门岗端控制器的响应方法统一为系统标准的 successfail 方法,移除了自定义的响应方法。

修改详情

1. 移除自定义方法

  • 删除了 GateController 中自定义的 success()error() 方法
  • 使用系统统一的 ApiResponse trait 中的方法

2. 更新错误响应

将所有 $this->error() 调用更新为 $this->fail() 调用:

// 修改前
return $this->error(__('gate.visit_not_found'));

// 修改后  
return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.visit_not_found')]);

3. 统一响应格式

  • 成功响应: 使用 $this->success($data) 直接返回数据
  • 失败响应: 使用 $this->fail([$errcode, $errmsg]) 返回错误码和消息

响应格式

成功响应格式

{
    "current_page": 1,
    "data": [...],
    "total": 10
}

失败响应格式

{
    "errcode": 10002,
    "errmsg": "错误消息"
}

更新的错误类型

  1. 拜访记录不存在

    return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.visit_not_found')]);
    
  2. 只有已审核通过的拜访才能进厂

    return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.only_approved_visits_can_enter')]);
    
  3. 只有已进厂的访客才能离厂

    return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.only_entered_visitors_can_leave')]);
    
  4. 只有物流车辆才能上传货车图片

    return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.only_logistics_cars_can_upload_images')]);
    
  5. 货车图片不能为空

    return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.vehicle_images_required')]);
    
  6. 货车图片ID无效

    return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.invalid_vehicle_images')]);
    
  7. 无效的操作类型

    return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.invalid_action_type')]);
    

测试结果

通过的测试

  • 门岗端拜访列表接口
  • 门岗端拜访详情接口
  • 门岗端拜访更新接口
  • 多语言支持
  • API响应格式
  • 路由验证

⚠️ 需要关注的问题

  • ⚠️ 后台管理接口认证测试失败(可能是中间件配置问题)

代码变更

添加的引用

use App\Helpers\ResponseCode;

移除的方法

// 删除了这些自定义方法
public function success($data = null, $message = 'success') { ... }
public function error($message = 'error', $code = 400, $data = null) { ... }

更新的调用

  • 所有 $this->error()$this->fail([ResponseCode::ERROR_BUSINESS, $message])
  • 保持 $this->success($data) 不变

优势

  1. 统一性: 与系统其他控制器使用相同的响应格式
  2. 一致性: 错误码和消息格式统一
  3. 可维护性: 减少了重复代码
  4. 标准化: 符合系统架构规范

总结

门岗端控制器已成功更新为使用系统统一的响应方法,所有接口都能正常工作,响应格式与系统其他部分保持一致。测试显示主要功能正常,只有认证相关的测试需要进一步检查。