opt.js 2.47 KB
/**
 * 逛操作models
 * @author: chenfeng<feng.chen@yoho.cn>
 * @date: 2016/09/07
 */
'use strict';

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

    /**
     * [逛资讯点赞/取消赞]
     * @param  {[int]} udid [唯一客户端标识]
     * @param  {[int]} id   [唯一资讯的ID]
     * @param  {[string]} opt  [操作(ok:表示确定,cancel:表示取消)]
     * @return {[array]}
     */
    praiseArticle(udid, id, opt) {
        let param = {
            article_id: id,
            udid: udid
        };

        if (opt === 'cancel') {
            return this.get({
                url: 'guang/api/v2/praise/cancel',
                data: param,
                api: global.yoho.ServiceAPI
            });
        } else {
            return this.get({
                url: 'guang/api/v2/praise/setPraise',
                data: param,
                api: global.yoho.ServiceAPI
            });
        }
    }

    /**
     * [逛资讯收藏/取消收藏 (APP里调用)]
     * @param  {[int]} uid [用户id]
     * @param  {[int]} id   [唯一资讯的ID]
     * @param  {[string]} opt  [操作(ok:表示确定,cancel:表示取消)]
     * @return {[array]}
     */
    collectArticle(uid, id, opt) {
        let param = {
            article_id: id,
            uid: uid
        };

        if (opt === 'cancel') {
            return this.get({
                url: 'guang/api/v1/favorite/cancelFavorite',
                data: param,
                api: global.yoho.ServiceAPI
            });
        } else {
            return this.get({
                url: 'guang/api/v1/favorite/setFavorite',
                data: param,
                api: global.yoho.ServiceAPI
            });
        }
    }

    // 品牌收藏

    favoriteBrand(uid, id, opt) {
        let param;

        if (opt === 'ok') {
            param = {
                id: id,
                uid: uid,
                type: 'brand'
            };
        } else {
            param = {
                fav_id: id,
                uid: uid,
                type: 'brand'
            };
        }


        if (opt === 'ok') {
            return this.get({
                url: 'app.favorite.add',
                data: param,
                api: global.yoho.API
            });
        } else {
            return this.get({
                url: 'app.favorite.cancel',
                data: param,
                api: global.yoho.API
            });
        }
    }
};