Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
4b3afa89
Commit
4b3afa89
authored
Sep 23, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
e7dc2c31
Pipeline
#14048
passed with stage
in 9 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
329 additions
and
6 deletions
+329
-6
user.js
app/controller/course/user.js
+56
-1
context.js
app/extend/context.js
+9
-0
mini_auth.js
app/middleware/mini_auth.js
+20
-0
course_log_user_gps.js
app/model/class/course_log_user_gps.js
+103
-0
course_user.js
app/model/class/course_user.js
+109
-0
course.js
app/router/course.js
+2
-0
institution.js
app/service/course/institution.js
+6
-5
user.js
app/service/course/user.js
+24
-0
No files found.
app/controller/course/user.js
View file @
4b3afa89
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
const
uuidv4
=
require
(
'uuid/v4'
);
class
UserController
extends
Controller
{
async
auth
()
{
const
{
ctx
,
app
}
=
this
;
const
code
=
ctx
.
request
.
body
.
code
=
'123123sfdsf'
;
if
(
!
code
)
{
ctx
.
failed
(
'error code'
);
}
const
wx_auth_ret
=
await
ctx
.
service
.
course
.
user
.
requestWxAuth
(
code
);
const
openid
=
wx_auth_ret
.
openid
;
// const session_key = wx_auth_ret.session_key;
let
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
if
(
!
user
||
!
user
.
uuid
)
{
const
uuid
=
uuidv4
();
user
=
await
ctx
.
classModel
.
CourseUser
.
add
({
uuid
,
openid
});
}
const
user_uuid
=
user
.
uuid
;
const
key
=
'course_user_session_'
+
user_uuid
;
await
app
.
memcache
.
set
(
key
,
{
user_uuid
,
openid
},
86400
);
const
token
=
ctx
.
helper
.
md5
(
openid
+
user_uuid
+
'jbwl'
);
ctx
.
set
(
'Session_Id'
,
key
);
ctx
.
set
(
'token'
,
token
);
const
result
=
{
user_uuid
};
ctx
.
success
({
result
});
}
async
registerUserInfo
()
{
const
{
ctx
}
=
this
;
const
uuid
=
ctx
.
userUuid
;
const
input_params
=
ctx
.
request
.
body
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
}
=
input_params
;
const
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
uuid
}
});
await
ctx
.
classModel
.
CourseUser
.
edit
({
params
:
{
avatar
,
nickname
,
sex
},
where
:
{
uuid
}
});
let
bindphone
=
0
;
if
(
user
.
phone
)
{
bindphone
=
1
;
}
const
result
=
{
bindphone
};
ctx
.
success
({
result
});
}
async
verify_auth
()
{
const
{
ctx
}
=
this
;
const
headers
=
ctx
.
request
.
headers
;
ctx
.
success
({
headers
});
}
/**
*
*/
...
...
app/extend/context.js
View file @
4b3afa89
...
...
@@ -12,6 +12,7 @@ const APPTYPEID = Symbol('Context#appTypeId');
const
OLDUSERID
=
Symbol
(
'Context#oldUserId'
);
const
USERID
=
Symbol
(
'Context#userId'
);
const
OLDCOOKIE
=
Symbol
(
'Context#oldCookie'
);
const
USERUUID
=
Symbol
(
'Context#userUuid'
);
module
.
exports
=
{
failed
(
message
)
{
...
...
@@ -172,6 +173,10 @@ module.exports = {
return
this
[
OLDCOOKIE
];
},
get
userUuid
()
{
return
this
[
USERUUID
];
},
setAppUserId
(
app_user_id
)
{
this
[
APPUSERID
]
=
app_user_id
;
},
...
...
@@ -203,4 +208,8 @@ module.exports = {
setOldCookie
(
cookie
)
{
this
[
OLDCOOKIE
]
=
cookie
;
},
setUserUuid
(
user_uuid
)
{
this
[
USERUUID
]
=
user_uuid
;
},
};
app/middleware/mini_auth.js
0 → 100644
View file @
4b3afa89
'use strict'
;
module
.
exports
=
(
options
,
app
)
=>
{
return
async
function
(
ctx
,
next
)
{
const
session_id
=
ctx
.
headers
.
Session_Id
;
const
key
=
'course_user_session_'
+
session_id
;
const
auth_info
=
await
app
.
memcache
.
get
(
key
);
const
openid
=
auth_info
.
openid
;
const
user_uuid
=
auth_info
.
user_uuid
;
const
token
=
ctx
.
headers
.
token
;
if
(
ctx
.
helper
.
md5
(
openid
+
user_uuid
+
'jbwl'
)
!=
token
)
{
ctx
.
failed
(
'login auth error'
);
}
ctx
.
setUserUuid
(
user_uuid
);
await
next
();
};
};
app/model/class/course_log_user_gps.js
0 → 100644
View file @
4b3afa89
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseLogUserGps
=
app
.
classModel
.
define
(
'course_log_user_gps'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
user_uuid
:
STRING
,
address
:
STRING
,
lat
:
DECIMAL
,
lng
:
DECIMAL
,
is_deleted
:
INTEGER
,
created_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_log_user_gps'
,
});
CourseLogUserGps
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseLogUserGps
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
CourseLogUserGps
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseLogUserGps
.
findAll
({
attributes
:
attributes
,
where
:
where
,
order
,
});
}
CourseLogUserGps
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
Number
(
data
.
limit
)
:
10
;
const
page
=
data
.
page
?
data
.
page
:
1
;
const
order
=
data
.
order
?
data
.
order
:
[];
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
condition
=
{
offset
:
(
page
-
1
)
*
limit
,
limit
,
where
:
where
,
order
:
order
,
attributes
:
attributes
,
};
const
{
count
,
rows
}
=
await
CourseLogUserGps
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
CourseLogUserGps
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
CourseLogUserGps
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
}
CourseLogUserGps
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseLogUserGps
.
update
(
params
,
{
where
:
where
})
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
}
return
CourseLogUserGps
;
};
\ No newline at end of file
app/model/class/course_user.js
0 → 100644
View file @
4b3afa89
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseUser
=
app
.
classModel
.
define
(
'course_user'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
uuid
:
STRING
,
app_id
:
STRING
,
app_user_id
:
STRING
,
app_type_id
:
STRING
,
user_id
:
STRING
,
phone
:
STRING
,
nickname
:
STRING
,
avatar
:
STRING
,
sex
:
STRING
,
openid
:
STRING
,
is_deleted
:
INTEGER
,
created_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_user'
,
});
CourseUser
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseUser
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
CourseUser
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseUser
.
findAll
({
attributes
:
attributes
,
where
:
where
,
order
,
});
}
CourseUser
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
Number
(
data
.
limit
)
:
10
;
const
page
=
data
.
page
?
data
.
page
:
1
;
const
order
=
data
.
order
?
data
.
order
:
[];
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
condition
=
{
offset
:
(
page
-
1
)
*
limit
,
limit
,
where
:
where
,
order
:
order
,
attributes
:
attributes
,
};
const
{
count
,
rows
}
=
await
CourseUser
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
CourseUser
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
CourseUser
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
}
CourseUser
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseUser
.
update
(
params
,
{
where
:
where
})
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
}
return
CourseUser
;
};
\ No newline at end of file
app/router/course.js
View file @
4b3afa89
...
...
@@ -15,6 +15,8 @@ module.exports = app => {
router
.
get
(
'/teachers'
,
'course.institution.teacherList'
);
router
.
get
(
'/teacher/:teacher_id'
,
'course.institution.teacherInfo'
);
router
.
get
(
'/user/auth'
,
'course.user.auth'
);
router
.
get
(
'/user/verify_auth'
,
'course.user.verify_auth'
);
router
.
get
(
'/user/baby'
,
'course.user.getBabyInfo'
);
router
.
post
(
'/user/baby'
,
'course.user.saveBabyInfo'
);
router
.
delete
(
'/user/baby'
,
'course.user.delBabyInfo'
);
...
...
app/service/course/institution.js
View file @
4b3afa89
...
...
@@ -11,7 +11,7 @@ class InstitutionService extends Service {
async
getInstitutions
(
input
)
{
const
{
ctx
}
=
this
;
const
{
cat
,
age
,
institution
}
=
input
;
const
{
cat
,
age
,
institution
,
lat
,
lng
}
=
input
;
let
where
=
{
status
:
1
,
is_deleted
:
0
};
if
(
cat
)
{
const
cat_ret
=
await
ctx
.
classModel
.
CourseCat
.
one
({
where
:
{
id
:
cat
}
});
...
...
@@ -38,7 +38,7 @@ class InstitutionService extends Service {
const
institutions
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
({
attributes
,
include
,
where
});
const
institution_area_list
=
await
this
.
getInstitutionAreaList
(
institutions
);
const
area_lbs
=
await
this
.
computeDistance
(
institution_area_list
);
const
area_lbs
=
await
this
.
computeDistance
(
institution_area_list
,
{
lat
,
lng
}
);
const
institution_areas
=
await
this
.
findShortestDistanceAreas
(
institution_area_list
,
area_lbs
);
const
ret
=
await
this
.
formatInstitutions
(
institution_areas
);
...
...
@@ -61,6 +61,7 @@ class InstitutionService extends Service {
institution_detail
=
institution_detail
[
0
];
institution_detail
.
address
=
current_area
.
address
;
institution_detail
.
phone
=
current_area
.
phone
;
institution_detail
.
description
=
institution
.
description
;
//处理图片
const
photo_album
=
[];
for
(
let
i
in
institution_images
)
{
...
...
@@ -143,7 +144,7 @@ class InstitutionService extends Service {
async
getInstitutionAreas
(
input
)
{
const
{
ctx
}
=
this
;
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'address'
,
'phone'
];
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'address'
,
'phone'
,
'lat'
,
'lng'
];
const
{
institution_id
,
page
,
limit
}
=
input
;
const
where
=
{
institution_id
};
const
areas
=
await
ctx
.
classModel
.
CourseArea
.
list
({
attributes
,
page
,
limit
,
where
});
...
...
@@ -190,10 +191,10 @@ class InstitutionService extends Service {
}
//distance=3km
async
computeDistance
(
lbs_array
,
distance
=
3
)
{
async
computeDistance
(
lbs_array
,
from_gps
,
distance
=
3
)
{
const
{
ctx
}
=
this
;
const
from
=
{
lat
:
'30.291210'
,
lng
:
'120.068642'
}
;
const
from
=
from_gps
;
const
driving_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'driving'
,
from
,
lbs_array
);
const
walking_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'walking'
,
from
,
lbs_array
);
...
...
app/service/course/user.js
View file @
4b3afa89
...
...
@@ -100,6 +100,30 @@ class UserService extends Service {
return
{
page
:
collect_institution_rows
.
page
,
count
:
collect_institution_rows
.
count
,
rows
:
ret
};
}
async
requestWxAuth
(
code
)
{
const
{
ctx
}
=
this
;
const
APPID
=
'wx4769ebba9b91f8ec'
;
const
SECRET
=
'1231312321312'
;
const
url
=
`https://api.weixin.qq.com/sns/jscode2session?appid=
${
APPID
}
&secret=
${
SECRET
}
&js_code=
${
code
}
&grant_type=authorization_code`
;
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{},
{
method
:
'GET'
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
course_mini_auth_ret
:
result
}));
if
(
result
.
status
===
200
)
{
ctx
.
failed
(
'授权失败'
);
}
const
ret
=
result
.
data
;
if
(
ret
.
errcode
!==
0
)
{
ctx
.
failed
(
ret
.
errmsg
);
}
const
openid
=
ret
.
openid
;
const
session_key
=
ret
.
session_key
;
return
{
openid
,
session_key
};
}
}
...
...
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