shop-service.js 970 Bytes
/**
 * Created by TaoHuang on 2016/6/28.
 */

'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const Api = require('./shop-api');

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

    getShopBannerAsync(shopId) {
        return this.api.shopBannerAsync(shopId).then((result) => {
            if (result.code === 200) {
                return _.includes(result.data.banner, DEFAULT_IMG) ? '' : result.data.banner;
            } else {
                return null;
            }
        });
    };

    queryShopByBrandIdAsync(sid, bid) {
        return co(function * () {
            let result = yield this.api.queryShopsByBrandId(sid, bid);

            if (_.get(result, 'code') !== 200) {
                return false;
            }

            return _.get(result, 'data[0]', {});
        }).bind(this)();
    }
};