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
31d23be2
Commit
31d23be2
authored
May 15, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add recommend option product
parent
9536083d
Pipeline
#7631
passed with stage
in 8 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
347 additions
and
0 deletions
+347
-0
recommend_channel_classify.js
app/model/block/recommend_channel_classify.js
+92
-0
recommend_channel_option.js
app/model/block/recommend_channel_option.js
+92
-0
recommend_channel_product.js
app/model/block/recommend_channel_product.js
+94
-0
loan.js
app/service/gjj/loan.js
+69
-0
No files found.
app/model/block/recommend_channel_classify.js
0 → 100644
View file @
31d23be2
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
ENUM
}
=
app
.
Sequelize
;
const
RecommendChannelClassify
=
app
.
blockModel
.
define
(
'recommend_channel_classify'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
title
:
STRING
,
description
:
STRING
,
type
:
ENUM
(
'loan'
,
'credit'
),
key
:
STRING
,
valid
:
INTEGER
,
// 注意,需要转成string
created_at
:
{
type
:
DATE
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_at
:
{
type
:
DATE
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'recommend_channel_classify'
,
});
RecommendChannelClassify
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
RecommendChannelClassify
.
findOne
({
attributes
,
where
,
});
};
RecommendChannelClassify
.
all
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
RecommendChannelClassify
.
findAll
({
attributes
,
where
,
});
};
RecommendChannelClassify
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
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
RecommendChannelClassify
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
};
RecommendChannelClassify
.
add
=
async
data
=>
{
try
{
// 返回promise对象实力 instance
const
res
=
await
RecommendChannelClassify
.
create
(
data
);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
};
RecommendChannelClassify
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
RecommendChannelClassify
.
update
(
params
,
{
where
,
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
};
return
RecommendChannelClassify
;
};
app/model/block/recommend_channel_option.js
0 → 100644
View file @
31d23be2
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
ENUM
}
=
app
.
Sequelize
;
const
RecommendChannelOption
=
app
.
blockModel
.
define
(
'recommend_channel_option'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
title
:
STRING
,
classify_id
:
INTEGER
,
order
:
INTEGER
,
status
:
ENUM
(
'offline'
,
'online'
),
valid
:
INTEGER
,
// 注意,需要转成string
created_at
:
{
type
:
DATE
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_at
:
{
type
:
DATE
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'recommend_channel_option'
,
});
RecommendChannelOption
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
RecommendChannelOption
.
findOne
({
attributes
,
where
,
});
};
RecommendChannelOption
.
all
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
RecommendChannelOption
.
findAll
({
attributes
,
where
,
});
};
RecommendChannelOption
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
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
RecommendChannelOption
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
};
RecommendChannelOption
.
add
=
async
data
=>
{
try
{
// 返回promise对象实力 instance
const
res
=
await
RecommendChannelOption
.
create
(
data
);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
};
RecommendChannelOption
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
RecommendChannelOption
.
update
(
params
,
{
where
,
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
};
return
RecommendChannelOption
;
};
app/model/block/recommend_channel_product.js
0 → 100644
View file @
31d23be2
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
ENUM
}
=
app
.
Sequelize
;
const
RecommendChannelProduct
=
app
.
blockModel
.
define
(
'recommend_channel_product'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
option_id
:
STRING
,
product_id
:
STRING
,
identifier
:
STRING
,
type
:
ENUM
(
'normal'
,
'quality'
),
order
:
INTEGER
,
status
:
ENUM
(
'offline'
,
'online'
),
valid
:
INTEGER
,
// 注意,需要转成string
created_at
:
{
type
:
DATE
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_at
:
{
type
:
DATE
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'recommend_channel_product'
,
});
RecommendChannelProduct
.
one
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
RecommendChannelProduct
.
findOne
({
attributes
,
where
,
});
};
RecommendChannelProduct
.
all
=
async
data
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
RecommendChannelProduct
.
findAll
({
attributes
,
where
,
});
};
RecommendChannelProduct
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
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
RecommendChannelProduct
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
};
RecommendChannelProduct
.
add
=
async
data
=>
{
try
{
// 返回promise对象实力 instance
const
res
=
await
RecommendChannelProduct
.
create
(
data
);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
};
RecommendChannelProduct
.
edit
=
async
data
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
RecommendChannelProduct
.
update
(
params
,
{
where
,
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
};
return
RecommendChannelProduct
;
};
app/service/gjj/loan.js
0 → 100644
View file @
31d23be2
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
const
R
=
require
(
'ramda'
)
class
LoanService
extends
Service
{
//通过 type=loan/credit 频道 option_ids 筛选项数组 all_product_ids
// async getProductsByOptions(option_ids, all_product_ids = []) {
// const { ctx } = this;
// if (!Array.isArray(option_ids) || !option_ids || option_ids.length === 0) {
// return all_product_ids;
// }
// let product_ids = all_product_ids;
// for (let i in option_ids) {
// const option_id = option_ids[i];
// const products = await ctx.service.RecommendChannelProduct.all({ where: { option_id: option_id } });
// if (!products || products.length === 0 || Object.keys(products).length === 0) {
// continue;
// }
// const recommend_product_ids = R.pluck(products, 'product_id');
// product_ids = R.intersection(product_ids, recommend_product_ids);
// }
// return product_ids;
// }
//获取筛选项列表 带 product_id
//return : [{"id":3,"title":"银行分类","description":"信用卡银行分类","_children":[{"id":12,"title":"招商银行","quality":["1"],"normal":["1"]},{"id":16,"title":"广发银行","quality":[],"normal":[]}]},{"id":4,"title":"主题分类","description":"信用卡主题分类","_children":[]},{"id":5,"title":"信用卡筛选项","description":"信用卡筛选项","_children":[]}]
async
getRecommendOptions
(
type
=
'credit'
,
keys
=
[
'loan_organization'
,
'loan_filter'
,
'credit_bank'
,
'credit_theme'
,
'credit_filter'
])
{
const
{
ctx
}
=
this
;
// const type = 'credit';
// const keys = ['loan_organization', 'loan_filter', 'credit_bank', 'credit_theme', 'credit_filter'];
let
classifies
=
await
ctx
.
blockModel
.
RecommendChannelClassify
.
all
({
where
:
{
type
:
type
,
valid
:
1
,
key
:
{
$in
:
keys
}
}
});
classifies
=
R
.
project
([
'id'
,
'title'
,
'description'
])(
classifies
);
const
classify_ids
=
R
.
pluck
(
'id'
,
classifies
);
let
options
=
await
ctx
.
blockModel
.
RecommendChannelOption
.
all
({
where
:
{
classify_id
:
{
$in
:
classify_ids
},
status
:
'online'
,
valid
:
1
},
order
:
[[
'order'
,
'asc'
]]
});
options
=
R
.
project
([
'id'
,
'title'
,
'classify_id'
])(
options
);
const
option_ids
=
R
.
pluck
(
'id'
,
options
);
let
option_products
=
await
ctx
.
blockModel
.
RecommendChannelProduct
.
all
({
where
:
{
option_id
:
{
$in
:
option_ids
},
valid
:
1
},
order
:
[[
'order'
,
'asc'
]]
});
option_products
=
R
.
project
([
'option_id'
,
'product_id'
,
'type'
])(
option_products
);
let
ret
=
[];
for
(
let
i
in
classifies
)
{
let
classify
=
classifies
[
i
];
const
classify_id
=
classify
.
id
;
let
temp_options
=
options
.
filter
(
option
=>
parseInt
(
option
.
classify_id
)
===
parseInt
(
classify_id
));
temp_options
=
R
.
project
([
'id'
,
'title'
])(
temp_options
);
for
(
let
j
in
temp_options
)
{
let
temp_option
=
temp_options
[
j
];
const
temp_option_id
=
temp_option
.
id
;
let
temp_option_products
=
option_products
.
filter
(
v
=>
parseInt
(
v
.
option_id
)
===
parseInt
(
temp_option_id
));
temp_option_products
=
R
.
groupBy
(
v
=>
{
return
v
.
type
===
'quality'
?
'quality'
:
'normal'
})(
temp_option_products
);
const
quality_product_ids
=
R
.
pluck
(
'product_id'
,
temp_option_products
.
quality
?
temp_option_products
.
quality
:
[]);
const
normal_product_ids
=
R
.
pluck
(
'product_id'
,
temp_option_products
.
normal
?
temp_option_products
.
normal
:
[]);
temp_options
[
j
].
quality
=
quality_product_ids
;
temp_options
[
j
].
normal
=
normal_product_ids
;
}
classify
.
_children
=
temp_options
;
ret
.
push
(
classify
);
}
return
ret
;
}
}
module
.
exports
=
LoanService
;
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