-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
854a13c
commit d629233
Showing
7 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
|
||
namespace App\Constants; | ||
|
||
enum GachaType: int | ||
{ | ||
/** | ||
* 新手池. | ||
*/ | ||
case NEW_USER = 100; | ||
|
||
/** | ||
* 常驻池. | ||
*/ | ||
case NORMAL = 200; | ||
|
||
/** | ||
* UP 角色池. | ||
*/ | ||
case ROLE = 301; | ||
|
||
/** | ||
* 武器池. | ||
*/ | ||
case WEAPON = 302; | ||
|
||
public static function enums(): array | ||
{ | ||
return [ | ||
self::NORMAL, | ||
self::ROLE, | ||
self::WEAPON, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
|
||
namespace App\Service; | ||
|
||
use App\Constants\GachaType; | ||
use App\Model\YsGachaLog; | ||
use App\Service\Dao\YsUserDao; | ||
use App\Service\SubService\Mihoyo; | ||
use Han\Utils\Service; | ||
use Hyperf\AsyncQueue\Annotation\AsyncQueueMessage; | ||
use Hyperf\Redis\Redis; | ||
use Throwable; | ||
|
||
class YsGachaLogService extends Service | ||
{ | ||
#[AsyncQueueMessage] | ||
public function load(int $userId): void | ||
{ | ||
$key = 'load:gacha:' . $userId; | ||
if (di()->get(Redis::class)->set($key, '1', ['EX' => 3600, 'NX'])) { | ||
try { | ||
$user = di()->get(YsUserDao::class)->first($userId); | ||
if (! $user) { | ||
return; | ||
} | ||
|
||
foreach (GachaType::enums() as $type) { | ||
$id = 0; | ||
while (true) { | ||
$result = di()->get(Mihoyo::class)->getGachaLog($user->auth_key, $type, $id); | ||
if (empty($result['list'])) { | ||
break; | ||
} | ||
foreach ($result['list'] as $re) { | ||
$id = $re['id']; | ||
|
||
$model = new YsGachaLog(); | ||
$model->id = $re['id']; | ||
$model->uid = $re['uid']; | ||
$model->gacha_type = $re['gacha_type']; | ||
$model->time = $re['time']; | ||
$model->name = $re['name']; | ||
$model->item_type = $re['item_type']; | ||
$model->rank_type = $re['rank_type']; | ||
try { | ||
$model->save(); | ||
} catch (Throwable) { | ||
break 2; | ||
} | ||
} | ||
} | ||
} | ||
} finally { | ||
di()->get(Redis::class)->del($key); | ||
} | ||
} | ||
} | ||
} |