Files
code-bang/backend/application/api/controller/Developer.php
T
2026-09-23 18:05:15 +08:00

72 lines
2.5 KiB
PHP

<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\service\DeveloperService;
use think\exception\HttpResponseException;
use think\Validate;
class Developer extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
/**
* 人才入驻资料提交
*
* @ApiMethod (POST)
* @param string $desc 需求描述
* @param array $images 图片数组
* @param array $files 文件数组
* @param string $contact 联系方式
* @param array $languageSelected 选中的编程语言
* @param array $frontSelected 选中的前端技术
* @param array $backendSelected 选中的后端技术
* @param array $otherSelected 选中的其它技术
*/
public function submit()
{
try {
if (!$this->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());
}
}
}