12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Models\User;
- use App\Base\BaseModel;
- use App\Models\Auth\AdminGroup;
- use App\Modules\Mini\Services\AuthService;
- use Illuminate\Auth\Authenticatable;
- use Illuminate\Support\Arr;
- /**
- * App\Models\User
- *
- * @property int $id
- * @property string $phone
- * @property string $password
- * @property string $email
- * @property int $status 0 禁用 1启用
- * @property int $group_id
- * @property array $extra 糊屎字段
- * @property \Illuminate\Support\Carbon|null $created_at
- * @property \Illuminate\Support\Carbon|null $updated_at
- * @property-read AdminGroup|null $group
- * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|User query()
- * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User whereExtra($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User whereGroupId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User wherePhone($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User whereStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
- * @mixin \Eloquent
- * @property-read \App\Models\User\UserCompany|null $company
- * @property string $openid 微信openid
- * @method static \Illuminate\Database\Eloquent\Builder|User whereOpenid($value)
- * @property string $name 用户昵称
- * @method static \Illuminate\Database\Eloquent\Builder|User whereName($value)
- * @property-read mixed $avatar
- */
- class User extends BaseModel implements \Illuminate\Contracts\Auth\Authenticatable
- {
- use Authenticatable;
- protected $table = "user";
- const STATUS_OK = 1;
- const STATUS_STOP = 2;
- protected $casts = [
- "extra" => "array",
- ];
- public function checkPassword($password): bool
- {
- return \Hash::check($password, $this->password);
- }
- public function hashPassword($password)
- {
- return \Hash::make($password);
- }
- public function group()
- {
- return $this->belongsTo(AdminGroup::class, "group_id", "id");
- }
- public function company()
- {
- return $this->hasOne(UserCompany::class, "user_id", "id");
- }
- public function getAvatarAttribute()
- {
- return Arr::get($this->extra, "wechat.avatar", "");
- }
- public function format()
- {
- return [
- "token" => app(AuthService::class)->encryptToken($this->id),
- "name" => $this->name,
- "phone" => $this->phone,
- "email" => $this->email,
- ];
- }
- }
|