2026-09-17 16:25:31 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\common\service;
|
|
|
|
|
|
|
|
|
|
use app\admin\model\Developers;
|
|
|
|
|
use app\common\traits\ServiceTrait;
|
|
|
|
|
use Exception;
|
|
|
|
|
use think\Db;
|
|
|
|
|
|
|
|
|
|
class DeveloperService
|
|
|
|
|
{
|
|
|
|
|
use ServiceTrait;
|
|
|
|
|
|
|
|
|
|
/** @var Developers */
|
|
|
|
|
public static $Model = Developers::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 人才入驻
|
|
|
|
|
*
|
|
|
|
|
* @param array $data 数据
|
|
|
|
|
* @param int $userId 用户ID
|
|
|
|
|
* @return bool
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static function create($data, $userId)
|
|
|
|
|
{
|
|
|
|
|
$saveData = [
|
|
|
|
|
'user_id' => $userId,
|
|
|
|
|
'job' => $data['job'] ?? '',
|
2026-09-23 18:05:15 +08:00
|
|
|
'tags' => implode(',', array_filter((array)($data['tags'] ?? []))),
|
2026-09-17 16:25:31 +08:00
|
|
|
'work_years' => $data['work_years'] ?? 0,
|
|
|
|
|
'contact' => $data['contact'] ?? '',
|
|
|
|
|
'desc' => $data['desc'] ?? '',
|
|
|
|
|
];
|
|
|
|
|
$existed = self::$Model::get(['user_id' => $userId]);
|
|
|
|
|
if (!$existed) {
|
|
|
|
|
$result = self::$Model::create($saveData);
|
|
|
|
|
} else {
|
|
|
|
|
$result = self::$Model::where('user_id', $userId)->update($saveData);
|
|
|
|
|
}
|
|
|
|
|
if (!$result) {
|
|
|
|
|
throw new Exception('需求保存失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $id
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function auditPass($id)
|
|
|
|
|
{
|
|
|
|
|
Db::transaction(function () use ($id) {
|
|
|
|
|
$developer = self::getOne(['id' => $id]);
|
|
|
|
|
if (!$developer) {
|
|
|
|
|
exception('该开发者不存在');
|
|
|
|
|
}
|
|
|
|
|
//修改审核状态
|
|
|
|
|
$developer->status = CommonService::STATUS_ON;
|
|
|
|
|
$saveRes = $developer->save();
|
|
|
|
|
if (!$saveRes) {
|
|
|
|
|
exception('更新审核状态失败');
|
|
|
|
|
}
|
|
|
|
|
//设置开发者角色
|
|
|
|
|
$user = UserService::getOne(['id' => $developer->user_id]);
|
|
|
|
|
$user->role = UserService::ROLE_DEV;
|
|
|
|
|
$saveRes2 = $user->save();
|
|
|
|
|
if (!$saveRes2) {
|
|
|
|
|
exception('更新用户角色失败');
|
|
|
|
|
}
|
|
|
|
|
//发送入驻成功通知
|
|
|
|
|
$msgData = [
|
|
|
|
|
'values' => [
|
|
|
|
|
'开发者',
|
|
|
|
|
date('Y-m-d H:i:s', $developer->createtime),
|
|
|
|
|
'审核成功',
|
|
|
|
|
SubscribeMessageService::MSG_MAP[SubscribeMessageService::MSG_TEMP_DEVELOPER_JOIN]['remark'],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
(new EasyWeChatService())->sendMsg($developer->user_id, SubscribeMessageService::MSG_TEMP_DEVELOPER_JOIN, $msgData);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|