...
|
...
|
@@ -8,11 +8,8 @@ const co = Promise.coroutine; |
|
|
|
|
|
const path = require('path');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const api = global.yoho.API;
|
|
|
const _ = require('lodash');
|
|
|
const Image = require('../../../utils/images');
|
|
|
const CurrencyData = require('./CurrencyData');
|
|
|
const SearchData = require('./SearchData');
|
|
|
const currencyApi = require('./currency-data');
|
|
|
|
|
|
// 使用 product中的分页逻辑
|
|
|
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
...
|
...
|
@@ -24,109 +21,132 @@ const convertUnitTime = (src) => { |
|
|
return moment.unix(src).format('YYYY-MM-DD');
|
|
|
};
|
|
|
|
|
|
const currencyData = (uid, condition)=>{
|
|
|
return co(function*() {
|
|
|
let result = {};
|
|
|
let yohoCoinInfo = yield CurrencyData.yohoCoinTotal(uid);
|
|
|
console.log(yohoCoinInfo);
|
|
|
if (yohoCoinInfo.code && yohoCoinInfo.code == 200) {
|
|
|
let yohoCoinInfoData = yohoCoinInfo.data;
|
|
|
result.myCurrency = yohoCoinInfoData.yohocoin_num ? yohoCoinInfoData.yohocoin_num : 0;
|
|
|
if (yohoCoinInfoData.nearExpCoinNum && yohoCoinInfoData.nearExpCoinNum > 0) {
|
|
|
result.tip.count = yohoCoinInfoData.nearExpCoinNum;
|
|
|
result.tip.date = 'Y年12月31日';
|
|
|
const currencyTabs = (type)=>{
|
|
|
let tabs = ['全部明细', '全部收入', '全部支出'],
|
|
|
result = [];
|
|
|
|
|
|
tabs.forEach(function(val, key) {
|
|
|
result.push({
|
|
|
active: key === parseInt(type, 10) ? true : false,
|
|
|
url: helpers.urlFormat('/home/currency', {type: key}),
|
|
|
name: val
|
|
|
});
|
|
|
});
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
const currencyOptions = (condition)=>{
|
|
|
let result = [], paramUrl = {};
|
|
|
let tabs = {90: '最近3个月明细', 180: '最近半年明细', 360: '最近一年明细'};
|
|
|
|
|
|
for (let name in tabs) {
|
|
|
if (condition.queryType) {
|
|
|
paramUrl.type = condition.queryType;
|
|
|
}
|
|
|
paramUrl.beginTime = convertUnitTime(new Date() / 1000 - parseInt(name, 10) * 3600 * 24);
|
|
|
|
|
|
result.push({
|
|
|
url: helpers.urlFormat('/home/currency', paramUrl),
|
|
|
name: tabs[name],
|
|
|
selected: condition.beginTime && paramUrl.beginTime === condition.beginTime ? true : false
|
|
|
});
|
|
|
}
|
|
|
let currency = yield currencyList(uid, condition);
|
|
|
result.currency = currency.list;
|
|
|
result.pager = currency.pager;
|
|
|
result.coinHelperUrl = '//www.yohobuy.com/help/detail?id=105';// yoho币帮助
|
|
|
result.tabs = currencyTabs(condition.queryType);
|
|
|
result.options = currencyOptions(condition);
|
|
|
return result;
|
|
|
})();
|
|
|
|
|
|
};
|
|
|
|
|
|
const currencyList = (uid, condition)=>{
|
|
|
return co(function*() {
|
|
|
let result = {'list': [], 'pager': []};
|
|
|
let result = {list: [], pager: []};
|
|
|
|
|
|
condition.limit = condition.limit || 15;
|
|
|
|
|
|
let data = yield CurrencyData.yohoCoinList(uid, condition);
|
|
|
let data = yield currencyApi.yohoCoinList(uid, condition);
|
|
|
|
|
|
if (_.get(data, 'code') === 200 && data.data.coinlist && !_.isEmpty(data.data.coinlist)) {
|
|
|
|
|
|
if (data.code && data.code == 200 && data.data.coinlist && !_.isEmpty(data.data.coinlist)) {
|
|
|
// data.data.coinlist.forEach(function(val,key){
|
|
|
for (let key = 0; key < data.data.coinlist.length; key++) {
|
|
|
let val = data.data.coinlist[key];
|
|
|
|
|
|
result.list[key] = {
|
|
|
date: val['date'],
|
|
|
desc: val['message'],
|
|
|
date: val.date,
|
|
|
desc: val.message,
|
|
|
isIncome: true
|
|
|
};
|
|
|
|
|
|
// 2:订单取消退还,9:下单使用,10:退货退还
|
|
|
if ([2, 9, 10].indexOf(val.type) > -1 && val.key) {
|
|
|
result.list[key].detailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: val['key']});
|
|
|
}
|
|
|
result.list[key].detailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: val.key});
|
|
|
} else if (Number(val.type) === 14 && val.key) { // 晒单奖励
|
|
|
let product = yield currencyApi.getProduct(Number(val.key), 1);
|
|
|
|
|
|
// 晒单奖励
|
|
|
else if (val.type == 14 && val.key) {
|
|
|
let product = yield SearchData.searchAll({query: Number(val.key), viewNum: 1});
|
|
|
if (product.code && product.code == 200 && !_.isEmpty(product.data.product_list) && !_.isEmpty(product.data.product_list[0].goods_list)) {
|
|
|
productId = product.data.product_list[0].product_id;
|
|
|
goodsId = product.data.product_list[0].goods_list[0].goods_id;
|
|
|
result.list[key].detailUrl = helpers.getUrlBySkc(productId, goodsId, product.data.product_list[0].cn_alphabet);
|
|
|
if (_.get(product, 'code') === 200 &&
|
|
|
!_.isEmpty(product.data.product_list) &&
|
|
|
!_.isEmpty(product.data.product_list[0].goods_list)) {
|
|
|
let productId = _.get(product, 'data.product_list[0].product_id');
|
|
|
let goodsId = _.get(product, 'data.product_list[0].goods_list[0].goods_id');
|
|
|
let alphabet = _.get(product, 'data.product_list[0].cn_alphabet');
|
|
|
|
|
|
result.list[key].detailUrl = helpers.getUrlBySkc(productId, goodsId, alphabet);
|
|
|
}
|
|
|
}
|
|
|
if (Number(val['num']) < 0) {
|
|
|
if (Number(val.num) < 0) {
|
|
|
result.list[key].isIncome = false;
|
|
|
}
|
|
|
result.list[key].value = val['num'] > 0 ? '+' + val['num'] : val['num'];
|
|
|
result.list[key].value = val.num > 0 ? '+' + val.num : val.num;
|
|
|
}
|
|
|
|
|
|
// 分页
|
|
|
let total = data.data.total;
|
|
|
let pagerObj = pager(total, {
|
|
|
page: data['data']['page'],
|
|
|
limit: condition['limit']
|
|
|
});
|
|
|
result.pager = Object.assign({
|
|
|
count: data.data.total,
|
|
|
curPage: data.data.page,
|
|
|
totalPages: Math.ceil(data.data.total / condition.limit)
|
|
|
}, pager(data.data.total, {
|
|
|
page: condition.page,
|
|
|
limit: condition.limit,
|
|
|
type: condition.queryType,
|
|
|
beginTime: condition.beginTime
|
|
|
}));
|
|
|
|
|
|
// result['pager']={};
|
|
|
// result['pager']['hasCheckAll'] = false;
|
|
|
// result['pager']['count'] = data['data']['total'];
|
|
|
// result['pager']['curPage'] = data['data']['page'];
|
|
|
// result['pager']['totalPages'] = Math.ceil(data['data']['total'] / condition['limit']);
|
|
|
// result['pager']['pagerHtml'] = HelperSearch::pager(data['data']['total'], condition['limit']);
|
|
|
}
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
const currencyTabs = (type)=>{
|
|
|
let result = ['全部明细', '全部收入', '全部支出'];
|
|
|
result = result.forEach(function(val, key) {
|
|
|
return {
|
|
|
active: key == type ? true : false,
|
|
|
url: helpers.urlFormat('/home/currency', {type: key})
|
|
|
|
|
|
const currencyData = (uid, prama)=>{
|
|
|
let condition = {
|
|
|
page: prama.page || 1,
|
|
|
queryType: prama.type || 0,
|
|
|
beginTime: prama.beginTime || convertUnitTime(new Date() / 1000 - 3600 * 24 * 90)
|
|
|
};
|
|
|
|
|
|
return co(function*() {
|
|
|
let result = {};
|
|
|
let yohoCoinInfo = yield currencyApi.yohoCoinTotal(uid);
|
|
|
|
|
|
if (_.get(yohoCoinInfo, 'code') === 200) {
|
|
|
let yohoCoinInfoData = yohoCoinInfo.data;
|
|
|
|
|
|
result.myCurrency = yohoCoinInfoData.yohocoin_num ? yohoCoinInfoData.yohocoin_num : 0;
|
|
|
if (_.get(yohoCoinInfoData, 'nearExpCoinNum') > 0) {
|
|
|
result.tip = {
|
|
|
count: yohoCoinInfoData.nearExpCoinNum,
|
|
|
date: new Date().getFullYear() + '年12月31日'
|
|
|
};
|
|
|
});
|
|
|
return result;
|
|
|
};
|
|
|
const currencyOptions = (condition)=>{
|
|
|
let result = [], paramUrl = {};
|
|
|
let tabs = {'90': '最近3个月明细', '180': '最近半年明细', '360': '最近一年明细'};
|
|
|
for (let name in tabs) {
|
|
|
if (condition.queryType) {
|
|
|
paramUrl.type = condition.queryType;
|
|
|
}
|
|
|
paramUrl.beginTime = convertUnitTime(new Date() / 1000 - 3600 * 24);
|
|
|
result.push({
|
|
|
url: helpers.urlFormat('/home/currency', paramUrl),
|
|
|
name: tabs[name],
|
|
|
selected: condition.beginTime && paramUrl.beginTime == condition.beginTime ? true : false
|
|
|
});
|
|
|
}
|
|
|
let currency = yield currencyList(uid, condition);
|
|
|
|
|
|
Object.assign(result, {
|
|
|
currency: currency.list,
|
|
|
pager: currency.pager,
|
|
|
coinHelperUrl: '//www.yohobuy.com/help/detail?id=105', // yoho币帮助
|
|
|
tabs: currencyTabs(condition.queryType),
|
|
|
options: currencyOptions(condition)
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
})();
|
|
|
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
...
|
...
|
|