router.js 9.38 KB
/**
 * router of sub app product
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2016/05/06
 */

'use strict';

const router = require('express').Router(); // eslint-disable-line

const auth = require('../../doraemon/middleware/auth');
const rewrite = require('../../doraemon/middleware/rewrite');
const cors = require('../../doraemon/middleware/cors');
const cRoot = './controllers';

// 商品详情controller
const detail = require(`${cRoot}/detail`);
const newDetail = require(`${cRoot}/new-detail`);

// sale controller
const sale = require(`${cRoot}/sale`);

// outlet controller
const outlet = require(`${cRoot}/outlet`);

// recommend-for-you controller
const recommendForYou = require(`${cRoot}/recommend-for-you`);

// search controller
const search = require(`${cRoot}/search`);

// 品类|品牌|店铺 controller
const list = require(`${cRoot}/list`);

// 新品到着 controller
const news = require(`${cRoot}/new`);

// 热销排行榜
const newsale = require(`${cRoot}/newsale`);

// recom
const recom = require(`${cRoot}/recom`);

// 秒杀 controller
const seckill = require(`${cRoot}/seckill`);

// 秒杀商品详情controller
const seckillDetail = require(`${cRoot}/seckill-detail`);

const newShop = require(`${cRoot}/new-shop`);

// 套装
const bundle = require(`${cRoot}/bundle`);

// 全球购
const globalPro = require(`${cRoot}/global`);

// 找相似
const similar = require(`${cRoot}/similar`);

// seo推广
const chanpin = require(`${cRoot}/chanpin`);
const newRecommend = require(`${cRoot}/new-recommend`);

// routers

// /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html

// 因为正则匹配原因,秒杀详情页路由要放在普通详情页前面,待解决
router.get(/^\/seckill\/show_([\d]+)/, seckillDetail.index); // 秒杀商品详情页 SKN 进入
router.get(/^\/seckill\/pro_([\d]+)_([\d]+)/, seckillDetail.index); // 秒杀商品详情页进入
router.get(/^\/pro_([\d]+)_([\d]+)/, newDetail.indexRedirect); // 商品详情页
// /show_51047967.html
router.get(/^\/show_([\d]+)/, newDetail.indexRedirect); // 商品详情页 SKN 进入
router.get(/^\/(\d+)\.html/, newDetail.index); // 商品详情页 SKN 进入 SEO优化

router.get('/detail/sknData.json', newDetail.sknData); // 商品咨询,评价,店铺
router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页
router.get('/detail/preference', detail.preference); // 为你优选
router.get('/detail/consults', detail.consults); // 商品咨询页
router.get('/detail/consultform', auth, detail.consultform); // 商品咨询表单页
router.get('/detail/comments', detail.comments); // 商品评价
router.get('/detail/newinfo', detail.getUser, newDetail.indexData); // 商品详情页-异步数据 (优化)
router.post('/detail/consultsubmit', auth, detail.consultsubmit); // 商品咨询提交接口


router.get('/detail/coupon.json', detail.brandCoupon); // 品牌券
router.post('/detail/coupon/save.json', auth, detail.getCoupon); // 获得 品牌券

router.get('/recom/maylike', recom.mayLike); // 你可能喜欢


// 限定商品
router.get('/detail/limit', detail.limit);

router.get('/recom/maylike', recom.mayLike);// 你可能喜欢
router.get('/recom/maylikekids', recom.mayLikeKids); // 潮童你可能喜欢
router.get('/recom/maylikelife', recom.mayLikelife); // 创意生活你可能喜欢

router.get('/seckillDetail/seckillData/:productskn', seckillDetail.getSeckillData); // 秒杀数据接口

router.post('/detail/consultupvote', detail.consultUpvoteOrUseful); // 商品咨询提交接口
router.post('/detail/consultuseful', detail.consultUpvoteOrUseful); // 商品咨询提交接口

router.get('/sale', rewrite.channel, sale.indexRedirect);
router.get('/sale/((breakingYards)?(vip)?(discount(/detail)?)?)', rewrite.channel, sale.indexRedirect);

router.get('/:channel-sale/discount/detail(/:pathParams)?',
    rewrite.resolve,
    rewrite.resolvePathParams,
    sale.discountDetail);
router.get('/:channel-sale/breakingYards(/:pathParams)?',
    rewrite.resolve,
    rewrite.resolvePathParams,
    sale.breakingYards);
router.get('/:channel-sale/vip(/:pathParams)?',
    rewrite.resolve,
    rewrite.resolvePathParams,
    sale.vip);
router.get('/:channel-sale/discount', rewrite.resolve, sale.discount);
router.get('/:channel-sale(/)?(*)?', rewrite.resolve, sale.index);

router.get('/sale/discount', sale.discount);
router.get('/sale/discount/detail', sale.discountDetail);
router.get('/sale/breakingYards', sale.breakingYards);
router.get('/sale/vip', sale.vip);
router.get('/sale/discount/getTime', sale.getTime);
router.get('/sale/search', rewrite.resolvePathParamsAjax, sale.search);
router.get('/sale/filter', sale.filter);

