Authored by 郝肖肖

Merge branch 'master' into feature/giftCart

Too many changes to show.

To preserve performance only 12 of 12+ files are displayed.

... ... @@ -138,7 +138,8 @@ const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, p
invoices_title: other.invoicesTitle,
invoice_content: other.invoicesContent,
receiverMobile: other.receiverMobile,
buyerTaxNumber: other.taxNumber
buyerTaxNumber: other.taxNumber,
invoice_payable_type: other.taxNumber ? 2 : 1
});
}
... ...
... ... @@ -6,8 +6,7 @@
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const favoriteService = require('../models/favorite-service');
const favoriteModel = require('../models/favorite-model');
const TABS = {
product: 'product',
... ... @@ -24,6 +23,7 @@ const index = (req, res, next)=> {
let reduction = req.query.is_reduction || 'N';
let promotion = req.query.is_promotion || 'N';
let limit = +req.query.limit || 10;
let favoriteService = req.ctx(favoriteModel);
co(function*() {
let data = {};
... ... @@ -58,6 +58,7 @@ const newProduct = (req, res, next) => {
let page = +req.query.page || 1;
let limit = +req.query.limit || 10;
let id = +req.query.id || 0;
let favoriteService = req.ctx(favoriteModel);
if (!id) {
return res.json({
... ... @@ -79,6 +80,8 @@ const reduction = (req, res, next) => {
let page = +req.query.page || 1;
let type = req.query.type || '';
let limit = 10;
let favoriteService = req.ctx(favoriteModel);
favoriteService.reductionAsync(uid, page, limit, type, 0, 'Y').then((result) => {
return res.render('home/favorite/reduction', result);
... ... @@ -89,6 +92,7 @@ const notice = (req, res, next) => {
let uid = req.user.uid;
let id = req.query.id;
let mobile = req.query.mobile;
let favoriteService = req.ctx(favoriteModel);
favoriteService.enableNoticeAsync(uid, mobile, id).then((result) => {
return res.json(result);
... ... @@ -98,6 +102,7 @@ const notice = (req, res, next) => {
const cancelNotice = (req, res, next) => {
let uid = req.user.uid;
let id = req.query.id;
let favoriteService = req.ctx(favoriteModel);
favoriteService.disableNoticeAsync(uid, id).then((result) => {
return res.json(result);
... ... @@ -109,6 +114,7 @@ const cancel = (req, res, next) => {
let id = req.query.id;
let type = req.query.type || 'product';
let group = req.query.group || {};
let favoriteService = req.ctx(favoriteModel);
if (!uid || !id) {
return res.json({
... ...
... ... @@ -8,7 +8,7 @@ const index = (req, res, next)=>{
let channel = req.yoho.channel;
let isStudent = req.user.isStudent;
indexService.index(uid, udid, channel, isStudent).then((result) => {
req.ctx(indexService).index(uid, udid, channel, isStudent).then(result => {
return res.render('index', {
module: 'home',
page: 'index',
... ...
... ... @@ -4,12 +4,13 @@ const _ = require('lodash');
const ordersService = require('../models/orders-service');
const index = (req, res, next) => {
let ordersModel = req.ctx(ordersService);
let uid = req.user.uid;
let page = _.parseInt(req.query.page) || 1;
let type = _.parseInt(req.query.type) || ordersService.ORDER_TYPE.all;
let type = _.parseInt(req.query.type) || ordersModel.ORDER_TYPE.all;
let limit = _.parseInt(req.query.limit) || 10;
ordersService.index(uid, page, limit, type).then((result) => {
ordersModel.index(uid, page, limit, type).then((result) => {
return res.render('home/orders/orders', {
meOrdersPage: true,
meOrders: result
... ... @@ -28,7 +29,7 @@ const reBuy = (req, res, next) => {
});
}
ordersService.reBuy(uid, orderId).then((result) => {
req.ctx(ordersService).reBuy(uid, orderId).then((result) => {
return res.json(result);
}).catch(next);
};
... ... @@ -46,7 +47,7 @@ const del = (req, res, next) => {
});
}
ordersService.del(uid, gender, channel, orderId).then((result) => {
req.ctx(ordersService).del(uid, gender, channel, orderId).then((result) => {
return res.json(result);
}).catch(next);
};
... ... @@ -80,7 +81,7 @@ const modifyAddress = (req, res, next) => {
});
}
ordersService.updateDeliveryAddress(orderId, userName, areaCode, address, mobile, phone, uid, udid)
req.ctx(ordersService).updateDeliveryAddress(orderId, userName, areaCode, address, mobile, phone, uid, udid)
.then(result => res.json(result))
.catch(next);
};
... ... @@ -96,7 +97,7 @@ const confirm = (req, res, next) => {
});
}
ordersService.confirm(uid, orderId).then((result) => {
req.ctx(ordersService).confirm(uid, orderId).then((result) => {
return res.json(result);
}).catch(next);
};
... ... @@ -107,7 +108,7 @@ const cancel = (req, res, next) => {
let reason = req.body.reason || '';
let reasonId = req.body.reasonId || '';
ordersService.cancel(uid, orderId, reason, reasonId)
req.ctx(ordersService).cancel(uid, orderId, reason, reasonId)
.then(result => res.json(result))
.catch(next);
};
... ... @@ -120,7 +121,7 @@ const detail = (req, res, next) => {
return res.redirect('/home');
}
ordersService.detail(uid, orderId).then((result) => {
req.ctx(ordersService).detail(uid, orderId).then((result) => {
if (_.isEmpty(result)) {
return res.redirect('/home');
}
... ... @@ -147,7 +148,7 @@ const express = (req, res, next) => {
});
}
ordersService.express(orderId, uid, payType, time).then((result) => {
req.ctx(ordersService).express(orderId, uid, payType, time).then((result) => {
return res.json(result);
}).catch(next);
};
... ... @@ -164,13 +165,13 @@ const refund = (req, res, next) => {
});
}
ordersService.refund(uid, orderId, reasonId).then((result) => {
req.ctx(ordersService).refund(uid, orderId, reasonId).then((result) => {
return res.json(result);
}).catch(next);
};
const refundReason = (req, res, next) => {
ordersService.refundReason().then((result) => {
req.ctx(ordersService).refundReason().then((result) => {
return res.json({
code: 200,
data: result
... ...
... ... @@ -12,7 +12,7 @@ const returnsModel = require('../models/returns');
const index = (req, res, next) => {
const page = req.query.page;
returnsModel.getReturnsList(req.user.uid, page, 10)
req.ctx(returnsModel).getReturnsList(req.user.uid, page, 10)
.then(data => {
const viewData = Object.assign({
module: 'home',
... ... @@ -32,7 +32,7 @@ const refundApply = (req, res, next) => {
const orderCode = req.query.orderCode;
const uid = req.user.uid;
returnsModel.getOrderRefund(orderCode, uid).then(result => {
req.ctx(returnsModel).getOrderRefund(orderCode, uid).then(result => {
res.render('returns/returns-apply', result);
}).catch(next);
};
... ... @@ -43,7 +43,7 @@ const refundApply = (req, res, next) => {
const saveRefund = (req, res, next) => {
const uid = req.user.uid;
returnsModel.saveRefund(req, uid).then(result => {
req.ctx(returnsModel).saveRefund(req, uid).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -95,7 +95,7 @@ const refundDetail = (req, res, next) => {
page: 'returns'
};
returnsModel.getRefundDetail(code, uid).then(result => {
req.ctx(returnsModel).getRefundDetail(code, uid).then(result => {
Object.assign(resData, result);
res.render('returns/returns-detail', resData);
}).catch(next);
... ... @@ -108,7 +108,7 @@ const saveExchange = (req, res, next) => {
let uid = req.user.uid;
returnsModel.saveExchange(req, uid).then(result => {
req.ctx(returnsModel).saveExchange(req, uid).then(result => {
res.send(result);
}).catch(next);
... ... @@ -125,7 +125,7 @@ const exchangeDetail = (req, res, next) => {
page: 'returns'
};
returnsModel.getChangeDetail(code, uid).then(result => {
req.ctx(returnsModel).getChangeDetail(code, uid).then(result => {
Object.assign(resData, result);
res.render('returns/returns-detail', resData);
}).catch(next);
... ... @@ -144,7 +144,7 @@ const getDelivery = (req, res, next) => {
let channel = req.yoho.channel;
// 调用接口获得该用户支持的换货方式(白金会员可享受上门换货,偏远地区不支持上门换货)
returnsModel.getDelivery(areaCode, uid, gender, channel).then(result => {
req.ctx(returnsModel).getDelivery(areaCode, uid, gender, channel).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -156,7 +156,7 @@ const exchangeApply = (req, res, next) => {
const orderCode = req.query.orderCode;
const uid = req.user.uid;
returnsModel.getOrderExchange(orderCode, uid).then(result => {
req.ctx(returnsModel).getOrderExchange(orderCode, uid).then(result => {
res.render('returns/returns-apply', result);
}).catch(next);
};
... ... @@ -168,7 +168,7 @@ const cancelRefund = (req, res, next) => {
let id = req.body.id;
let uid = req.user.uid;
returnsModel.getCancelRefund(id, uid).then(result => {
req.ctx(returnsModel).getCancelRefund(id, uid).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -180,7 +180,7 @@ const cancelChange = (req, res, next) => {
let id = req.body.id;
let uid = req.user.uid;
returnsModel.getCancelChange(id, uid).then(result => {
req.ctx(returnsModel).getCancelChange(id, uid).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -197,7 +197,7 @@ const setExpressNumber = (req, res, next) => {
let expressNumber = req.body.expressNumber;
let expressCompany = req.body.expressCompany;
returnsModel.setExpressNumber(id, expressId, expressNumber, uid, expressCompany, isChange).then(result => {
req.ctx(returnsModel).setExpressNumber(id, expressId, expressNumber, uid, expressCompany, isChange).then(result => {
if (res.code && res.code === 201) {
res.json({message: '请求失败'});
... ... @@ -216,7 +216,7 @@ const refundCompute = (req, res, next) => {
let orderCode = req.body.orderCode;
let goods = req.body.goods;
returnsModel.refundCompute(uid, orderCode, goods).then(d => {
req.ctx(returnsModel).refundCompute(uid, orderCode, goods).then(d => {
res.json(d);
}).catch(next);
};
... ...
'use strict';
const api = global.yoho.API;
const service = global.yoho.ServiceAPI;
const _ = require('lodash');
// const URL_PRODUCT_FAVORITE = 'shops/service/v1/favorite/';
const URL_ARTICLE_FAVORITE = '/guang/api/v1/favorite/';
// const URL_ARTICLE_FAVORITE_BRAND = '/guang/service/v2/favorite/toggleBrand';
/**
* 根据uid和商品的id查询是否被用户收藏
* @param int $uid
* @param int $productId
* @return boolean 收藏 true 未收藏 false
*/
const getUidProductFav = (uid, productId)=> {
let options = {
method: 'web.favorite.isFavorite',
id: productId,
uid: uid,
type: 'product'
};
return api.get('', options);
};
const favoriteArticleData = (uid, udid, page, limit)=> {
let options = {
uid: uid,
udid: udid,
page: page,
limit: limit
};
return service.get(URL_ARTICLE_FAVORITE + 'getUserFavArticleList', options);
};
const cancelArticle = (uid, id) => {
return service.get(URL_ARTICLE_FAVORITE + 'cancelFavorite', {
uid: uid,
article_id: id
});
};
const getFavoriteProductList = (uid, page, limit)=> {
let options = {
method: 'web.favorite.product',
uid: uid,
page: 0,
limit: limit || 10
};
return api.get('', options);
};
const redutionCount = (uid)=> {
return api.get('', {
method: 'web.redution.count',
uid: uid
});
};
const favoriteBrandData = (uid, page, limit) => {
return api.get('', {
method: 'app.favorite.brand',
uid: uid,
page: page || 1,
limit: limit || 10
});
};
const redutionAdd = (uid, mobile, pid) => {
return api.get('', {
method: 'web.redution.add',
uid: uid,
mobile: mobile,
productId: pid
});
};
const redutionCancel = (uid, pid) => {
return api.get('', {
method: 'web.redution.cancel',
uid: uid,
productIds: pid
});
};
const _cancel = (type, uid, ids) => {
return api.get('', {
method: 'web.favorite.cancel',
favIds: ids,
uid: uid,
type: type
});
};
module.exports = {
getUidProductFav,
getFavoriteProductList,
favoriteArticleData,
favoriteBrandData,
redutionCount,
redutionAdd,
redutionCancel,
cancel: {
product: _.partial(_cancel, 'product', _, _),
shop: _.partial(_cancel, 'shop', _, _),
brand: _.partial(_cancel, 'brand', _, _),
article: cancelArticle
}
};
... ... @@ -4,9 +4,8 @@ const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const pager = require('./pager').handlePagerData;
const favoriteApi = require('./favorite-api');
const URL_ARTICLE_FAVORITE = '/guang/api/v1/favorite/';
const TABS = [
{type: 'product', name: '商品收藏'},
... ... @@ -14,384 +13,501 @@ const TABS = [
{type: 'article', name: '文章收藏'}
];
const getFavoriteTabs = (type) => {
type = type || 'product';
module.exports = class favorite extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return TABS.map((item) => {
item.active = item.type === type;
item.url = helpers.urlFormat('/home/favorite', {type: item.type});
return item;
});
};
const _getSortInfo = (categoryList, sort)=> {
if (_.isEmpty(categoryList)) {
return false;
getFavoriteTabs(type) {
type = type || 'product';
return TABS.map((item) => {
item.active = item.type === type;
item.url = helpers.urlFormat('/home/favorite', {type: item.type});
return item;
});
}
let result = {};
_getSortInfo(categoryList, sort) {
if (_.isEmpty(categoryList)) {
return false;
}
result.all = categoryList.map((category) => {
return {
name: category.category_name,
url: helpers.urlFormat('/home/favorite', {sort_id: category.category_id}),
count: category.num,
focus: category.category_id === sort
};
});
let defaultCategory = {
name: '全部',
url: helpers.urlFormat('/home/favorite'),
count: _.sumBy(categoryList, category => category.num),
focus: sort === 0
};
result.all.unshift(defaultCategory);
result.default = result.all.slice(0, 7);
return result;
};
let result = {};
const getGoodsInfo = (data, page, limit)=> {
let result = data.slice((page - 1) * limit, page * limit).map((item) => {
return {
skn: item.product_id,
img: helpers.image(item.image, 100, 100),
name: item.product_name,
url: helpers.getUrlBySkc(item.product_skn),
price: item.sales_price,
priceDown: item.price_down,
buyNow: helpers.getUrlBySkc(item.product_skn),
soldOut: item.storage === 0 ? true : '',
hadNoticed: item.is_subscribe_reduction === 'Y' ? true : '',
activites: {
count: item.promotion_list ? item.promotion_list.length : 0,
list: _.get(item, 'promotion_list', []).map((val) => {
return {
type: val.promotion_type,
name: val.promotion_title
};
})
}
};
});
result.all = categoryList.map((category) => {
return {
name: category.category_name,
url: helpers.urlFormat('/home/favorite', {sort_id: category.category_id}),
count: category.num,
focus: category.category_id === sort
};
});
if (_.isEmpty(result)) {
return {
empty: '您没有收藏商品'
let defaultCategory = {
name: '全部',
url: helpers.urlFormat('/home/favorite'),
count: _.sumBy(categoryList, category => category.num),
focus: sort === 0
};
}
return result;
};
result.all.unshift(defaultCategory);
result.default = result.all.slice(0, 7);
return result;
}
/**
* 降价提醒
*/
const _redutionCount = (uid)=> {
return co(function*() {
let data = yield favoriteApi.redutionCount(uid);
let result = {
count: 0,
phone: '',
url: '/home/favorite/reduction'
};
getGoodsInfo(data, page, limit) {
let result = data.slice((page - 1) * limit, page * limit).map((item) => {
return {
skn: item.product_id,
img: helpers.image(item.image, 100, 100),
name: item.product_name,
url: helpers.getUrlBySkc(item.product_skn),
price: item.sales_price,
priceDown: item.price_down,
buyNow: helpers.getUrlBySkc(item.product_skn),
soldOut: item.storage === 0 ? true : '',
hadNoticed: item.is_subscribe_reduction === 'Y' ? true : '',
activites: {
count: item.promotion_list ? item.promotion_list.length : 0,
list: _.get(item, 'promotion_list', []).map((val) => {
return {
type: val.promotion_type,
name: val.promotion_title
};
})
}
};
});
if (data.data.num) {
result.count = +data.data.num;
result.phone = data.data.mobile;
if (_.isEmpty(result)) {
return {
empty: '您没有收藏商品'
};
}
return result;
})();
};
}
/**
* 降价提醒
*/
_redutionCount(uid) {
let that = this;
return co(function*() {
let data = yield that.redutionCount(uid);
let result = {
count: 0,
phone: '',
url: '/home/favorite/reduction'
};
const favoriteProductListAsync = (uid, page, limit, selectedSort, subscribe, reduction, promotion, query) => {
return co(function*() {
let result = {
sort: {},
reduction: {},
filter: {},
goods: {},
pager: {}
};
if (data.data.num) {
result.count = +data.data.num;
result.phone = data.data.mobile;
}
return result;
})();
}
favoriteProductListAsync(uid, page, limit, selectedSort, subscribe, reduction, promotion, query) {
let that = this;
let product = yield favoriteApi.getFavoriteProductList(uid, 1, 500);
result.sort = _getSortInfo(_.get(product, 'data.category_list'), selectedSort);
result.reduction = yield _redutionCount(uid);
let productList = (function() {
let products = _.get(product, 'data.product_list', []);
if (reduction === 'Y' && promotion === 'Y') {
// 参加活动的降价商品
return products.filter(pro => pro.is_price_down === 'Y' && pro.is_join_promotion === 'Y');
} else if (selectedSort) {
// 商品分类过滤
return products.filter(pro => pro.category_id === selectedSort);
} else if (subscribe === 'Y') {
// 订阅降价通知过滤
return products.filter(pro => pro.is_subscribe_reduction === 'Y');
} else if (reduction === 'Y') {
// 降价商品过滤
return products.filter(pro => pro.is_price_down === 'Y');
} else if (promotion === 'Y') {
// 参加活动商品过滤
return products.filter(pro => pro.is_join_promotion === 'Y');
} else {
return products;
return co(function*() {
let result = {
sort: {},
reduction: {},
filter: {},
goods: {},
pager: {}
};
let product = yield that.getFavoriteProductList(uid, 1, 500);
result.sort = that._getSortInfo(_.get(product, 'data.category_list'), selectedSort);
result.reduction = yield that._redutionCount(uid);
let productList = (function() {
let products = _.get(product, 'data.product_list', []);
if (reduction === 'Y' && promotion === 'Y') {
// 参加活动的降价商品
return products.filter(pro => pro.is_price_down === 'Y' && pro.is_join_promotion === 'Y');
} else if (selectedSort) {
// 商品分类过滤
return products.filter(pro => pro.category_id === selectedSort);
} else if (subscribe === 'Y') {
// 订阅降价通知过滤
return products.filter(pro => pro.is_subscribe_reduction === 'Y');
} else if (reduction === 'Y') {
// 降价商品过滤
return products.filter(pro => pro.is_price_down === 'Y');
} else if (promotion === 'Y') {
// 参加活动商品过滤
return products.filter(pro => pro.is_join_promotion === 'Y');
} else {
return products;
}
}());
result.filter = (function() {
if (reduction === 'N' && promotion === 'N') {
return {
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y'}),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
activityChecked: ''
};
} else if (reduction === 'N' && promotion === 'Y') {
return {
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite'),
activityChecked: ''
};
} else if (reduction === 'Y' && promotion === 'N') {
return {
reductionUrl: helpers.urlFormat('/home/favorite'),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
activityChecked: ''
};
} else {
return {
reductionUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y'}),
activityChecked: ''
};
}
}());
let total = productList.length;
let pageTotal = Math.ceil(total / limit);
page = page > pageTotal ? pageTotal : page;
result.goods = that.getGoodsInfo(productList, page, limit);
result.pager = pager(total, Object.assign(query, {hasCheckAll: true}));
return result;
})();
}
favoriteBrandListAsync(uid, page, limit, type) {
let that = this;
return co(function*() {
let result = {
brands: {
empty: '您没有收藏品牌',
pager: {}
}
};
let brand = yield that.favoriteBrandData(uid, page, limit);
if (!brand.data || !brand.data.page_total) {
return result;
}
}());
result.filter = (function() {
if (reduction === 'N' && promotion === 'N') {
return {
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y'}),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
activityChecked: ''
};
} else if (reduction === 'N' && promotion === 'Y') {
return {
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite'),
activityChecked: ''
};
} else if (reduction === 'Y' && promotion === 'N') {
return {
reductionUrl: helpers.urlFormat('/home/favorite'),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
activityChecked: ''
};
} else {
if (!brand.data.brand_list) {
return result;
}
result.brands = _.get(brand, 'data.brand_list', []).map((item) => {
return {
reductionUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
reductionChecked: '',
activityUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y'}),
activityChecked: ''
id: item.brand_id,
brandOrShopType: item.brandOrShopType || '',
shop_id: item.shop_id || '',
img: helpers.image(item.brand_ico, 100, 100),
url: helpers.urlFormat('', {shopId: item.shop_id || ''}, item.brand_domain),
name: item.brand_name,
naCount: item.new_product_num,
colCount: item.brand_favorite_num
};
}
}());
});
let total = productList.length;
let pageTotal = Math.ceil(total / limit);
let total = brand.data.total || 0;
page = page > pageTotal ? pageTotal : page;
page = brand.data.page || 0;
result.pager = pager(total, {page, limit, type, hasCheckAll: true});
return result;
})();
}
result.goods = getGoodsInfo(productList, page, limit);
result.pager = pager(total, Object.assign(query, {hasCheckAll: true}));
favoriteArticleListAsync(uid, udid, page, limit, type) {
let that = this;
return result;
})();
};
return co(function*() {
let result = {};
const favoriteBrandListAsync = (uid, page, limit, type)=> {
return co(function*() {
let result = {
brands: {
empty: '您没有收藏品牌',
pager: {}
let articles = yield that.favoriteArticleData(uid, udid, page, limit);
result.articles = _.get(articles, 'data.data', []).map((item) => {
return {
id: item.id,
name: item.title,
img: helpers.image(item.src, 146, 96),
desc: item.intro,
url: helpers.urlFormat(`/guang/${item.id}.html`, null)
};
});
let total = articles.data.total || 0;
result.pager = pager(total, {page, limit, type, hasCheckAll: true});
if (_.isEmpty(result.articles)) {
result.articles = {
empty: '你尚未收藏任何文章!'
};
}
};
let brand = yield favoriteApi.favoriteBrandData(uid, page, limit);
if (!brand.data || !brand.data.page_total) {
return result;
}
})();
}
if (!brand.data.brand_list) {
return result;
}
newProductAsync(uid, page, limit, id) {
let that = this;
result.brands = _.get(brand, 'data.brand_list', []).map((item) => {
return {
id: item.brand_id,
brandOrShopType: item.brandOrShopType || '',
shop_id: item.shop_id || '',
img: helpers.image(item.brand_ico, 100, 100),
url: helpers.urlFormat('', {shopId: item.shop_id || ''}, item.brand_domain),
name: item.brand_name,
naCount: item.new_product_num,
colCount: item.brand_favorite_num
};
});
return co(function * () {
let products = yield that.favoriteBrandData(uid, page, limit);
let total = brand.data.total || 0;
return _.get(products, 'data.brand_list', []).reduce((total, cur) => {
if (id !== cur.brand_id) {
return total;
}
page = brand.data.page || 0;
result.pager = pager(total, {page, limit, type, hasCheckAll: true});
return result;
})();
};
if (cur.new_product_num === 0) {
return total;
}
const favoriteArticleListAsync = (uid, udid, page, limit, type)=> {
return co(function*() {
let result = {};
total = _.concat(total, _.take(_.get(cur, 'new_product', []), 20).map((pro) => {
return {
img: pro.default_images,
url: helpers.getUrlBySkc(pro.product_skn),
name: pro.product_name,
salePrice: pro.sales_price === pro.market_price ? '' : pro.sales_price,
marketPrice: pro.market_price
};
}));
return total;
}, []);
})();
}
let articles = yield favoriteApi.favoriteArticleData(uid, udid, page, limit);
reductionAsync(uid, page, limit) {
let result = {};
result.articles = _.get(articles, 'data.data', []).map((item) => {
result.tabs = this.getFavoriteTabs('product');
return this.favoriteProductListAsync(uid, page, limit, 0, 'Y').then((products) => {
result.goods = products.goods;
result.reductionUrl = helpers.urlFormat('/home/fovorite');
return {
id: item.id,
name: item.title,
img: helpers.image(item.src, 146, 96),
desc: item.intro,
url: helpers.urlFormat(`/guang/${item.id}.html`, null)
meFavoritePage: true,
meFavorite: result
};
});
let total = articles.data.total || 0;
}
result.pager = pager(total, {page, limit, type, hasCheckAll: true});
enableNoticeAsync(uid, mobile, id) {
let that = this;
if (_.isEmpty(result.articles)) {
result.articles = {
empty: '你尚未收藏任何文章!'
return co(function *() {
let result = {
code: 400,
message: '订阅失败'
};
}
return result;
})();
};
if (!uid || !mobile || !id) {
return result;
}
const newProductAsync = (uid, page, limit, id) => {
return co(function * () {
let products = yield favoriteApi.favoriteBrandData(uid, page, limit);
let data = yield that.redutionAdd(uid, mobile, id);
return _.get(products, 'data.brand_list', []).reduce((total, cur) => {
if (id !== cur.brand_id) {
return total;
if (data.code === 200) {
result.code = 200;
return data;
}
if (cur.new_product_num === 0) {
return total;
if (data.code === 500) {
result.code = 500;
switch (data.message) {
case 'count must be lt 5':
result.message = '您的订阅数已经到达上限';
break;
case 'mobile must bu not null':
result.message = '请填写手机号';
break;
default:
result.message = '订阅失败';
break;
}
}
total = _.concat(total, _.take(_.get(cur, 'new_product', []), 20).map((pro) => {
return result;
})();
}
disableNoticeAsync(uid, id) {
let that = this;
return co(function * () {
if (!uid || !id) {
return {
img: pro.default_images,
url: helpers.getUrlBySkc(pro.product_skn),
name: pro.product_name,
salePrice: pro.sales_price === pro.market_price ? '' : pro.sales_price,
marketPrice: pro.market_price
code: 400,
message: '取消失败'
};
}));
}
return total;
}, []);
})();
};
return yield that.redutionCancel(uid, id);
})();
}
const reductionAsync = (uid, page, limit) =>{
let result = {};
/**
* ids 是 group,品牌删除
*/
cancelBrandAsync(uid, ids, group) {
let that = this;
result.tabs = getFavoriteTabs('product');
return favoriteProductListAsync(uid, page, limit, 0, 'Y').then((products) => {
result.goods = products.goods;
result.reductionUrl = helpers.urlFormat('/home/fovorite');
return {
meFavoritePage: true,
meFavorite: result
};
});
return co(function *() {
let result;
};
if (group.bid) {
result = yield that._cancel('brand', uid, group.bid);
}
const enableNoticeAsync = (uid, mobile, id) => {
return co(function *() {
let result = {
code: 400,
message: '订阅失败'
};
if (group.sid) {
result = yield that._cancel('shop', uid, group.sid);
}
if (!group) {
result = yield that._cancel('brand', uid, ids);
}
console.log(result);
if (!uid || !mobile || !id) {
return result;
})();
}
/**
* ids 可能是 group
*/
cancelAsync(uid, ids, group, type) {
if (type === 'brand') {
return this.cancelBrandAsync(uid, ids, group);
} else if (type === 'article') {
return this.cancelArticle(uid, ids);
}
let data = yield favoriteApi.redutionAdd(uid, mobile, id);
return this._cancel(type, uid, ids);
}
if (data.code === 200) {
result.code = 200;
return data;
}
if (data.code === 500) {
result.code = 500;
switch (data.message) {
case 'count must be lt 5':
result.message = '您的订阅数已经到达上限';
break;
case 'mobile must bu not null':
result.message = '请填写手机号';
break;
default:
result.message = '订阅失败';
break;
}
}
return result;
})();
};
/** ***data api below*****/
const disableNoticeAsync = (uid, id) => {
return co(function * () {
if (!uid || !id) {
return {
code: 400,
message: '取消失败'
};
}
/**
* 根据uid和商品的id查询是否被用户收藏
* @param int $uid
* @param int $productId
* @return boolean 收藏 true 未收藏 false
*/
getUidProductFav(uid, productId) {
let data = {
method: 'web.favorite.isFavorite',
id: productId,
uid: uid,
type: 'product'
};
return yield favoriteApi.redutionCancel(uid, id);
})();
};
return this.get({data: data});
}
/**
* ids 是 group,品牌删除
*/
const cancelBrandAsync = co(function * (uid, ids, group) {
favoriteBrandData(uid, page, limit) {
return this.get({data: {
method: 'app.favorite.brand',
uid: uid,
page: page || 1,
limit: limit || 10
}});
}
let result;
getFavoriteProductList(uid, page, limit) {
let data = {
method: 'web.favorite.product',
uid: uid,
page: 0,
limit: limit || 10
};
if (group.bid) {
result = yield favoriteApi.cancel.brand(uid, group.bid);
return this.get({data: data});
}
if (group.sid) {
result = yield favoriteApi.cancel.shop(uid, group.sid);
redutionAdd(uid, mobile, pid) {
return this.get({data: {
method: 'web.redution.add',
uid: uid,
mobile: mobile,
productId: pid
}});
}
if (!group) {
result = yield favoriteApi.cancel.brand(uid, ids);
redutionCount(uid) {
return this.get({data: {
method: 'web.redution.count',
uid: uid
}});
}
return result;
});
_cancel(type, uid, ids) {
return this.get({data: {
method: 'web.favorite.cancel',
favIds: ids,
uid: uid,
type: type
}});
}
/**
* ids 可能是 group
*/
const cancelAsync = (uid, ids, group, type) => {
if (type === 'brand') {
return cancelBrandAsync(uid, ids, group);
redutionCancel(uid, pid) {
return this.get({data: {
method: 'web.redution.cancel',
uid: uid,
productIds: pid
}});
}
return favoriteApi.cancel[type](uid, ids);
};
favoriteArticleData(uid, udid, page, limit) {
let data = {
uid: uid,
udid: udid,
page: page,
limit: limit
};
return this.get({
url: URL_ARTICLE_FAVORITE + 'getUserFavArticleList',
data: data,
api: global.yoho.ServiceAPI
});
}
cancelArticle(uid, id) {
return this.get({
url: URL_ARTICLE_FAVORITE + 'cancelFavorite',
data: {
uid: uid,
article_id: id
},
api: global.yoho.ServiceAPI
});
}
module.exports = {
getFavoriteTabs,
favoriteBrandListAsync,
favoriteProductListAsync,
favoriteArticleListAsync,
newProductAsync,
reductionAsync,
enableNoticeAsync,
disableNoticeAsync,
cancelBrandAsync,
cancelAsync
};
... ...
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const pendingOrderCount = (uid) => {
return api.get('', {
method: 'web.SpaceOrders.getPendingOrderCount',
uid: uid
});
};
pendingOrderCount(uid) {
let options = {
method: 'web.SpaceOrders.getPendingOrderCount',
uid: uid
};
const unreadMessageCount = (uid, udid)=>{
return api.get('', {
method: 'app.home.getInfoNum',
uid: uid,
udid: udid
});
};
return this.get({data: options});
}
const needCommentCount = (uid) =>{
return api.get('', {
method: 'show.notCommentRecordCount',
uid: uid
});
};
unreadMessageCount(uid, udid) {
let options = {
method: 'app.home.getInfoNum',
uid: uid,
udid: udid
};
const guessBrand = () => {
return api.get('', {
method: 'web.search.favorBrand'
});
};
return this.get({data: options});
}
const newArrival = () => {
return api.get('', {
method: 'web.search.search',
sales: 'Y',
outlets: 2,
stocknumber: 1,
new: 'Y',
order: 's_t_desc',
viewNum: 0
});
};
needCommentCount(uid) {
let options = {
method: 'show.notCommentRecordCount',
uid: uid
};
/**
* 优选新品
*
* @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
* @param $uid 用户ID
* @param $udid 设备ID
* @param $rec_pos 位置码
* @param $limit 数量限制
* @return array 接口返回的数据
*/
const recommend = (channelNum, uid, udid, pos, limit) => {
return api.get('', {
method: 'app.home.newPreference',
yh_channel: channelNum,
uid: uid,
udid: udid,
rec_pos: pos,
limit: limit
});
};
return this.get({data: options});
}
/**
* 根据节点和运行模式选择静态内容
* @param $node 20141219-100447
* @param string $mode
* @return mixed
*/
const getByNodeContent = (node, mode) => {
return api.get('', {
method: 'web.html.content',
mode: mode,
node: node
});
};
guessBrand() {
let options = {
method: 'web.search.favorBrand'
};
return this.get({data: options});
}
newArrival() {
let options = {
method: 'web.search.search',
sales: 'Y',
outlets: 2,
stocknumber: 1,
new: 'Y',
order: 's_t_desc',
viewNum: 0
};
return this.get({data: options});
}
/**
* 优选新品
*
* @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
* @param $uid 用户ID
* @param $udid 设备ID
* @param $rec_pos 位置码
* @param $limit 数量限制
* @return array 接口返回的数据
*/
recommend(channelNum, uid, udid, pos, limit) {
let options = {
method: 'app.home.newPreference',
yh_channel: channelNum,
uid: uid,
udid: udid,
rec_pos: pos,
limit: limit
};
return this.get({data: options});
}
/**
* 根据节点和运行模式选择静态内容
* @param $node 20141219-100447
* @param string $mode
* @return mixed
*/
getByNodeContent(node, mode) {
let options = {
method: 'web.html.content',
mode: mode,
node: node
};
module.exports = {
pendingOrderCount,
unreadMessageCount,
needCommentCount,
guessBrand,
newArrival,
recommend,
getByNodeContent
return this.get({data: options});
}
};
... ...
... ... @@ -7,8 +7,8 @@ const Fn = require('lodash/fp');
const helpers = global.yoho.helpers;
const orderService = require('./orders-service');
const indexApi = require('./index-api');
const OrderService = require('./orders-service');
const IndexApi = require('./index-api');
const CHANNEL_NUM = {
boys: 1,
... ... @@ -28,164 +28,183 @@ const IMG_DOMAIN = {
]
};
/**
* 处理品牌的图片
*/
const _handleBrandLogo = (url) => {
if (_.startsWith(url, 'http://') || !url) {
return url;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
let node = url.substr(15, 2);
/**
* 处理品牌的图片
*/
_handleBrandLogo(url) {
if (_.startsWith(url, 'http://') || !url) {
return url;
}
return `//${IMG_DOMAIN[node][(url.length % 2)]}/brandLogo${url}`;
};
let node = url.substr(15, 2);
const _channelNum = channel => CHANNEL_NUM[channel] || CHANNEL_NUM.boys;
return `//${IMG_DOMAIN[node][(url.length % 2)]}/brandLogo${url}`;
}
/**
* 处理品牌
*/
const _handleBrand = (brands, needNum) => {
const handle = Fn.pipe(Fn.filter({is_hot: 'Y'}), Fn.take(needNum), Fn.map((brand) => ({
href: helpers.urlFormat('', null, brand.brand_domain),
logo: _handleBrandLogo(brand.brand_ico, 'brandLogo'),
name: brand.brand_name
})));
_channelNum(channel) {
return CHANNEL_NUM[channel] || CHANNEL_NUM.boys;
}
return handle(brands);
};
/**
* 处理品牌
*/
_handleBrand(brands, needNum) {
let that = this;
/**
* 处理商品
*/
const _handleProduct = (products) => {
return products.map((product) => {
let img = helpers.image(_.get(product, 'default_images', ''), 100, 100);
const handle = Fn.pipe(Fn.filter({is_hot: 'Y'}), Fn.take(needNum), Fn.map((brand) => ({
href: helpers.urlFormat('', null, brand.brand_domain),
logo: that._handleBrandLogo(brand.brand_ico, 'brandLogo'),
name: brand.brand_name
})));
if (img.indexOf('imageView') !== -1) {
img = img.split('imageView', 1) +
'imageMogr2/thumbnail/100x100/extent/100x100/background/d2hpdGU=/position/center/quality/90';
}
return handle(brands);
}
return {
href: helpers.getUrlBySkc(product.product_skn),
thumb: img,
name: product.product_name,
price: product.sales_price,
productId: product.product_id
};
});
};
/**
* 处理商品
*/
_handleProduct(products) {
return products.map(product => {
let img = helpers.image(_.get(product, 'default_images', ''), 100, 100);
if (img.indexOf('imageView') !== -1) {
img = img.split('imageView', 1) +
'imageMogr2/thumbnail/100x100/extent/100x100/background/d2hpdGU=/position/center/quality/90';
}
return {
href: helpers.getUrlBySkc(product.product_skn),
thumb: img,
name: product.product_name,
price: product.sales_price,
productId: product.product_id
};
});
}
/**
* 消息数量提示
*/
const _msgNumber = co(function * (uid, udid) {
let result = [
{href: helpers.urlFormat('/home/orders'), name: '待处理订单', count: 0},
{href: helpers.urlFormat('/home/message'), name: '未读消息', count: 0},
{href: helpers.urlFormat('/home/comment'), name: '待评论商品', count: 0}
];
let reqData = yield Promise.props({
pending: indexApi.pendingOrderCount(uid), // 待处理订单
unread: indexApi.unreadMessageCount(uid, udid), // 未读消息
needComment: indexApi.needCommentCount(uid) // 待评论商品
});
result[0].count = _.get(reqData, 'pending.data.count', 0);
result[1].count = _.get(reqData, 'unread.data.inbox_total', 0);
result[2].count = _.get(reqData, 'needComment.data', 0);
return result;
});
/**
* 最新订单
*/
const _recentOrder = co(function * (uid) {
let latestOrder = yield orderService.getOrders(uid, 1, 2, orderService.ORDER_TYPE.all);
return {
more: helpers.urlFormat('/home/orders'),
orders: latestOrder
};
});
/**
* 你喜欢的品牌
*/
const _guessYouLikeBrand = co(function * () {
let brand = yield indexApi.guessBrand();
const NEED_BRAND_NUM = 6;
return _handleBrand(_.get(brand, 'data', []), NEED_BRAND_NUM);
});
/**
* 新品
*/
const _newProduct = co(function * () {
let newProduct = yield indexApi.newArrival();
return _handleProduct(_.get(newProduct, 'data.product_list', []));
});
/**
* 为你优选
*/
const _recommend = co(function * (channelNum, uid, udid) {
let resData = yield indexApi.recommend(channelNum, uid, udid, '100004', 30);
return _handleProduct(_.get(resData, 'data.product_list', []));
});
/**
* 底部banner
*/
const _footerBanner = co(function * () {
const CODE = '20110609-152143';
let banner = yield indexApi.getByNodeContent(CODE);
return _.get(banner, 'data', '').replace(/http:\/\//g, '//');
});
/**
* 取消订单
*/
const _cancelReason = orderService.closeReason;
const index = co(function * (uid, udid, channel, isStudent) {
let reqData = yield Promise.props({
msgNumber: _msgNumber(uid, udid),
recentOrder: _recentOrder(uid),
guessBrand: _guessYouLikeBrand(),
newProduct: _newProduct(),
recommendProduct: _recommend(_channelNum(channel), uid, udid),
footerBanner: _footerBanner(),
reason: _cancelReason()
});
return {
content: {
certifiedName: +isStudent ? '学生身份已验证' : '身份验证',
certifiedUrl: helpers.urlFormat('/product/students/'),
messages: reqData.msgNumber,
latestOrders: Object.assign(reqData.recentOrder, {cancelReason: reqData.reason}),
favBrand: {
more: '/brands',
brands: reqData.guessBrand
},
newArrival: reqData.newProduct
},
recommend: reqData.recommendProduct,
banner: reqData.footerBanner
};
});
module.exports = {
index
};
/**
* 消息数量提示
*/
_msgNumber(uid, udid) {
let that = this;
return co(function * () {
let result = [
{href: helpers.urlFormat('/home/orders'), name: '待处理订单', count: 0},
{href: helpers.urlFormat('/home/message'), name: '未读消息', count: 0},
{href: helpers.urlFormat('/home/comment'), name: '待评论商品', count: 0}
];
let reqData = yield Promise.props({
pending: new IndexApi(that.ctx).pendingOrderCount(uid), // 待处理订单
unread: new IndexApi(that.ctx).unreadMessageCount(uid, udid), // 未读消息
needComment: new IndexApi(that.ctx).needCommentCount(uid) // 待评论商品
});
result[0].count = _.get(reqData, 'pending.data.count', 0);
result[1].count = _.get(reqData, 'unread.data.inbox_total', 0);
result[2].count = _.get(reqData, 'needComment.data', 0);
return result;
})();
}
/**
* 最新订单
*/
_recentOrder(uid) {
let orderServiceModel = new OrderService(this.ctx);
return orderServiceModel.getOrders(uid, 1, 2, orderServiceModel.ORDER_TYPE.all).then(latestOrder => {
return {
more: helpers.urlFormat('/home/orders'),
orders: latestOrder
};
});
}
/**
* 你喜欢的品牌
*/
_guessYouLikeBrand() {
const NEED_BRAND_NUM = 6;
return new IndexApi(this.ctx).guessBrand().then(brand => {
return this._handleBrand(_.get(brand, 'data', []), NEED_BRAND_NUM);
});
}
/**
* 新品
*/
_newProduct() {
return new IndexApi(this.ctx).newArrival().then(newProduct => {
return this._handleProduct(_.get(newProduct, 'data.product_list', []));
});
}
/**
* 为你优选
*/
_recommend(channelNum, uid, udid) {
return new IndexApi(this.ctx).recommend(channelNum, uid, udid, '100004', 30).then(resData => {
return this._handleProduct(_.get(resData, 'data.product_list', []));
});
}
/**
* 底部banner
*/
_footerBanner() {
const CODE = '20110609-152143';
return new IndexApi(this.ctx).getByNodeContent(CODE).then(banner => {
return _.get(banner, 'data', '').replace(/http:\/\//g, '//');
});
}
/**
* 取消订单
*/
_cancelReason() {
return new OrderService(this.ctx).closeReason();
}
index(uid, udid, channel, isStudent) {
let that = this;
return co(function * () {
let reqData = yield Promise.props({
msgNumber: that._msgNumber(uid, udid),
recentOrder: that._recentOrder(uid),
guessBrand: that._guessYouLikeBrand(),
newProduct: that._newProduct(),
recommendProduct: that._recommend(that._channelNum(channel), uid, udid),
footerBanner: that._footerBanner(),
reason: that._cancelReason()
});
return {
content: {
certifiedName: +isStudent ? '学生身份已验证' : '身份验证',
certifiedUrl: helpers.urlFormat('/product/students/'),
messages: reqData.msgNumber,
latestOrders: Object.assign(reqData.recentOrder, {cancelReason: reqData.reason}),
favBrand: {
more: '/brands',
brands: reqData.guessBrand
},
newArrival: reqData.newProduct
},
recommend: reqData.recommendProduct,
banner: reqData.footerBanner
};
})();
}
};
... ...
... ... @@ -3,7 +3,10 @@
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 我的订单-分页
... ... @@ -13,15 +16,17 @@ const api = global.yoho.API;
* @param type type 获取订单类型 type=1全部,type=2待付款,type=3待发货,type=4待收货,type=5待评论(已成功) 7取消
* @return type
*/
exports.getUserOrders = (uid, page, limit, type)=>{
return api.get('', {
method: 'app.SpaceOrders.get',
uid: uid,
type: type,
page: page,
limit: limit
});
};
getUserOrders(uid, page, limit, type) {
let options = {
method: 'app.SpaceOrders.get',
uid: uid,
type: type,
page: page,
limit: limit
};
return this.get({data: options});
}
/**
* 订单详情
... ... @@ -29,14 +34,15 @@ exports.getUserOrders = (uid, page, limit, type)=>{
* @param type orderCode
* @return type
*/
exports.getOrderDetail = (uid, orderCode)=>{
return api.get('', {
method: 'app.SpaceOrders.detail',
uid: uid,
order_code: orderCode
});
};
getOrderDetail(uid, orderCode) {
let options = {
method: 'app.SpaceOrders.detail',
uid: uid,
order_code: orderCode
};
return this.get({data: options});
}
/**
* 取消订单
... ... @@ -44,21 +50,22 @@ exports.getOrderDetail = (uid, orderCode)=>{
* @param type orderCode
* @return type
*/
exports.cancelUserOrder = (uid, orderCode, reason, reasonId)=>{
let options = {
method: 'app.SpaceOrders.close',
uid: uid,
order_code: orderCode
};
if (reasonId) {
Object.assign(options, {
reasonId: reasonId,
reasons: reason
});
}
return api.get('', options);
};
cancelUserOrder(uid, orderCode, reason, reasonId) {
let options = {
method: 'app.SpaceOrders.close',
uid: uid,
order_code: orderCode
};
if (reasonId) {
Object.assign(options, {
reasonId: reasonId,
reasons: reason
});
}
return this.get({data: options});
}
/**
* 确认订单
... ... @@ -66,42 +73,46 @@ exports.cancelUserOrder = (uid, orderCode, reason, reasonId)=>{
* @param type orderCode
* @return type
*/
exports.confirmUserOrder = (uid, orderCode)=>{
return api.get('', {
method: 'app.SpaceOrders.confirm',
uid: uid,
order_code: orderCode
});
};
confirmUserOrder(uid, orderCode) {
let options = {
method: 'app.SpaceOrders.confirm',
uid: uid,
order_code: orderCode
};
return this.get({data: options});
}
/**
* 获取虚拟订单ticketCode
* @param type orderCode
* @return type
*/
exports.getTicketCode = (orderCode)=>{
let options = {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: orderCode
};
getTicketCode(orderCode) {
let options = {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: orderCode
};
return api.get('', options);
};
return this.get({data: options});
}
/**
/**
* 我的订单-查看物流
*
* @param int orderCode 订单号
* @param int uid 用户ID
* @return array
*/
exports.getLogisticsData = (orderCode, uid)=>{
return api.get('', {
method: 'app.express.li',
order_code: orderCode,
uid: uid
});
};
getLogisticsData(orderCode, uid) {
let options = {
method: 'app.express.li',
order_code: orderCode,
uid: uid
};
return this.get({data: options});
}
/**
* 获取历史订单
... ... @@ -109,14 +120,16 @@ exports.getLogisticsData = (orderCode, uid)=>{
* @param type page
* @param type limit
*/
exports.getHistoryOrders = (uid, page, limit)=>{
return api.get('', {
method: 'app.SpaceOrders.history',
uid: uid,
page: page,
limit: limit
});
};
getHistoryOrders(uid, page, limit) {
let options = {
method: 'app.SpaceOrders.history',
uid: uid,
page: page,
limit: limit
};
return this.get({data: options});
}
/**
* 更新订单的支付方式
... ... @@ -126,26 +139,28 @@ exports.getHistoryOrders = (uid, page, limit)=>{
* @param int uid 用户ID
* @return array
*/
exports.updateOrderPayment = (orderCode, payment, uid)=>{
let options = {
method: 'app.SpaceOrders.updateOrdersPaymentByCode',
order_code: Number(orderCode),
payment: payment,
uid: uid
};
return api.get('', options);
};
updateOrderPayment(orderCode, payment, uid) {
let options = {
method: 'app.SpaceOrders.updateOrdersPaymentByCode',
order_code: Number(orderCode),
payment: payment,
uid: uid
};
return this.get({data: options});
}
/**
* 取消订单原因列表
* @return type
*/
exports.closeReasons = ()=>{
return api.get('', {
method: 'app.SpaceOrders.closeReasons'
});
};
closeReasons() {
let options = {
method: 'app.SpaceOrders.closeReasons'
};
return this.get({data: options});
}
/**
* 订单详情页——地址修改
... ... @@ -153,30 +168,30 @@ exports.closeReasons = ()=>{
* @param type address_id
* @return type
*/
exports.updateDeliveryAddress = (orderId, userName, areaCode, address, mobile, phone, uid, udid)=>{
let options = {
method: 'app.SpaceOrders.updateDeliveryAddress',
order_code: orderId,
user_name: userName,
area_code: areaCode,
address: address,
uid: uid
};
updateDeliveryAddress(orderId, userName, areaCode, address, mobile, phone, uid, udid) {
let options = {
method: 'app.SpaceOrders.updateDeliveryAddress',
order_code: orderId,
user_name: userName,
area_code: areaCode,
address: address,
uid: uid
};
if (mobile) {
Object.assign(options, {mobile: mobile});
}
if (mobile) {
Object.assign(options, {mobile: mobile});
}
if (phone) {
Object.assign(options, {phone: phone});
}
if (phone) {
Object.assign(options, {phone: phone});
}
if (udid) {
Object.assign(options, {udid: udid});
}
if (udid) {
Object.assign(options, {udid: udid});
}
return api.get('', options);
};
return this.get({data: options});
}
/**
* 查看订单详情
... ... @@ -186,67 +201,75 @@ exports.updateDeliveryAddress = (orderId, userName, areaCode, address, mobile, p
* @param string sessionKey 用户会话
* @return array
*/
exports.viewOrderData = (orderCode, uid, sessionKey)=>{
return api.get('', {
method: 'app.SpaceOrders.info',
order_code: orderCode,
uid: uid,
session_key: sessionKey
});
};
viewOrderData(orderCode, uid, sessionKey) {
let options = {
method: 'app.SpaceOrders.info',
order_code: orderCode,
uid: uid,
session_key: sessionKey
};
/**
* 重新加入购物车
*/
exports.reBuy = (uid, orderId) => {
return api.get('', {
method: 'app.Shopping.readd',
uid: uid,
order_code: orderId
});
};
return this.get({data: options});
}
/**
* 删除订单数据
*/
exports.del = (uid, gender, channel, orderId) => {
return api.get('', {
method: 'app.SpaceOrders.delOrderByCode',
uid: uid,
gender: gender,
yh_channel: channel,
order_code: orderId
});
};
/**
* 重新加入购物车
*/
reBuy(uid, orderId) {
let options = {
method: 'app.Shopping.readd',
uid: uid,
order_code: orderId
};
/**
* 申请退款
*/
exports.refund = (uid, orderId, reasonId, reason) => {
let params = {
uid: uid,
order_code: orderId
};
return this.get({data: options});
}
/**
* 删除订单数据
*/
del(uid, gender, channel, orderId) {
let options = {
method: 'app.SpaceOrders.delOrderByCode',
uid: uid,
gender: gender,
yh_channel: channel,
order_code: orderId
};
if (reasonId) {
params.reason_id = reasonId;
return this.get({data: options});
}
if (reason) {
params.reason = reason;
/**
* 申请退款
*/
refund(uid, orderId, reasonId, reason) {
let options = {
method: 'app.SpaceOrders.refundApply',
uid: uid,
order_code: orderId
};
if (reasonId) {
options.reason_id = reasonId;
}
if (reason) {
options.reason = reason;
}
return this.get({data: options});
}
return api.get('', Object.assign({
method: 'app.SpaceOrders.refundApply'
}, params));
};
/**
* 申请退款原因
*/
refundReason() {
let options = {
method: 'app.SpaceOrders.refundApplyReasons'
};
/**
* 申请退款原因
*/
exports.refundReason = () => {
return api.get('', {
method: 'app.SpaceOrders.refundApplyReasons'
});
return this.get({data: options});
}
};
... ...
... ... @@ -7,917 +7,945 @@ const moment = require('moment');
const helpers = global.yoho.helpers;
const pager = require('./pager').handlePagerData;
const orderApi = require('./orders-api');
const OrderApi = require('./orders-api');
const ChannelConfig = require('./channel-config');
/**
* 转换价格
*
* @param float|string $price 价格
* @return float|string 转换之后的价格
*/
const transPrice = (price) => {
return price ? (price * 1).toFixed(2) : '0.00';
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.ORDER_TYPE = {
all: 1, // 全部
waitingForPay: 2, // 待付款
waitingForSend: 3, // 待发货
waitingForReceive: 4, // 待收货
completed: 5, // 已完成
canceled: 7 // 已取取消
};
const ORDER_TYPE = {
all: 1, // 全部
waitingForPay: 2, // 待付款
waitingForSend: 3, // 待发货
waitingForReceive: 4, // 待收货
completed: 5, // 已完成
canceled: 7 // 已取取消
};
this.ORDER_EMPTY_DESC = {
1: '您还没有任何订单',
5: '您目前还没有成功的订单',
7: '您还没有任何取消的订单'
};
const ORDER_EMPTY_DESC = {
1: '您还没有任何订单',
5: '您目前还没有成功的订单',
7: '您还没有任何取消的订单'
};
this.TABS = [
{type: 1, name: '现有订单'},
{type: 5, name: '成功订单'},
{type: 7, name: '已取消订单'}
];
const TABS = [
{type: 1, name: '现有订单'},
{type: 5, name: '成功订单'},
{type: 7, name: '已取消订单'}
];
const ORDER_OP_ALL = [
{
type: 'closeOrder',
name: '取消订单',
cancelOrder: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'buyNow',
name: '立即付款',
payNow: true,
hrefFun: it => helpers.urlFormat('/shopping/newpay', {ordercode: it})
},
{
type: 'getExpress',
name: '查看物流',
express: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'confirm',
name: '确认订单',
confirmReceived: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'delOrder',
name: '删除订单',
delOrder: true,
hrefFun: () => ''
},
{
type: 'lookQrcode',
name: '查看二维码',
qrcode: true,
hrefFun: it => helpers.urlFormat('/home/qrcode', {orderCode: it})
},
{
type: 'afterService',
name: '售后服务',
afterService: true,
hrefFun: () => ''
},
{
type: 'exchange',
name: '申请换货',
optDis: true,
hrefFun: it => helpers.urlFormat('/home/returns/exchangerequest', {orderCode: it})
},
{
type: 'refund',
name: '申请退货',
optDis: true,
hrefFun: it => helpers.urlFormat('/home/returns/refundrequest', {orderCode: it})
},
{
type: 'shareOrder',
name: '晒单评价',
comment: true,
hrefFun: it => helpers.urlFormat('/home/comment/order', {orderId: it})
},
{
type: 'readd',
name: '再次购买',
reBuy: true,
hrefFun: () => ''
},
{
type: 'showDetail',
name: '查看订单',
showDetail: true,
hrefFun: it => helpers.urlFormat('/home/orders/detail', {orderCode: it})
},
{
type: 'refundApply',
name: '申请退款',
refund: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'deposit',
name: '定金预售商品只能在APP端操作',
deposit: true,
hrefFun: () => ''
this.ORDER_OP_ALL = [
{
type: 'closeOrder',
name: '取消订单',
cancelOrder: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'buyNow',
name: '立即付款',
payNow: true,
hrefFun: it => helpers.urlFormat('/shopping/newpay', {ordercode: it})
},
{
type: 'getExpress',
name: '查看物流',
express: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'confirm',
name: '确认订单',
confirmReceived: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'delOrder',
name: '删除订单',
delOrder: true,
hrefFun: () => ''
},
{
type: 'lookQrcode',
name: '查看二维码',
qrcode: true,
hrefFun: it => helpers.urlFormat('/home/qrcode', {orderCode: it})
},
{
type: 'afterService',
name: '售后服务',
afterService: true,
hrefFun: () => ''
},
{
type: 'exchange',
name: '申请换货',
optDis: true,
hrefFun: it => helpers.urlFormat('/home/returns/exchangerequest', {orderCode: it})
},
{
type: 'refund',
name: '申请退货',
optDis: true,
hrefFun: it => helpers.urlFormat('/home/returns/refundrequest', {orderCode: it})
},
{
type: 'shareOrder',
name: '晒单评价',
comment: true,
hrefFun: it => helpers.urlFormat('/home/comment/order', {orderId: it})
},
{
type: 'readd',
name: '再次购买',
reBuy: true,
hrefFun: () => ''
},
{
type: 'showDetail',
name: '查看订单',
showDetail: true,
hrefFun: it => helpers.urlFormat('/home/orders/detail', {orderCode: it})
},
{
type: 'refundApply',
name: '申请退款',
refund: true,
hrefFun: () => 'javascript:void(0)' // eslint-disable-line
},
{
type: 'deposit',
name: '定金预售商品只能在APP端操作',
deposit: true,
hrefFun: () => ''
}
];
}
];
const _getTabs = (type) => {
type = type || 1;
return TABS.map((tab) => {
tab.active = tab.type === type;
tab.url = helpers.urlFormat('/home/orders', {page: 1, type: tab.type});
return tab;
});
};
const _getOrderStatus = (isCancel, status, payType, payStatus, statusStr) => {
// 初始化:未取消,待付款
let ret = {
cancel: false,
keyName: 'noPay'
};
if (isCancel === 'Y') {
ret = {cancel: true, statusStr: '已取消'};
} else {
switch (status) {
case 0:
// '订单已成功,等待付款'
if (payType !== 2 && payStatus === 'N') {
ret.keyName = 'noPay';
} else if (payType !== 2 && payStatus === 'Y') {
// '订单已付款,等待备货中'
ret.keyName = 'paid';
} else if (payType === 2 && payStatus === 'N') {
// '订单已成功,等待备货中'-货到付款
ret.keyName = 'complete';
}
break;
case 1:
case 2:
case 3:
// '订单已付款,等待备货中'
ret.keyName = 'paid';
break;
case 4:
case 5:
// '订单已发货'
ret.keyName = 'shipped';
break;
case 6:
// '交易完成';
ret.keyName = 'reback';
break;
default:
ret.keyName = 'unknown';
}
/**
* 转换价格
*
* @param float|string $price 价格
* @return float|string 转换之后的价格
*/
transPrice(price) {
return price ? (price * 1).toFixed(2) : '0.00';
}
ret.statusStr = statusStr;
return ret;
};
_getTabs(type) {
type = type || 1;
const _getOperateInfo = (orderCode, operators) => {
return _.flatten(operators.map(it => ORDER_OP_ALL.filter(op => op.type === it).map((op) => {
return Object.assign({}, op, {
href: op.hrefFun(orderCode)
return this.TABS.map((tab) => {
tab.active = tab.type === type;
tab.url = helpers.urlFormat('/home/orders', {page: 1, type: tab.type});
return tab;
});
})));
};
}
_getOrderStatus(isCancel, status, payType, payStatus, statusStr) {
// 初始化:未取消,待付款
let ret = {
cancel: false,
keyName: 'noPay'
};
if (isCancel === 'Y') {
ret = {cancel: true, statusStr: '已取消'};
} else {
switch (status) {
case 0:
// '订单已成功,等待付款'
if (payType !== 2 && payStatus === 'N') {
ret.keyName = 'noPay';
} else if (payType !== 2 && payStatus === 'Y') {
// '订单已付款,等待备货中'
ret.keyName = 'paid';
} else if (payType === 2 && payStatus === 'N') {
// '订单已成功,等待备货中'-货到付款
ret.keyName = 'complete';
}
break;
case 1:
case 2:
case 3:
// '订单已付款,等待备货中'
ret.keyName = 'paid';
break;
case 4:
case 5:
// '订单已发货'
ret.keyName = 'shipped';
break;
case 6:
// '交易完成';
ret.keyName = 'reback';
break;
default:
ret.keyName = 'unknown';
}
}
ret.statusStr = statusStr;
return ret;
}
_getOperateInfo(orderCode, operators) {
return _.flatten(operators.map(it => this.ORDER_OP_ALL.filter(op => op.type === it).map((op) => {
return Object.assign({}, op, {
href: op.hrefFun(orderCode)
});
})));
}
_getGoodsTag(attribute, goodsType) {
let goodsTagName = '';
const _getGoodsTag = (attribute, goodsType) => {
let goodsTagName = '';
switch (goodsType) {
switch (goodsType) {
// 赠品
case 'gift':
goodsTagName = 'freebie';
break;
// 赠品
case 'gift':
goodsTagName = 'freebie';
break;
// 加价购
case 'price_gift':
goodsTagName = 'advanceBuy';
break;
// 加价购
case 'price_gift':
goodsTagName = 'advanceBuy';
break;
// 预售
case 'advance':
goodsTagName = 'preSaleGood';
break;
// 预售
case 'advance':
goodsTagName = 'preSaleGood';
break;
// outlet
case 'outlet':
goodsTagName = '';
break;
// outlet
case 'outlet':
goodsTagName = '';
break;
// 免单
case 'free':
goodsTagName = '';
break;
// 免单
case 'free':
goodsTagName = '';
break;
// 电子
case 'ticket':
goodsTagName = 'virtualGood';
break;
default:
break;
}
// 电子
case 'ticket':
// 虚拟
if (attribute === 3) {
goodsTagName = 'virtualGood';
break;
default:
break;
}
}
// 虚拟
if (attribute === 3) {
goodsTagName = 'virtualGood';
return goodsTagName;
}
return goodsTagName;
};
_getUrlSafe(url) {
if (!url) {
return '';
}
const _getUrlSafe = (url) => {
if (!url) {
return '';
}
const WhiteList = ['/special_', '/special/'];
const WhiteList = ['/special_', '/special/'];
if (_.some(WhiteList, (val) => _.includes(url, val))) {
return url;
}
if (_.some(WhiteList, (val) => _.includes(url, val))) {
return url;
return url.replace('http://', '//');
}
return url.replace('http://', '//');
};
_getExpressInfo(orderCode, uid, paymentType, createTime, isDetail) {
let that = this;
return co(function * () {
let result = {};
const _getExpressInfo = (orderCode, uid, paymentType, createTime, isDetail) => {
return co(function * () {
isDetail = isDetail || false;
let result = {};
isDetail = isDetail || false;
result.logisticsUrl = '';
result.logisticsImg = '';
result.logisticsCompany = '';
result.courierNumbe = '';
result.logistics = [];
result.logisticsUrl = '';
result.logisticsImg = '';
result.logisticsCompany = '';
result.courierNumbe = '';
result.logistics = [];
if (paymentType === 1) {
if (isDetail) {
result.logistics.push('');
} else {
result.logistics.push(moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss') + ' 您的订单已提交,等待付款');
if (paymentType === 1) {
if (isDetail) {
result.logistics.push('');
} else {
result.logistics.push(moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss') + ' 您的订单已提交,等待付款');
}
}
}
if (paymentType === 2) {
if (isDetail) {
result.logistics = result.logistics.concat([
moment.unix(createTime).format('YYYY-M-D H:m:s'),
' ',
'您的订单已提交,等待审核'
]);
} else {
result.logistics.push(moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss') + ' 您的订单已提交,等待审核');
if (paymentType === 2) {
if (isDetail) {
result.logistics = result.logistics.concat([
moment.unix(createTime).format('YYYY-M-D H:m:s'),
' ',
'您的订单已提交,等待审核'
]);
} else {
result.logistics.push(moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss') + ' 您的订单已提交,等待审核');
}
}
}
// 有物流
if (orderCode) {
let logistics = yield orderApi.getLogisticsData(orderCode, uid);
// 有物流
if (orderCode) {
let logistics = yield new OrderApi(that.ctx).getLogisticsData(orderCode, uid);
if (_.has(logistics, 'data')) {
result.logisticsUrl = _getUrlSafe(logistics.data.url);
result.logisticsImg = logistics.data.logo || '';
result.logisticsCompany = logistics.data.caption || '';
result.courierNumbe = logistics.data.express_number || '';
let expressDetail = logistics.data.express_detail || [];
if (_.has(logistics, 'data')) {
result.logisticsUrl = that._getUrlSafe(logistics.data.url);
result.logisticsImg = logistics.data.logo || '';
result.logisticsCompany = logistics.data.caption || '';
result.courierNumbe = logistics.data.express_number || '';
let expressDetail = logistics.data.express_detail || [];
if (!_.isEmpty(expressDetail)) {
let logisticsTmp = result.logistics[0]; // 暂存
if (!_.isEmpty(expressDetail)) {
let logisticsTmp = result.logistics[0]; // 暂存
result.logistics = [];
expressDetail.forEach((value) => {
let pos = value.accept_address.indexOf(' ');
result.logistics = [];
expressDetail.forEach((value) => {
let pos = value.accept_address.indexOf(' ');
pos = pos === -1 ? 0 : pos;
pos = pos === -1 ? 0 : pos;
let city = value.accept_address.substr(0, pos);
let exInfo = value.accept_address.substr(pos);
let city = value.accept_address.substr(0, pos);
let exInfo = value.accept_address.substr(pos);
if (isDetail) {
result.logistics.push([value.acceptTime, city, exInfo]);
} else {
result.logistics.push(value.acceptTime + city + exInfo);
}
});
if (isDetail) {
result.logistics.push([value.acceptTime, city, exInfo]);
} else {
result.logistics.push(value.acceptTime + city + exInfo);
}
});
// 把最初的处理放最后
result.logistics.push(logisticsTmp);
// 把最初的处理放最后
result.logistics.push(logisticsTmp);
}
}
}
}
return result;
})();
return result;
})();
}
};
/**
* 获取我的订单列表数据
*/
const getOrders = (uid, page, limit, type, isPage)=> {
return co(function *() {
isPage = isPage || false;
let orderInfo = yield orderApi.getUserOrders(uid, page, limit, type).then(res => _.get(res, 'data', {}));
/**
* 获取我的订单列表数据
*/
getOrders(uid, page, limit, type, isPage) {
let that = this;
if (_.isEmpty(_.get(orderInfo, 'order_list', []))) {
return {
empty: ORDER_EMPTY_DESC[type] || '',
list: []
};
}
return co(function *() {
isPage = isPage || false;
let result = {};
let orderInfo = yield new OrderApi(that.ctx).getUserOrders(
uid, page, limit, type
).then(res => _.get(res, 'data', {}));
const handleOrder = function(order) {
order.payment_type = +order.payment_type;
if (_.isEmpty(_.get(orderInfo, 'order_list', []))) {
return {
empty: that.ORDER_EMPTY_DESC[type] || '',
list: []
};
}
let newOrder = {};
let result = {};
newOrder.orderNum = order.order_code; // 订单标识
newOrder.orderTime = moment.unix(_.get(order, 'create_time')).format('YYYY-MM-DD HH:mm:ss');
newOrder.time = _.get(order, 'create_time');
newOrder.payType = _.get(order, 'payment_type');
newOrder.title = _.get(order, 'order_title');
const handleOrder = function(order) {
order.payment_type = +order.payment_type;
if (order.is_cancel === 'Y' || order.status === 6) {
newOrder.canDelete = true; // 删除订单
}
let newOrder = {};
let statusInfo = _getOrderStatus(order.is_cancel, order.status, order.payment_type,
order.payment_status, order.status_str
);
newOrder.orderNum = order.order_code; // 订单标识
newOrder.orderTime = moment.unix(_.get(order, 'create_time')).format('YYYY-MM-DD HH:mm:ss');
newOrder.time = _.get(order, 'create_time');
newOrder.payType = _.get(order, 'payment_type');
newOrder.title = _.get(order, 'order_title');
// 订单状态
if (statusInfo.cancel) {
newOrder.cancel = statusInfo.cancel;
} else {
if (statusInfo.keyName) {
newOrder[statusInfo.keyName] = true;
if (order.is_cancel === 'Y' || order.status === 6) {
newOrder.canDelete = true; // 删除订单
}
}
newOrder.statusStr = statusInfo.statusStr;
let statusInfo = that._getOrderStatus(order.is_cancel, order.status, order.payment_type,
order.payment_status, order.status_str
);
newOrder.goods = _.get(order, 'order_goods', []).map((good) => {
let newGood = {};
// 订单状态
if (statusInfo.cancel) {
newOrder.cancel = statusInfo.cancel;
} else {
if (statusInfo.keyName) {
newOrder[statusInfo.keyName] = true;
}
}
newGood.href = helpers.getUrlBySkc(good.product_skn);
newGood.thumb = helpers.image(good.goods_image, 100, 100);
newGood.name = good.product_name;
newGood.color = good.factory_color_name;
newGood.size = good.size_name;
newOrder.statusStr = statusInfo.statusStr;
newGood.price = transPrice(good.sales_price);// 默认显示销售价
newGood.isVipPrice = good.discount_tag === 'V';
newGood.isStuPrice = good.discount_tag === 'S';
newOrder.goods = _.get(order, 'order_goods', []).map((good) => {
let newGood = {};
// 划线的价格
if (+good.real_pay_price < +good.sales_price) {
newGood.price = transPrice(good.real_pay_price);// 显示分摊价
newGood.linePrice = transPrice(good.sales_price); // 划线的价格
}
newGood.href = helpers.getUrlBySkc(good.product_skn);
newGood.thumb = helpers.image(good.goods_image, 100, 100);
newGood.name = good.product_name;
newGood.color = good.factory_color_name;
newGood.size = good.size_name;
newGood.price = that.transPrice(good.sales_price);// 默认显示销售价
newGood.isVipPrice = good.discount_tag === 'V';
newGood.isStuPrice = good.discount_tag === 'S';
// 赠品、加价购
if (good.goods_type === 'gift' || good.goods_type === 'price_gift') {
newGood.price = transPrice(good.goods_price);// 显示成交价
newGood.linePrice = transPrice(good.sales_price); // 划线的价格
}
let buyNum = _.parseInt(good.buy_number);
let refundNum = _.parseInt(good.refund_num);
// 划线的价格
if (+good.real_pay_price < +good.sales_price) {
newGood.price = that.transPrice(good.real_pay_price);// 显示分摊价
newGood.linePrice = that.transPrice(good.sales_price); // 划线的价格
}
newGood.count = buyNum;
newGood.refundStatus = refundNum > 0;// 只要发生一件退换,退换过的标记
newGood.goRefundUrl = helpers.urlFormat('/home/returns');
newGood.arrivalDate = good.expect_arrival_time;
// 赠品、加价购
if (good.goods_type === 'gift' || good.goods_type === 'price_gift') {
newGood.price = that.transPrice(good.goods_price);// 显示成交价
newGood.linePrice = that.transPrice(good.sales_price); // 划线的价格
}
let goodsTagName = _getGoodsTag(+order.attribute, good.goods_type);
let buyNum = _.parseInt(good.buy_number);
let refundNum = _.parseInt(good.refund_num);
if (goodsTagName) {
newGood[goodsTagName] = true;
}
newGood.count = buyNum;
newGood.refundStatus = refundNum > 0;// 只要发生一件退换,退换过的标记
newGood.goRefundUrl = helpers.urlFormat('/home/returns');
newGood.arrivalDate = good.expect_arrival_time;
return newGood;
});
let goodsTagName = that._getGoodsTag(+order.attribute, good.goods_type);
newOrder.pay = order.amount; // 付款数
newOrder.fregit = order.shipping_cost; // 邮费
if (goodsTagName) {
newGood[goodsTagName] = true;
}
// 操作
let op = _.get(order, 'links', []);
return newGood;
});
// 新增加一些操作
op.unshift('showDetail');
newOrder.pay = order.amount; // 付款数
newOrder.fregit = order.shipping_cost; // 邮费
if (_.get(order, 'is_support_exchange', 'N') === 'Y') {
op.push('exchange');
}
// 操作
let op = _.get(order, 'links', []);
if (_.get(order, 'is_support_refund', 'N') === 'Y') {
op.push('refund');
}
// 新增加一些操作
op.unshift('showDetail');
if (+order.attribute === 9) {
op = ['deposit'];
}
if (_.get(order, 'is_support_exchange', 'N') === 'Y') {
op.push('exchange');
}
newOrder.operation = _getOperateInfo(order.order_code, op);
if (_.get(order, 'is_support_refund', 'N') === 'Y') {
op.push('refund');
}
return newOrder;
};
if (+order.attribute === 9) {
op = ['deposit'];
}
result.list = _.get(orderInfo, 'order_list', []).map(handleOrder);
newOrder.operation = that._getOperateInfo(order.order_code, op);
if (isPage) {
result.pager = {
total: orderInfo.total,
pageTotal: orderInfo.page_total,
page: orderInfo.page
return newOrder;
};
}
return result;
})();
};
result.list = _.get(orderInfo, 'order_list', []).map(handleOrder);
const index = (uid, page, limit, type) => {
return co(function * () {
let result = yield Promise.props({
orders: getOrders(uid, page, limit, type, true),
cancelReason: orderApi.closeReasons().then(res => _.get(res, 'data', ''))
});
if (isPage) {
result.pager = {
total: orderInfo.total,
pageTotal: orderInfo.page_total,
page: orderInfo.page
};
}
result.pager = pager(_.get(result, 'orders.pager.total', 0), {page, limit, type});
return result;
})();
}
return Object.assign(result, {
tabs: _getTabs(type)
});
})();
};
index(uid, page, limit, type) {
let that = this;
const reBuy = (uid, orderId) => {
return co(function * () {
let newOrder = yield orderApi.reBuy(uid, orderId);
return co(function * () {
let result = yield Promise.props({
orders: that.getOrders(uid, page, limit, type, true),
cancelReason: new OrderApi(that.ctx).closeReasons().then(res => _.get(res, 'data', ''))
});
if (newOrder.code !== 200) {
return {
code: 400,
message: '商品加入购物车失败'
};
}
result.pager = pager(_.get(result, 'orders.pager.total', 0), {page, limit, type});
return {
code: 200,
message: '商品已重新加入购物车',
data: newOrder.data
};
})();
};
return Object.assign(result, {
tabs: that._getTabs(type)
});
})();
}
const del = co(function * (uid, gender, channel, orderId) {
let orderInfo = yield orderApi.del(uid, gender, channel, orderId);
reBuy(...params) {
let that = this;
if (!_.has(orderInfo, 'code')) {
return {
code: 400,
message: '删除失败'
};
return co(function * () {
let newOrder = yield new OrderApi(that.ctx).reBuy(...params);
if (newOrder.code !== 200) {
return {
code: 400,
message: '商品加入购物车失败'
};
}
return {
code: 200,
message: '商品已重新加入购物车',
data: newOrder.data
};
})();
}
return orderInfo;
});
del(...params) {
return new OrderApi(this.ctx).del(...params).then(orderInfo => {
const _getVirtualPro = (isCancel, status, createTime) => {
let process = {
middleStatus: [
{
name: '1. 提交订单',
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
},
{
name: '2. 已发货'
},
{
name: '3. 交易完成'
if (!_.has(orderInfo, 'code')) {
return {
code: 400,
message: '删除失败'
};
}
]
};
if (isCancel === 'N') {
if (status === 0) {
process.percent = '30%';
process.middleStatus[0].cur = true;
} else if (status > 0 && status < 6) {
process.percent = '80%';
process.middleStatus[1].cur = true;
} else if (status === 6) {
process.percent = '100%';
process.middleStatus[2].cur = true;
}
return orderInfo;
});
}
return process;
};
_getVirtualPro(isCancel, status, createTime) {
let progress = {
middleStatus: [
{
name: '1. 提交订单',
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
},
{
name: '2. 已发货'
},
{
name: '3. 交易完成'
}
]
};
const _getNormalPro = (isCancel, status, createTime) => {
let process = {
middleStatus: [
{
name: '1. 提交订单',
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
},
{
name: '2. 商品出库'
},
{
name: '3. 等待收货'
},
{
name: '4. 交易完成'
if (isCancel === 'N') {
if (status === 0) {
progress.percent = '30%';
progress.middleStatus[0].cur = true;
} else if (status > 0 && status < 6) {
progress.percent = '80%';
progress.middleStatus[1].cur = true;
} else if (status === 6) {
progress.percent = '100%';
progress.middleStatus[2].cur = true;
}
]
};
if (isCancel === 'N') {
if (status === 0) {
process.percent = '25%';
process.middleStatus[0].cur = true;
} else if (status > 0 && status < 4) {
process.percent = '50%';
process.middleStatus[1].cur = true;
} else if (status >= 4 && status < 6) {
process.percent = '75%';
process.middleStatus[2].cur = true;
} else if (status === 6) {
process.percent = '100%';
process.middleStatus[3].cur = true;
}
return progress;
}
return process;
};
_getNormalPro(isCancel, status, createTime) {
let progress = {
middleStatus: [
{
name: '1. 提交订单',
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
},
{
name: '2. 商品出库'
},
{
name: '3. 等待收货'
},
{
name: '4. 交易完成'
}
]
};
const _getOfflineBySelf = (isCancel, status, createTime) => {
let process = {
middleStatus: [
{
name: '1. 提交订单',
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
},
{
name: '2. 交易完成'
if (isCancel === 'N') {
if (status === 0) {
progress.percent = '25%';
progress.middleStatus[0].cur = true;
} else if (status > 0 && status < 4) {
progress.percent = '50%';
progress.middleStatus[1].cur = true;
} else if (status >= 4 && status < 6) {
progress.percent = '75%';
progress.middleStatus[2].cur = true;
} else if (status === 6) {
progress.percent = '100%';
progress.middleStatus[3].cur = true;
}
]
};
if (isCancel === 'N') {
if (status === 0) {
process.percent = '50%';
process.middleStatus[0].cur = true;
} else if (status === 6) {
process.percent = '100%';
process.middleStatus[1].cur = true;
}
return progress;
}
return process;
};
_getOfflineBySelf(isCancel, status, createTime) {
let progress = {
middleStatus: [
{
name: '1. 提交订单',
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
},
{
name: '2. 交易完成'
}
]
};
const _getOrderDetailOp = (orderId, payment, status,
isCancel, paymentStatus, paymentType,
orderType, attribute, refundStatus) => {
let operation = {};
if (isCancel === 'N') {
if (status === 0) {
progress.percent = '50%';
progress.middleStatus[0].cur = true;
} else if (status === 6) {
progress.percent = '100%';
progress.middleStatus[1].cur = true;
}
}
// 立刻付款
if (paymentType === 1 && paymentStatus === 'N' && isCancel === 'N' && payment !== 19) {
Object.assign(operation, {
goPay: helpers.urlFormat('/shopping/newpay', {ordercode: orderId})
});
return progress;
}
// 取消订单
if (status < 3 && isCancel === 'N' && paymentStatus === 'N' && orderType !== 5) {
Object.assign(operation, {
cancelOrder: true
});
}
_getOrderDetailOp(orderId, payment, status,
isCancel, paymentStatus, paymentType,
orderType, attribute, refundStatus) {
let operation = {};
// 订单已支付
if (paymentType === 1 && paymentStatus === 'Y' && status < 6) {
Object.assign(operation, {
paid: true
});
}
// 立刻付款
if (paymentType === 1 && paymentStatus === 'N' && isCancel === 'N' && payment !== 19) {
Object.assign(operation, {
goPay: helpers.urlFormat('/shopping/newpay', {ordercode: orderId})
});
}
// 确认收货
if (status >= 4 && status < 6 && refundStatus === 0 && attribute !== 3 && isCancel === 'N') {
Object.assign(operation, {
shipped: true
});
}
// 取消订单
if (status < 3 && isCancel === 'N' && paymentStatus === 'N' && orderType !== 5) {
Object.assign(operation, {
cancelOrder: true
});
}
// 订单已取消
if (isCancel === 'Y') {
Object.assign(operation, {
cancel: true
});
}
// 订单已支付
if (paymentType === 1 && paymentStatus === 'Y' && status < 6) {
Object.assign(operation, {
paid: true
});
}
// 虚拟查看二维码
if (attribute === 3) {
Object.assign(operation, {
checkQrCode: helpers.urlFormat('/home/orders/ticket', {orderCode: orderId})
});
}
// 确认收货
if (status >= 4 && status < 6 && refundStatus === 0 && attribute !== 3 && isCancel === 'N') {
Object.assign(operation, {
shipped: true
});
}
return operation;
};
// 订单已取消
if (isCancel === 'Y') {
Object.assign(operation, {
cancel: true
});
}
const _getPackageInfo = (cartInfo) => {
// 是否拆单
if (cartInfo.is_multi_package !== 'Y') {
return [];
}
// 虚拟查看二维码
if (attribute === 3) {
Object.assign(operation, {
checkQrCode: helpers.urlFormat('/home/orders/ticket', {orderCode: orderId})
});
}
return _.get(cartInfo, 'package_list', []).map((pack) => {
let newPack = {
supplierId: pack.supplier_id,
fee: pack.shopping_cost === '0.00' ? '' : pack.shopping_cost,
orign: pack.shopping_orig_cost,
count: pack.shopping_cut_cost
};
return operation;
}
newPack.goodlist = _.get(pack, 'goods_list', []).map((good) => {
let tagInfo = ChannelConfig.orderTagArr[good.goods_type] || '';
_getPackageInfo(cartInfo) {
// 是否拆单
if (cartInfo.is_multi_package !== 'Y') {
return [];
}
return {
src: helpers.image(good.goods_images, 90, 90),
goodsType: tagInfo.name || '',
classname: tagInfo.classname || '',
link: 'javascritp:void(0)'
return _.get(cartInfo, 'package_list', []).map((pack) => {
let newPack = {
supplierId: pack.supplier_id,
fee: pack.shopping_cost === '0.00' ? '' : pack.shopping_cost,
orign: pack.shopping_orig_cost,
count: pack.shopping_cut_cost
};
});
return newPack;
});
};
const isOfflineBySelf = (orderDetail) => {
return orderDetail.is_offlineshops === 'Y' && orderDetail.is_delivery_offline === 'Y';
};
newPack.goodlist = _.get(pack, 'goods_list', []).map((good) => {
let tagInfo = ChannelConfig.orderTagArr[good.goods_type] || '';
const _getOrderDetail = co(function * (uid, orderId) {
let orderInfo = yield orderApi.getOrderDetail(uid, orderId);
let detail = {};
return {
src: helpers.image(good.goods_images, 90, 90),
goodsType: tagInfo.name || '',
classname: tagInfo.classname || '',
link: 'javascritp:void(0)'
};
});
if (orderInfo.code === 400) {
return orderInfo;
return newPack;
});
}
if (orderInfo.data) {
let orderDetail = orderInfo.data;
isOfflineBySelf(orderDetail) {
return orderDetail.is_offlineshops === 'Y' && orderDetail.is_delivery_offline === 'Y';
}
orderDetail.payment_type = +orderDetail.payment_type;
_getOrderDetail(uid, orderId) {
let that = this;
detail.orderNum = orderDetail.order_code;
return co(function * () {
let orderInfo = yield new OrderApi(that.ctx).getOrderDetail(uid, orderId);
let detail = {};
// 订单状态
let statusInfo = _getOrderStatus(
orderDetail.is_cancel, +orderDetail.status,
orderDetail.payment_type, orderDetail.payment_status, orderDetail.status_str
);
if (orderInfo.code === 400) {
return orderInfo;
}
detail.statusStr = statusInfo.statusStr;
if (orderInfo.data) {
let orderDetail = orderInfo.data;
// 订单是否已完成
detail.complete = +orderDetail.status === 6;
orderDetail.payment_type = +orderDetail.payment_type;
detail.progress = statusInfo.cancel ? false : (function() {
// 未取消订单,进度
if (+orderDetail.attribute === 3) {
return _getVirtualPro(orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time);
} else {
if (isOfflineBySelf(orderDetail)) {
return _getOfflineBySelf(orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time);
}
detail.orderNum = orderDetail.order_code;
return _getNormalPro(orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time);
}
}());
// 订单状态
let statusInfo = that._getOrderStatus(
orderDetail.is_cancel, +orderDetail.status,
orderDetail.payment_type, orderDetail.payment_status, orderDetail.status_str
);
// 物流信息
detail.traceOrder = {};
detail.traceOrder.orderDate = moment.unix(orderDetail.create_time).format('YYYY.MM.DD HH:mm:ss');
let expressInfo = yield _getExpressInfo(orderId, uid, +orderDetail.payment_type, orderDetail.create_time, true);
detail.statusStr = statusInfo.statusStr;
detail.traceOrder.logistics = expressInfo.logistics;
// 订单是否已完成
detail.complete = +orderDetail.status === 6;
if (_.get(expressInfo, 'logistics[0]')) {
detail.hastrace = true;
} else {
detail.hastrace = false;
}
detail.progress = statusInfo.cancel ? false : (function() {
// 未取消订单,进度
if (+orderDetail.attribute === 3) {
return that._getVirtualPro(orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time);
} else {
if (that.isOfflineBySelf(orderDetail)) {
return that._getOfflineBySelf(
orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time
);
}
detail.traceOrder.logisticsCompany = expressInfo.logisticsCompany;
detail.traceOrder.courierNumbe = expressInfo.courierNumbe;
return that._getNormalPro(orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time);
}
}());
// 虚拟商品
if (+orderDetail.attribute === 3) {
detail.virtualGood = true;
detail.virtualPayMode = {
payMode: ChannelConfig.payType[orderDetail.payment_type],
phone: _.fill(orderDetail.mobile.split(''), '*', 3, 4).join('')
};
} else {
detail.virtualGood = false;
detail.noramlPayMode = {
payMode: ChannelConfig.payType[orderDetail.payment_type],
payWay: orderDetail.payment_name,
deliverTime: orderDetail.delivery_time || ''
};
// 物流信息
detail.traceOrder = {};
detail.traceOrder.orderDate = moment.unix(orderDetail.create_time).format('YYYY.MM.DD HH:mm:ss');
let expressInfo = yield that._getExpressInfo(
orderId, uid, +orderDetail.payment_type, orderDetail.create_time, true
);
// 配送信息
detail.orderInfo = {
receiver: orderDetail.user_name,
address: orderDetail.area + orderDetail.address,
phone: _.fill(orderDetail.mobile.split(''), '*', 3, 4).join('') +
(orderDetail.phone ? ',' + _.fill(orderDetail.phone.split(''), '*', 3, 5).join('') : '')
};
detail.traceOrder.logistics = expressInfo.logistics;
if (_.get(orderDetail, 'is_offlineshops') === 'Y') {
if (_.get(orderDetail, 'is_delivery_offline') === 'Y') {
detail.orderInfo.offlineBySelf = true;
detail.offlineBySelf = true; // 进度条的处理
if (_.get(expressInfo, 'logistics[0]')) {
detail.hastrace = true;
} else {
detail.orderInfo.offlineByExpress = true;
detail.hastrace = false;
}
detail.offline = true;
detail.orderInfo.offlineStore = _.get(orderDetail, 'offline_store', '');
} else {
detail.orderInfo.normal = true;
}
detail.editInfo = {
userName: orderDetail.user_name,
address: orderDetail.address,
areaCode: orderDetail.area_code,
mobile: orderDetail.mobile,
phoneNum: _.nth(_.split(orderDetail.phone), 0) || '',
phoneCode: _.nth(_.split(orderDetail.phone), 1) || ''
};
}
detail.traceOrder.logisticsCompany = expressInfo.logisticsCompany;
detail.traceOrder.courierNumbe = expressInfo.courierNumbe;
// 商品信息
if (orderDetail.order_goods) {
detail.goods = _.get(orderDetail, 'order_goods', []).map((good) => {
let newGood = {
url: helpers.getUrlBySkc(good.product_skn),
img: helpers.image(good.goods_image, 60, 60),
name: good.product_name,
color: good.factory_color_name,
size: good.size_name,
price: transPrice(good.sales_price), // 默认显示销售价
isVipPrice: good.discount_tag === 'V',
isStuPrice: good.discount_tag === 'S',
coin: good.yoho_give_coin,
num: good.buy_number,
sum: good.goods_amount,
sku: good.product_sku,
[_getGoodsTag(+orderDetail.attribute, good.goods_type)]: true
};
// 虚拟商品
if (+orderDetail.attribute === 3) {
detail.virtualGood = true;
detail.virtualPayMode = {
payMode: ChannelConfig.payType[orderDetail.payment_type],
phone: _.fill(orderDetail.mobile.split(''), '*', 3, 4).join('')
};
} else {
detail.virtualGood = false;
detail.noramlPayMode = {
payMode: ChannelConfig.payType[orderDetail.payment_type],
payWay: orderDetail.payment_name,
deliverTime: orderDetail.delivery_time || ''
};
// 配送信息
detail.orderInfo = {
receiver: orderDetail.user_name,
address: orderDetail.area + orderDetail.address,
phone: _.fill(orderDetail.mobile.split(''), '*', 3, 4).join('') +
(orderDetail.phone ? ',' + _.fill(orderDetail.phone.split(''), '*', 3, 5).join('') : '')
};
if (_.get(orderDetail, 'is_offlineshops') === 'Y') {
if (_.get(orderDetail, 'is_delivery_offline') === 'Y') {
detail.orderInfo.offlineBySelf = true;
detail.offlineBySelf = true; // 进度条的处理
} else {
detail.orderInfo.offlineByExpress = true;
}
// 划线的价格
if (+good.real_pay_price < +good.sales_price) {
newGood.price = transPrice(good.real_pay_price);// 显示分摊价
newGood.linePrice = transPrice(good.sales_price); // 划线的价格
detail.offline = true;
detail.orderInfo.offlineStore = _.get(orderDetail, 'offline_store', '');
} else {
detail.orderInfo.normal = true;
}
detail.editInfo = {
userName: orderDetail.user_name,
address: orderDetail.address,
areaCode: orderDetail.area_code,
mobile: orderDetail.mobile,
phoneNum: _.nth(_.split(orderDetail.phone), 0) || '',
phoneCode: _.nth(_.split(orderDetail.phone), 1) || ''
};
}
// 赠品、加价购
if (good.goods_type === 'gift' || good.goods_type === 'price_gift') {
newGood.price = transPrice(good.goods_price);// 显示成交价
newGood.linePrice = transPrice(good.sales_price); // 划线的价格
// 商品信息
if (orderDetail.order_goods) {
detail.goods = _.get(orderDetail, 'order_goods', []).map((good) => {
let newGood = {
url: helpers.getUrlBySkc(good.product_skn),
img: helpers.image(good.goods_image, 60, 60),
name: good.product_name,
color: good.factory_color_name,
size: good.size_name,
price: that.transPrice(good.sales_price), // 默认显示销售价
isVipPrice: good.discount_tag === 'V',
isStuPrice: good.discount_tag === 'S',
coin: good.yoho_give_coin,
num: good.buy_number,
sum: good.goods_amount,
sku: good.product_sku,
[that._getGoodsTag(+orderDetail.attribute, good.goods_type)]: true
};
// 划线的价格
if (+good.real_pay_price < +good.sales_price) {
newGood.price = that.transPrice(good.real_pay_price);// 显示分摊价
newGood.linePrice = that.transPrice(good.sales_price); // 划线的价格
}
// 赠品、加价购
if (good.goods_type === 'gift' || good.goods_type === 'price_gift') {
newGood.price = that.transPrice(good.goods_price);// 显示成交价
newGood.linePrice = that.transPrice(good.sales_price); // 划线的价格
}
return newGood;
});
}
return newGood;
});
}
// 详情页-订单付费详情
if (orderDetail.promotion_formulas) {
detail.orderBalance = _.get(orderDetail, 'promotion_formulas', []).map((promotion) => {
return {
promotion: promotion.promotion,
account: promotion.promotion_amount
};
});
// 详情页-订单付费详情
if (orderDetail.promotion_formulas) {
detail.orderBalance = _.get(orderDetail, 'promotion_formulas', []).map((promotion) => {
return {
promotion: promotion.promotion,
account: promotion.promotion_amount
};
});
detail.orderBalance.push({
promotion: '实际应支付',
account: orderDetail.amount
});
}
detail.orderBalance.push({
promotion: '实际应支付',
account: orderDetail.amount
});
}
// 发票
if (orderDetail.invoice) {
detail.invoiceMode = true;
detail.invoiceType = (+_.get(orderDetail, 'invoice.type', 0)) === 2 ? '电子发票' : '纸质发票';
detail.showInvoice = _.get(orderDetail, 'invoice.showInvoice');
detail.pdfUrl = detail.showInvoice ? _.get(orderDetail, 'invoice.pdfUrl') : '';
detail.title = _.get(orderDetail, 'invoice.title') || '';
detail.contentValue = _.get(orderDetail, 'invoice.contentValue') || '个人';
}
// 发票
if (orderDetail.invoice) {
detail.invoiceMode = true;
detail.invoiceType = (+_.get(orderDetail, 'invoice.type', 0)) === 2 ? '电子发票' : '纸质发票';
detail.showInvoice = _.get(orderDetail, 'invoice.showInvoice');
detail.pdfUrl = detail.showInvoice ? _.get(orderDetail, 'invoice.pdfUrl') : '';
detail.title = _.get(orderDetail, 'invoice.title') || '';
detail.contentValue = _.get(orderDetail, 'invoice.contentValue') || '个人';
}
detail.totalYoho = orderDetail.yoho_give_coin;
detail.yohoCoinUrl = helpers.urlFormat('/help/detail', {id: 105}); // 有货币介绍
detail.remark = orderDetail.remark;
detail.operation = that._getOrderDetailOp(
orderDetail.order_code, +orderDetail.payment, +orderDetail.status,
orderDetail.is_cancel, orderDetail.payment_status, orderDetail.payment_type,
+orderDetail.order_type, +orderDetail.attribute, +orderDetail.refund_status
);
detail.packageTitle = orderDetail.package_title;
detail.packages = that._getPackageInfo(orderDetail);
// 判断是否可以修改地址
if (orderDetail.can_update_delivery_address === 'Y') {
detail.changeable = true;
}
detail.totalYoho = orderDetail.yoho_give_coin;
detail.yohoCoinUrl = helpers.urlFormat('/help/detail', {id: 105}); // 有货币介绍
detail.remark = orderDetail.remark;
detail.operation = _getOrderDetailOp(orderDetail.order_code, +orderDetail.payment, +orderDetail.status,
orderDetail.is_cancel, orderDetail.payment_status, orderDetail.payment_type,
+orderDetail.order_type, +orderDetail.attribute, +orderDetail.refund_status);
// 判断是否可以修改省份
if (orderDetail.is_support_change_province === 'N') {
detail.changeProvince = true;
}
detail.packageTitle = orderDetail.package_title;
detail.packages = _getPackageInfo(orderDetail);
return detail;
}
})();
}
// 判断是否可以修改地址
if (orderDetail.can_update_delivery_address === 'Y') {
detail.changeable = true;
}
// 判断是否可以修改省份
if (orderDetail.is_support_change_province === 'N') {
detail.changeProvince = true;
}
closeReason() {
return new OrderApi(this.ctx).closeReasons().then((result) => {
return _.get(result, 'data', []);
});
}
return detail;
refundReason() {
return new OrderApi(this.ctx).refundReason().then((result) => {
return _.get(result, 'data', []);
});
}
});
const updateDeliveryAddress = orderApi.updateDeliveryAddress;
detail(uid, orderId) {
let that = this;
const confirm = orderApi.confirmUserOrder;
return co(function * () {
let apiData = yield Promise.props({
detailData: that._getOrderDetail(uid, orderId),
reason: that.closeReason()
});
const cancel = orderApi.cancelUserOrder;
if (apiData.detailData.code === 400) {
return {};
}
const closeReason = () => {
return orderApi.closeReasons().then((result) => {
return _.get(result, 'data', []);
});
};
return {
detail: apiData.detailData,
package: apiData.detailData.package,
cancelReason: apiData.reason
};
})();
}
const refundReason = () => {
return orderApi.refundReason().then((result) => {
return _.get(result, 'data', []);
});
};
updateDeliveryAddress(...params) {
return new OrderApi(this.ctx).updateDeliveryAddress(...params);
}
const refund = orderApi.refund;
confirm(...params) {
return new OrderApi(this.ctx).confirmUserOrder(...params);
}
const detail = co(function * (uid, orderId) {
let apiData = yield Promise.props({
detailData: _getOrderDetail(uid, orderId),
reason: closeReason()
});
cancel(...params) {
return new OrderApi(this.ctx).cancelUserOrder(...params);
}
if (apiData.detailData.code === 400) {
return {};
refund(...params) {
return new OrderApi(this.ctx).refund(...params);
}
return {
detail: apiData.detailData,
package: apiData.detailData.package,
cancelReason: apiData.reason
};
});
const express = _.partial(_getExpressInfo, _, _, _, _, true);
module.exports = {
index,
ORDER_TYPE,
reBuy,
del,
updateDeliveryAddress,
confirm,
cancel,
detail,
getOrders,
closeReason,
express,
refund,
refundReason
express(orderCode, uid, paymentType, createTime) {
return this._getExpressInfo(orderCode, uid, paymentType, createTime, true);
}
};
... ...
... ... @@ -5,259 +5,258 @@
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取订单退货信息
*/
const getRefundGoodsAsync = (orderCode, uid) => {
return api.get('', {
method: 'app.refund.goodsList',
order_code: orderCode,
uid: uid
}, {code: 200});
};
/**
* 获取订单退货信息
*/
getRefundGoodsAsync(orderCode, uid) {
let options = {
method: 'app.refund.goodsList',
order_code: orderCode,
uid: uid
};
/**
* 获取退货详情
*/
const getRefundDetailAsync = (id, uid) => {
return api.get('', {
method: 'app.refund.detail',
id: id,
uid: uid
}, {code: 200});
};
return this.get({data: options, param: {code: 200}});
}
/**
* 获取换货详情
*/
const getChangeDetailAsync = (id, uid) => {
return api.get('', {
method: 'app.change.detail',
id: id,
uid: uid
}, {code: 200});
};
/**
* 获取退货详情
*/
getRefundDetailAsync(id, uid) {
let options = {
method: 'app.refund.detail',
id: id,
uid: uid
};
/**
* 获取订单换货信息
*/
const getExchangeGoodsAsync = (orderCode, uid) => {
return api.get('', {
method: 'app.change.goodsList',
order_code: orderCode,
uid: uid
}, {code: 200});
};
return this.get({data: options, param: {code: 200}});
}
/**
* 获取商品信息
*/
const getProductDataAsync = (skn) => {
return api.get('', {
method: 'app.product.data',
product_skn: skn
}, {code: 200});
};
/**
* 获取换货详情
*/
getChangeDetailAsync(id, uid) {
let options = {
method: 'app.change.detail',
id: id,
uid: uid
};
/**
* 快递公司列表
*/
const getExpressCompanyAsync = () => {
return api.get('', {
method: 'app.express.getExpressCompany'
}, {code: 200});
};
return this.get({data: options, param: {code: 200}});
}
/**
* 取消退货申请
* @param $id
* @param $uid
* @return mixed
*/
const cancelRefundAsync = (id, uid) =>{
/**
* 获取订单换货信息
*/
getExchangeGoodsAsync(orderCode, uid) {
let options = {
method: 'app.change.goodsList',
order_code: orderCode,
uid: uid
};
let options = {
method: 'app.refund.cancel',
id: id,
uid: uid
};
return this.get({data: options, param: {code: 200}});
}
return api.post('', options);
};
/**
* 获取商品信息
*/
getProductDataAsync(skn) {
let options = {
method: 'app.product.data',
product_skn: skn
};
/**
* 取消换货申请
* @param $id
* @param $uid
* @return mixed
*/
const cancelChangeAsync = (id, uid) =>{
return this.get({data: options, param: {code: 200}});
}
let options = {
method: 'app.change.cancel',
id: id,
uid: uid
};
/**
* 快递公司列表
*/
getExpressCompanyAsync() {
let options = {
method: 'app.express.getExpressCompany'
};
return api.post('', options);
};
return this.get({data: options, param: {code: 200}});
}
/**
* 设置快递
* @param $id
* @param $expressId
* @param $expressNumber
* @param $uid
* @param $expressCompany
* @param $isChange
* @return mixed
*/
const setExpressNumberAsync = (id, expressId, expressNumber, uid, expressCompany, isChange) =>{
let options = {
method: isChange ? 'app.change.setexpress' : 'app.refund.setexpress',
id: id,
express_id: expressId,
express_number: expressNumber,
uid: uid,
express_company: expressCompany
};
return api.post('', options);
};
/**
* 取消退货申请
* @param $id
* @param $uid
* @return mixed
*/
cancelRefundAsync(id, uid) {
/**
* save退货申请
* @param $orderCode
* @param $uid
* @param $goods
* @param $payment
* @return mixed
*/
const refundSubmit = (orderCode, uid, goods, payment) =>{
let options = {
method: 'app.refund.cancel',
id: id,
uid: uid
};
let options = {
method: 'app.refund.submit',
order_code: orderCode,
uid: uid,
goods: goods,
payment: payment
};
return this.post({data: options});
}
return api.post('', options);
};
/**
* 取消换货申请
* @param $id
* @param $uid
* @return mixed
*/
cancelChangeAsync(id, uid) {
/**
* save换货申请
* @param $orderCode
* @param $goods
* @param $consigneeName
* @param $areaCode
* @param $address
* @param $mobile
* @param $zipCode
* @param $deliveryType
* @param $uid
* @return mixed
*/
const exchangeSubmit = (orderCode, goods, consigneeName, areaCode, address, mobile, zipCode, deliveryType, uid) =>{
let options = {
method: 'app.change.submit',
order_code: orderCode,
uid: uid,
goods: goods,
consignee_name: consigneeName,
area_code: areaCode,
address: address,
mobile: mobile,
zip_code: zipCode,
delivery_tpye: deliveryType
};
return api.post('', options);
};
let options = {
method: 'app.change.cancel',
id: id,
uid: uid
};
/**
* 获取换货方式
* @param $uid
* @param $areaCode
* @param $gender
* @param $yhChannel
* @return mixed
*/
const getDeliveryAsync = (areaCode, uid, gender, channel) => {
return this.post({data: options});
}
let options = {
method: 'app.change.getDelivery',
uid: uid,
area_code: areaCode,
gender: gender,
yh_channel: channel
};
/**
* 设置快递
* @param $id
* @param $expressId
* @param $expressNumber
* @param $uid
* @param $expressCompany
* @param $isChange
* @return mixed
*/
setExpressNumberAsync(id, expressId, expressNumber, uid, expressCompany, isChange) {
return api.post('', options);
};
let options = {
method: isChange ? 'app.change.setexpress' : 'app.refund.setexpress',
id: id,
express_id: expressId,
express_number: expressNumber,
uid: uid,
express_company: expressCompany
};
/**
* 发送站内信
* @param int $uid
* @param string $title
* @param int $content
* @param int $type
* @param string $verify_key
* @param int $send_uid
* @param string $call_back
* @return array
*/
const sendMessage = (uid, title, content, type, verifyKey, sendUid) =>{
let options = {
method: 'web.inbox.setSingleMessage',
uid: uid,
send_uid: sendUid || 0,
verify_key: verifyKey || '',
content: content,
title: title,
type: type || 1
};
return api.post('', options);
};
return this.post({data: options});
}
/**
* [退货结算]
* @param {[type]} uid [uid]
* @param {[type]} orderCode [订单号]
* @param {[type]} goods [商品详细]
* @return {[type]} [{}]
*/
const refundComputeAsync = (uid, orderCode, goods) => {
let options = {
method: 'app.refund.compute',
order_code: orderCode,
uid: uid,
goods: goods
};
return api.get('', options);
};
/**
* save退货申请
* @param $orderCode
* @param $uid
* @param $goods
* @param $payment
* @return mixed
*/
refundSubmit(orderCode, uid, goods, payment) {
let options = {
method: 'app.refund.submit',
order_code: orderCode,
uid: uid,
goods: goods,
payment: payment
};
return this.post({data: options});
}
/**
* save换货申请
* @param $orderCode
* @param $goods
* @param $consigneeName
* @param $areaCode
* @param $address
* @param $mobile
* @param $zipCode
* @param $deliveryType
* @param $uid
* @return mixed
*/
exchangeSubmit(orderCode, goods, consigneeName, areaCode, address, mobile, zipCode, deliveryType, uid) {
let options = {
method: 'app.change.submit',
order_code: orderCode,
uid: uid,
goods: goods,
consignee_name: consigneeName,
area_code: areaCode,
address: address,
mobile: mobile,
zip_code: zipCode,
delivery_tpye: deliveryType
};
return this.post({data: options});
}
/**
* 获取换货方式
* @param $uid
* @param $areaCode
* @param $gender
* @param $yhChannel
* @return mixed
*/
getDeliveryAsync(areaCode, uid, gender, channel) {
let options = {
method: 'app.change.getDelivery',
uid: uid,
area_code: areaCode,
gender: gender,
yh_channel: channel
};
return this.post({data: options});
}
/**
* 发送站内信
* @param int $uid
* @param string $title
* @param int $content
* @param int $type
* @param string $verify_key
* @param int $send_uid
* @param string $call_back
* @return array
*/
sendMessage(uid, title, content, type, verifyKey, sendUid) {
let options = {
method: 'web.inbox.setSingleMessage',
uid: uid,
send_uid: sendUid || 0,
verify_key: verifyKey || '',
content: content,
title: title,
type: type || 1
};
return this.post({data: options});
}
/**
* [退货结算]
* @param {[type]} uid [uid]
* @param {[type]} orderCode [订单号]
* @param {[type]} goods [商品详细]
* @return {[type]} [{}]
*/
refundComputeAsync(uid, orderCode, goods) {
let options = {
method: 'app.refund.compute',
order_code: orderCode,
uid: uid,
goods: goods
};
module.exports = {
getRefundGoodsAsync,
refundSubmit,
exchangeSubmit,
sendMessage,
getRefundDetailAsync,
getExchangeGoodsAsync,
getChangeDetailAsync,
getProductDataAsync,
getExpressCompanyAsync,
cancelRefundAsync,
cancelChangeAsync,
getDeliveryAsync,
setExpressNumberAsync,
refundComputeAsync
return this.get({data: options});
}
};
... ...