Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d8adf571
authored
Nov 12, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
关联查询
parent
7c00f2ef
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
5 deletions
+53
-5
app/Api/Controllers/UserController.php
+8
-2
app/Models/DoctorModel.php
+6
-0
app/Models/PatientModel.php
+6
-0
app/Models/PharmacistModel.php
+6
-0
app/Models/User.php
+22
-0
database/migrations/2014_10_12_000000_create_users_table.php
+1
-1
database/migrations/2024_11_04_135741_create_patient_table.php
+2
-2
database/migrations/2024_11_04_220223_create_doctor_table.php
+1
-0
database/migrations/2024_11_04_224709_create_pharmacist_table.php
+1
-0
No files found.
app/Api/Controllers/UserController.php
View file @
d8adf571
...
@@ -10,8 +10,13 @@ class UserController extends BaseApiController
...
@@ -10,8 +10,13 @@ class UserController extends BaseApiController
{
{
public
function
userInfo
()
public
function
userInfo
()
{
{
$userId
=
auth
(
'api'
)
->
user
()
->
id
;
$authInfo
=
auth
(
'api'
)
->
user
();
$data
=
[
'id'
=>
$userId
,
'login_type'
=>
User
::
LOGIN_TYPE_USER
];
$data
=
[
'id'
=>
$authInfo
->
id
,
'name'
=>
$authInfo
->
name
,
'nick_name'
=>
$authInfo
->
nick_name
,
'avatar'
=>
$authInfo
->
avatar
,
];
return
$this
->
success
(
$data
);
return
$this
->
success
(
$data
);
}
}
...
@@ -21,6 +26,7 @@ public function login(Request $request)
...
@@ -21,6 +26,7 @@ public function login(Request $request)
{
{
$code
=
$request
->
input
(
'code'
);
$code
=
$request
->
input
(
'code'
);
$credentials
=
app
(
'wechat.mini_program'
)
->
auth
->
session
(
$code
);
$credentials
=
app
(
'wechat.mini_program'
)
->
auth
->
session
(
$code
);
// $credentials['openid'] = 'textopenid';
if
(
$credentials
[
'openid'
]
??
''
)
{
if
(
$credentials
[
'openid'
]
??
''
)
{
$user
=
User
::
firstOrCreate
([
'openid'
=>
$credentials
[
'openid'
]]);
$user
=
User
::
firstOrCreate
([
'openid'
=>
$credentials
[
'openid'
]]);
// 追加登录类型到token里面,前端需要带在header头中 Authorization:Bearer Token
// 追加登录类型到token里面,前端需要带在header头中 Authorization:Bearer Token
...
...
app/Models/DoctorModel.php
View file @
d8adf571
...
@@ -12,4 +12,10 @@ class DoctorModel extends Model
...
@@ -12,4 +12,10 @@ class DoctorModel extends Model
use
SoftDeletes
;
use
SoftDeletes
;
protected
$table
=
'doctor'
;
protected
$table
=
'doctor'
;
// 医师所属于的用户,一对一
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
,
'user_id'
,
'id'
);
}
}
}
app/Models/PatientModel.php
View file @
d8adf571
...
@@ -26,4 +26,10 @@ class PatientModel extends Model
...
@@ -26,4 +26,10 @@ class PatientModel extends Model
self
::
SEX_MALE
=>
'男'
,
self
::
SEX_MALE
=>
'男'
,
self
::
SEX_FEMALE
=>
'女'
,
self
::
SEX_FEMALE
=>
'女'
,
];
];
// 问诊人所属于的用户,多对一
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
,
'user_id'
,
'id'
);
}
}
}
app/Models/PharmacistModel.php
View file @
d8adf571
...
@@ -12,4 +12,10 @@ class PharmacistModel extends Model
...
@@ -12,4 +12,10 @@ class PharmacistModel extends Model
use
SoftDeletes
;
use
SoftDeletes
;
protected
$table
=
'pharmacist'
;
protected
$table
=
'pharmacist'
;
// 药师所属于的用户,一对一
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
,
'user_id'
,
'id'
);
}
}
}
app/Models/User.php
View file @
d8adf571
...
@@ -22,6 +22,10 @@ class User extends Authenticatable implements JWTSubject
...
@@ -22,6 +22,10 @@ class User extends Authenticatable implements JWTSubject
'name'
,
'name'
,
'email'
,
'email'
,
'password'
,
'password'
,
'openid'
,
'avatar'
,
'nick_name'
,
'last_login_type'
,
];
];
/**
/**
...
@@ -58,6 +62,24 @@ class User extends Authenticatable implements JWTSubject
...
@@ -58,6 +62,24 @@ class User extends Authenticatable implements JWTSubject
self
::
LOGIN_TYPE_PHARMACIST
=>
'药师'
,
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必须要实现的方法
// 下面是jwt-aut必须要实现的方法
/**
/**
* Get the identifier that will be stored in the subject claim of the JWT.
* Get the identifier that will be stored in the subject claim of the JWT.
...
...
database/migrations/2014_10_12_000000_create_users_table.php
View file @
d8adf571
...
@@ -19,7 +19,7 @@ public function up(): void
...
@@ -19,7 +19,7 @@ public function up(): void
$table
->
string
(
'password'
)
->
nullable
();
$table
->
string
(
'password'
)
->
nullable
();
$table
->
rememberToken
();
$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
(
'avatar'
)
->
nullable
()
->
comment
(
'头像'
);
$table
->
string
(
'nick_name'
,
100
)
->
nullable
()
->
comment
(
'昵称'
);
$table
->
string
(
'nick_name'
,
100
)
->
nullable
()
->
comment
(
'昵称'
);
$table
->
tinyInteger
(
'last_login_type'
)
->
default
(
0
)
->
comment
(
'最后一次登录类型[0=普通用户,1=医师,2=药师]'
);
$table
->
tinyInteger
(
'last_login_type'
)
->
default
(
0
)
->
comment
(
'最后一次登录类型[0=普通用户,1=医师,2=药师]'
);
...
...
database/migrations/2024_11_04_135741_create_patient_table.php
View file @
d8adf571
...
@@ -18,8 +18,8 @@ public function up(): void
...
@@ -18,8 +18,8 @@ public function up(): void
$table
->
tinyInteger
(
'gender'
)
->
default
(
0
)
->
comment
(
'性别。[1=男性,2=女性,0=未知]'
);
$table
->
tinyInteger
(
'gender'
)
->
default
(
0
)
->
comment
(
'性别。[1=男性,2=女性,0=未知]'
);
$table
->
string
(
'id_card'
,
18
)
->
index
(
'idx_idcard'
)
->
comment
(
'身份证号'
);
$table
->
string
(
'id_card'
,
18
)
->
index
(
'idx_idcard'
)
->
comment
(
'身份证号'
);
$table
->
string
(
'mobile'
,
11
)
->
index
(
'idx_mobile'
)
->
comment
(
'手机号'
);
$table
->
string
(
'mobile'
,
11
)
->
index
(
'idx_mobile'
)
->
comment
(
'手机号'
);
$table
->
bigInteger
(
'user_id'
)
->
default
(
0
)
->
index
(
'idx_userid'
)
->
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
->
bigInteger
(
'pharmacy_id'
)
->
default
(
0
)
->
index
(
'idx_pharmacyid'
)
->
comment
(
'药店表ID
。药店添加问诊人猜有值
'
);
$table
->
boolean
(
'is_default'
)
->
default
(
0
)
->
comment
(
'默认问诊人,用户添加的才需要设置[0=否,1=是]'
);
$table
->
boolean
(
'is_default'
)
->
default
(
0
)
->
comment
(
'默认问诊人,用户添加的才需要设置[0=否,1=是]'
);
$table
->
timestamps
();
$table
->
timestamps
();
...
...
database/migrations/2024_11_04_220223_create_doctor_table.php
View file @
d8adf571
...
@@ -32,6 +32,7 @@ public function up()
...
@@ -32,6 +32,7 @@ public function up()
$table
->
text
(
'introduction'
)
->
nullable
()
->
comment
(
'简介'
);
$table
->
text
(
'introduction'
)
->
nullable
()
->
comment
(
'简介'
);
$table
->
boolean
(
'status'
)
->
default
(
0
)
->
comment
(
'是否启用[0=未启用,1=启用]'
);
$table
->
boolean
(
'status'
)
->
default
(
0
)
->
comment
(
'是否启用[0=未启用,1=启用]'
);
$table
->
text
(
'signed_pic'
)
->
nullable
()
->
comment
(
'签名照'
);
$table
->
text
(
'signed_pic'
)
->
nullable
()
->
comment
(
'签名照'
);
$table
->
bigInteger
(
'user_id'
)
->
nullable
()
->
unique
(
'uk_userid'
)
->
comment
(
'用户表ID'
);
$table
->
timestamps
();
$table
->
timestamps
();
$table
->
softDeletes
();
$table
->
softDeletes
();
});
});
...
...
database/migrations/2024_11_04_224709_create_pharmacist_table.php
View file @
d8adf571
...
@@ -25,6 +25,7 @@ public function up()
...
@@ -25,6 +25,7 @@ public function up()
$table
->
string
(
'physician_license'
)
->
comment
(
'执业资格证书'
);
$table
->
string
(
'physician_license'
)
->
comment
(
'执业资格证书'
);
$table
->
string
(
'signed_pic'
)
->
comment
(
'签名照'
);
$table
->
string
(
'signed_pic'
)
->
comment
(
'签名照'
);
$table
->
boolean
(
'status'
)
->
default
(
0
)
->
comment
(
'启用[0=未启用,1=启用]'
);
$table
->
boolean
(
'status'
)
->
default
(
0
)
->
comment
(
'启用[0=未启用,1=启用]'
);
$table
->
bigInteger
(
'user_id'
)
->
nullable
()
->
unique
(
'uk_userid'
)
->
comment
(
'用户表ID'
);
$table
->
timestamps
();
$table
->
timestamps
();
$table
->
softDeletes
();
$table
->
softDeletes
();
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment