similar.js 1008 Bytes
'use strict';

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

class SimilarModel 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;
        });
    }
}

module.exports = SimilarModel;