123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App;
- use Illuminate\Notifications\Notifiable;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Tymon\JWTAuth\Facades\JWTAuth;
- use Illuminate\Support\Facades\DB;
- class User extends Authenticatable
- {
- use Notifiable;
- public $timestamps = false;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'name', 'phone', 'password',
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password', 'remember_token',
- ];
- /**
- * 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 [];
- }
- public static function updateUserLoginInfo($userid, $data) {
- $status = DB::table('users')->where('id', $userid)->update(['token' => $data['token'],'phone_verified'=>1,'last_login_time'=>$data['last_login_time'],'login_num'=>$data['login_num']+1]);
- return $status;
- }
- public static function updateToken($userid, $token) {
- $status = DB::table('users')->where('id', $userid)->update(['token' => $token]);
- return $status;
- }
- public static function getCurrentUser() {
- $token = getenv('HTTP_TOKEN') ? getenv('HTTP_TOKEN') : (isset($_GET['token']) ? $_GET['token'] : '');
- if($token) {
- return self::getUserInfoByToken($token);
- } else {
- return array();
- }
- }
- public static function getUserInfoByToken($token) {
- $user = User::where('token', $token)->first();
- return !empty($user) ? $user : null;
- }
- public static function parseToken($token) {
- $user = DB::table('users')->where('token', $token)->first();
- return !empty($user) ? $user : null;
- }
- public function getAccounts()
- {
- return $this->belongsToMany('App\Models\Account', 'user_account', 'user_id', 'account_id')->withPivot('is_master','tid');
- }
- public static function updatePhoneVerified($mobile,$type) //检测账户注册到哪个步骤
- {
- $user_info = self::where('mobile', $mobile)->first();
- if (!$user_info) {
- $user_info = new self();
- $user_info->mobile = $mobile;
- }
- if ($type) $user_info->phone_verified = $type;
- $user_info->save();
- return $user_info;
- }
- }
|