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

82 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Wallet extends Model
{
/**
* @var string
*/
protected $primaryKey = 'user_id';
/**
* @var bool
*/
public $incrementing = false;
/**
* @var array
*/
protected $attributes = [
'withdrawable' => true,
];
/**
* @var array
*/
protected $fillable = [
'user_id',
'balance',
'total_expenses',
'total_revenue',
'withdrawable',
'password', //安全密码
];
/**
* @var array
*/
protected $casts = [
'withdrawable' => 'bool',
];
/**
* 资产日志
*
*/
public function logs()
{
return $this->hasMany(WalletLog::class, 'wallet_id');
}
/**
* 设置此用户的安全密码
*
* @param string $value
* @return void
*/
public function setPasswordAttribute($value): void
{
if ((string) $value === '') {
$value = null;
} else {
$value = md5($value);
}
$this->attributes['password'] = $value;
}
/**
* 确认给定的密码是否正确
*
* @param string $password
* @return bool
*/
public function verifyPassword(string $password): bool
{
return $this->password && md5($password) === $this->password;
}
}