重构*_weight为*_weight

This commit is contained in:
2026-03-07 10:07:44 +08:00
parent 7e5585aee0
commit fe1ceeb4fb
9 changed files with 127 additions and 128 deletions

View File

@@ -82,7 +82,7 @@ class UserLogic
$token = $tokenResult['access_token'];
UserCache::setSessionByUsername($username, $token);
$userArr = $player->hidden(['password'])->toArray();
$userArr = $player->hidden(['password', 'is_up', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'])->toArray();
UserCache::setUser((int) $player->id, $userArr);
UserCache::setPlayerByUsername($username, $userArr);

View File

@@ -19,7 +19,7 @@ class LotteryService
private int $playerId;
private ?int $configType0Id = null;
private ?int $configType1Id = null;
/** @var array{t1_wight?:int,t2_wight?:int,t3_wight?:int,t4_wight?:int,t5_wight?:int} */
/** @var array{t1_weight?:int,t2_weight?:int,t3_weight?:int,t4_weight?:int,t5_weight?:int} */
private array $playerWeights = [];
public function __construct(int $playerId)
@@ -62,11 +62,11 @@ class LotteryService
$s->configType0Id = $config0 ? (int) $config0->id : null;
$s->configType1Id = $config1 ? (int) $config1->id : null;
$s->playerWeights = [
't1_wight' => (int) ($player->t1_wight ?? 0),
't2_wight' => (int) ($player->t2_wight ?? 0),
't3_wight' => (int) ($player->t3_wight ?? 0),
't4_wight' => (int) ($player->t4_wight ?? 0),
't5_wight' => (int) ($player->t5_wight ?? 0),
't1_weight' => (int) ($player->t1_weight ?? 0),
't2_weight' => (int) ($player->t2_weight ?? 0),
't3_weight' => (int) ($player->t3_weight ?? 0),
't4_weight' => (int) ($player->t4_weight ?? 0),
't5_weight' => (int) ($player->t5_weight ?? 0),
];
$s->save();
return $s;
@@ -83,33 +83,33 @@ class LotteryService
Cache::set($key, json_encode($data), self::EXPIRE);
}
/** 根据奖池配置的 t1_wight..t5_wight 权重随机抽取档位 T1-T5 */
/** 根据奖池配置的 t1_weight..t5_weight 权重随机抽取档位 T1-T5 */
public static function drawTierByWeights(DiceLotteryConfig $config): string
{
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
$weights = [
(int) ($config->t1_wight ?? 0),
(int) ($config->t2_wight ?? 0),
(int) ($config->t3_wight ?? 0),
(int) ($config->t4_wight ?? 0),
(int) ($config->t5_wight ?? 0),
(int) ($config->t1_weight ?? 0),
(int) ($config->t2_weight ?? 0),
(int) ($config->t3_weight ?? 0),
(int) ($config->t4_weight ?? 0),
(int) ($config->t5_weight ?? 0),
];
return self::drawTierByWeightArray($tiers, $weights);
}
/**
* 根据玩家 t1_wightt5_wight 权重随机抽取中奖档位 T1-T5
* t1_wight=T1, t2_wight=T2, t3_wight=T3, t4_wight=T4, t5_wight=T5
* 根据玩家 t1_weightt5_weight 权重随机抽取中奖档位 T1-T5
* t1_weight=T1, t2_weight=T2, t3_weight=T3, t4_weight=T4, t5_weight=T5
*/
public static function drawTierByPlayerWeights(DicePlayer $player): string
{
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
$weights = [
(int) ($player->t1_wight ?? 0),
(int) ($player->t2_wight ?? 0),
(int) ($player->t3_wight ?? 0),
(int) ($player->t4_wight ?? 0),
(int) ($player->t5_wight ?? 0),
(int) ($player->t1_weight ?? 0),
(int) ($player->t2_weight ?? 0),
(int) ($player->t3_weight ?? 0),
(int) ($player->t4_weight ?? 0),
(int) ($player->t5_weight ?? 0),
];
return self::drawTierByWeightArray($tiers, $weights);
}

View File

@@ -20,11 +20,11 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $safety_line 安全线
* @property $create_time 创建时间
* @property $update_time 修改时间
* @property $t1_wight T1池权重
* @property $t2_wight T2池权重
* @property $t3_wight T3池权重
* @property $t4_wight T4池权重
* @property $t5_wight T5池权重
* @property $t1_weight T1池权重
* @property $t2_weight T2池权重
* @property $t3_weight T3池权重
* @property $t4_weight T4池权重
* @property $t5_weight T5池权重
*/
class DiceLotteryConfig extends BaseModel
{

View File

@@ -23,17 +23,17 @@ use app\dice\model\lottery_config\DiceLotteryConfig;
* @property $status 状态
* @property $coin 平台币
* @property $is_up 倍率
* @property $t1_wight T1池权重
* @property $t2_wight T2池权重
* @property $t3_wight T3池权重
* @property $t4_wight T4池权重
* @property $t5_wight T5池权重
* @property $t1_weight T1池权重
* @property $t2_weight T2池权重
* @property $t3_weight T3池权重
* @property $t4_weight T4池权重
* @property $t5_weight T5池权重
* @property $total_ticket_count 总抽奖次数
* @property $paid_ticket_count 购买抽奖次数
* @property $free_ticket_count 赠送抽奖次数
* @property $created_at 创建时间
* @property $updated_at 更新时间
* @property $deleted_at 删除时间
* @property $create_time 创建时间
* @property $update_time 更新时间
* @property $delete_time 删除时间
*/
class DicePlayer extends BaseModel
{
@@ -49,10 +49,9 @@ class DicePlayer extends BaseModel
*/
protected $table = 'dice_player';
/** 创建时间字段dice_player 表为 created_at */
protected $createTime = 'created_at';
/** 更新时间字段dice_player 表为 updated_at */
protected $updateTime = 'updated_at';
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 新增前:生成唯一 uid昵称 name 默认使用 uid
@@ -83,7 +82,7 @@ class DicePlayer extends BaseModel
}
/**
* 从 DiceLotteryConfig type=0 取 t1_wightt5_wight 作为玩家未设置时的默认值
* 从 DiceLotteryConfig type=0 取 t1_weightt5_weight 作为玩家未设置时的默认值
*/
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
{
@@ -91,7 +90,7 @@ class DicePlayer extends BaseModel
if (!$config) {
return;
}
$fields = ['t1_wight', 't2_wight', 't3_wight', 't4_wight', 't5_wight'];
$fields = ['t1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'];
foreach ($fields as $field) {
try {
$val = $model->getAttr($field);

View File

@@ -19,11 +19,11 @@ class DiceLotteryConfigValidate extends BaseValidate
protected $rule = [
'name' => 'require',
'type' => 'require',
't1_wight' => 'require',
't2_wight' => 'require',
't3_wight' => 'require',
't4_wight' => 'require',
't5_wight' => 'require',
't1_weight' => 'require',
't2_weight' => 'require',
't3_weight' => 'require',
't4_weight' => 'require',
't5_weight' => 'require',
];
/**
@@ -32,11 +32,11 @@ class DiceLotteryConfigValidate extends BaseValidate
protected $message = [
'name' => '名称必须填写',
'type' => '奖池类型必须填写',
't1_wight' => 'T1池权重必须填写',
't2_wight' => 'T2池权重必须填写',
't3_wight' => 'T3池权重必须填写',
't4_wight' => 'T4池权重必须填写',
't5_wight' => 'T5池权重必须填写',
't1_weight' => 'T1池权重必须填写',
't2_weight' => 'T2池权重必须填写',
't3_weight' => 'T3池权重必须填写',
't4_weight' => 'T4池权重必须填写',
't5_weight' => 'T5池权重必须填写',
];
/**
@@ -46,20 +46,20 @@ class DiceLotteryConfigValidate extends BaseValidate
'save' => [
'name',
'type',
't1_wight',
't2_wight',
't3_wight',
't4_wight',
't5_wight',
't1_weight',
't2_weight',
't3_weight',
't4_weight',
't5_weight',
],
'update' => [
'name',
'type',
't1_wight',
't2_wight',
't3_wight',
't4_wight',
't5_wight',
't1_weight',
't2_weight',
't3_weight',
't4_weight',
't5_weight',
],
];