shop-service.js 1 KB
/**
 * 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');

const DEFAULT_IMG = '01091c21f2317a64f123f1649fbbccf7ba';

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)();
    }
};