user-service.js 1.45 KB
/**
 * Created by TaoHuang on 2017/4/17.
 */

'use strict';

const _ = require('lodash');
const md5 = require('yoho-md5');
const Context = require('../common/context');
const Api = require('../common/api');
const apiDomain = global.yoho.apiDomain;
const config = global.yoho.config;

class UserService extends Context {
    constructor() {
        super();
        this.api = this.instance(Api);
    }
    login(account, password) {
        return this.api.post(apiDomain.erp.login, {
            account,
            password,
            platform: config.platform
        }).then(userInfo => {
            this.api.get(`http://192.168.102.211:30016/loginInter?user=${account}&password=${password}`).then(res => {
                console.log(res);
            });
            if (userInfo.code !== 200 || !userInfo.data.pid) {
                return Promise.reject({code: 500, message: '用户名密码错误'});
            }
            return userInfo.data;
        });
    }

    getShops(pid) {
        return this.api.get(apiDomain.platform.queryShopsByAdminPid, {
            userId: pid
        }).then(result => {
            if (result.code === 200) {
                _.each(result.data, shop => {
                    shop.id = md5(shop.shopName);
                });
            }
            return result;
        });
    }

    profile(pid) {
        return this.instance(Api).get(apiDomain.shop.profile.url, {userId: pid});
    }
}


module.exports = UserService;