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
0c69d658
Commit
0c69d658
authored
Nov 15, 2019
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tag & logo
parent
e3708872
Pipeline
#16461
passed with stage
in 8 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
31 deletions
+146
-31
courseInstitutionToTag.js
app/model/class/courseInstitutionToTag.js
+43
-0
courseTag.js
app/model/class/courseTag.js
+42
-0
course_institution.js
app/model/class/course_institution.js
+25
-24
institutionSub.js
app/service/course/institutionSub.js
+36
-7
No files found.
app/model/class/courseInstitutionToTag.js
0 → 100644
View file @
0c69d658
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
ENUM
}
=
app
.
Sequelize
;
const
CourseInstitutionToTag
=
app
.
classModel
.
define
(
'course_institution_to_tag'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
institution_id
:
INTEGER
,
tag_id
:
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
;
},
},
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_institution_to_tag'
,
});
return
CourseInstitutionToTag
;
};
app/model/class/courseTag.js
0 → 100644
View file @
0c69d658
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
ENUM
}
=
app
.
Sequelize
;
const
CourseTag
=
app
.
classModel
.
define
(
'course_tag'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
name
:
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_tag'
,
});
return
CourseTag
;
};
app/model/class/course_institution.js
View file @
0c69d658
'use strict'
;
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
const
moment
=
require
(
'moment'
);
...
@@ -13,7 +13,7 @@ module.exports = app => {
...
@@ -13,7 +13,7 @@ module.exports = app => {
id
:
{
id
:
{
type
:
INTEGER
,
type
:
INTEGER
,
primaryKey
:
true
,
primaryKey
:
true
,
autoIncrement
:
true
autoIncrement
:
true
,
},
},
name
:
STRING
,
name
:
STRING
,
type
:
STRING
,
type
:
STRING
,
...
@@ -22,6 +22,7 @@ module.exports = app => {
...
@@ -22,6 +22,7 @@ module.exports = app => {
class_type
:
STRING
,
class_type
:
STRING
,
teacher_count
:
INTEGER
,
teacher_count
:
INTEGER
,
teacher_experience
:
INTEGER
,
teacher_experience
:
INTEGER
,
logo
:
STRING
,
corner
:
STRING
,
corner
:
STRING
,
min_age
:
INTEGER
,
min_age
:
INTEGER
,
max_age
:
INTEGER
,
max_age
:
INTEGER
,
...
@@ -39,7 +40,7 @@ module.exports = app => {
...
@@ -39,7 +40,7 @@ module.exports = app => {
const
date
=
this
.
getDataValue
(
'created_time'
);
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
}
},
},
{
},
{
timestamps
:
false
,
timestamps
:
false
,
tableName
:
'course_institution'
,
tableName
:
'course_institution'
,
...
@@ -48,29 +49,29 @@ module.exports = app => {
...
@@ -48,29 +49,29 @@ module.exports = app => {
CourseInstitution
.
hasMany
(
CourseArea
,
{
CourseInstitution
.
hasMany
(
CourseArea
,
{
foreignKey
:
{
foreignKey
:
{
name
:
'institution_id'
,
name
:
'institution_id'
,
allowNull
:
false
allowNull
:
false
,
}
},
});
});
CourseInstitution
.
one
=
async
(
data
)
=>
{
CourseInstitution
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseInstitution
.
findOne
({
return
await
CourseInstitution
.
findOne
({
attributes
:
attributes
,
attributes
,
where
:
where
,
where
,
});
});
}
};
CourseInstitution
.
all
=
async
(
data
)
=>
{
CourseInstitution
.
all
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseInstitution
.
findAll
({
return
await
CourseInstitution
.
findAll
({
attributes
:
attributes
,
attributes
,
where
:
where
,
where
,
order
,
order
,
});
});
}
};
CourseInstitution
.
list
=
async
(
data
=
{})
=>
{
CourseInstitution
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
Number
(
data
.
limit
)
:
10
;
const
limit
=
data
.
limit
?
Number
(
data
.
limit
)
:
10
;
...
@@ -81,35 +82,35 @@ module.exports = app => {
...
@@ -81,35 +82,35 @@ module.exports = app => {
const
condition
=
{
const
condition
=
{
offset
:
(
page
-
1
)
*
limit
,
offset
:
(
page
-
1
)
*
limit
,
limit
,
limit
,
where
:
where
,
where
,
order
:
order
,
order
,
attributes
:
attributes
,
attributes
,
};
};
const
{
count
,
rows
}
=
await
CourseInstitution
.
findAndCountAll
(
condition
);
const
{
count
,
rows
}
=
await
CourseInstitution
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
return
{
page
,
count
,
rows
};
}
};
CourseInstitution
.
add
=
async
(
data
)
=>
{
CourseInstitution
.
add
=
async
data
=>
{
try
{
try
{
//返回promise对象实力 instance
// 返回promise对象实力 instance
const
res
=
await
CourseInstitution
.
create
(
data
);
const
res
=
await
CourseInstitution
.
create
(
data
);
//
从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
//
从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
return
res
.
id
;
}
catch
(
error
)
{
}
catch
(
error
)
{
throw
(
error
);
throw
(
error
);
}
}
}
};
CourseInstitution
.
edit
=
async
(
data
)
=>
{
CourseInstitution
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
where
=
data
.
where
;
const
params
=
data
.
params
;
const
params
=
data
.
params
;
try
{
try
{
const
res
=
await
CourseInstitution
.
update
(
params
,
{
where
:
where
})
const
res
=
await
CourseInstitution
.
update
(
params
,
{
where
});
return
res
;
return
res
;
}
catch
(
error
)
{
}
catch
(
error
)
{
throw
(
error
);
throw
(
error
);
}
}
}
};
return
CourseInstitution
;
return
CourseInstitution
;
...
...
app/service/course/institutionSub.js
View file @
0c69d658
...
@@ -127,8 +127,22 @@ class InstitutionSubService extends Service {
...
@@ -127,8 +127,22 @@ class InstitutionSubService extends Service {
// 是否已收藏
// 是否已收藏
const
userCollect
=
await
ctx
.
classModel
.
CourseUserCollection
.
findOne
({
where
:
{
institution_id
,
user_uuid
:
userUuid
,
is_deleted
:
0
}
});
const
userCollect
=
await
ctx
.
classModel
.
CourseUserCollection
.
findOne
({
where
:
{
institution_id
,
user_uuid
:
userUuid
,
is_deleted
:
0
}
});
// 获取所有标签
const
allTags
=
await
ctx
.
classModel
.
CourseTag
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
}
});
const
tagList
=
[];
for
(
const
v
of
allTags
)
{
tagList
[
v
.
id
]
=
v
;
}
let
tags
=
await
ctx
.
classModel
.
CourseInstitutionToTag
.
findAll
({
where
:
{
institution_id
:
institution
.
id
,
status
:
'online'
,
is_deleted
:
0
}
});
tags
=
_
.
orderBy
(
tags
,
[
'sort'
],
[
'asc'
]);
institution
.
tags
=
[];
for
(
const
v
of
tags
)
{
institution
.
tags
.
push
(
tagList
[
v
.
tag_id
]);
}
institution
.
phone
=
areas
.
length
>
0
?
areas
[
0
].
phone
:
''
;
institution
.
phone
=
areas
.
length
>
0
?
areas
[
0
].
phone
:
''
;
institution
.
distance
=
areas
.
length
>
0
?
areas
[
0
].
distance
:
'
'
;
institution
.
distance
=
areas
.
length
>
0
?
String
(
areas
[
0
].
distance
)
+
'km'
:
'无法计算
'
;
institution
.
travel_method
=
areas
.
length
>
0
?
areas
[
0
].
travel_method
:
''
;
institution
.
travel_method
=
areas
.
length
>
0
?
areas
[
0
].
travel_method
:
''
;
institution
.
travel_tips
=
areas
.
length
>
0
?
areas
[
0
].
travel_tips
:
''
;
institution
.
travel_tips
=
areas
.
length
>
0
?
areas
[
0
].
travel_tips
:
''
;
...
@@ -284,6 +298,13 @@ class InstitutionSubService extends Service {
...
@@ -284,6 +298,13 @@ class InstitutionSubService extends Service {
}
}
institutionCats
=
await
ctx
.
classModel
.
CourseInstitutionToCat
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
,
institution_id
:
{
$in
:
institutionIds
}
}
});
institutionCats
=
await
ctx
.
classModel
.
CourseInstitutionToCat
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
,
institution_id
:
{
$in
:
institutionIds
}
}
});
// 获取所有标签
const
allTags
=
await
ctx
.
classModel
.
CourseTag
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
}
});
const
tagList
=
[];
for
(
const
v
of
allTags
)
{
tagList
[
v
.
id
]
=
v
;
}
// 用户已收藏机构列表
// 用户已收藏机构列表
const
userInstitutions
=
await
ctx
.
classModel
.
CourseUserCollection
.
findAll
({
where
:
{
is_deleted
:
0
,
user_uuid
:
userUuid
}
});
const
userInstitutions
=
await
ctx
.
classModel
.
CourseUserCollection
.
findAll
({
where
:
{
is_deleted
:
0
,
user_uuid
:
userUuid
}
});
const
userInstitutionIds
=
R
.
pluck
(
'id'
,
userInstitutions
);
const
userInstitutionIds
=
R
.
pluck
(
'id'
,
userInstitutions
);
...
@@ -308,6 +329,14 @@ class InstitutionSubService extends Service {
...
@@ -308,6 +329,14 @@ class InstitutionSubService extends Service {
institutionList
[
i
].
cats
.
push
(
catList
[
v
]);
institutionList
[
i
].
cats
.
push
(
catList
[
v
]);
}
}
// 标签
let
tags
=
await
ctx
.
classModel
.
CourseInstitutionToTag
.
findAll
({
where
:
{
institution_id
:
institutionList
[
i
].
id
,
status
:
'online'
,
is_deleted
:
0
}
});
tags
=
_
.
orderBy
(
tags
,
[
'sort'
],
[
'asc'
]);
institutionList
[
i
].
tags
=
[];
for
(
const
v
of
tags
)
{
institutionList
[
i
].
tags
.
push
(
tagList
[
v
.
tag_id
]);
}
// 优先获取机构详情图
// 优先获取机构详情图
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
});
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
)
{
if
(
institutionImages
.
length
<
3
)
{
...
@@ -316,7 +345,7 @@ class InstitutionSubService extends Service {
...
@@ -316,7 +345,7 @@ class InstitutionSubService extends Service {
}
}
institutionList
[
i
].
images
=
institutionImages
;
institutionList
[
i
].
images
=
institutionImages
;
institutionList
[
i
].
distance
=
(
institutionList
[
i
].
distance
/
1000
).
toFixed
(
1
)
;
institutionList
[
i
].
distance
=
String
((
institutionList
[
i
].
distance
/
1000
).
toFixed
(
1
))
+
'km'
;
institutionList
[
i
].
phone
=
institutionList
[
i
].
area
.
length
>
0
?
institutionList
[
i
].
area
[
0
].
phone
:
''
;
institutionList
[
i
].
phone
=
institutionList
[
i
].
area
.
length
>
0
?
institutionList
[
i
].
area
[
0
].
phone
:
''
;
// 是否已收藏
// 是否已收藏
...
@@ -487,20 +516,20 @@ class InstitutionSubService extends Service {
...
@@ -487,20 +516,20 @@ class InstitutionSubService extends Service {
}
}
//搜索关联
//
搜索关联
async
getSuggestSearch
(
input
)
{
async
getSuggestSearch
(
input
)
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
{
search
}
=
input
;
const
{
search
}
=
input
;
let
results
=
[];
let
results
=
[];
if
(
!
ctx
.
isEmpty
(
search
))
{
if
(
!
ctx
.
isEmpty
(
search
))
{
const
institutions
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
,
name
:
{
$like
:
'%'
+
search
+
'%'
}
},
limit
:
10
,
attributes
:
[
'id'
,
'name'
,
'status'
,
'is_deleted'
]
})
const
institutions
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
({
where
:
{
status
:
'online'
,
is_deleted
:
0
,
name
:
{
$like
:
'%'
+
search
+
'%'
}
},
limit
:
10
,
attributes
:
[
'id'
,
'name'
,
'status'
,
'is_deleted'
]
});
results
=
R
.
pluck
(
'name'
,
institutions
);
results
=
R
.
pluck
(
'name'
,
institutions
);
}
}
const
ret
=
{
const
ret
=
{
results
,
results
,
count
:
results
.
length
,
count
:
results
.
length
,
}
}
;
return
ret
;
return
ret
;
}
}
...
...
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