| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class PaymentDirectRecharge extends BaseModel
- {
- use SoftDeletes;
- protected $table = 'payment_direct_recharges';
- protected $guarded = [];
- protected $hidden = ['deleted_at'];
- protected $casts = [
- 'amount' => 'decimal:2',
- 'recharge_channel_group_ids' => 'array',
- 'status' => 'integer',
- ];
- protected $appends = ['fee_rate', 'fee_fixed', 'actual_amount'];
- public function rechargeChannel()
- {
- return $this->belongsTo(RechargeChannel::class, 'recharge_channel_id');
- }
- public function getFeeRateAttribute($value = null): string
- {
- return $this->rechargeChannel
- ? bcmul((string)$this->rechargeChannel->rate, '100', 4)
- : '0.0000';
- }
- public function getFeeFixedAttribute($value = null): string
- {
- return bcadd((string)($this->rechargeChannel->fee_fixed ?? 0), '0', 4);
- }
- /** 扣除三方手续费(金额 × 费率 + 每笔固定费,平台承担)后平台实际收到的金额。 */
- public function getActualAmountAttribute(): string
- {
- $rate = $this->rechargeChannel ? (string)$this->rechargeChannel->rate : '0';
- $fee = bcadd(bcmul((string)$this->amount, $rate, 6), $this->fee_fixed, 6);
- return bcsub((string)$this->amount, $fee, 2);
- }
- }
|