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

111 lines
2.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class PayLog extends Model
{
/**
* 支付状态
*/
public const STATUS_PENDING = 0; // 待付款
public const STATUS_SUCCESS = 1; // 成功
public const STATUS_FAILED = 2; // 失败
public const PAY_WAY_WXPAY_APP = 'wxpay_app'; // 微信支付 - App 支付
public const PAY_WAY_WXPAY_JSAPI = 'wxpay_jsapi'; // 微信支付 - JSAPI 支付
public const PAY_WAY_WXPAY_MINI = 'wxpay_mini'; // 微信支付 - 小程序支付
public const PAY_WAY_WXPAY_H5 = 'wxpay_h5'; // 微信支付 - H5 支付
public const PAY_WAY_WALLET = 'wallet'; // 钱包付款(可提现)
public const PAY_WAY_BALANCE = 'balance'; // 余额支付
public const PAY_WAY_OFFLINE = 'offline'; // 线下支付
/**
* @var array
*/
protected $attributes = [
'status' => self::STATUS_PENDING,
];
/**
* @var array
*/
protected $casts = [
'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, [
static::PAY_WAY_WXPAY_APP,
static::PAY_WAY_WXPAY_JSAPI,
static::PAY_WAY_WXPAY_MINI,
static::PAY_WAY_WXPAY_H5,
]);
}
/**
* 确认支付方式是否是线下支付
*
* @return bool
*/
public function isOffline(): bool
{
return $this->pay_way === static::PAY_WAY_OFFLINE;
}
/**
* 确认支付方式是否是钱包付款
*
* @return bool
*/
public function isWallet(): bool
{
return $this->pay_way === static::PAY_WAY_WALLET;
}
/**
* 确认支付方式是否是余额支付
*
* @return bool
*/
public function isBalance(): bool
{
return $this->pay_way === static::PAY_WAY_BALANCE;
}
}