UserTrait.php
5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
/**
* +-----------------------------------------------------------------------------------------------------------------------
* trait :对象的用户和修改用户trait
* +-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Models\Traits
* @package App\Models\Traits
* @author Richer <yangzi1028@163.com>
* @date 2021年6月30日10:18:21
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Models\Traits;
use App\Models\Chat\ChatRecord;
use App\Models\Chat\ChatRecordItem;
use App\Models\System\AccessRecord;
use App\Models\User\Commission;
use App\Models\User\InviteRecord;
use App\Models\User\TimesRecord;
use App\Models\User\User;
use App\Models\User\UserInfo;
use App\Models\User\Wallet;
use App\Models\User\WalletRecord;
use App\Models\User\WithdrawRecord;
use App\Models\UserWalletRecord;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\hasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
/**
* Trait UserTrait
*
* @category App\Models\Traits
* @package App\Models\Traits
* @author Richer <yangzi1028@163.com>
* @date 2021年6月30日10:18:21
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
trait UserTrait
{
use notifiable {
notify as protected laravelNotify;
}
use CanOrder, ModelAppendFieldTrait;
use SoftDeletes;
protected $message = '';
/**
* @return string
*/
public function getMessage()
{
return $this->message ? : __('operate_succeeded');
}
/**
* @return BelongsTo
*/
public function parent(): BelongsTo
{
return $this->belongsTo(get_class($this), 'pid', 'id');
}
/**
* @return BelongsTo
*/
public function grandfather(): BelongsTo
{
return $this->belongsTo(get_class($this), 'gid', 'id');
}
/**
* @return HasMany
*/
public function children(): HasMany
{
return $this->hasMany(get_class($this), 'pid', 'id');
}
/**
* @return HasMany
*/
public function children1(): HasMany
{
return $this->hasMany(get_class($this), 'gid', 'id');
}
/**
* @return hasMany
*/
public function allChildren()
{
if ($this->partner == 1) {
return $this->children()->with('allChildren');
}
return $this->children();
}
// public function team
/**
* 我的详情
*
* @return hasOne
*/
public function info(): hasOne
{
return $this->hasOne(UserInfo::class);
}
/**
* @return HasMany
*/
public function accessRecords(): HasMany
{
return $this->hasMany(AccessRecord::class, 'user_id', 'id');
}
/**
* @return HasMany
*/
public function timesRecords(): HasMany
{
return $this->hasMany(TimesRecord::class);
}
/**
* @return HasMany
*/
public function chatRecords(): HasMany
{
return $this->hasMany(ChatRecord::class);
}
/**
* @return HasMany
*/
public function chatRecordItems(): HasMany
{
return $this->hasMany(ChatRecordItem::class);
}
/**
* 钱包
*
* @return hasOne
*/
public function wallet(): hasOne
{
return $this->hasOne(Wallet::class);
}
/**
* @return HasMany
*/
public function inviteRecords(): HasMany
{
return $this->hasMany(InviteRecord::class);
}
/**
* @return HasMany
*/
public function invitedRecords(): HasMany
{
return $this->hasMany(InviteRecord::class, 'invited_user_id');
}
/**
*
* @return HasMany
*/
public function walletRecords(): HasMany
{
return $this->hasMany(WalletRecord::class);
}
/**
*
* @return HasMany
*/
public function commissions(): HasMany
{
return $this->hasMany(WalletRecord::class)->where('type', WalletRecord::INCREASE);
}
/**
* @return HasMany
*/
public function withdrawals(): HasMany
{
return $this->hasMany(WithdrawRecord::class);
}
/**
* @param $value
*/
public function setAvatarAttribute($value)
{
// 需要判断前端传来的路径是否是全路径,如果是全路径需要截取为相对路径
$this->attributes['avatar'] = substr_file_path($value);
}
/**
* @param $value
* @return string
* @throws GuzzleException
*/
public function getAvatarAttribute($value): string
{
return splice_file_path($value);
}
/**
* @param $value
*/
public function setInviteQrCodeAttribute($value)
{
// 需要判断前端传来的路径是否是全路径,如果是全路径需要截取为相对路径
$this->attributes['invite_qr_code'] = substr_file_path($value);
}
/**
* @param $value
* @return string
* @throws GuzzleException
*/
public function getInviteQrCodeAttribute($value): string
{
return splice_file_path($value);
}
}