Files
code-bang/backend/application/api/controller/Developer.php
T

59 lines
1.9 KiB
PHP
Raw Normal View History

2026-09-17 16:25:31 +08:00
<?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 联系方式
*/
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_filter(array_merge($params['languageSelected'], $params['frontSelected'], $params['backendSelected']));
DeveloperService::instance()->create($params, $userId);
$this->success('申请已提交,等待审核通过即可接单');
} catch (\Exception $e) {
if ($e instanceof HttpResponseException) {
throw $e;
}
$this->error($e->getMessage());
}
}
}