Recharge.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models;
  3. use App\Constants\Util;
  4. class Recharge extends BaseModel
  5. {
  6. protected $table = 'recharges';
  7. // protected $fillable = ['member_id', 'confirmations', 'coin', 'txid','block_time','block_height' ,'net' ,'coin' ,'amount' ,'to_address' ,'from_address' ,'status'];
  8. protected $hidden = ['recharge_bonus_snapshot'];
  9. protected $casts = ['recharge_bonus_snapshot' => 'array'];
  10. protected static function booted()
  11. {
  12. parent::booted();
  13. static::creating(function ($order) {
  14. if (strtoupper((string)$order->coin) === 'USDT' && !array_key_exists('recharge_bonus_snapshot', $order->getAttributes())) {
  15. $snapshot = \App\Services\RechargeBonusService::capture('usdt', (string)$order->member_id);
  16. if ($snapshot !== null) $order->recharge_bonus_snapshot = $snapshot;
  17. }
  18. });
  19. }
  20. const STATUS_STAY = 0;
  21. const STATUS_SUCCESS = 1;
  22. const STATUS_FAIL = 2;
  23. const STATUS_IGNORE = 3;
  24. public static $STATUS = [
  25. 0 => '待确认',
  26. 1 => '已确认',
  27. 2 => '失败',
  28. 3 => '已忽略',
  29. ];
  30. const TYPE_AUTO = 1; // 自动
  31. const TYPE_HAND = 2; // 手动
  32. public function member()
  33. {
  34. return $this->belongsTo(User::class, 'member_id', 'member_id')
  35. ->select(['id', 'member_id', 'username', 'first_name', 'admin_note', 'status', 'phone', 'visitor_id', 'register_ip']);
  36. }
  37. protected function getAmountAttribute($value)
  38. {
  39. return floatval($value);
  40. }
  41. protected function getImageAttribute($value)
  42. {
  43. return Util::ensureUrl($value);
  44. }
  45. protected function setImageAttribute($value)
  46. {
  47. $this->attributes['image'] = Util::replacePartInUrl($value);
  48. }
  49. }