6
0
Fork 0
jiqu-library-server/app/Models/WalletLog.php

69 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model;
class WalletLog extends Model
{
use Filterable;
use HasDateTimeFormatter;
public const ACTION_MIGRATE_OLD = 0; // 老数据迁移
public const ACTION_ORDER_PAID = 1;
public const ACTION_ORDER_CANCELLED = 2;
public const ACTION_ORDER_AFTER_SALE = 3;
public const ACTION_WITHDRAW_BANK = 4;
public const ACTION_WITHDRAW_BALACNE = 5;
public const ACTION_WITHDRAW_FAILED = 6;
public const ACTION_ADMIN_RECHARGE = 7;
public const ACTION_ADMIN_DEDUCTION = 8;
public const ACTION_QUOTA_V1 = 9;
public const ACTION_DISTRIBUTION_PRE_INCOME = 10;
/**
* @var array
*/
protected $fillable = [
'user_id',
'loggable_id',
'loggable_type',
'action',
'before_balance',
'change_balance',
'remarks',
];
/**
* 此提现关联的用户
*
* @return void
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* 提现到余额的明细
*
* @param [type] $query
*/
public function scopeOnlyWithdrawBalance($query)
{
return $query->where('action', '=', self::ACTION_WITHDRAW_BALACNE);
}
/**
* 获取变动金额
*
* @return string
*/
public function getChangeBalanceFormatAttribute()
{
return trim_trailing_zeros(bcdiv($this->attributes['change_balance'], 100, 2));
}
}