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', 'payable_type', 'payable_id', ]; /** * {@inheritdoc} */ protected static function booted() { parent::creating(function ($payLog) { if ($payLog->pay_sn === null) { do { $payLog->pay_sn = serial_number(); } while (static::where('pay_sn', $payLog->pay_sn)->exists()); } }); } /** * 获取支付记录所属的模型 */ 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::WxpayJsApi, PayWay::WxpayH5, PayWay::WxpayMiniProgram, ]); } /** * 确认支付方式是否是支付宝付款 * * @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; } }