1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bavix\Wallet\Models; |
4
|
|
|
|
5
|
|
|
use function array_merge; |
6
|
|
|
use function config; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
9
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Transfer. |
13
|
|
|
* |
14
|
|
|
* @property string $status |
15
|
|
|
* @property int $discount |
16
|
|
|
* @property int $deposit_id |
17
|
|
|
* @property int $withdraw_id |
18
|
|
|
* @property string $from_type |
19
|
|
|
* @property int $from_id |
20
|
|
|
* @property string $to_type |
21
|
|
|
* @property int $to_id |
22
|
|
|
* @property string $uuid |
23
|
|
|
* @property int $fee |
24
|
|
|
* |
25
|
|
|
* @property Transaction $deposit |
26
|
|
|
* @property Transaction $withdraw |
27
|
|
|
*/ |
28
|
|
|
class Transfer extends Model |
29
|
|
|
{ |
30
|
|
|
public const STATUS_EXCHANGE = 'exchange'; |
31
|
|
|
public const STATUS_TRANSFER = 'transfer'; |
32
|
|
|
public const STATUS_PAID = 'paid'; |
33
|
|
|
public const STATUS_REFUND = 'refund'; |
34
|
|
|
public const STATUS_GIFT = 'gift'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $fillable = [ |
40
|
|
|
'status', |
41
|
|
|
'discount', |
42
|
|
|
'deposit_id', |
43
|
|
|
'withdraw_id', |
44
|
|
|
'from_type', |
45
|
|
|
'from_id', |
46
|
|
|
'to_type', |
47
|
|
|
'to_id', |
48
|
|
|
'uuid', |
49
|
|
|
'fee', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $casts = [ |
56
|
|
|
'deposit_id' => 'int', |
57
|
|
|
'withdraw_id' => 'int', |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
51 |
|
public function getCasts(): array |
64
|
|
|
{ |
65
|
51 |
|
return array_merge( |
66
|
51 |
|
parent::getCasts(), |
67
|
51 |
|
config('wallet.transfer.casts', []) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
180 |
|
public function getTable(): string |
75
|
|
|
{ |
76
|
180 |
|
if (! $this->table) { |
77
|
180 |
|
$this->table = config('wallet.transfer.table', 'transfers'); |
78
|
|
|
} |
79
|
|
|
|
80
|
180 |
|
return parent::getTable(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return MorphTo |
85
|
|
|
*/ |
86
|
5 |
|
public function from(): MorphTo |
87
|
|
|
{ |
88
|
5 |
|
return $this->morphTo(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return MorphTo |
93
|
|
|
*/ |
94
|
4 |
|
public function to(): MorphTo |
95
|
|
|
{ |
96
|
4 |
|
return $this->morphTo(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return BelongsTo |
101
|
|
|
*/ |
102
|
28 |
|
public function deposit(): BelongsTo |
103
|
|
|
{ |
104
|
28 |
|
return $this->belongsTo(Transaction::class, 'deposit_id'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return BelongsTo |
109
|
|
|
*/ |
110
|
29 |
|
public function withdraw(): BelongsTo |
111
|
|
|
{ |
112
|
29 |
|
return $this->belongsTo(Transaction::class, 'withdraw_id'); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|