新增统计,小游戏,系统设置
This commit is contained in:
32
app/admin/model/PromoReward.php
Normal file
32
app/admin/model/PromoReward.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
use think\model;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
* PromoReward 模型
|
||||
*/
|
||||
class PromoReward extends model
|
||||
{
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $updateTime = false;
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getGameTypeTextAttr($value, $data)
|
||||
{
|
||||
$gameType = $data['game_type'] ?? 0;
|
||||
return UserScoreLog::GAME_TYPE_LIST[$gameType] ?? 'Unknown Game';
|
||||
}
|
||||
protected $append = ['game_type_text'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Exception;
|
||||
use think\model;
|
||||
use think\model\relation\BelongsTo;
|
||||
use Throwable;
|
||||
use app\admin\model\UserScoreLog;
|
||||
|
||||
/**
|
||||
* UserScoreLog 模型
|
||||
@@ -29,6 +27,11 @@ class UserScore extends model
|
||||
if (bccomp($before, $after, 2) !== 0) {
|
||||
// 计算分值变动(after - before)
|
||||
$change = bcsub($after, $before);
|
||||
if ($change >= 0) {
|
||||
$type = 1;
|
||||
} else {
|
||||
$type = 2;
|
||||
}
|
||||
$userScoreLog = new UserScoreLog();
|
||||
$userScoreLog->save([
|
||||
'user_id' => $model->user_id,
|
||||
@@ -36,7 +39,9 @@ class UserScore extends model
|
||||
'before' => $before,
|
||||
'after' => $after,
|
||||
'score' => $change,
|
||||
'memo' => '管理员手动调整', // 建议增加备注字段区分来源
|
||||
'memo' => $model->memo ?? '',
|
||||
'type' => $type,
|
||||
'created_by'=> $model->created_by ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@ class UserScoreLog extends model
|
||||
protected $updateTime = false;
|
||||
|
||||
const GAME_TYPE_LIST = [
|
||||
1001 => 'Lucky Wheel', // 大转盘
|
||||
1002 => 'Golden Eggs', // 砸金蛋
|
||||
1003 => 'Daily Mission', // 每日任务
|
||||
1004 => 'Plinko Ball', // 普林科弹球
|
||||
268 => 'plinko ball',
|
||||
269 => 'smash eggs',
|
||||
270 => 'spin wheel',
|
||||
];
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
@@ -37,13 +36,9 @@ class UserScoreLog extends model
|
||||
public function getGameTypeTextAttr($value, $data)
|
||||
{
|
||||
$gameType = $data['game_type'] ?? 0;
|
||||
|
||||
// 如果需要严格的多语言,可以在这里根据 $lang 切换,或者直接配合系统的 lang() 助手函数
|
||||
// 这里我们先直接返回对应的标准国际化名称
|
||||
return self::GAME_TYPE_LIST[$gameType] ?? 'Unknown Game';
|
||||
}
|
||||
|
||||
// 3. 别忘了把获取器追加到模型的可见输出数组里
|
||||
protected $append = ['game_type_text'];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user