首页修改,jk8修改,历史记录相关,api权限

This commit is contained in:
2026-06-04 10:53:45 +08:00
parent 95684c784e
commit 1975d24db3
16 changed files with 565 additions and 96 deletions

View File

@@ -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');
}
}