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