similar.js 980 Bytes
'use strict';

const utils = '../../../utils';
const _ = require('lodash');
const productProcess = require(`${utils}/product-process`);

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

    list(params) {
        let options = {
            data: {
                method: 'app.search.findLike',
                product_skn: params.skn
            },
            param: {
                code: 200
            }
        };

        return this.get(options).then(result => {
            let resu = {
                goodInfo: [],
                list: []
            };

            if (_.get(result, 'data', false)) {
                resu.goodInfo = productProcess.processProductList(result.data);
            }

            if (_.get(result, 'data.product_list', false)) {
                resu.list = productProcess.processProductList(result.data.product_list);
            }

            return resu;
        });
    }
};