auth->isLogin()) { $this->error('请先登录'); } $userId = $this->auth->id ?? -1; $params = $this->request->post(); // 定义验证规则 $validate = new Validate([ 'desc' => 'require|min:10', 'contact' => 'require', ], [ 'desc.require' => '简介描述不能为空', 'desc.min' => '简介描述至少10个字符', 'contact.require' => '联系方式不能为空' ]); // 验证数据 if (!$validate->check($params)) { $this->error($validate->getError()); } if (DeveloperService::getOne(['user_id' => $userId])) { exception('您已经申请入驻,请勿重复申请!'); } // 合并各技术分类选中的标签(编程语言/前端技术/后端技术/其它技术) $params['tags'] = array_values(array_unique(array_filter(array_merge( (array)($params['languageSelected'] ?? []), (array)($params['frontSelected'] ?? []), (array)($params['backendSelected'] ?? []), (array)($params['otherSelected'] ?? []) )))); if (empty($params['tags'])) { $this->error('技能标签不能为空'); } DeveloperService::instance()->create($params, $userId); $this->success('申请已提交,等待审核通过即可接单'); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } }