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

'use strict';

const logger = global.yoho.logger;
const serviceAPI = global.yoho.ServiceAPI;
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 serviceAPI.get('suggest/api/v1/suggest/getList', {
            udid: udid,
            page: page,
            limit: limit
        }).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 serviceAPI.get('suggest/api/v1/suggest/is_reliable', {
            uid: uid,
            udid: udid,
            is_reliable: reliable,
            suggest_id: suggestId
        });
    }

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

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

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

        return serviceAPI.get('suggest/api/v1/suggest/saveSuggest', per);
    }
};