...
|
...
|
@@ -5,90 +5,94 @@ const api = global.yoho.API; |
|
|
const _ = require('lodash');
|
|
|
const logger = global.yoho.logger;
|
|
|
|
|
|
const _yohoCoin = (uid) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.yoho.yohocoin',
|
|
|
uid: uid
|
|
|
}).then((result) => {
|
|
|
let data = [];
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
data = result.data;
|
|
|
} else {
|
|
|
logger.error('youhocoin code no 200');
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const bannerData = (contentCode) => {
|
|
|
|
|
|
return serviceAPI.get('operations/api/v5/resource/get', {
|
|
|
content_code: contentCode
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
|
|
|
return result.data;
|
|
|
|
|
|
} else {
|
|
|
logger.error('banner is not 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const myCurrency = (uid, contentCode) => {
|
|
|
return Promise.all([_yohoCoin(uid), bannerData(contentCode)])
|
|
|
.then((result) => {
|
|
|
class myCurrencyModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
_yohoCoin(uid) {
|
|
|
return api.get('', {
|
|
|
method: 'app.yoho.yohocoin',
|
|
|
uid: uid
|
|
|
}).then((result) => {
|
|
|
let data = [];
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
data = result.data;
|
|
|
} else {
|
|
|
logger.error('youhocoin code no 200');
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
bannerData(contentCode) {
|
|
|
|
|
|
return serviceAPI.get('operations/api/v5/resource/get', {
|
|
|
content_code: contentCode
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
|
|
|
return result.data;
|
|
|
|
|
|
} else {
|
|
|
logger.error('banner is not 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
myCurrency(uid, contentCode) {
|
|
|
return Promise.all([
|
|
|
this._yohoCoin(uid),
|
|
|
this.bannerData(contentCode)
|
|
|
]).then((result) => {
|
|
|
|
|
|
return {
|
|
|
yohoCoin: result[0],
|
|
|
banner: result[1]
|
|
|
};
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const currencyDetail = (uid, page, limit) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.yohocoin.lists',
|
|
|
uid: uid,
|
|
|
page: page,
|
|
|
limit: limit
|
|
|
}).then((result) => {
|
|
|
let data = [];
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
data = _.get(result, 'data.coinlist', []);
|
|
|
|
|
|
_.forEach(data, (perCoin, key) => {
|
|
|
if (perCoin.num > 0) {
|
|
|
data[key].num = '+' + perCoin.num;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const currencyDetailIndex = (uid, page, limit) => {
|
|
|
return Promise.all(
|
|
|
[currencyDetail(uid, page, limit), _yohoCoin(uid)]
|
|
|
).then(result => {
|
|
|
return {
|
|
|
coinlist: result[0],
|
|
|
yohoCoin: result[1]
|
|
|
};
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
myCurrency,
|
|
|
currencyDetailIndex,
|
|
|
currencyDetail,
|
|
|
bannerData
|
|
|
}; |
|
|
}
|
|
|
|
|
|
currencyDetail(uid, page, limit) {
|
|
|
return api.get('', {
|
|
|
method: 'app.yohocoin.lists',
|
|
|
uid: uid,
|
|
|
page: page,
|
|
|
limit: limit
|
|
|
}).then((result) => {
|
|
|
let data = [];
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
data = _.get(result, 'data.coinlist', []);
|
|
|
|
|
|
_.forEach(data, (perCoin, key) => {
|
|
|
if (perCoin.num > 0) {
|
|
|
data[key].num = '+' + perCoin.num;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
currencyDetailIndex(uid, page, limit) {
|
|
|
return Promise.all([
|
|
|
this.currencyDetail(uid, page, limit),
|
|
|
this._yohoCoin(uid)
|
|
|
]).then(result => {
|
|
|
return {
|
|
|
coinlist: result[0],
|
|
|
yohoCoin: result[1]
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = myCurrencyModel; |
...
|
...
|
|