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

'use strict';

const logger = global.yoho.logger;
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const config = global.yoho.config;
const helpers = global.yoho.helpers;

const suggestData = (udid, page, limit) => {

    return serviceAPI.get('suggest/api/v1/suggest/getList', {
        udid: udid,
        page: page,
        limit: limit
    }).then((result) => {
        // console.log(result)
        if (result && result.code === 200) {
            _.forEach(result.data.list, function(data) {

                data = _.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('收藏商品 cood 不是 200');
        }
    });
};

const upAndDown = (uid, udid, reliable, suggestId) => {

    return serviceAPI.get('suggest/api/v1/suggest/is_reliable', {
        uid: uid,
        udid: udid,
        is_reliable: reliable,
        suggest_id: suggestId
    });
};

// 提交
const 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);
};

module.exports = {
    suggestData,
    upAndDown,
    saveSuggest
};