Blame view

apps/guang/models/guang-new.js 3.28 KB
李靖 authored
1 2 3
'use strict';

const _ = require('lodash');
4
const helpers = global.yoho.helpers;
李靖 authored
5 6 7 8 9 10 11 12 13 14

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

    _indexRes(params) {
        let options = {
            url: '/operations/api/v5/resource/get',
            data: {
15
                content_code: '5523199f921ee2297b509397a224d9e8',
李靖 authored
16 17 18 19 20 21 22 23 24 25
                gender: params.gender
            },
            api: global.yoho.ServiceAPI
        };

        return this.get(options).then(result => {
            return result;
        });
    }
李靖 authored
26 27 28 29 30
    list(params) {
        let options = {
            url: '/guang/api/v1/article/getHomePageList',
            data: {
                page: params.page || 1,
李靖 authored
31
                limit: params.limit || 10
李靖 authored
32 33 34 35 36 37 38 39 40 41 42
            },
            api: global.yoho.ServiceAPI
        };

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

            if (_.get(result, 'data.guangList')) {
                resu.list = result.data.guangList;
李靖 authored
43 44

                _.forEach(resu.list, (val) => {
李靖 authored
45
                    val.play = val.hasVideoFlag === 1;
李靖 authored
46
                });
李靖 authored
47 48 49 50 51
            }
            return resu;
        });
    }
李靖 authored
52 53 54 55 56
    index(params) {
        return Promise.all([
            this._indexRes(params)
        ]).then((result) => {
            let resu = {
李靖 authored
57 58
                floorRes: {},
                gender: encodeURIComponent(params.gender)
李靖 authored
59 60 61 62
            };

            if (_.get(result, '[0].data')) {
                _.forEach(result[0].data, (val) => {
63
                    if (val.template_name === 'focus' && _.get(val, 'data')) {
李靖 authored
64
                        resu.floorRes.focus = _.get(val, 'data');
65 66 67
                        _.forEach(val.data, (d) => {
                            d.src = helpers.image(d.src, 750, 480);
                        });
李靖 authored
68
                    }
69
                    if (val.template_name === '3:4ImageListFloor' && _.get(val, 'data.list')) {
李靖 authored
70
                        resu.floorRes.type = _.get(val, 'data.list');
71 72 73
                        _.forEach(val.data.list, (d) => {
                            d.src = helpers.image(d.src, 200, 640);
                        });
李靖 authored
74
                    }
75
                    if (val.template_name === 'GuangRqFloor' && _.get(val, 'data.list')) {
李靖 authored
76
                        resu.floorRes.renQi = _.get(val, 'data.list');
77 78 79
                        _.forEach(val.data.list, (d) => {
                            d.src = helpers.image(d.src, 690, 430);
                        });
李靖 authored
80
                    }
81
                    if (val.template_name === 'GuangDpFloor' && _.get(val, 'data.list')) {
李靖 authored
82
                        resu.floorRes.daPei = _.get(val, 'data.list');
83 84 85
                        _.forEach(val.data.list, (d) => {
                            d.src = helpers.image(d.src, 590, 370);
                        });
李靖 authored
86
                    }
87
                    if (val.template_name === 'GuangHhFloor' && _.get(val, 'data.list')) {
李靖 authored
88
                        resu.floorRes.haoHuo = _.get(val, 'data.list');
89 90 91
                        _.forEach(val.data.list, (d) => {
                            d.src = helpers.image(d.src, 360, 224);
                        });
李靖 authored
92 93 94 95 96 97 98 99 100 101
                    }
                });
            }

            return resu;
        });
    }
}

module.exports = newGuang;