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