jingcai-php/app/Model/Seller/ShopRecharge.php

54 lines
1.3 KiB
PHP
Executable File

<?php
namespace App\Model\Seller;
use App\Enums\BoolEnum;
use App\Enums\PayState;
use App\Exceptions\JingCaiException;
use App\Model\BaseModel;
use Illuminate\Support\Facades\Log;
class ShopRecharge extends BaseModel
{
public function shop() {
return $this->belongsTo(Shop::class, 'shop_id', 'id');
}
public function seller() {
return $this->belongsTo(Seller::class, 'seller_id', 'id');
}
public function scopeSn($query, $sn) {
$query->where('recharge_sn', $sn);
}
public function isCompleted()
{
return $this->pay_state == PayState::SUCCESS;
}
/**
* //TODO 充值单完成逻辑
* 完成充值单(更新充值单数据)
*/
public function setCompleted()
{
$trade = $this->trade;
$this->received_money = $this->pay_money;
$this->pay_at = date('Y-m-d H:i:s');
$this->out_trade_success = BoolEnum::YES;
$this->pay_state = PayState::SUCCESS;
// 实收与支付金额不相等
if (!bc_equal($this->received_money, $this->pay_money)) {
$this->pay_state = PayState::UNEQUAL;
}
$this->save();
}
public function isSuccess()
{
return $this->pay_state == PayState::SUCCESS;
}
}