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
1a562059
Commit
1a562059
authored
Nov 13, 2019
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add course
parent
dd401208
Pipeline
#16297
passed with stage
in 46 seconds
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
856 additions
and
375 deletions
+856
-375
institutionSub.js
app/controller/course/institutionSub.js
+99
-0
courseStudentVideo.js
app/model/class/courseStudentVideo.js
+46
-0
course_cat.js
app/model/class/course_cat.js
+90
-92
course_images.js
app/model/class/course_images.js
+83
-82
course_institution_to_cat.js
app/model/class/course_institution_to_cat.js
+4
-4
course_log_user_gps.js
app/model/class/course_log_user_gps.js
+4
-4
course_user.js
app/model/class/course_user.js
+93
-94
course_user_baby.js
app/model/class/course_user_baby.js
+89
-90
course_user_collection.js
app/model/class/course_user_collection.js
+4
-4
course.js
app/router/course.js
+32
-0
institutionSub.js
app/service/course/institutionSub.js
+307
-0
config.local.js
config/config.local.js
+5
-5
No files found.
app/controller/course/institutionSub.js
0 → 100644
View file @
1a562059
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
class
InstitutionSubController
extends
Controller
{
/**
* 机构列表
*/
async
institutionList
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
request
.
body
;
const
results
=
await
ctx
.
service
.
course
.
institutionSub
.
getInstitutions
(
input_params
);
ctx
.
success
({
results
});
}
/**
* 机构详情
*/
async
institutionInfo
()
{
const
{
ctx
}
=
this
;
let
input_params
=
ctx
.
params
;
const
query
=
ctx
.
query
;
input_params
=
Object
.
assign
(
input_params
,
query
);
const
result
=
await
ctx
.
service
.
course
.
institutionSub
.
getInstitution
(
input_params
);
ctx
.
success
({
result
});
}
/**
* 课程列表
*/
async
classList
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
request
.
body
;
const
results
=
await
ctx
.
service
.
course
.
institutionSub
.
getClasses
(
input_params
);
ctx
.
success
({
results
});
}
/**
* 课程详情
*/
async
classInfo
()
{
const
{
ctx
}
=
this
;
const
class_id
=
ctx
.
params
.
class_id
;
if
(
!
class_id
)
{
ctx
.
failed
(
'error class_id'
);
}
const
ret
=
await
ctx
.
service
.
course
.
institutionSub
.
getClass
(
class_id
);
ctx
.
success
(
ret
);
}
/**
* 老师列表
*/
async
teacherList
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
request
.
body
;
const
ret
=
await
ctx
.
service
.
course
.
institutionSub
.
getTeachers
(
input_params
);
ctx
.
success
(
ret
);
}
/**
* 老师详情
*/
async
teacherInfo
()
{
const
{
ctx
}
=
this
;
const
teacher_id
=
ctx
.
params
.
teacher_id
;
if
(
!
teacher_id
)
{
ctx
.
failed
(
'error teacher_id'
);
}
const
ret
=
await
ctx
.
service
.
course
.
institutionSub
.
getTeacher
(
teacher_id
);
ctx
.
success
(
ret
);
}
// 获取分类
async
getCats
()
{
const
{
ctx
}
=
this
;
const
ret
=
await
ctx
.
service
.
course
.
institutionSub
.
getCats
();
ctx
.
success
(
ret
);
}
}
module
.
exports
=
InstitutionSubController
;
app/model/class/courseStudentVideo.js
0 → 100644
View file @
1a562059
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseStudentVideo
=
app
.
classModel
.
define
(
'course_student_video'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
institution_id
:
INTEGER
,
video_url
:
STRING
,
title
:
STRING
,
age
:
STRING
,
time
:
STRING
,
sort
:
INTEGER
,
status
:
ENUM
(
'offline'
,
'online'
),
is_deleted
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_student_video'
,
});
return
CourseStudentVideo
;
};
app/model/class/course_cat.js
View file @
1a562059
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseCat
=
app
.
classModel
.
define
(
'course_cat'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
first_id
:
INTEGER
,
parent_id
:
INTEGER
,
level
:
INTEGER
,
name
:
STRING
,
image
:
STRING
,
color
:
STRING
,
tips
:
STRING
,
status
:
ENUM
(
'offline'
,
'online'
),
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_cat'
,
});
const
CourseCat
=
app
.
classModel
.
define
(
'course_cat'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
parent_id
:
INTEGER
,
name
:
STRING
,
image
:
STRING
,
color
:
STRING
,
tips
:
STRING
,
status
:
ENUM
(
'offline'
,
'online'
),
is_deleted
:
INTEGER
,
sort
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_cat'
,
});
CourseCat
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseCat
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
CourseCat
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseCat
.
findOne
({
attributes
,
where
,
});
};
CourseCat
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseCat
.
findAll
({
attributes
:
attributes
,
where
:
where
,
order
,
});
}
CourseCat
.
all
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseCat
.
findAll
({
attributes
,
where
,
order
,
});
};
CourseCat
.
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
CourseCat
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
CourseCat
.
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
,
order
,
attributes
,
};
const
{
count
,
rows
}
=
await
CourseCat
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
};
CourseCat
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
CourseCat
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
CourseCat
.
add
=
async
data
=>
{
try
{
// 返回promise对象实力 instance
const
res
=
await
CourseCat
.
create
(
data
);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
};
CourseCat
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseCat
.
update
(
params
,
{
where
:
where
})
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
CourseCat
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseCat
.
update
(
params
,
{
where
});
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
};
return
CourseCat
;
return
CourseCat
;
};
\ No newline at end of file
};
app/model/class/course_images.js
View file @
1a562059
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseImages
=
app
.
classModel
.
define
(
'course_images'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
type
:
INTEGER
,
type_id
:
INTEGER
,
image_url
:
STRING
,
video_url
:
STRING
,
is_cover
:
INTEGER
,
is_video
:
INTEGER
,
sort
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_images'
,
});
const
CourseImages
=
app
.
classModel
.
define
(
'course_images'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
type
:
INTEGER
,
type_id
:
INTEGER
,
image_url
:
STRING
,
video_url
:
STRING
,
is_cover
:
INTEGER
,
is_video
:
INTEGER
,
sort
:
INTEGER
,
status
:
ENUM
(
'offline'
,
'online'
),
is_deleted
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_images'
,
});
CourseImages
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseImages
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
CourseImages
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseImages
.
findOne
({
attributes
,
where
,
});
};
CourseImages
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseImages
.
findAll
({
attributes
:
attributes
,
where
:
where
,
order
,
});
}
CourseImages
.
all
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseImages
.
findAll
({
attributes
,
where
,
order
,
});
};
CourseImages
.
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
CourseImages
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
CourseImages
.
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
,
order
,
attributes
,
};
const
{
count
,
rows
}
=
await
CourseImages
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
};
CourseImages
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
CourseImages
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
CourseImages
.
add
=
async
data
=>
{
try
{
// 返回promise对象实力 instance
const
res
=
await
CourseImages
.
create
(
data
);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
};
CourseImages
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseImages
.
update
(
params
,
{
where
:
where
})
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
CourseImages
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseImages
.
update
(
params
,
{
where
});
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
};
return
CourseImages
;
return
CourseImages
;
};
\ No newline at end of file
};
app/model/class/course_institution_to_cat.js
View file @
1a562059
...
...
@@ -16,19 +16,19 @@ module.exports = app => {
cat_id
:
INTEGER
,
status
:
ENUM
(
'offline'
,
'online'
),
is_deleted
:
INTEGER
,
created_
at
:
{
created_
time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_
at
'
);
const
date
=
this
.
getDataValue
(
'created_
time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_
at
:
{
updated_
time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_
at
'
);
const
date
=
this
.
getDataValue
(
'updated_
time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
...
...
app/model/class/course_log_user_gps.js
View file @
1a562059
...
...
@@ -17,19 +17,19 @@ module.exports = app => {
lat
:
DECIMAL
,
lng
:
DECIMAL
,
is_deleted
:
INTEGER
,
created_
at
:
{
created_
time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_
at
'
);
const
date
=
this
.
getDataValue
(
'created_
time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_
at
:
{
updated_
time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_
at
'
);
const
date
=
this
.
getDataValue
(
'updated_
time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
...
...
app/model/class/course_user.js
View file @
1a562059
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
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'
,
});
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_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time
'
);
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
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseUser
.
findOne
({
attributes
,
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
.
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
,
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
.
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
,
order
,
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
.
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
);
}
CourseUser
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseUser
.
update
(
params
,
{
where
});
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
};
return
CourseUser
;
return
CourseUser
;
};
\ No newline at end of file
};
app/model/class/course_user_baby.js
View file @
1a562059
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseUserBaby
=
app
.
classModel
.
define
(
'course_user_baby'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
user_uuid
:
STRING
,
gender
:
ENUM
(
'boy'
,
'girl'
),
birth
:
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_user_baby'
,
});
const
CourseUserBaby
=
app
.
classModel
.
define
(
'course_user_baby'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
user_uuid
:
STRING
,
gender
:
ENUM
(
'boy'
,
'girl'
),
birth
:
STRING
,
address
:
STRING
,
lat
:
DECIMAL
,
lng
:
DECIMAL
,
is_deleted
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_user_baby'
,
});
CourseUserBaby
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseUserBaby
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
CourseUserBaby
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseUserBaby
.
findOne
({
attributes
,
where
,
});
};
CourseUserBaby
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseUserBaby
.
findAll
({
attributes
:
attributes
,
where
:
where
,
order
,
});
}
CourseUserBaby
.
all
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseUserBaby
.
findAll
({
attributes
,
where
,
order
,
});
};
CourseUserBaby
.
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
CourseUserBaby
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
CourseUserBaby
.
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
,
order
,
attributes
,
};
const
{
count
,
rows
}
=
await
CourseUserBaby
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
};
CourseUserBaby
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
CourseUserBaby
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
CourseUserBaby
.
add
=
async
data
=>
{
try
{
// 返回promise对象实力 instance
const
res
=
await
CourseUserBaby
.
create
(
data
);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
};
CourseUserBaby
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseUserBaby
.
update
(
params
,
{
where
:
where
})
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
CourseUserBaby
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseUserBaby
.
update
(
params
,
{
where
});
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
};
return
CourseUserBaby
;
return
CourseUserBaby
;
};
\ No newline at end of file
};
app/model/class/course_user_collection.js
View file @
1a562059
...
...
@@ -15,19 +15,19 @@ module.exports = app => {
user_uuid
:
STRING
,
institution_id
:
INTEGER
,
is_deleted
:
INTEGER
,
created_
at
:
{
created_
time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_
at
'
);
const
date
=
this
.
getDataValue
(
'created_
time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_
at
:
{
updated_
time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_
at
'
);
const
date
=
this
.
getDataValue
(
'updated_
time
'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
...
...
app/router/course.js
View file @
1a562059
...
...
@@ -31,4 +31,36 @@ module.exports = app => {
router
.
get
(
'third'
,
'/wechat/callbackAction'
,
'course.wechat.check'
);
router
.
post
(
'third'
,
'/wechat/callbackAction'
,
'course.wechat.callbackAction'
);
router
.
post
(
'third'
,
'/wechat/test'
,
'course.wechat.test'
);
// 版本二
router
.
get
(
'third'
,
'/sub/cats'
,
'course.institutionSub.getCats'
);
// 分类
router
.
get
(
'third'
,
'/sub/options'
,
'course.option.getOptions'
);
// 筛选项
router
.
post
(
'third'
,
'/sub/address'
,
miniAuth
,
'course.location.getAddress'
);
// 根据经纬度或ip获取地理位置信息
router
.
post
(
'third'
,
'/sub/institutions'
,
miniAuth
,
'course.institutionSub.institutionList'
);
// 机构列表
router
.
get
(
'third'
,
'/sub/institutions'
,
miniAuth
,
'course.institutionSub.institutionList'
);
// 机构列表
router
.
get
(
'third'
,
'/sub/institution/:institution_id'
,
miniAuth
,
'course.institutionSub.institutionInfo'
);
// 机构详情
router
.
post
(
'third'
,
'/sub/classes'
,
miniAuth
,
'course.institution.classList'
);
// 课程列表
router
.
get
(
'third'
,
'/sub/classes'
,
miniAuth
,
'course.institution.classList'
);
// 课程列表
router
.
get
(
'third'
,
'/sub/class/:class_id'
,
miniAuth
,
'course.institution.classInfo'
);
// 课程详情
router
.
post
(
'third'
,
'/sub/teachers'
,
miniAuth
,
'course.institution.teacherList'
);
// 老师列表
router
.
get
(
'third'
,
'/sub/teachers'
,
miniAuth
,
'course.institution.teacherList'
);
// 老师详情
router
.
get
(
'third'
,
'/sub/teacher/:teacher_id'
,
miniAuth
,
'course.institution.teacherInfo'
);
// 老师详情
router
.
post
(
'third'
,
'/sub/user/auth'
,
'course.user.auth'
);
// 微信授权登录
router
.
post
(
'third'
,
'/sub/user/register_user'
,
miniAuth
,
'course.user.registerUserInfo'
);
// 授权后注册用户
router
.
get
(
'third'
,
'/sub/user/baby'
,
miniAuth
,
'course.user.getBabyInfo'
);
// 获取baby信息
router
.
post
(
'third'
,
'/sub/user/baby'
,
miniAuth
,
'course.user.saveBabyInfo'
);
// 保存baby信息
router
.
delete
(
'third'
,
'/sub/user/baby'
,
miniAuth
,
'course.user.delBabyInfo'
);
// 删除baby信息
router
.
get
(
'third'
,
'/sub/user/collection/institution'
,
miniAuth
,
'course.user.getCollectInstitutions'
);
// 收藏的机构列表
router
.
post
(
'third'
,
'/sub/user/collection/institution'
,
miniAuth
,
'course.user.collectInstitution'
);
// 收藏机构
router
.
delete
(
'third'
,
'/sub/user/collection/institution'
,
miniAuth
,
'course.user.delCollectInstitution'
);
// 取消收藏机构
router
.
get
(
'third'
,
'/sub/wechat/callbackAction'
,
'course.wechat.check'
);
router
.
post
(
'third'
,
'/sub/wechat/callbackAction'
,
'course.wechat.callbackAction'
);
router
.
post
(
'third'
,
'/sub/wechat/test'
,
'course.wechat.test'
);
};
app/service/course/institutionSub.js
0 → 100644
View file @
1a562059
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
const
R
=
require
(
'ramda'
);
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
class
InstitutionSubService
extends
Service
{
// 获取分类
async
getCats
()
{
const
{
ctx
}
=
this
;
const
AllCats
=
await
ctx
.
classModel
.
CourseCat
.
findAll
({
where
:
{
status
:
1
,
is_deleted
:
0
}
});
const
rootCats
=
[];
let
ret
=
[];
// 先取出一级分类
for
(
const
v
of
AllCats
)
{
if
(
v
.
parent_id
===
0
)
{
rootCats
[
v
.
id
]
=
v
.
dataValues
;
rootCats
[
v
.
id
].
child
=
[{
id
:
0
,
value
:
v
.
id
,
name
:
'全部'
,
parent_id
:
0
,
image
:
''
,
color
:
''
,
tips
:
''
,
status
:
'online'
,
is_deleted
:
0
}];
}
}
// 放入二级分类
for
(
const
v
of
AllCats
)
{
if
(
v
.
parent_id
>
0
)
{
v
.
value
=
v
.
id
;
rootCats
[
v
.
parent_id
].
child
.
push
(
v
);
}
}
const
sort
=
function
(
a
,
b
)
{
return
a
.
sort
-
b
.
sort
;
};
// 整理
for
(
const
v
of
rootCats
)
{
if
(
!
ctx
.
isEmpty
(
v
))
{
v
.
child
=
R
.
sort
(
sort
)(
v
.
child
);
ret
.
push
(
v
);
}
}
ret
=
R
.
sort
(
sort
)(
ret
);
return
{
results
:
ret
};
}
// 获取机构详情
async
getInstitution
(
input
)
{
const
{
ctx
}
=
this
;
const
userUUID
=
ctx
.
userUUID
;
const
{
institution_id
}
=
input
;
const
lat
=
ctx
.
isEmpty
(
input
.
lat
)
?
0
:
input
.
lat
;
const
lng
=
ctx
.
isEmpty
(
input
.
lng
)
?
0
:
input
.
lng
;
const
institution
=
await
ctx
.
classModel
.
CourseInstitution
.
findOne
({
where
:
{
id
:
institution_id
,
status
:
'online'
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
institution
))
{
ctx
.
failed
(
'机构不存在'
);
}
// 顶部相册
const
images
=
await
ctx
.
classModel
.
CourseImages
.
findAll
({
where
:
{
type
:
1
,
type_id
:
institution_id
,
status
:
'online'
,
is_deleted
:
0
}
});
// 去重
const
checkList
=
[];
let
album
=
[];
for
(
const
v
of
images
)
{
if
((
v
.
is_video
===
0
&&
checkList
.
includes
(
v
.
image_url
))
||
(
v
.
is_video
===
1
&&
checkList
.
includes
(
v
.
video_url
)))
{
continue
;
}
album
.
push
(
v
);
}
// 排序,视频在前
const
albumSort
=
function
(
a
,
b
)
{
if
(
a
.
is_video
===
b
.
is_video
)
{
return
a
.
sort
-
b
.
sort
;
}
return
b
.
is_video
-
a
.
is_video
;
};
album
=
R
.
sort
(
albumSort
)(
album
);
// 学习成果
const
student_video
=
await
ctx
.
classModel
.
CourseStudentVideo
.
findAll
({
where
:
{
institution_id
,
status
:
'online'
,
is_deleted
:
0
},
order
:
[[
'sort'
,
'asc'
]]
});
// 教师
const
teachers
=
await
ctx
.
classModel
.
CourseTeacher
.
findAll
({
where
:
{
institution_id
,
status
:
'online'
,
is_deleted
:
0
}
});
// 课程
const
classes
=
await
ctx
.
classModel
.
CourseClass
.
findAll
({
where
:
{
institution_id
,
status
:
'online'
,
is_deleted
:
0
}
});
// 处理课程封面图
const
classHandle
=
[];
if
(
classes
.
length
>
0
)
{
for
(
const
v
of
classes
)
{
classHandle
.
push
(
ctx
.
classModel
.
CourseImages
.
findOne
({
where
:
{
type
:
2
,
type_id
:
v
.
id
,
status
:
'online'
,
is_deleted
:
0
,
is_cover
:
1
}
}));
}
const
classImages
=
await
Promise
.
all
(
classHandle
).
then
(
result
=>
{
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
for
(
const
i
in
classes
)
{
classes
[
i
].
image
=
classImages
[
i
];
}
}
// 校区
let
areas
=
await
ctx
.
classModel
.
CourseArea
.
findAll
({
where
:
{
institution_id
,
status
:
'online'
,
is_deleted
:
0
}
});
const
areaHandle
=
[];
if
(
areas
.
length
>
0
)
{
for
(
const
v
of
areas
)
{
areaHandle
.
push
(
this
.
formatArea
(
v
,
{
lng
,
lat
}));
}
areas
=
await
Promise
.
all
(
areaHandle
).
then
(
result
=>
{
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
}
areas
=
_
.
orderBy
(
areas
,
[
'distance'
],
[
'asc'
]);
// 是否已收藏
const
userCollect
=
await
ctx
.
classModel
.
CourseUserCollection
.
findOne
({
where
:
{
institution_id
,
user_uuid
:
userUUID
,
is_deleted
:
0
}
});
const
ret
=
{
album
,
detail
:
institution
,
student_video
,
teachers
,
classes
,
areas
,
is_collected
:
ctx
.
isEmpty
(
userCollect
)
?
0
:
1
,
};
return
ret
;
}
// 处理校区
async
formatArea
(
area
,
location
)
{
const
{
ctx
,
service
}
=
this
;
if
(
ctx
.
isEmpty
(
area
))
{
return
{};
}
const
distance
=
await
service
.
course
.
lbs
.
getDistance
({
lng
:
location
.
lng
,
lat
:
location
.
lat
},
{
lng
:
area
.
lng
,
lat
:
area
.
lat
});
// 暂定3公里以内步行
area
.
travel_method
=
distance
<
3000
?
'walking'
:
'driving'
;
const
lbsResult
=
await
service
.
course
.
lbs
.
getLBSDistance
(
area
.
travel_method
,
{
lng
:
location
.
lng
,
lat
:
location
.
lat
},
[{
lng
:
area
.
lng
,
lat
:
area
.
lat
}]);
if
(
lbsResult
.
results
.
length
>
0
)
{
area
.
distance
=
(
lbsResult
.
results
[
0
].
distance
/
1000
).
toFixed
(
1
);
area
.
duration
=
lbsResult
.
results
[
0
].
duration
;
const
minute
=
area
.
travel_method
===
'walking'
?
Math
.
ceil
(
area
.
distance
/
80
)
:
Math
.
ceil
(
area
.
duration
/
60
);
area
.
travel_tips
=
area
.
travel_method
===
'walking'
?
`距我
${
area
.
distance
}
km,步行
${
minute
}
分钟`
:
`距我
${
area
.
distance
}
km,开车
${
minute
}
分钟`
;
}
else
{
area
.
distance
=
999999
;
area
.
duration
=
0
;
area
.
travel_tips
=
''
;
}
return
area
;
}
// 机构列表
async
getInstitutions
(
input
)
{
const
{
ctx
,
service
}
=
this
;
const
userUUID
=
ctx
.
userUUID
;
const
{
cat_id
,
age
,
distance
,
address
,
page
,
limit
}
=
input
;
const
lat
=
ctx
.
isEmpty
(
input
.
lat
)
?
0
:
input
.
lat
;
const
lng
=
ctx
.
isEmpty
(
input
.
lng
)
?
0
:
input
.
lng
;
// 保存定位记录
if
(
address
&&
lat
&&
lng
)
{
ctx
.
classModel
.
CourseLogUserGps
.
created
({
user_uuid
:
userUUID
,
address
,
lat
,
lng
,
created_time
:
moment
().
format
(
'YYYY-MM-DD HH:mm:ss'
)
});
}
let
institutionIds
=
[];
let
institutionList
=
[];
let
institutionCats
=
[];
const
filter
=
{
where
:
{
status
:
'online'
,
is_deleted
:
0
}
};
// 年龄筛选
if
(
Number
(
age
)
>
0
)
{
filter
.
where
.
min_age
=
{
$lte
:
age
};
filter
.
where
.
max_age
=
{
$gte
:
age
};
}
// 分类筛选
if
(
Number
(
cat_id
)
>
0
)
{
// 如果是一级分类,则需要加入该分类下所有子分类
const
cats
=
await
ctx
.
classModel
.
CourseCat
.
findAll
({
where
:
{
parent_id
:
cat_id
,
status
:
'online'
,
is_deleted
:
0
}
});
const
catIds
=
R
.
pluck
(
'id'
,
cats
);
catIds
.
push
(
Number
(
cat_id
));
institutionCats
=
await
ctx
.
classModel
.
CourseInstitutionToCat
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
,
cat_id
:
{
$in
:
catIds
}
}
});
const
institutionIds
=
R
.
pluck
(
'institution_id'
,
institutionCats
);
filter
.
where
.
id
=
{
$in
:
institutionIds
};
}
institutionList
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
(
filter
);
institutionList
=
R
.
pluck
(
'dataValues'
,
institutionList
);
institutionIds
=
R
.
pluck
(
'id'
,
institutionList
);
// 获取机构对应的校区
const
areaList
=
await
ctx
.
classModel
.
CourseArea
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
,
institution_id
:
{
$in
:
institutionIds
}
}
});
// 计算校区对应的距离
const
areaHandle
=
[];
for
(
const
v
of
areaList
)
{
areaHandle
.
push
(
service
.
course
.
lbs
.
getDistance
({
lat
,
lng
},
{
lat
:
v
.
lat
,
lng
:
v
.
lng
}));
}
const
areaDistanceCalcResult
=
await
Promise
.
all
(
areaHandle
).
then
(
result
=>
{
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
for
(
const
i
in
areaList
)
{
areaList
[
i
].
distance
=
areaDistanceCalcResult
[
i
];
}
// 选出最短距离的校区
for
(
const
v
of
areaList
)
{
for
(
const
i
in
institutionList
)
{
if
(
institutionList
[
i
].
id
===
v
.
institution_id
)
{
if
(
ctx
.
isEmpty
(
institutionList
[
i
].
area
)
||
(
institutionList
[
i
].
area
.
distance
>
v
.
distance
))
{
institutionList
[
i
].
area
=
v
;
}
}
}
}
// 格式化机构距离
for
(
const
i
in
institutionList
)
{
institutionList
[
i
].
distance
=
ctx
.
isEmpty
(
institutionList
[
i
].
area
)
?
999999.0
:
institutionList
[
i
].
area
.
distance
;
}
institutionList
=
_
.
orderBy
(
institutionList
,
[
'distance'
],
[
'asc'
]);
// 距离筛选
if
(
Number
(
distance
)
>
0
)
{
for
(
const
i
in
institutionList
)
{
if
(
institutionList
[
i
].
distance
>
Number
(
distance
))
{
institutionList
=
institutionList
.
slice
(
0
,
i
);
break
;
}
}
}
// 分页
const
ret
=
{
results
:
[],
count
:
institutionList
.
length
,
};
institutionList
=
institutionList
.
slice
(
Number
(
page
-
1
)
*
Number
(
limit
),
Number
(
page
)
*
Number
(
limit
));
institutionIds
=
R
.
pluck
(
'id'
,
institutionList
);
// 获取所有分类
const
allCats
=
await
ctx
.
classModel
.
CourseCat
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
}
});
const
catList
=
[];
for
(
const
v
of
allCats
)
{
catList
[
v
.
id
]
=
v
;
}
institutionCats
=
await
ctx
.
classModel
.
CourseInstitutionToCat
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
,
institution_id
:
{
$in
:
institutionIds
}
}
});
// 用户已收藏机构列表
const
userInstitutions
=
await
ctx
.
classModel
.
CourseUserCollection
.
findAll
({
where
:
{
is_deleted
:
0
,
user_uuid
:
userUUID
}
});
const
userInstitutionIds
=
R
.
pluck
(
'id'
,
userInstitutions
);
// 机构图片及格式化
for
(
const
i
in
institutionList
)
{
// 格式化机构分类(展示一级分类)
let
cats
=
[];
for
(
const
v
of
institutionCats
)
{
if
(
v
.
institution_id
===
institutionList
[
i
].
id
)
{
if
(
catList
[
v
.
cat_id
].
parent_id
===
0
)
{
cats
.
push
(
v
.
cat_id
);
}
else
{
cats
.
push
(
catList
[
v
.
cat_id
].
parent_id
);
}
}
}
// 去重
cats
=
_
.
uniq
(
cats
);
institutionList
[
i
].
cats
=
[];
for
(
const
v
of
cats
)
{
institutionList
[
i
].
cats
.
push
(
catList
[
v
]);
}
// 优先获取机构详情图
let
institutionImages
=
await
ctx
.
classModel
.
CourseImages
.
findAll
({
where
:
{
type
:
1
,
type_id
:
institutionList
[
i
].
id
,
status
:
'online'
,
is_deleted
:
0
},
order
:
[[
'sort'
,
'asc'
]],
limit
:
3
});
if
(
institutionImages
.
length
<
3
)
{
const
defaultImages
=
await
ctx
.
classModel
.
CourseImages
.
findAll
({
where
:
{
type
:
4
,
type_id
:
{
$in
:
cats
},
status
:
'online'
,
is_deleted
:
0
},
limit
:
3
-
institutionImages
.
length
});
institutionImages
=
institutionImages
.
concat
(
defaultImages
);
}
institutionList
[
i
].
images
=
institutionImages
;
institutionList
[
i
].
distance
=
(
institutionList
[
i
].
distance
/
1000
).
toFixed
(
1
);
// 是否已收藏
institutionList
[
i
].
is_collected
=
userInstitutionIds
.
includes
(
institutionList
[
i
].
id
)
?
1
:
0
;
ret
.
results
.
push
(
institutionList
[
i
]);
}
return
ret
;
}
}
module
.
exports
=
InstitutionSubService
;
config/config.local.js
View file @
1a562059
...
...
@@ -17,7 +17,7 @@ module.exports = appInfo => {
domainWhiteList
:
[],
};
config
.
middleware
=
[
'errorHandler'
,
'deviceLogin'
,
'deviceInit'
,
'responseSet'
];
config
.
middleware
=
[
'errorHandler'
,
'deviceLogin'
,
'deviceInit'
,
'responseSet'
];
config
.
middleware
=
[];
exports
.
multipart
=
{
...
...
@@ -90,7 +90,7 @@ module.exports = appInfo => {
// other sequelize configurations
dialect
:
'mysql'
,
host
:
'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com'
,
database
:
'prometheus_
uat
'
,
database
:
'prometheus_
dev
'
,
username
:
'prometheus'
,
password
:
'q9t8Ay4qIUW4sw3s25K28'
,
port
:
3306
,
...
...
@@ -103,7 +103,7 @@ module.exports = appInfo => {
// other sequelize configurations
dialect
:
'mysql'
,
host
:
'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com'
,
database
:
'class_
uat
'
,
database
:
'class_
dev
'
,
username
:
'class_testing'
,
password
:
'WV862L32451I6KD58tU9K'
,
port
:
3306
,
...
...
@@ -170,11 +170,11 @@ module.exports = appInfo => {
config
.
TX_LBS_URL
=
'https://apis.map.qq.com/ws'
;
// 地址解析;逆地址解析
//我的信用-通化检测
//
我的信用-通化检测
config
.
YYS_APP_KEY
=
'A86BB96F55B64DCE87A46E919A347993'
;
config
.
YYS_APPLY_APPSECRET
=
'a695e9b3c0f1e3f15fb0b958fd3a4b67'
;
//运营商报告
//
运营商报告
config
.
YYS_REPORT_KEY
=
'F4E0CA710F484CFFB1756741696E29A3'
;
config
.
YYS_REPORT_APPSECRET
=
'233B8E10E31B4C899EE6FEB3AEC22F140B6528BF'
;
config
.
YYS_REPORT_URL
=
'http://47.96.253.64:8049/mycredit/thxdReport'
;
...
...
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