request->param('inspection_type_id'); if(intval($inspectId) <= 0){ $this->error('验货类型ID不能为空'); } $params['inspection_type_id'] = $inspectId; $params = [ 'status' => StatusEnum::ENABLED, ]; $options = InspectService::getInspectionItems($params); $this->success('获取成功', $options); } /** * 提交验货任务 * * @ApiTitle (提交验货任务) * @ApiSummary (提交验货任务,包含验货结果和照片信息) * @ApiMethod (POST) * @ApiRoute (/api/inspection/index/submitTask) * @ApiParams (name="order_id", type="integer", required=true, description="订单ID") * @ApiParams (name="order_goods_id", type="integer", required=true, description="订单商品ID") * @ApiParams (name="inspector_id", type="integer", required=true, description="验货员ID") * @ApiParams (name="remark", type="string", required=false, description="备注信息") * @ApiParams (name="images", type="string", required=false, description="任务图片,多张用逗号分隔") * @ApiParams (name="start_time", type="integer", required=false, description="任务开始时间戳") * @ApiParams (name="end_time", type="integer", required=false, description="任务结束时间戳") * @ApiParams (name="task_id", type="integer", required=false, description="任务ID,更新时传入") * @ApiParams (name="results", type="array", required=true, description="验货结果数组") * @ApiParams (name="results.item_id", type="integer", required=true, description="检查项ID") * @ApiParams (name="results.name", type="string", required=false, description="检查项名称") * @ApiParams (name="results.is_qualified", type="integer", required=true, description="是否合格 0:否 1:是") * @ApiParams (name="results.remark", type="string", required=false, description="不合格原因") * @ApiParams (name="results.photos", type="array", required=false, description="照片数组") * @ApiParams (name="results.photos.photo_url", type="string", required=true, description="照片URL") * @ApiReturnParams (name="code", type="integer", required=true, sample="1") * @ApiReturnParams (name="msg", type="string", required=true, sample="验货任务提交成功") * @ApiReturnParams (name="data", type="object", description="返回数据") * @ApiReturn ({ 'code':'1', 'msg':'验货任务提交成功', 'data': { 'task_id': 123 } }) */ public function submitTask() { $params = $this->request->post(); // 验证必要参数 if (empty($params['order_id'])) { $this->error('订单ID不能为空'); } if (empty($params['order_goods_id'])) { $this->error('订单商品ID不能为空'); } $params['inspector_id'] = $this->auth->id; if (empty($params['results']) || !is_array($params['results'])) { $this->error('验货结果不能为空'); } // 组装任务数据 $taskData = [ 'order_id' => $params['order_id'], 'order_goods_id' => $params['order_goods_id'], 'inspector_id' => $params['inspector_id'], 'remark' => $params['remark'] ?? '', 'images' => $params['images'] ?? '', 'start_time' => $params['start_time'] ?? time(), 'end_time' => $params['end_time'] ?? time(), 'task_status' => 1, // 进行中 'status' => 1 // 开启 ]; // 如果是更新任务,传入task_id if (!empty($params['task_id'])) { $taskData['task_id'] = $params['task_id']; } // 组装结果数据 $resultData = []; foreach ($params['results'] as $result) { if (empty($result['item_id'])) { $this->error('检查项ID不能为空'); } $resultItem = [ 'item_id' => $result['item_id'], 'name' => $result['name'] ?? '', 'is_qualified' => $result['is_qualified'] ?? 1, 'remark' => $result['remark'] ?? '', 'photos' => $result['photos'] ?? [] ]; $resultData[] = $resultItem; } $inspectUid = $this->auth->id; // 调用服务提交验货任务 list($code, $msg, $data) = InspectService::submitInspectionTask($taskData, $resultData,$inspectUid); if ($code == 1) { $this->success($msg, $data); } else { $this->error($msg); } } // }