dootask/app/Models/UserTransfer.php
kuaifan 2f8dee44c2 refactor(mail): 邮件发送弃用 guanguans/notify 改用 symfony/mailer
guanguans/notify 在本项目仅用于 SMTP 发信,但其 1.x 线已停更、email 渠道
自 3.x 起被上游移除(无升级路径)。改用项目已自带的 symfony/mailer(Laravel
13 传递依赖),零新增依赖,并一并移除孤儿依赖 overtrue/http、symfony/options-resolver。

- EmailNoticeTask / UserEmailVerification / SystemController 三处发信改为
  new Mailer(Transport::fromDsn(...)) + new Email();API 1:1 等价
  (from/to/subject/html 同名,verify_peer=0 仍受 symfony 8.x 支持,
  notify 本就裸调 symfony 故异常透传不变、getCode()===550 仍成立)
- 移除 UserTransfer 未使用的 notify import
- 顺带修复既有 bug:超时判断字面量 "Timed Out" 与 symfony 实际消息
  "timed out" 大小写不匹配,改 stripos 大小写不敏感

验证:phpstan 0 错误、composer audit 无公告;邮箱验证码、系统邮件测试两条
链路实测发信成功。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 06:10:47 +00:00

112 lines
4.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use App\Exceptions\ApiException;
use App\Module\Base;
use Carbon\Carbon;
/**
* App\Models\UserTransfer
*
* @property int $id
* @property int|null $original_userid 原作者
* @property int|null $new_userid 交接人
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelAppend()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelHidden()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel change($array)
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel getKeyValue()
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer query()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel remove()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel saveOrIgnore()
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer whereNewUserid($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer whereOriginalUserid($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserTransfer whereUpdatedAt($value)
* @mixin \Eloquent
*/
class UserTransfer extends AbstractModel
{
/**
* 开始移交
* @return void
*/
public function start()
{
// 移交部门
UserDepartment::transfer($this->original_userid, $this->new_userid);
// 移交项目身份
ProjectUser::transfer($this->original_userid, $this->new_userid);
// 移交任务身份
ProjectTaskUser::transfer($this->original_userid, $this->new_userid);
// 移交文件
File::transfer($this->original_userid, $this->new_userid);
// 离职移出群组
$this->exitDialog();
}
/**
* 退出群组
* @return void
*/
public function exitDialog()
{
$lastId = 0;
$limit = 100;
while (true) {
$query = WebSocketDialog::select(['web_socket_dialogs.*'])
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
->where('web_socket_dialogs.type', 'group')
->where('web_socket_dialogs.group_type', '!=', 'okr')
->where('u.userid', $this->original_userid)
->orderBy('web_socket_dialogs.id')
->limit($limit);
if ($lastId) {
$query->where('web_socket_dialogs.id', '>', $lastId);
}
$list = $query->get();
// 没有数据了就退出
if ($list->isEmpty()) {
break;
}
// 记录最后一条记录的ID
$lastId = $list->last()->id;
// 离职员工退出群
foreach ($list as $dialog) {
$dialog->exitGroup($this->original_userid, 'remove', false, false);
if ($dialog->owner_id === $this->original_userid) {
// 如果是群主则把交接人设为群主
$dialog->owner_id = $this->new_userid;
if ($dialog->save()) {
$dialog->joinGroup($this->new_userid, 0);
// 同步 role=1保证 deputy_ids 与 owner_id 一致
// 若 new_userid 之前是群管理员role=2升为群主后必须从 deputy 列表移出
WebSocketDialogUser::where('dialog_id', $dialog->id)
->where('userid', $this->new_userid)
->update(['role' => 1]);
$dialog->pushMsg("groupUpdate", [
'id' => $dialog->id,
'owner_id' => $dialog->owner_id,
'deputy_ids' => $dialog->fresh()->deputy_ids,
]);
}
}
}
// 如果返回的数据少于限制数,说明已经是最后一批
if ($list->count() < $limit) {
break;
}
}
}
}