1.新增默认彩金池配置
2.优化关联彩金池配置的名称显示 3.优化一键测试权重 4.优化底注配置
This commit is contained in:
@@ -17,7 +17,8 @@ use app\dice\model\DiceModel;
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $name 名称
|
||||
* @property $remark 备注
|
||||
* @property $remark 奖池名称(后台展示名)
|
||||
* @property $config_note 配置备注
|
||||
* @property $safety_line 安全线
|
||||
* @property $kill_enabled 是否启用杀分:0=关闭 1=开启
|
||||
* @property $create_time 创建时间
|
||||
@@ -31,6 +32,9 @@ use app\dice\model\DiceModel;
|
||||
*/
|
||||
class DiceLotteryPoolConfig extends DiceModel
|
||||
{
|
||||
/** 玩家默认彩金池(新玩家关联;付费未杀分时运行时读取该池 T1–T5 权重) */
|
||||
public const NAME_PLAYER_DEFAULT = 'playerDefault';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
@@ -43,6 +47,9 @@ class DiceLotteryPoolConfig extends DiceModel
|
||||
*/
|
||||
protected $table = 'dice_lottery_pool_config';
|
||||
|
||||
/** 列表/关联 JSON 附带奖池展示名 */
|
||||
protected $append = ['display_name'];
|
||||
|
||||
/**
|
||||
* 按名称与渠道查找奖池配置(一键测试等场景,避免命中其他渠道同名配置)
|
||||
*/
|
||||
@@ -53,12 +60,57 @@ class DiceLotteryPoolConfig extends DiceModel
|
||||
return $query->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否玩家默认模板池(运行时按该池权重抽档,改池配置即对所有关联玩家生效)
|
||||
*/
|
||||
public function isPlayerDefaultTemplate(): bool
|
||||
{
|
||||
return (string) ($this->name ?? '') === self::NAME_PLAYER_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台展示用奖池名称:优先 remark,否则 name
|
||||
*
|
||||
* @param array<string, mixed>|self $row
|
||||
*/
|
||||
public static function displayLabel($row): string
|
||||
{
|
||||
// 禁止对模型实例 toArray():append display_name 会再次触发本方法,导致内存耗尽
|
||||
if ($row instanceof self) {
|
||||
$data = $row->getData();
|
||||
$remark = trim((string) ($data['remark'] ?? ''));
|
||||
if ($remark !== '') {
|
||||
return $remark;
|
||||
}
|
||||
return trim((string) ($data['name'] ?? ''));
|
||||
}
|
||||
$remark = trim((string) ($row['remark'] ?? ''));
|
||||
if ($remark !== '') {
|
||||
return $remark;
|
||||
}
|
||||
return trim((string) ($row['name'] ?? ''));
|
||||
}
|
||||
|
||||
public function getDisplayNameAttr(): string
|
||||
{
|
||||
$data = $this->getData();
|
||||
$remark = trim((string) ($data['remark'] ?? ''));
|
||||
if ($remark !== '') {
|
||||
return $remark;
|
||||
}
|
||||
return trim((string) ($data['name'] ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* 名称 搜索
|
||||
*/
|
||||
public function searchNameAttr($query, $value)
|
||||
{
|
||||
$query->where('name', 'like', '%'.$value.'%');
|
||||
$like = '%' . $value . '%';
|
||||
$query->where(function ($q) use ($like) {
|
||||
$q->where('name', 'like', $like)
|
||||
->whereOr('remark', 'like', $like);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,13 +88,17 @@ class DicePlayRecord extends DiceModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 按彩金池配置名称模糊(diceLotteryPoolConfig.name) */
|
||||
/** 按彩金池奖池名称或内部标识模糊搜索 */
|
||||
public function searchLotteryConfigNameAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$ids = DiceLotteryPoolConfig::where('name', 'like', '%' . $value . '%')->column('id');
|
||||
$like = '%' . $value . '%';
|
||||
$ids = DiceLotteryPoolConfig::where(function ($q) use ($like) {
|
||||
$q->where('name', 'like', $like)
|
||||
->whereOr('remark', 'like', $like);
|
||||
})->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('lottery_config_id', $ids);
|
||||
} else {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\player;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\DiceModel;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
|
||||
@@ -84,44 +85,61 @@ class DicePlayer extends DiceModel
|
||||
if ($name === null || $name === '') {
|
||||
$model->setAttr('name', $uid);
|
||||
}
|
||||
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig name=default 的 id,没有则为 0
|
||||
// 创建玩家时:未指定则关联 name=playerDefault(玩家默认彩金池),没有则为 0
|
||||
try {
|
||||
$lotteryConfigId = $model->getAttr('lottery_config_id');
|
||||
} catch (\Throwable $e) {
|
||||
$lotteryConfigId = null;
|
||||
}
|
||||
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
|
||||
$config = self::findDefaultLotteryConfigForPlayer($model);
|
||||
$config = self::findPlayerDefaultLotteryConfigForPlayer($model);
|
||||
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
|
||||
}
|
||||
// 彩金池权重默认取 name=default 的奖池配置
|
||||
// 展示用权重:从玩家关联的彩金池复制(playerDefault 在抽奖时仍实时读池配置)
|
||||
self::setDefaultWeightsFromLotteryConfig($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按玩家所属渠道查找 default 彩金池配置
|
||||
* 按玩家所属渠道查找玩家默认彩金池(name=playerDefault)
|
||||
*/
|
||||
protected static function findDefaultLotteryConfigForPlayer(DicePlayer $model): ?DiceLotteryPoolConfig
|
||||
protected static function findPlayerDefaultLotteryConfigForPlayer(DicePlayer $model): ?DiceLotteryPoolConfig
|
||||
{
|
||||
$query = DiceLotteryPoolConfig::where('name', 'default');
|
||||
try {
|
||||
$deptId = $model->getAttr('dept_id');
|
||||
if ($deptId !== null && $deptId !== '' && $deptId > 0) {
|
||||
$query->where('dept_id', $deptId);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore
|
||||
$deptId = null;
|
||||
}
|
||||
|
||||
return $query->find();
|
||||
$normalizedDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($model);
|
||||
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
|
||||
$normalizedDeptId = (int) $deptId;
|
||||
}
|
||||
$config = DiceLotteryPoolConfig::findByNameForDept(
|
||||
DiceLotteryPoolConfig::NAME_PLAYER_DEFAULT,
|
||||
$normalizedDeptId
|
||||
);
|
||||
if ($config) {
|
||||
return $config;
|
||||
}
|
||||
return DiceLotteryPoolConfig::findByNameForDept('default', $normalizedDeptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 DiceLotteryPoolConfig name=default 取 t1_weight~t5_weight 作为玩家未设置时的默认值
|
||||
* 从玩家关联彩金池(或 playerDefault / default)取 t1_weight~t5_weight 作为未设置时的默认值
|
||||
*/
|
||||
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
|
||||
{
|
||||
$config = self::findDefaultLotteryConfigForPlayer($model);
|
||||
$config = null;
|
||||
try {
|
||||
$lotteryConfigId = (int) $model->getAttr('lottery_config_id');
|
||||
} catch (\Throwable $e) {
|
||||
$lotteryConfigId = 0;
|
||||
}
|
||||
if ($lotteryConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($lotteryConfigId);
|
||||
}
|
||||
if (!$config) {
|
||||
$config = self::findPlayerDefaultLotteryConfigForPlayer($model);
|
||||
}
|
||||
if (!$config) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user