117 lines
3.6 KiB
PHP
117 lines
3.6 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | saiadmin [ saiadmin快速开发框架 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Author: your name
|
||
// +----------------------------------------------------------------------
|
||
namespace app\dice\model\lottery_pool_config;
|
||
|
||
use app\dice\helper\AdminScopeHelper;
|
||
use app\dice\helper\ConfigScopeEditHelper;
|
||
use app\dice\model\DiceModel;
|
||
|
||
/**
|
||
* 色子奖池配置模型
|
||
*
|
||
* dice_lottery_pool_config 色子奖池配置
|
||
*
|
||
* @property $id ID
|
||
* @property $name 名称
|
||
* @property $remark 奖池名称(后台展示名)
|
||
* @property $config_note 配置备注
|
||
* @property $safety_line 安全线
|
||
* @property $kill_enabled 是否启用杀分:0=关闭 1=开启
|
||
* @property $create_time 创建时间
|
||
* @property $update_time 修改时间
|
||
* @property $t1_weight T1池权重
|
||
* @property $t2_weight T2池权重
|
||
* @property $t3_weight T3池权重
|
||
* @property $t4_weight T4池权重
|
||
* @property $t5_weight T5池权重
|
||
* @property $profit_amount 池子累计盈利(每局付费按 win_coin-paid_amount,免费按 win_coin 累加;仅展示不可编辑)
|
||
*/
|
||
class DiceLotteryPoolConfig extends DiceModel
|
||
{
|
||
/** 玩家默认彩金池(新玩家关联;付费未杀分时运行时读取该池 T1–T5 权重) */
|
||
public const NAME_PLAYER_DEFAULT = 'playerDefault';
|
||
|
||
/**
|
||
* 数据表主键
|
||
* @var string
|
||
*/
|
||
protected $pk = 'id';
|
||
|
||
/**
|
||
* 数据库表名称
|
||
* @var string
|
||
*/
|
||
protected $table = 'dice_lottery_pool_config';
|
||
|
||
/** 列表/关联 JSON 附带奖池展示名 */
|
||
protected $append = ['display_name'];
|
||
|
||
/**
|
||
* 按名称与渠道查找奖池配置(一键测试等场景,避免命中其他渠道同名配置)
|
||
*/
|
||
public static function findByNameForDept(string $name, int $deptId): ?self
|
||
{
|
||
$query = (new self())->where('name', $name);
|
||
ConfigScopeEditHelper::applyDeptIdWhere($query, AdminScopeHelper::normalizeRecordDeptId($deptId));
|
||
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)
|
||
{
|
||
$like = '%' . $value . '%';
|
||
$query->where(function ($q) use ($like) {
|
||
$q->where('name', 'like', $like)
|
||
->whereOr('remark', 'like', $like);
|
||
});
|
||
}
|
||
|
||
}
|