AgentRecharge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models\Agent;
  3. use App\Constants\Util;
  4. use App\Models\BaseModel;
  5. class AgentRecharge extends BaseModel
  6. {
  7. public const TYPE_AUTO = 1;
  8. public const TYPE_HAND = 2;
  9. public const STATUS_STAY = 0;
  10. public const STATUS_SUCCESS = 1;
  11. public const STATUS_FAIL = 2;
  12. public const STATUS_IGNORE = 3;
  13. protected $table = 'agent_recharges';
  14. protected $guarded = ['id'];
  15. protected $hidden = [];
  16. protected $appends = ['status_text'];
  17. protected $casts = [
  18. 'agent_id' => 'integer', 'type' => 'integer', 'status' => 'integer', 'confirmations' => 'integer',
  19. 'usdt_amount' => 'decimal:4', 'exchange_rate' => 'decimal:4', 'amount' => 'decimal:4',
  20. 'audit_admin_id' => 'integer', 'confirmed_at' => 'datetime',
  21. ];
  22. public function agent()
  23. {
  24. return $this->belongsTo(Agent::class);
  25. }
  26. public function getStatusTextAttribute(): string
  27. {
  28. return [self::STATUS_STAY => '待确认', self::STATUS_SUCCESS => '已到账', self::STATUS_FAIL => '已驳回', self::STATUS_IGNORE => '已忽略'][(int) $this->status] ?? '';
  29. }
  30. /** 同会员充值:库里存相对路径,输出时补全域名。 */
  31. protected function getImageAttribute($value)
  32. {
  33. return $value ? Util::ensureUrl($value) : '';
  34. }
  35. protected function setImageAttribute($value)
  36. {
  37. $this->attributes['image'] = (string) Util::replacePartInUrl($value);
  38. }
  39. }