更新代码
This commit is contained in:
46
app/Models/Payment.php
Normal file
46
app/Models/Payment.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user