PaymentDirectRecharge.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\SoftDeletes;
  4. class PaymentDirectRecharge extends BaseModel
  5. {
  6. use SoftDeletes;
  7. protected $table = 'payment_direct_recharges';
  8. protected $guarded = [];
  9. protected $hidden = ['deleted_at'];
  10. protected $casts = [
  11. 'amount' => 'decimal:2',
  12. 'recharge_channel_group_ids' => 'array',
  13. 'status' => 'integer',
  14. ];
  15. protected $appends = ['fee_rate', 'actual_amount'];
  16. public function rechargeChannel()
  17. {
  18. return $this->belongsTo(RechargeChannel::class, 'recharge_channel_id');
  19. }
  20. public function getFeeRateAttribute($value = null): string
  21. {
  22. return $this->rechargeChannel
  23. ? bcmul((string)$this->rechargeChannel->rate, '100', 4)
  24. : '0.0000';
  25. }
  26. public function getActualAmountAttribute(): string
  27. {
  28. $rate = $this->rechargeChannel ? (string)$this->rechargeChannel->rate : '0';
  29. return bcsub((string)$this->amount, bcmul((string)$this->amount, $rate, 6), 2);
  30. }
  31. }