GroupOut.php
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace App\Console\Commands;
use App\Helpers\IMHelper;
use App\Http\Service\UserService;
use App\Models\GroupHasMember;
use App\Models\SystemConfig;
use Illuminate\Console\Command;
class GroupOut extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'group:out';
/**
* The console command description.
*
* @var string
*/
protected $description = '自动退出团队';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
GroupHasMember::with(['group:id,user_id', 'member:id,business_id'])->where('status', 2)
->where('updated_at', '<=', now()->subDays($this->getLimitDay()))
->eachById(function (GroupHasMember $member) {
$response = IMHelper::sendSingleChatMessage($member->getAttribute('member_id'), $member->getRelation('group')?->getAttribute('user_id') ?? 0, [
"MsgBody" => IMHelper::createOnlineMessage('TIMCustomElem', [
"Data" => ['businessID' => 'invite_tip', 'content' => '', 'text' => '自动退出团队', 'tipStatus' => 8, 'title' => '', 'version' => 4],
"Desc" => "notification", "Ext" => "url"
]),
"OfflinePushInfo" => IMHelper::createOfflineMessage('', '自动退出团队')
]);
UserService::deleteGroupMember($member->getRelation('member'));
info('自动退出团队', $response->json());
});
return self::SUCCESS;
}
public function getLimitDay()
{
return SystemConfig::query()->where('identifier', 'F_bk65qzuTXvyemFAl4DR')->value('content') ?? 7;
}
}