优化一键测试权重
This commit is contained in:
@@ -8,6 +8,7 @@ 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;
|
||||
|
||||
@@ -33,6 +34,7 @@ use think\model\relation\BelongsTo;
|
||||
* @property $super_win_coin 中大奖平台币
|
||||
* @property $reward_win_coin 摇色子中奖平台币
|
||||
* @property $admin_id 所属管理员
|
||||
* @property int|null $reward_config_record_id 关联 DiceRewardConfigRecord.id(权重测试记录)
|
||||
*/
|
||||
class DicePlayRecordTest extends BaseModel
|
||||
{
|
||||
@@ -66,6 +68,15 @@ class DicePlayRecordTest extends BaseModel
|
||||
return $this->belongsTo(DiceRewardConfig::class, 'reward_config_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的权重测试记录
|
||||
* reward_config_record_id -> DiceRewardConfigRecord.id
|
||||
*/
|
||||
public function diceRewardConfigRecord(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceRewardConfigRecord::class, 'reward_config_record_id', 'id');
|
||||
}
|
||||
|
||||
/** 抽奖类型 0=付费 1=赠送 */
|
||||
public function searchLotteryTypeAttr($query, $value)
|
||||
{
|
||||
@@ -119,4 +130,12 @@ class DicePlayRecordTest extends BaseModel
|
||||
$query->whereRaw('1=0');
|
||||
}
|
||||
}
|
||||
|
||||
/** 点数和 roll_number(摇取点数和 5-30) */
|
||||
public function searchRollNumberAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('roll_number', '=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\reward_config_record;
|
||||
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use think\model\relation\HasMany;
|
||||
|
||||
/**
|
||||
* 奖励配置权重测试记录模型
|
||||
@@ -17,15 +19,24 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
* @property int $test_count 测试次数 100/500/1000/5000/10000
|
||||
* @property array $weight_config_snapshot 测试时权重配比快照:按档位 id,grid_number,tier,weight
|
||||
* @property array $tier_weights_snapshot 测试时 T1-T5 档位权重快照(来自奖池配置)
|
||||
* @property int|null $lottery_config_id 测试时使用的奖池配置 ID
|
||||
* @property int|null $lottery_config_id 测试时使用的奖池配置 ID(兼容旧:付费+免费共用)
|
||||
* @property int|null $paid_lottery_config_id 付费抽奖奖池配置 ID,默认 type=0
|
||||
* @property int|null $free_lottery_config_id 免费抽奖奖池配置 ID,默认 type=1
|
||||
* @property int $total_play_count 总模拟次数(s_count+n_count)
|
||||
* @property int $over_play_count 已完成次数
|
||||
* @property int $status 状态 -1失败 0进行中 1成功
|
||||
* @property string|null $remark 失败时记录原因
|
||||
* @property int $s_count 顺时针模拟次数
|
||||
* @property int $n_count 逆时针模拟次数
|
||||
* @property int $s_count 顺时针模拟次数(兼容旧数据)
|
||||
* @property int $n_count 逆时针模拟次数(兼容旧数据)
|
||||
* @property int $paid_s_count 付费抽奖顺时针次数
|
||||
* @property int $paid_n_count 付费抽奖逆时针次数
|
||||
* @property int $free_s_count 免费抽奖顺时针次数
|
||||
* @property int $free_n_count 免费抽奖逆时针次数
|
||||
* @property array|null $paid_tier_weights 付费自定义档位权重 T1-T5
|
||||
* @property array|null $free_tier_weights 免费自定义档位权重 T1-T5
|
||||
* @property array $result_counts 落点统计 grid_number=>出现次数
|
||||
* @property array|null $tier_counts 档位出现次数 T1=>count
|
||||
* @property float|null $platform_profit 平台赚取金额(付费抽取次数×100-玩家总收益)
|
||||
* @property int|null $admin_id 执行测试的管理员ID
|
||||
* @property string|null $create_time 创建时间
|
||||
*/
|
||||
@@ -33,8 +44,10 @@ class DiceRewardConfigRecord extends BaseModel
|
||||
{
|
||||
/** 状态:失败 */
|
||||
public const STATUS_FAIL = -1;
|
||||
/** 状态:进行中 */
|
||||
/** 状态:待执行(队列中) */
|
||||
public const STATUS_RUNNING = 0;
|
||||
/** 状态:执行中(已被某进程领取,防止定时器重入重复执行) */
|
||||
public const STATUS_EXECUTING = 2;
|
||||
/** 状态:成功 */
|
||||
public const STATUS_SUCCESS = 1;
|
||||
|
||||
@@ -42,7 +55,31 @@ class DiceRewardConfigRecord extends BaseModel
|
||||
|
||||
protected $table = 'dice_reward_config_record';
|
||||
|
||||
protected $json = ['weight_config_snapshot', 'tier_weights_snapshot', 'result_counts', 'tier_counts'];
|
||||
protected $json = ['weight_config_snapshot', 'tier_weights_snapshot', 'result_counts', 'tier_counts', 'paid_tier_weights', 'free_tier_weights'];
|
||||
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
/**
|
||||
* 关联的测试抽奖记录(通过 reward_config_record_id)
|
||||
*/
|
||||
public function playRecordTests(): HasMany
|
||||
{
|
||||
return $this->hasMany(DicePlayRecordTest::class, 'reward_config_record_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关联的 DicePlayRecordTest 统计平台赚取平台币
|
||||
* platform_profit = 关联的付费(lottery_type=0)抽取次数 × 100 - 关联的 win_coin 求和
|
||||
* @param int $recordId dice_reward_config_record.id
|
||||
* @return float
|
||||
*/
|
||||
public static function computePlatformProfitFromRelated(int $recordId): float
|
||||
{
|
||||
$paidCount = DicePlayRecordTest::where('reward_config_record_id', $recordId)
|
||||
->where('lottery_type', 0)
|
||||
->count();
|
||||
$sumWinCoin = (float) DicePlayRecordTest::where('reward_config_record_id', $recordId)
|
||||
->sum('win_coin');
|
||||
return round($paidCount * 100 - $sumWinCoin, 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user