suggest.js 1.9 KB
/**
* 个人中心意见反馈
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/09/01
*/

'use strict';

const logger = global.yoho.logger;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');

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

    suggestData(uid, udid, page, limit) {

        return this.get({
            url: 'suggest/api/v1/suggest/getList',
            data: {
                udid: udid,
                page: page,
                limit: limit
            },
            api: global.yoho.ServiceAPI
        }).then((result) => {
            if (result && result.code === 200 && result.data) {
                _.forEach(result.data.list, function(data) {

                    Object.assign(data, {
                        good: data.is_reliable === 1,
                        bad: data.is_reliable === 2,
                        none: data.is_reliable === 0
                    });
                });
                return camelCase(result.data.list);
            } else {
                logger.error('fav goods code no 200');
            }
        });
    }

    upAndDown(uid, udid, reliable, suggestId) {
        return this.get({
            url: 'suggest/api/v1/suggest/is_reliable',
            data: {
                uid: uid,
                udid: udid,
                is_reliable: reliable,
                suggest_id: suggestId
            },
            api: global.yoho.ServiceAPI
        });
    }

    // 提交
    saveSuggest(uid, content, image, suggestType) {

        let per = {
            uid: uid,
            content: content,
            suggest_type: suggestType
        };

        if (image !== null) {
            per.image = image;
        }

        return this.get({
            url: 'suggest/api/v1/suggest/saveSuggest',
            data: per,
            api: global.yoho.ServiceAPI
        });
    }
};