You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.0 KiB

5 years ago
<?php
namespace App;
use App\Models\ManagerProject;
use App\Models\Project;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
/**
* App\Manager
*
* @property int $id
* @property string|null $name
* @property string|null $type
* @property string|null $username
* @property string|null $sex
* @property string|null $birthday
* @property string|null $mobile
* @property string|null $openid
* @property string|null $unionid
* @property string|null $password
* @property string|null $remember_token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read mixed $type_name
* @property-read \Illuminate\Database\Eloquent\Collection|ManagerProject[] $managerProjects
* @property-read int|null $manager_projects_count
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @property-read int|null $notifications_count
* @property-read \Illuminate\Database\Eloquent\Collection|Project[] $projects
* @property-read int|null $projects_count
* @method static \Illuminate\Database\Eloquent\Builder|Manager newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Manager newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Manager query()
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereBirthday($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereMobile($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereOpenid($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereSex($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereUnionid($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Manager whereUsername($value)
* @mixin \Eloquent
*/
class Manager extends Authenticatable implements JWTSubject
{
use Notifiable;
CONST GUARD_NAME = "manager";
5 years ago
public $appends = ["type_name", "avatar_url"];
5 years ago
public function getAvatarUrlAttribute()
{
$protocol = request()->secure() ? "https" : "http";
if (!$this->avatar) {
switch ($this->sex) {
case "男":
$this->avatar = "/images/male.png";
break;
case "女":
$this->avatar = "/images/female.png";
break;
}
}
return $this->avatar ? $protocol . "://" . request()->getHost() . $this->avatar : $this->avatar;
}
5 years ago
public function getTypeNameAttribute()
{
$type_name = $this->type;
switch ($this->type) {
case "teacher":
$type_name = "管理老师";
break;
case "manager":
$type_name = "项目经理";
break;
}
return $type_name;
}
public function guardName()
{
return self::GUARD_NAME;
}
// Rest omitted for brevity
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
3 years ago
'type', 'name', 'sex', 'username', 'password', 'openid', 'unionid', 'mobile', 'birthday', 'avatar', 'order_status_ability'
5 years ago
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'verified_at' => 'datetime',
];
public function managerProjects()
{
return $this->hasMany(ManagerProject::class, "manager_id", "id");
}
public function projects()
{
return $this->hasManyThrough(Project::class, ManagerProject::class, "manager_id", "id", "id", "project_id");
}
}