优化抽奖方式,以及记录相关信息
This commit is contained in:
@@ -12,7 +12,6 @@ use app\dice\logic\play_record\DicePlayRecordLogic;
|
||||
use app\dice\validate\play_record\DicePlayRecordValidate;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
@@ -57,7 +56,6 @@ class DicePlayRecordController extends BaseController
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'diceRewardConfig',
|
||||
'diceLotteryPoolConfig',
|
||||
]);
|
||||
|
||||
@@ -101,23 +99,6 @@ class DicePlayRecordController extends BaseController
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取奖励配置选项(id、ui_text、tier)
|
||||
*/
|
||||
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
|
||||
public function getRewardConfigOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceRewardConfig::field('id,ui_text,tier')->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return [
|
||||
'id' => $item['id'],
|
||||
'ui_text' => $item['ui_text'] ?? '',
|
||||
'tier' => $item['tier'] ?? ''
|
||||
];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
|
||||
@@ -50,7 +50,7 @@ class DicePlayRecordTestController extends BaseController
|
||||
['roll_number', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$query->with(['diceLotteryPoolConfig', 'diceRewardConfig']);
|
||||
$query->with(['diceLotteryPoolConfig']);
|
||||
|
||||
// 按当前筛选条件统计:平台总盈利 = 付费金额(paid_amount 求和) - 玩家总收益(win_coin 求和)
|
||||
$sumQuery = clone $query;
|
||||
|
||||
@@ -19,6 +19,26 @@ use support\think\Db;
|
||||
class WeightTestRunner
|
||||
{
|
||||
private const BATCH_SIZE = 10;
|
||||
/** 测试记录写库白名单字段 */
|
||||
private const PLAY_RECORD_TEST_COLUMNS = [
|
||||
'reward_config_record_id',
|
||||
'admin_id',
|
||||
'lottery_config_id',
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'win_coin',
|
||||
'super_win_coin',
|
||||
'reward_win_coin',
|
||||
'direction',
|
||||
'reward_tier',
|
||||
'ante',
|
||||
'paid_amount',
|
||||
'start_index',
|
||||
'target_index',
|
||||
'roll_array',
|
||||
'roll_number',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* 执行指定测试记录:按付费/免费、顺/逆方向交替模拟(付费顺→付费逆→免费顺→免费逆),每 10 条写入一次测试表并更新进度
|
||||
@@ -194,10 +214,10 @@ class WeightTestRunner
|
||||
'reward_config_record_id' => $rewardConfigRecordId,
|
||||
];
|
||||
$keys = [
|
||||
'player_id', 'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
|
||||
'super_win_coin', 'reward_win_coin', 'use_coins', 'direction', 'reward_config_id',
|
||||
'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
|
||||
'super_win_coin', 'reward_win_coin', 'direction', 'reward_tier',
|
||||
'ante', 'paid_amount',
|
||||
'start_index', 'target_index', 'roll_array', 'roll_number', 'lottery_name', 'status',
|
||||
'start_index', 'target_index', 'roll_array', 'roll_number', 'status',
|
||||
];
|
||||
foreach ($keys as $k) {
|
||||
if (array_key_exists($k, $row)) {
|
||||
@@ -223,7 +243,19 @@ class WeightTestRunner
|
||||
return;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
DicePlayRecordTest::create($row);
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
$payload = [];
|
||||
foreach (self::PLAY_RECORD_TEST_COLUMNS as $column) {
|
||||
if (array_key_exists($column, $row)) {
|
||||
$payload[$column] = $row[$column];
|
||||
}
|
||||
}
|
||||
if ($payload === []) {
|
||||
continue;
|
||||
}
|
||||
Db::name((new DicePlayRecordTest())->getTable())->insert($payload);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ use think\model\relation\BelongsTo;
|
||||
* @property $reward_win_coin 摇色子中奖平台币
|
||||
* @property $use_coins 消耗平台币(兼容字段:付费局=paid_amount,免费局=0)
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $reward_tier 中奖档位:T1,T2,T3,T4,T5,BIGWIN
|
||||
* @property $lottery_id 奖池
|
||||
* @property $start_index 起始索引
|
||||
* @property $target_index 结束索引
|
||||
@@ -64,15 +64,6 @@ class DicePlayRecord extends BaseModel
|
||||
return $this->belongsTo(DicePlayer::class, 'player_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 中奖配置
|
||||
* 关联模型 diceRewardConfig
|
||||
*/
|
||||
public function diceRewardConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceRewardConfig::class, 'reward_config_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 彩金池配置
|
||||
* 关联模型 diceLotteryPoolConfig
|
||||
@@ -252,24 +243,19 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
$ids = DiceRewardConfig::where('ui_text', 'like', '%' . $value . '%')->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('reward_config_id', $ids);
|
||||
$query->whereIn('target_index', $ids);
|
||||
} else {
|
||||
$query->whereRaw('1=0');
|
||||
}
|
||||
}
|
||||
|
||||
/** 按奖励档位(diceRewardConfig.tier,中奖名 T1-T5) */
|
||||
/** 按奖励档位(表字段 reward_tier,中奖名 T1-T5/BIGWIN) */
|
||||
public function searchRewardTierAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$ids = DiceRewardConfig::where('tier', '=', $value)->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('reward_config_id', $ids);
|
||||
} else {
|
||||
$query->whereRaw('1=0');
|
||||
}
|
||||
$query->where('reward_tier', '=', $value);
|
||||
}
|
||||
|
||||
/** 方向 0=顺时针 1=逆时针 */
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
namespace app\dice\model\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use think\model\relation\BelongsTo;
|
||||
@@ -25,7 +24,7 @@ use think\model\relation\BelongsTo;
|
||||
* @property int|null $ante 底注/注数(dice_ante_config.mult)
|
||||
* @property int|null $paid_amount 付费金额(付费局=ante*100,免费局=0)
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $reward_tier 中奖档位:T1,T2,T3,T4,T5,BIGWIN
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
* @property $start_index 起始索引
|
||||
@@ -61,15 +60,6 @@ class DicePlayRecordTest extends BaseModel
|
||||
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 奖励配置(终点格 = target_index 对应 DiceRewardConfig.id,表中为 reward_config_id)
|
||||
* 关联 reward_config_id -> DiceRewardConfig.id
|
||||
*/
|
||||
public function diceRewardConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceRewardConfig::class, 'reward_config_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的权重测试记录
|
||||
* reward_config_record_id -> DiceRewardConfigRecord.id
|
||||
@@ -135,18 +125,13 @@ class DicePlayRecordTest extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 中奖档位(按 reward_config_id 对应 DiceRewardConfig.tier) */
|
||||
/** 中奖档位(按表字段 reward_tier) */
|
||||
public function searchRewardTierAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$ids = DiceRewardConfig::where('tier', '=', $value)->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('reward_config_id', $ids);
|
||||
} else {
|
||||
$query->whereRaw('1=0');
|
||||
}
|
||||
$query->where('reward_tier', '=', $value);
|
||||
}
|
||||
|
||||
/** 点数和 roll_number(摇取点数和 5-30) */
|
||||
|
||||
@@ -32,6 +32,7 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
* @property $total_ticket_count 总抽奖次数
|
||||
* @property $paid_ticket_count 购买抽奖次数
|
||||
* @property $free_ticket_count 赠送抽奖次数
|
||||
* @property array|null $free_ticket 免费抽奖券:{"ante":1,"count":1}
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 更新时间
|
||||
* @property $delete_time 删除时间
|
||||
@@ -54,6 +55,10 @@ class DicePlayer extends BaseModel
|
||||
|
||||
protected $updateTime = 'update_time';
|
||||
|
||||
protected $json = ['free_ticket'];
|
||||
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
/**
|
||||
* 新增前:生成唯一 uid,昵称 name 默认使用 uid
|
||||
* 用 try-catch 避免表尚未含 uid 时 getAttr/getData 抛 InvalidArgumentException
|
||||
|
||||
@@ -22,7 +22,7 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'lottery_type' => 'require',
|
||||
'is_win' => 'require',
|
||||
'win_coin' => 'require',
|
||||
'reward_config_id' => 'require',
|
||||
'reward_tier' => 'require',
|
||||
'roll_array' => 'require|checkRollArray',
|
||||
];
|
||||
|
||||
@@ -35,7 +35,7 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'lottery_type' => '抽奖类型必须填写',
|
||||
'is_win' => '中奖必须填写',
|
||||
'win_coin' => '赢取平台币必须填写',
|
||||
'reward_config_id' => '奖励配置必须填写',
|
||||
'reward_tier' => '中奖档位必须填写',
|
||||
'roll_array.require' => '摇取点数必须填写',
|
||||
];
|
||||
|
||||
@@ -49,7 +49,7 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'win_coin',
|
||||
'reward_config_id',
|
||||
'reward_tier',
|
||||
'roll_array',
|
||||
],
|
||||
'update' => [
|
||||
@@ -58,7 +58,7 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'win_coin',
|
||||
'reward_config_id',
|
||||
'reward_tier',
|
||||
'roll_array',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -21,7 +21,7 @@ class DicePlayRecordTestValidate extends BaseValidate
|
||||
'lottery_type' => 'require',
|
||||
'is_win' => 'require',
|
||||
'direction' => 'require',
|
||||
'reward_config_id' => 'require',
|
||||
'reward_tier' => 'require',
|
||||
'status' => 'require',
|
||||
];
|
||||
|
||||
@@ -33,7 +33,7 @@ class DicePlayRecordTestValidate extends BaseValidate
|
||||
'lottery_type' => '抽奖类型:0=付费,1=免费必须填写',
|
||||
'is_win' => '中大奖:0=无,1=中奖必须填写',
|
||||
'direction' => '方向:0=顺时针,1=逆时针必须填写',
|
||||
'reward_config_id' => '奖励配置id必须填写',
|
||||
'reward_tier' => '中奖档位必须填写',
|
||||
'status' => '状态:0=失败,1=成功必须填写',
|
||||
];
|
||||
|
||||
@@ -46,7 +46,7 @@ class DicePlayRecordTestValidate extends BaseValidate
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'direction',
|
||||
'reward_config_id',
|
||||
'reward_tier',
|
||||
'status',
|
||||
],
|
||||
'update' => [
|
||||
@@ -54,7 +54,7 @@ class DicePlayRecordTestValidate extends BaseValidate
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'direction',
|
||||
'reward_config_id',
|
||||
'reward_tier',
|
||||
'status',
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user