48 lines
952 B
PHP
48 lines
952 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Utils\Helper;
|
|
|
|
class OrderPayment extends Model
|
|
{
|
|
const WXPAY = 'wxpay';
|
|
const BALANCE = 'balance';
|
|
|
|
protected $dates = [
|
|
'end_at',
|
|
];
|
|
|
|
public function refund()
|
|
{
|
|
return $this->morphOne(PaymentRefund::class, 'orderable');
|
|
}
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
self::creating(function ($model) {
|
|
$model->out_trade_no = Helper::orderid(20, 'P');
|
|
});
|
|
|
|
}
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
public function getTypeTextAttribute()
|
|
{
|
|
switch ($this->type) {
|
|
case self::WXPAY:
|
|
return '<span class="label label-success">微信支付</span>';
|
|
break;
|
|
case self::BALANCE:
|
|
return '<span class="label label-warning">余额支付</span>';
|
|
break;
|
|
}
|
|
}
|
|
}
|