47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use RuLong\Order\Models\Order;
|
|
|
|
class Payment extends Model
|
|
{
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
self::creating(function ($model) {
|
|
$model->state = 'INIT';
|
|
$model->trade_no = 'T' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
|
|
});
|
|
}
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|