router.get('/outlet', outlet.index);
router.get('/outlet/activity', outlet.activityDetail);
router.get('/outlet/activityTime', outlet.activityTime);
router.get('/outlet/activityinfo', outlet.activityList);

router.get('/recommend-for-you/userCenter', recommendForYou.userCenter);
router.get('/recommend-for-you/cart', recommendForYou.cart);

router.get('/seckill', seckill.index); // 秒杀列表页
router.get('/seckill/list', seckill.indexData);
router.post('/seckill/remind', seckill.remind); // only app; 秒杀提醒
router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表根据活动id获取商品列表

router.get('/search', search.index); // 搜索主页
router.get('/search/list', rewrite.resolvePathParams, search.list); // 搜索落地页
router.get('/search/filter', rewrite.resolvePathParamsAjax, search.filter); // filter
router.get('/search/fuzzyDatas', search.fuzzyDatas); // fuzzyDatas
router.get('/search/search', rewrite.resolvePathParamsAjax, search.search); // ajax 请求商品数据

router.get('/search/so/:query.html', rewrite.sortParams, chanpin.keyword); // 推广落地页
router.get('/search/chanpin/:id.html', rewrite.sortParams, chanpin.keyId);
router.get('/search/chanpin/goods', chanpin.searchGoods); // 搜索的商品
router.get('/search/brand/goods', search.searchBrandGoods); // 搜索品牌下的商品
router.get('/search/shop/goods', search.searchShopGoods); // 搜索店铺下的商品

router.get('/list/global(/:pathParams)?', rewrite.resolvePathParams, globalPro.list); // 全球购路由重写 全球购列表页

// router.get('/index/index', rewrite.sortParams, list.category); // 旧 品类首页
// router.get('/list/index', rewrite.sortParams, list.category); // 旧 兼容 PC 的链接

router.get('/list(/:pathParams)?', rewrite.resolvePathParams, list.listNew); // 列表新的 URL
router.get('/search/category',
    cors,
    rewrite.resolvePathParamsAjax,
    list.getCategoryGoods);

// 品牌 | 店铺
router.get('/index/shopAppCookie', list.shopAppCookie);
router.get('/index/shopFav', list.shopFav);
router.get('/index/category', list.shopCategory);
router.get('/index/getBrandCouponsList', list.getBrandCouponsList);

router.get('/shop', newShop.redirect); // 老路由重定向前置处理
router.get('/shop/:domain-:shop_id.html', newShop.entry); // 新入口
router.get('/shop/:domain-(:shop_id)(/:pathParams)?', rewrite.resolvePathParams, newShop.goodsList); // 店铺商品列表
router.get('/shop/goodslist',
    cors,
    rewrite.resolveShopPathParamsAjax,
    newShop.goodsListAjax); // 店铺商品列表异步查询

router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller
router.get('/index/brandFav', newShop.brandFav);
router.get('/new/shop/hotlist', newShop.shopHotList);
router.get('/index/getShopCouponsList', cors, newShop.getShopCouponsList);
router.post('/index/userCoupon', cors, newShop.userCoupon);
router.get('/red-shop', newShop.redShop); // 红人店铺
router.get('/index/intro', list.shopIntro); // 店铺介绍
router.get('/opt/favoriteBrand', list.favoriteBrand); // 品牌|店铺收藏|取消收藏
router.get('/index/allBrand', newShop.allBrand); // 店铺全部品牌

// 新品到着
router.get('/new', rewrite.channel, news.newGoodsRedirect);

// 新品到着 SEO优化
router.get('/:channel-new(/:pathParams)?', rewrite.resolve, rewrite.resolvePathParams, news.newGoods);
router.get('/list/new', news.newGoods); // 兼容 PC 的链接
router.get('/new/selectNewSale', rewrite.resolvePathParamsAjax, news.selectNewSale);
router.get('/new/filter', rewrite.resolvePathParamsAjax, news.filter);
router.get('/newnew', news._newGoods); // TODO: repleace /new
router.get('/new/recommend-shop.json', news.recommendShop);
router.get('/new/goods.json', news.fetchNew);
router.get('/new/goods-filter', news.goodsFilter);
router.get('/new/shops', news.brands);

// 新品到着(blk)
router.get('/blknew', news.blkNewGoods);

router.get('/newsale/hotrank', newsale.index); // 热销排行榜
router.get('/newsale/selectHotrank', newsale.selectHotrank); // 热销排行榜

router.get('/bundle/detail', bundle.detail); // 套装详情页
router.post('/bundle/cart/add', bundle.addToCart); // 套装加入购物车

router.post('/opt/favoriteProduct', newDetail.favoriteProduct); // 商品收藏、取消收藏
router.get('/detail/limitHelp', newDetail.limitHelp);

router.get('/global/list', globalPro.redirect); // 全球购列表页
router.get('/global/search', rewrite.resolvePathParamsAjax, globalPro.search); // 全球购列表页搜索数据
router.get(/^\/global\/(\d+)\.html/, globalPro.detail); // 全球购店铺详情页
router.get('/global/gethtml', globalPro.gethtml); // 全球购商品信息

router.get('/similar', similar.index); // 找相似

router.get('/new-recommend/getRecommend', newRecommend.getRecommend); // 新为你优选

module.exports = router;