$this->userId, 'orgId'=>$this->orgId, 'qualityTaskId'=>input('qualityTaskId'), 'qualityAddrId'=>input('qualityAddrId'), 'images'=>input('images'), 'content'=>input('content'), 'checkJson'=>input('checkJson'), ]; // checkJson新格式:[{"id":1,"title":"表单名称","forms":[{"remark":"","result":"1","title":"测试","type":"0"}]}] // $json = input('json'); // if (!$json) { // HelpHander::error('参数不正确'); // } // $jsonArray=json_decode($json,true); if(!$jsonArray['checkJson']){ HelpHander::error('检查结果不能为空'); } if(!$jsonArray['qualityTaskId']){ HelpHander::error('参数错误'); } if(!$jsonArray['qualityAddrId']){ HelpHander::error('参数错误'); } $patrolTask = Db::name('quality_task') ->where('id',$jsonArray['qualityTaskId']) ->where('del',0) ->find(); if(!$patrolTask){ HelpHander::error('任务不存在'); } if(!in_array($patrolTask['status'],[0,1])){ HelpHander::error('任务已处理'); } $curTime = time(); $startTime = strtotime($patrolTask['start_time']); $endTime = strtotime($patrolTask['end_time']); if($curTime < $startTime || $curTime > $endTime){ HelpHander::error('不在任务时间范围内,无法提交'); } // 检查该任务是已保存 $res = Db::name('quality_record') ->where('quality_task_id',$jsonArray['qualityTaskId']) ->where('id',$jsonArray['qualityAddrId']) ->find(); if($res){ HelpHander::error('该检查内容已上传记录'); } $countrecord = Db::name('quality_record') ->where('quality_task_id',$jsonArray['qualityTaskId']) ->count(); $quality_group_id = Db::name('quality_task_addr')->where('id',$jsonArray['qualityAddrId'])->value('quality_group_id'); Db::startTrans(); try { $data=[ 'org_id'=>$jsonArray['orgId'], 'user_id'=>$jsonArray['userId'], 'quality_task_id'=>$jsonArray['qualityTaskId'], 'quality_addr_id'=>$jsonArray['qualityAddrId'], 'quality_group_id'=>$quality_group_id, 'images'=>$jsonArray['images'], 'content'=>isset($jsonArray['content'])?$jsonArray['content']:'', 'check_json'=>$jsonArray['checkJson'], 'create_time'=>date('Y-m-d H:i:s'), 'create_yyyy'=>date('Y'), 'create_yyyymm'=>date('Ym'), 'create_yyyymmdd'=>date('Ymd'), ]; $addRecord=Db::name('quality_record')->insert($data); if(!$addRecord){ exception('保存失败'); } $countaddr = Db::name('quality_task_addr')->where('quality_task_id',$jsonArray['qualityTaskId'])->count(); if($countaddr == $countrecord + 1){ $status = 2; }else{ $status = 1; } if($patrolTask['status'] != $status){ $a = [ 'status'=>$status, 'update_time'=>getTime(), ]; $save = Db::name('quality_task') ->where('id',$jsonArray['qualityTaskId']) ->update($a); if(!$save){ exception('操作失败'); } if(in_array($status,[2,3,5])){ Db::name('task') ->where('bus_id', $jsonArray['qualityTaskId']) ->where('type', (new Task())::TASK_TYPE_QUALITY) ->delete(); } } Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); HelpHander::error( $e->getMessage()); } HelpHander::success([],'操作成功'); } public function detail(){ $id = input('id/d',0); $record = Db::name('quality_record') ->where('quality_addr_id',$id) ->field('id,user_id,images,content,check_json,create_time') ->find(); if(!$record){ HelpHander::error('记录不存在'); } $uname = Db::name('user')->where('id',$record['user_id'])->value('real_name'); $record['uname'] = $uname?$uname:''; unset($record['user_id']); $record['check_json'] = json_decode($record['check_json'],true); HelpHander::success($record,'成功'); } }