重构DiceLotteryConfig为DiceLotteryPoolConfig
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\lottery_config;
|
||||
namespace app\dice\model\lottery_pool_config;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
|
||||
@@ -27,7 +27,7 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
* @property $t5_weight T5池权重
|
||||
* @property $ev 池子累计盈利(游戏结算时累加,仅展示不可编辑)
|
||||
*/
|
||||
class DiceLotteryConfig extends BaseModel
|
||||
class DiceLotteryPoolConfig extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\play_record;
|
||||
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
@@ -71,12 +71,12 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 彩金配置
|
||||
* 关联模型 diceLotteryConfig
|
||||
* 彩金池配置
|
||||
* 关联模型 diceLotteryPoolConfig
|
||||
*/
|
||||
public function diceLotteryConfig(): BelongsTo
|
||||
public function diceLotteryPoolConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryConfig::class, 'lottery_config_id', 'id');
|
||||
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
|
||||
/** 按玩家用户名模糊(dicePlayer.username) */
|
||||
@@ -93,13 +93,13 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 按彩金池配置名称模糊(diceLotteryConfig.name) */
|
||||
/** 按彩金池配置名称模糊(diceLotteryPoolConfig.name) */
|
||||
public function searchLotteryConfigNameAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$ids = DiceLotteryConfig::where('name', 'like', '%' . $value . '%')->column('id');
|
||||
$ids = DiceLotteryPoolConfig::where('name', 'like', '%' . $value . '%')->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('lottery_config_id', $ids);
|
||||
} else {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace app\dice\model\player;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家模型
|
||||
@@ -78,14 +78,14 @@ class DicePlayer extends BaseModel
|
||||
if ($name === null || $name === '') {
|
||||
$model->setAttr('name', $uid);
|
||||
}
|
||||
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryConfig type=0 的 id,没有则为 0
|
||||
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig type=0 的 id,没有则为 0
|
||||
try {
|
||||
$lotteryConfigId = $model->getAttr('lottery_config_id');
|
||||
} catch (\Throwable $e) {
|
||||
$lotteryConfigId = null;
|
||||
}
|
||||
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
|
||||
$config = DiceLotteryConfig::where('type', 0)->find();
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
|
||||
}
|
||||
// 彩金池权重默认取 type=0 的奖池配置
|
||||
@@ -93,11 +93,11 @@ class DicePlayer extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 DiceLotteryConfig type=0 取 t1_weight~t5_weight 作为玩家未设置时的默认值
|
||||
* 从 DiceLotteryPoolConfig type=0 取 t1_weight~t5_weight 作为玩家未设置时的默认值
|
||||
*/
|
||||
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
|
||||
{
|
||||
$config = DiceLotteryConfig::where('type', 0)->find();
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
if (!$config) {
|
||||
return;
|
||||
}
|
||||
@@ -185,8 +185,8 @@ class DicePlayer extends BaseModel
|
||||
/**
|
||||
* 关联彩金池配置
|
||||
*/
|
||||
public function diceLotteryConfig()
|
||||
public function diceLotteryPoolConfig()
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryConfig::class, 'lottery_config_id', 'id');
|
||||
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user