40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class KeysOrder extends Model
|
|
{
|
|
//
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
self::creating(function ($model) {
|
|
$model->state = 'INIT';
|
|
$model->trade_no = 'K' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
|
|
});
|
|
}
|
|
|
|
protected function getTypeTextAttribute()
|
|
{
|
|
if ($this->type == 'BALANCE') {
|
|
return '<span style="color: orangered">余额支付</span>';
|
|
} elseif ($this->type == 'WECHAT') {
|
|
return '<span style="color: green">微信支付</span>';
|
|
} else {
|
|
return $this->type;
|
|
}
|
|
}
|
|
|
|
protected function getStateTextAttribute()
|
|
{
|
|
if ($this->state == 'SUCCESS') {
|
|
return '<span style="color: green">支付完成</span>';
|
|
} elseif ($this->state == 'INIT') {
|
|
return '<span style="color: orangered">待支付</span>';
|
|
} else {
|
|
return $this->state;
|
|
}
|
|
}
|
|
}
|