guang-new.js 2.25 KB
'use strict';

const _ = require('lodash');

class newGuang extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    _indexRes(params) {
        let options = {
            url: '/operations/api/v5/resource/get',
            data: {
                content_code: '44153d54effebaf803a2deee06b3ea5a',
                gender: params.gender
            },
            api: global.yoho.ServiceAPI
        };

        return this.get(options).then(result => {
            return result;
        });
    }

    list(params) {
        let options = {
            url: '/guang/api/v1/article/getHomePageList',
            data: {
                page: params.page || 1,
                limit: params.limit || 2
            },
            api: global.yoho.ServiceAPI
        };

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

            if (_.get(result, 'data.guangList')) {
                resu.list = result.data.guangList;
            }
            return resu;
        });
    }

    index(params) {
        return Promise.all([
            this._indexRes(params)
        ]).then((result) => {
            let resu = {
                floorRes: {},
                gender: encodeURIComponent(params.gender)
            };

            if (_.get(result, '[0].data')) {
                _.forEach(result[0].data, (val) => {
                    if (val.template_name === 'focus') {
                        resu.floorRes.focus = _.get(val, 'data');
                    }
                    if (val.template_name === '3:4ImageListFloor') {
                        resu.floorRes.type = _.get(val, 'data.list');
                    }
                    if (val.template_name === 'GuangRqFloor') {
                        resu.floorRes.renQi = _.get(val, 'data.list');
                    }
                    if (val.template_name === 'GuangDpFloor') {
                        resu.floorRes.daPei = _.get(val, 'data.list');
                    }
                    if (val.template_name === 'GuangHhFloor') {
                        resu.floorRes.haoHuo = _.get(val, 'data.list');
                    }
                });
            }

            return resu;
        });
    }
}

module.exports = newGuang;