recom.js 3.29 KB
'use strict';

const logger = global.yoho.logger;
const utils = '../../../utils';
const productProcess = require(`${utils}/product-process`);

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    mayLike(uid, page, limit, gender, udid, recPos, channel, clientId) {
        return this.get({
            data: {
                method: 'app.search.newLast7day',
                uid: uid,
                page: page,
                limit: limit,
                udid: udid,
                rec_pos: recPos,
                yh_channel: channel,
                gender: gender,
                client_id: clientId
            }
        }).then(result => {

            if (result && result.code === 200) {

                if (result.data.page_total && page <= result.data.page_total) {
                    if (result.data.product_list) {

                        return productProcess.processProductList(result.data.product_list, {
                            showSimilar: true
                        });

                    } else {
                        return false;
                    }
                }
            } else {
                logger.error('mayLike code no 200');
            }
        });
    }

    mayLikeKids(page, limit, channel) {
        return this.get({
            data: {
                method: 'app.search.kids',
                page: page,
                limit: limit,
                yh_channel: channel
            }
        }).then((result) => {

            if (result && result.code === 200) {

                if (page > result.data.page_total) {
                    return;
                }

                if (result.data.product_list) {

                    return productProcess.processProductList(result.data.product_list, {
                        showSimilar: true
                    });

                }
            } else {
                logger.error('mayLikeKids code no 200');
            }
        });
    }

    mayLikelife(page, limit) {
        return this.get({
            data: {
                method: 'app.search.lifeStyle',
                page: page,
                limit: limit,
                yh_channel: '4'
            }
        }).then(result => {
            if (result && result.code === 200) {
                let formData = {
                    goodsContainer: []
                };

                if (result.data.product_list.top) {
                    let build = {};

                    build.show = true;

                    build.goods = productProcess.processProductList(result.data.product_list.top, {
                        showTags: false,
                        showSimilar: true
                    });

                    formData.goodsContainer.push(build);
                }

                if (result.data.product_list.top) {
                    let build = {};

                    build.show = true;

                    build.goods = productProcess.processProductList(result.data.product_list.new, {
                        showTags: false,
                        showSimilar: true
                    });

                    formData.goodsContainer.push(build);
                }

                return formData;

            } else {
                return {};
            }
        });
    }
};