1, 'title' => '请问您目前的工作状态是全职工作还是自由工作?', 'options' => [ '全职工作', '自由工作' ], 'type' => 1, ], [ 'id' => 2, 'title' => '请问您是否有独立上门给客户提供家电维修/清洗/安装的经验?', 'options' => [ '有', '没有' ], 'type' => 1, ], [ 'id' => 3, 'title' => '请问您有没有在其他同类型平台的工作经验?', 'options' => [ '有', '没有' ], 'type' => 1, ], [ 'id' => 4, 'title' => '请简要说明平台名称、工作时间年限、所服务的类目', 'type' => 3, ], [ 'id' => 5, 'title' => '请选择您具备的经验?', 'options' => [ '家电维修', '家电清洗', '家电安装', '不具备以上经验' ], 'type' => 1, ] ]; private array $list2 = [ [ 'id' => 6, 'title' => '请选择您会的项目?最多选5个,最后会根据您所选的项目进行答题。', 'options' => [ '空调加氟', '空调维修', '冰箱','制冷设备','油烟机','洗衣机','甩干机','燃气热水器','电热水器','燃气灶','干洗机', ], 'type' => 2, ], [ 'id' => 7, 'title' => '请选择您会的项目?最多选5个,最后会根据您所选的项目进行答题。', 'options' => [ '天井机','风管机','家用中央空调','空调','油烟机','洗衣机','热水器','燃气灶','冰箱' ], 'type' => 2, ], [ 'id' => 8, 'title' => '请根据您的实际情况选择会哪些家电安装?', 'options' => [ '空调','其他' ], 'type' => 1, ], ]; private array $list3 = [ [ 'id' => 9, 'title' => '请选择您持有的证书?', 'options' => [ '低压电工作业', '高压电工作业', '高处作业', '制冷与空调作业', '焊接与热切割作业', '无', ], 'type' => 1, ], [ 'id' => 10, 'title' => '请简单描述您具备的其他技能?', 'type' => 3, ] ]; public function lists(Request $request) { // 获取单个 POST 参数 $worker_register_id = $request->post('worker_register_id'); $step = $request->post('step'); // 获取所有 POST 参数 $data = $request->post('data'); if ( !in_array($step, [1,2,3,4])) { return $this->fail('参数错误'); } if ($step > 1 && (empty($data) || !is_array($data))) { return $this->fail('答案不可为空'); } $worker_register_id = MasterWorkerRegister::where('id',$worker_register_id)->value('id'); if (!$worker_register_id) { return $this->fail('ID有误'); } $msg = '操作成功'; $has_next = 1; $is_success = 0; $tmplist = array_column($list, null, 'step'); if ($step == 1 ) { $result[] = $list; } elseif ($step == 2) { foreach($data as $item) { if (empty($item['id']) || ($item['id'] != 4 && empty($item['options']))) { return $this->fail('参数错误3'); } if ($item['id'] == 5) { $options = $item['options']; } } if (empty($options)) { return $this->fail('请选择您具备的经验'); } $key = array_search($options, $tmplist[5]['options']); if ($key === false || !isset($list2[$key])) { $msg = '很抱歉,您的测试未通过,感谢您的关注!'; $has_next = 0; $result = []; } else { //根据上一步的选项判断 $result[] = $list2[$key]; } } elseif ($step == 3) { $data = $data[0]; $id = empty($data['id']) ? 0 : $data['id']; if ($id == 6 || $id == 7) { $type = $id == 6 ? 2 : 1; $question = MasterWorkerLogic::getQuestion(['type' => $type, 'category' => $data['options']]); foreach($question['list'] as $key => $item) { $temp = [ "id" => $item['id'], "title" => $item['title'], "options" => explode(",",$item['options']), "type" => strpos($item['title'], '多选题') !== false ? 2 : 1, ]; $result[] = $temp; } } elseif ($id == 8) { if ($data['options'] == '空调') { $result[] = $list3; } else { $msg = '很抱歉,您的测试未通过,感谢您的关注!'; $has_next = 0; $result = []; } } else { $msg = '很抱歉,您的测试未通过,感谢您的关注!'; $has_next = 0; $result = []; } } else { $result[] = $list3[0]; } return $this->success($msg, ['has_next' => $has_next,'is_success' => $is_success, 'list' => $result], 1, 1); } }