mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
add temporary invite use idRedisKey
This commit is contained in:
@@ -12,14 +12,14 @@ class InviteAddTemporary extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'invite:tmp {uid} {days} {count}';
|
protected $signature = 'invite:tmp {idRedisKey} {days} {count}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Add temporary invite to user, argument: uid(Multiple comma separated), days, count';
|
protected $description = 'Add temporary invite to user, argument: idRedisKey, days, count';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
@@ -28,14 +28,13 @@ class InviteAddTemporary extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$uid = $this->argument('uid');
|
$idRedisKey = $this->argument('idRedisKey');
|
||||||
$days = $this->argument('days');
|
$days = $this->argument('days');
|
||||||
$count = $this->argument('count');
|
$count = $this->argument('count');
|
||||||
$log = "uid: $uid, days: $days, count: $count";
|
$log = "idRedisKey: $idRedisKey, days: $days, count: $count";
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
$uidArr = preg_split('/[\s,]+/', $uid);
|
GenerateTemporaryInvite::dispatch($idRedisKey, $days, $count);
|
||||||
GenerateTemporaryInvite::dispatch($uidArr, $days, $count);
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Nexus\Database\NexusDB;
|
||||||
|
|
||||||
class GenerateTemporaryInvite implements ShouldQueue
|
class GenerateTemporaryInvite implements ShouldQueue
|
||||||
{
|
{
|
||||||
@@ -19,7 +20,7 @@ class GenerateTemporaryInvite implements ShouldQueue
|
|||||||
|
|
||||||
private int $count;
|
private int $count;
|
||||||
|
|
||||||
private array $uidArr;
|
private string $idRedisKey;
|
||||||
|
|
||||||
private int $days;
|
private int $days;
|
||||||
|
|
||||||
@@ -28,9 +29,9 @@ class GenerateTemporaryInvite implements ShouldQueue
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(array $uidArr, int $days, int $count)
|
public function __construct(string $idRedisKey, int $days, int $count)
|
||||||
{
|
{
|
||||||
$this->uidArr = $uidArr;
|
$this->idRedisKey = $idRedisKey;
|
||||||
$this->days = $days;
|
$this->days = $days;
|
||||||
$this->count = $count;
|
$this->count = $count;
|
||||||
}
|
}
|
||||||
@@ -57,7 +58,13 @@ class GenerateTemporaryInvite implements ShouldQueue
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$toolRep = new ToolRepository();
|
$toolRep = new ToolRepository();
|
||||||
foreach ($this->uidArr as $uid) {
|
$idStr = NexusDB::cache_get($this->idRedisKey);
|
||||||
|
if (empty($idStr)) {
|
||||||
|
do_log("no idStr of idRedisKey: {$this->idRedisKey}...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$idArr = explode(",", $idStr);
|
||||||
|
foreach ($idArr as $uid) {
|
||||||
try {
|
try {
|
||||||
$hashArr = $toolRep->generateUniqueInviteHash([], $this->count, $this->count);
|
$hashArr = $toolRep->generateUniqueInviteHash([], $this->count, $this->count);
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|||||||
@@ -59,10 +59,12 @@ while (true) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$idStr = implode(',', $idArr);
|
$idStr = implode(',', $idArr);
|
||||||
|
$idRedisKey = sprintf("temporary_invite:%d", microtime(true));
|
||||||
|
\Nexus\Database\NexusDB::cache_put($idRedisKey, $idStr);
|
||||||
if ($isTypeTmpInvite) {
|
if ($isTypeTmpInvite) {
|
||||||
$command = sprintf(
|
$command = sprintf(
|
||||||
'invite:tmp %s %s %s',
|
'invite:tmp %s %s %s',
|
||||||
$idStr, $duration, $amount
|
$idRedisKey, $duration, $amount
|
||||||
);
|
);
|
||||||
$output = executeCommand($command, 'string', true);
|
$output = executeCommand($command, 'string', true);
|
||||||
do_log(sprintf('command: %s, output: %s', $command, $output));
|
do_log(sprintf('command: %s, output: %s', $command, $output));
|
||||||
|
|||||||
Reference in New Issue
Block a user