6
0
Fork 0
jiqu-library-server/app/Models/PayLog.php

117 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use App\Enums\PayWay;
use Illuminate\Database\Eloquent\Model;
class PayLog extends Model
{
/**
* 支付状态
*/
public const STATUS_PENDING = 0; // 待付款
public const STATUS_SUCCESS = 1; // 成功
public const STATUS_FAILED = 2; // 失败
/**
* @var array
*/
protected $attributes = [
'status' => self::STATUS_PENDING,
];
/**
* @var array
*/
protected $casts = [
'pay_way' => PayWay::class,
'pay_at' => 'datetime',
];
/**
* @var array
*/
protected $fillable = [
'pay_sn',
'pay_way',
'pay_at',
'out_trade_no',
'status',
'failed_reason',
];
/**
* 获取支付记录所属的模型
*/
public function payable()
{
return $this->morphTo();
}
/**
* 获取支付记录是否是待付款
*/
public function isPending()
{
return $this->status === static::STATUS_PENDING;
}
/**
* 确认支付方式是否是微信支付
*
* @return bool
*/
public function isWxpay(): bool
{
return in_array($this->pay_way, [
PayWay::WxpayApp,
PayWay::WxpayJs,
PayWay::WxpayH5,
PayWay::WxpayMp,
]);
}
/**
* 确认支付方式是否是支付宝付款
*
* @return bool
*/
public function isAlipay(): bool
{
return in_array($this->pay_way, [
PayWay::AlipayApp,
]);
}
/**
* 确认支付方式是否是线下支付
*
* @return bool
*/
public function isOffline(): bool
{
return $this->pay_way === PayWay::Offline;
}
/**
* 确认支付方式是否是钱包付款
*
* @return bool
*/
public function isWallet(): bool
{
return $this->pay_way === PayWay::Wallet;
}
/**
* 确认支付方式是否是余额支付
*
* @return bool
*/
public function isBalance(): bool
{
return $this->pay_way === PayWay::Balance;
}
}