首页修改,jk8修改,历史记录相关,api权限
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\relation\HasMany;
|
||||
|
||||
/**
|
||||
* Bank
|
||||
@@ -46,4 +47,9 @@ class Bank extends Model
|
||||
{
|
||||
return is_null($value) ? null : (float)$value;
|
||||
}
|
||||
|
||||
public function MoneyLog(): hasMany
|
||||
{
|
||||
return $this->hasMany(UserMoneyLog::class, 'bank_id');
|
||||
}
|
||||
}
|
||||
34
app/admin/model/MoneyLogHistory.php
Normal file
34
app/admin/model/MoneyLogHistory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\model\relation\HasMany;
|
||||
use Throwable;
|
||||
use think\model;
|
||||
use think\Exception;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
* MoneyLogHistory 模型
|
||||
*/
|
||||
class MoneyLogHistory extends model
|
||||
{
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $updateTime = false;
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function moneyLog(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserMoneyLog::class, 'money_log_id');
|
||||
}
|
||||
|
||||
public function admin(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'created_by');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use app\admin\library\Auth;
|
||||
use think\model\relation\HasMany;
|
||||
use Throwable;
|
||||
use think\model;
|
||||
use think\Exception;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
@@ -22,23 +22,29 @@ class UserMoneyLog extends model
|
||||
* 入库前
|
||||
* @throws Throwable
|
||||
*/
|
||||
public static function onBeforeInsert($model): void
|
||||
// public static function onAfterInsert($model): void
|
||||
// {
|
||||
// $new = new MoneyLogHistory();
|
||||
// $new->money_log_id = $model->id;
|
||||
// $new->bank_befter = '';
|
||||
// $new->bank_after = $model->bank->bank_name;
|
||||
// $new->create_time = time();
|
||||
// $new->save();
|
||||
//
|
||||
// }
|
||||
|
||||
public static function onAfterUpdate($model): void
|
||||
{
|
||||
$user = User::where('id', $model->user_id)->lock(true)->find();
|
||||
if (!$user) {
|
||||
throw new Exception("The user can't find it");
|
||||
}
|
||||
if (!$model->memo) {
|
||||
throw new Exception("Change note cannot be blank");
|
||||
}
|
||||
$model->before = $user->money;
|
||||
$history = MoneyLogHistory::where('money_log_id', $model->id)->find();
|
||||
$new = new MoneyLogHistory();
|
||||
$new->money_log_id = $model->id;
|
||||
$new->bank_befter = $history->bank_after ?? '';
|
||||
$new->bank_after = $model->bank->bank_name;
|
||||
$new->created_by = Auth::instance()->getInfo()['id'];
|
||||
$new->create_time = time();
|
||||
$new->save();
|
||||
|
||||
$user->money += $model->money;
|
||||
$user->save();
|
||||
|
||||
$model->after = $user->money;
|
||||
}
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
{
|
||||
return false;
|
||||
@@ -88,4 +94,9 @@ class UserMoneyLog extends model
|
||||
{
|
||||
return $this->hasMany(UserScoreLog::class, 'money_log_id');
|
||||
}
|
||||
|
||||
public function bank(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Bank::class, 'bank_id');
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,13 @@ class UserScoreLog extends model
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $updateTime = false;
|
||||
|
||||
const GAME_TYPE_LIST = [
|
||||
1001 => 'Lucky Wheel', // 大转盘
|
||||
1002 => 'Golden Eggs', // 砸金蛋
|
||||
1003 => 'Daily Mission', // 每日任务
|
||||
1004 => 'Plinko Ball', // 普林科弹球
|
||||
];
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
{
|
||||
return false;
|
||||
@@ -26,4 +33,17 @@ class UserScoreLog extends model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
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