Authored by 郭成尧

'订单列表数据已出'

@@ -48,9 +48,10 @@ exports.getOrders = (req, res, next) => { @@ -48,9 +48,10 @@ exports.getOrders = (req, res, next) => {
48 yh_channel: req.query.channel || 1, 48 yh_channel: req.query.channel || 1,
49 uid: req.user.uid || 8039759 // TODO 待删除 49 uid: req.user.uid || 8039759 // TODO 待删除
50 }).then(result => { 50 }).then(result => {
  51 + console.log(result);
51 res.render('order-content', { 52 res.render('order-content', {
52 layout: false, 53 layout: false,
53 - order: result 54 + orders: result
54 }); 55 });
55 }).catch(next); 56 }).catch(next);
56 }; 57 };
@@ -6,6 +6,78 @@ const camelCase = global.yoho.camelCase; @@ -6,6 +6,78 @@ const camelCase = global.yoho.camelCase;
6 const _ = require('lodash'); 6 const _ = require('lodash');
7 7
8 /** 8 /**
  9 + * 门票
  10 + * @type {{SINGLE_TICKETS_SKN: number}}
  11 + */
  12 +const TICKETS = {
  13 + SINGLE_TICKETS_SKN: 51335912, // 展览票(单日票)skn
  14 + PACKAGE_TICKETS_SKN: 51335908 // 套票skn
  15 +};
  16 +
  17 +/**
  18 + * 格式化订单商品
  19 + * @private
  20 + */
  21 +const _formatOrderGoods = (orderGoods, count, haveLink, tickets) => {
  22 + let result = [];
  23 +
  24 + _.forEach(orderGoods, value => {
  25 + let goods = {
  26 + thumb: value.goods_image,
  27 + name: value.product_name,
  28 + color: value.color_name,
  29 + size: value.size_name,
  30 + price: value.goods_price,
  31 + count: value.buy_number
  32 + };
  33 +
  34 + /* gift=>是否赠品,advanceBuy=>是否加价购 */
  35 + if (value.goods_type === 'gift') {
  36 + Object.assign(goods, {
  37 + gift: true
  38 + });
  39 + } else if (value.goods_type === 'price_gift') {
  40 + Object.assign(goods, {
  41 + advanceBuy: true
  42 + });
  43 + }
  44 +
  45 + /* 上市期 */
  46 + if (value.expect_arrival_time) {
  47 + Object.assign(goods, {
  48 + appearDate: value.expect_arrival_time
  49 + });
  50 + }
  51 +
  52 + /* 商品链接 */
  53 + if (haveLink && value.product_skn) {
  54 + Object.assign(goods, {
  55 + link: helpers.urlFormat('/product/show_' + value.product_skn + '.html')
  56 + });
  57 + }
  58 +
  59 + /* 累计购买数 */
  60 + count += parseInt(value.buy_number, 10);
  61 +
  62 + /* 门票 */
  63 + if (tickets) {
  64 +
  65 + /* 展览票不显示区域 */
  66 + if (value.product_skn === TICKETS.SINGLE_TICKETS_SKN) {
  67 + delete goods.size;
  68 + }
  69 + Object.assign(goods, {
  70 + tickets: true
  71 + });
  72 + }
  73 +
  74 + result.push(goods);
  75 + });
  76 +
  77 + return result;
  78 +};
  79 +
  80 +/**
9 * 获取快递有关信息 81 * 获取快递有关信息
10 * @private 82 * @private
11 */ 83 */
@@ -205,14 +277,46 @@ const getOrders = (params) => { @@ -205,14 +277,46 @@ const getOrders = (params) => {
205 277
206 return _getOrderData(params).then(result => { 278 return _getOrderData(params).then(result => {
207 if (result.data && result.data.page_total && params.page <= result.data.page_total && result.data.order_list) { 279 if (result.data && result.data.page_total && params.page <= result.data.page_total && result.data.order_list) {
  280 + let count = 0;
  281 +
208 _.forEach(result.data.order_list, value => { 282 _.forEach(result.data.order_list, value => {
  283 +
  284 + /* 订单件数清零 */
  285 + count = 0;
209 let perOrder = _getOrderStatus(value); 286 let perOrder = _getOrderStatus(value);
210 287
  288 + /* 是否是虚拟商品 */
  289 + let isTickets = order.virtual_type && parseInt(order.virtual_type, 10) === 3;
  290 +
  291 + Object.assign(perOrder, {
  292 + orderNum: value.order_code,
  293 + orderStatus: value.status_str,
  294 + sumCost: value.amount,
  295 + goods: _formatOrderGoods(value.order_goods, count, false, isTickets),
  296 + detailUrl: helpers.urlFormat('/home/orderdetail', {order_code: value.order_code}),
  297 + count: count,
  298 + isVirtual: isTickets
  299 + });
  300 +
  301 + /* 如果运费大于0,会显示运费 */
  302 + if (parseFloat(value.shipping_cost) > 0) {
  303 + Object.assign(perOrder, {
  304 + shippingCost: value.shipping_cost
  305 + });
  306 + }
  307 +
  308 + /* 倒计时时间 */
  309 + if (value.counter_flag && value.counter_flag === 'Y') {
  310 + Object.assign(perOrder, {
  311 + leftTime: parseInt(value.pay_lefttime, 10) * 1000
  312 + });
  313 + }
  314 +
211 finalResult.push(perOrder); 315 finalResult.push(perOrder);
212 }); 316 });
213 } 317 }
214 318
215 - return finalResult; 319 + return camelCase(finalResult);
216 }); 320 });
217 }; 321 };
218 322
  1 +<div class="order-good" data-id="{{id}}">
  2 + <div class="thumb-wrap">
  3 + {{#if link}}
  4 + <a href="{{link}}"><img class="thumb lazy" data-original="{{image thumb 90 120}}"></a>
  5 + {{else}}
  6 + <img class="thumb lazy" data-original="{{image thumb 90 120}}">
  7 + {{/if}}
  8 + <p class="tag{{#if gift}} gift-tag{{/if}}{{#if advanceBuy}} advance-buy-tag{{/if}}"></p>
  9 + </div>
  10 + <div class="deps">
  11 + <p class="name row">{{name}}</p>
  12 + <p class="row">
  13 + {{#if color}}
  14 + <span class="color">
  15 + {{#if tickets}}日期{{else}}颜色{{/if}}:{{color}}
  16 + </span>
  17 + {{/if}}
  18 +
  19 + {{#if size}}
  20 + <span class="size">
  21 + {{#if tickets}}区域{{else}}尺码{{/if}}:{{size}}
  22 + </span>
  23 + {{/if}}
  24 + </p>
  25 + <p class="row price-wrap">
  26 + <span class="price">
  27 + ¥{{price}}
  28 + </span>
  29 + <span class="count">
  30 + ×{{count}}
  31 + </span>
  32 + {{#if appearDate}}
  33 + <span class="appear-date">上市期:{{appearDate}}</span>
  34 + {{/if}}
  35 + </p>
  36 + </div>
  37 +</div>
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 </header> 5 </header>
6 <section class="order-goods"> 6 <section class="order-goods">
7 {{# goods}} 7 {{# goods}}
8 - {{> me/order/good}} 8 + {{> order/good}}
9 {{/ goods}} 9 {{/ goods}}
10 </section> 10 </section>
11 <footer class="footer"> 11 <footer class="footer">