...
|
...
|
@@ -7,10 +7,36 @@ |
|
|
const Context = require('../common/context');
|
|
|
const Api = require('../common/api');
|
|
|
const apiDomain = global.yoho.apiDomain;
|
|
|
const co = global.yoho.co;
|
|
|
|
|
|
class loginModel extends Context {
|
|
|
login(username, password) {
|
|
|
return this.instance(Api).post(apiDomain.auth.login, JSON.stringify([username, password, 2]));
|
|
|
let self = this;
|
|
|
|
|
|
return co(function * () {
|
|
|
let userInfo = yield self.instance(Api).post(apiDomain.auth.login, JSON.stringify([username, password, 2])).catch(console.log);
|
|
|
|
|
|
if (userInfo.code !== 200 || !userInfo.data.pid) {
|
|
|
return Promise.reject({code: 500, message: '登录服务器错误'});
|
|
|
}
|
|
|
|
|
|
let shopInfo = yield self.profile(userInfo.data.pid);
|
|
|
|
|
|
if (shopInfo.code !== 200) {
|
|
|
return Promise.reject({code: 500, message: '用户获取店铺错误'});
|
|
|
}
|
|
|
|
|
|
let user = Object.assign(userInfo.data, shopInfo.data);
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
data: user
|
|
|
};
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
profile(pid) {
|
|
|
return this.instance(Api).get(apiDomain.shop.profile, {userId: pid});
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|