Commit d8adf571 by lujunyi

关联查询

parent 7c00f2ef
......@@ -10,8 +10,13 @@ class UserController extends BaseApiController
{
public function userInfo()
{
$userId = auth('api')->user()->id;
$data = ['id' => $userId, 'login_type' => User::LOGIN_TYPE_USER];
$authInfo = auth('api')->user();
$data = [
'id' => $authInfo->id,
'name' => $authInfo->name,
'nick_name' => $authInfo->nick_name,
'avatar' => $authInfo->avatar,
];
return $this->success($data);
}
......@@ -21,6 +26,7 @@ public function login(Request $request)
{
$code = $request->input('code');
$credentials = app('wechat.mini_program')->auth->session($code);
// $credentials['openid'] = 'textopenid';
if ($credentials['openid'] ?? '') {
$user = User::firstOrCreate(['openid' => $credentials['openid']]);
// 追加登录类型到token里面,前端需要带在header头中 Authorization:Bearer Token
......
......@@ -12,4 +12,10 @@ class DoctorModel extends Model
use SoftDeletes;
protected $table = 'doctor';
// 医师所属于的用户,一对一
public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}
}
......@@ -26,4 +26,10 @@ class PatientModel extends Model
self::SEX_MALE => '男',
self::SEX_FEMALE => '女',
];
// 问诊人所属于的用户,多对一
public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}
}
......@@ -12,4 +12,10 @@ class PharmacistModel extends Model
use SoftDeletes;
protected $table = 'pharmacist';
// 药师所属于的用户,一对一
public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}
}
......@@ -22,6 +22,10 @@ class User extends Authenticatable implements JWTSubject
'name',
'email',
'password',
'openid',
'avatar',
'nick_name',
'last_login_type',
];
/**
......@@ -58,6 +62,24 @@ class User extends Authenticatable implements JWTSubject
self::LOGIN_TYPE_PHARMACIST => '药师',
];
// 用户关联的医生,一对一
public function doctor()
{
return $this->hasOne(DoctorModel::class, 'user_id', 'id');
}
// 用户关联的药师,一对一
public function pharmacist()
{
return $this->hasOne(PharmacistModel::class, 'user_id', 'id');
}
// 用户关联的问诊人,一对多
public function patient()
{
return $this->hasMany(PatientModel::class, 'user_id', 'id');
}
// 下面是jwt-aut必须要实现的方法
/**
* Get the identifier that will be stored in the subject claim of the JWT.
......
......@@ -19,7 +19,7 @@ public function up(): void
$table->string('password')->nullable();
$table->rememberToken();
$table->string('openid', 40)->nullable()->unique('uk_openid')->comment('小程序openid');
$table->string('openid', 40)->unique('uk_openid')->comment('小程序openid');
$table->string('avatar')->nullable()->comment('头像');
$table->string('nick_name', 100)->nullable()->comment('昵称');
$table->tinyInteger('last_login_type')->default(0)->comment('最后一次登录类型[0=普通用户,1=医师,2=药师]');
......
......@@ -18,8 +18,8 @@ public function up(): void
$table->tinyInteger('gender')->default(0)->comment('性别。[1=男性,2=女性,0=未知]');
$table->string('id_card', 18)->index('idx_idcard')->comment('身份证号');
$table->string('mobile', 11)->index('idx_mobile')->comment('手机号');
$table->bigInteger('user_id')->default(0)->index('idx_userid')->comment('用户表ID');
$table->bigInteger('pharmacy_id')->default(0)->index('idx_pharmacyid')->comment('药店表ID');
$table->bigInteger('user_id')->default(0)->index('idx_userid')->comment('用户表ID。用户添加问诊人才有值');
$table->bigInteger('pharmacy_id')->default(0)->index('idx_pharmacyid')->comment('药店表ID。药店添加问诊人猜有值');
$table->boolean('is_default')->default(0)->comment('默认问诊人,用户添加的才需要设置[0=否,1=是]');
$table->timestamps();
......
......@@ -32,6 +32,7 @@ public function up()
$table->text('introduction')->nullable()->comment('简介');
$table->boolean('status')->default(0)->comment('是否启用[0=未启用,1=启用]');
$table->text('signed_pic')->nullable()->comment('签名照');
$table->bigInteger('user_id')->nullable()->unique('uk_userid')->comment('用户表ID');
$table->timestamps();
$table->softDeletes();
});
......
......@@ -25,6 +25,7 @@ public function up()
$table->string('physician_license')->comment('执业资格证书');
$table->string('signed_pic')->comment('签名照');
$table->boolean('status')->default(0)->comment('启用[0=未启用,1=启用]');
$table->bigInteger('user_id')->nullable()->unique('uk_userid')->comment('用户表ID');
$table->timestamps();
$table->softDeletes();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment