mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
fix: 修复退出群组不完全的问题
This commit is contained in:
parent
bab37530e4
commit
f28b99b516
@ -7,8 +7,9 @@ use Cache;
|
|||||||
use Request;
|
use Request;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
use Response;
|
use Response;
|
||||||
use App\Module\Doo;
|
|
||||||
use App\Models\File;
|
use App\Models\File;
|
||||||
|
use App\Models\UserTransfer;
|
||||||
|
use App\Module\Doo;
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
use App\Module\Extranet;
|
use App\Module\Extranet;
|
||||||
use App\Module\RandomColor;
|
use App\Module\RandomColor;
|
||||||
@ -24,6 +25,7 @@ use App\Tasks\CloseMeetingRoomTask;
|
|||||||
use App\Tasks\UnclaimedTaskRemindTask;
|
use App\Tasks\UnclaimedTaskRemindTask;
|
||||||
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
||||||
use Laravolt\Avatar\Avatar;
|
use Laravolt\Avatar\Avatar;
|
||||||
|
use Swoole\Coroutine;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,6 +261,27 @@ class IndexController extends InvokeController
|
|||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 迁移辅助路由
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function migration__userdialog()
|
||||||
|
{
|
||||||
|
if (Request::header('app-key') !== env('APP_KEY')) {
|
||||||
|
return Base::retError("key error");
|
||||||
|
}
|
||||||
|
go(function() {
|
||||||
|
Coroutine::sleep(3);
|
||||||
|
UserTransfer::orderBy('id')->chunkById(10, function ($transfers) {
|
||||||
|
/** @var UserTransfer $transfer */
|
||||||
|
foreach ($transfers as $transfer) {
|
||||||
|
$transfer->exitDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return Base::retSuccess('success');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桌面客户端发布
|
* 桌面客户端发布
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -50,29 +50,58 @@ class UserTransfer extends AbstractModel
|
|||||||
// 移交文件
|
// 移交文件
|
||||||
File::transfer($this->original_userid, $this->new_userid);
|
File::transfer($this->original_userid, $this->new_userid);
|
||||||
// 离职移出群组
|
// 离职移出群组
|
||||||
WebSocketDialog::select(['web_socket_dialogs.*'])
|
$this->exitDialog();
|
||||||
->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)
|
* 退出群组
|
||||||
->orderByDesc('web_socket_dialogs.id')
|
* @return void
|
||||||
->chunk(100, function($list) {
|
*/
|
||||||
/** @var WebSocketDialog $dialog */
|
public function exitDialog()
|
||||||
foreach ($list as $dialog) {
|
{
|
||||||
// 离职员工退出群
|
$lastId = 0;
|
||||||
$dialog->exitGroup($this->original_userid, 'remove', false, false);
|
$limit = 100;
|
||||||
if ($dialog->owner_id === $this->original_userid) {
|
while (true) {
|
||||||
// 如果是群主则把交接人设为群主
|
$query = WebSocketDialog::select(['web_socket_dialogs.*'])
|
||||||
$dialog->owner_id = $this->new_userid;
|
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||||
if ($dialog->save()) {
|
->where('web_socket_dialogs.type', 'group')
|
||||||
$dialog->joinGroup($this->new_userid, 0);
|
->where('web_socket_dialogs.group_type', '!=', 'okr')
|
||||||
$dialog->pushMsg("groupUpdate", [
|
->where('u.userid', $this->original_userid)
|
||||||
'id' => $dialog->id,
|
->orderBy('web_socket_dialogs.id')
|
||||||
'owner_id' => $dialog->owner_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);
|
||||||
|
$dialog->pushMsg("groupUpdate", [
|
||||||
|
'id' => $dialog->id,
|
||||||
|
'owner_id' => $dialog->owner_id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// 如果返回的数据少于限制数,说明已经是最后一批
|
||||||
|
if ($list->count() < $limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\UserTransfer;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class ProcessUserTransferDialog extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (UserTransfer::count() === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
\App\Module\Ihttp::ihttp_request('http://127.0.0.1:' . config('laravels.listen_port') . '/migration/userdialog', [], [
|
||||||
|
'app-key' => env('APP_KEY')
|
||||||
|
], 10);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
info($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user