提交代码
This commit is contained in:
39
app/Models/CardPayment.php
Normal file
39
app/Models/CardPayment.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class CardPayment extends Model
|
||||
{
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::creating(function ($model) {
|
||||
$model->state = 'INIT';
|
||||
$model->trade_no = 'C' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
|
||||
});
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(CardOrder::class, 'card_order_id', 'id');
|
||||
}
|
||||
|
||||
public function getStateTextAttribute()
|
||||
{
|
||||
switch ($this->state) {
|
||||
case 'INIT':
|
||||
return '<span style="color:#2180ea">未支付</span>';
|
||||
break;
|
||||
case 'SUCCESS':
|
||||
return '<span style="color:#14d000">已支付</span>';
|
||||
break;
|
||||
case 'OVER':
|
||||
return '<span style="color:#ff0000">已结束</span>';
|
||||
break;
|
||||
default:
|
||||
return "未知状态";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user