Skip to content

Commit

Permalink
Add recommendation/delivery api
Browse files Browse the repository at this point in the history
  • Loading branch information
aojiaotage committed Aug 31, 2019
1 parent c259668 commit c2c7474
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
72 changes: 69 additions & 3 deletions app/controller/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ class SiteController extends Controller {
const recList = products.map(p => {
return {
'action': {
'type': 'product',
'type': 'product',
'path': p.id,
'log_code': 'recom_list_0-1#eid=force_15:0:0:0:0:0:0:0:0:7354&tid=BlankRec-78cpaAwFqwUTL0eVFuqCzg==&page=list&pid=7354',
'recommend_code': 'recom_list_0-1#eid=force_15:0:0:0:0:0:0:0:0:7354&tid=BlankRec-78cpaAwFqwUTL0eVFuqCzg==&page=list&pid=7354',
},
},
'image_url': '//i8.mifile.cn/v1/a1/48af122b-362c-dae5-8305-899805faf635.webp',
'is_multi_price': false,
'market_price': '799',
Expand All @@ -104,7 +104,7 @@ class SiteController extends Controller {
'product_desc': `<font color=\'#ff4a00\'>${p.product_desc}`,
'product_tag': '',
};
})
});

this.ctx.body = {
code: 0,
Expand Down Expand Up @@ -134,6 +134,72 @@ class SiteController extends Controller {
};
}

async recommend() {

const products = await this.ctx.service.product.listProducts({ limit: 10 });

const recList = products.map(p => {
return {
action: {
type: 'product',
path: p.id,
log_code: 'recom_list_0-1#eid=force_15:0:0:0:0:0:0:0:0:7354&tid=BlankRec-78cpaAwFqwUTL0eVFuqCzg==&page=list&pid=7354',
recommend_code: 'recom_list_0-1#eid=force_15:0:0:0:0:0:0:0:0:7354&tid=BlankRec-78cpaAwFqwUTL0eVFuqCzg==&page=list&pid=7354',
},
image_url: '//i8.mifile.cn/v1/a1/48af122b-362c-dae5-8305-899805faf635.webp',
big_image_url: '//i8.mifile.cn/v1/a1/48af122b-362c-dae5-8305-899805faf635.webp',
is_multi_price: false,
market_price: '799',
name: p.name,
price: '699',
product_desc: `<font color=\'#ff4a00\'>${p.product_desc}`,
product_tag: '',
};
});

this.ctx.body = {
code: 0,
data: {
recommend_list: recList,
title: '为你推荐',
},
};
}

async estDelivery() {

let address = {
address: '北京市 西城区',
id: '',
};

const userId = this.ctx.session.user && this.ctx.session.user.id;

if (userId) {
address = (await this.ctx.service.address.listAddresses(
{ userIds: [userId] }))[0];
}

this.ctx.body = {
code: 0,
data: {
address: {
address: address.address,
},
address_info: {
address: address.address,
address_id: address.id,
},
datas: [
{
stock_status: '有现货',
},
],
title: '为你推荐',
},
};
}

async category() {
this.ctx.body = {
code: 0,
Expand Down
3 changes: 1 addition & 2 deletions app/model/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ module.exports = app => {

if (found) {
found.nums += item.nums;
await Model.update(found, {
await Model.update(found.toJSON(), {
where: {
id: {
[Op.eq]: found.id,
},
},
values: found,
});
return found;
} else {
Expand Down
6 changes: 6 additions & 0 deletions app/router/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ module.exports = app => {
router.get('/api/v1/site/nav', controller.site.navList);
router.get('/api/v1/site/home', controller.site.homePage);
router.get('/api/v1/site/category', controller.site.category);
// 购物车中推荐
router.get('/api/v1/site/forRecommend', controller.site.forRecommend);

// 商品页面推荐
router.get('/api/v1/site/recommend', controller.site.recommend);

router.get('/api/v1/site/estDelivery', controller.site.estDelivery);

};

0 comments on commit c2c7474

Please sign in to comment.