Blame view

apps/service/models/im.js 1.12 KB
陈轩 authored
1 2
'use strict';
陈轩 authored
3 4
const _ = require('lodash');
陈轩 authored
5 6 7 8 9 10 11
/**
 *  im 接口数据的 处理
 */

/**
 *  function: 处理 订单返回的数据
 */
陈轩 authored
12
exports.handleOrderList = (data, w, h) => {
陈轩 authored
13
    if (_.isEmpty(data)) {
陈轩 authored
14 15 16
        return;
    }
陈轩 authored
17
    function replaceWH(img) {
18
        return img.replace(/(^https?:|\{width\}|\{height\})/g, function($0) {
陈轩 authored
19 20
            const dict = {
                '{width}': w,
21 22 23
                '{height}': h,
                'http:': '',
                'https:': ''
陈轩 authored
24 25 26 27 28 29
            };

            return dict[$0];
        });
    }
陈轩 authored
30 31 32 33 34
    data.forEach(order => {
        order.goods = order.ordersGoodsBoList.map(good => {
            return {
                id: good.productSku,
                name: good.productName,
陈轩 authored
35
                thumb: replaceWH(good.imgUrl),
陈轩 authored
36 37 38
                color: good.colorName,
                size: good.sizeName,
                count: good.buyNumber,
陈轩 authored
39 40
                price: good.lastPrice,
                tariffPrice: good.tariffPrice
陈轩 authored
41 42 43 44 45 46 47
            };
        });
        order.count = order.ordersGoodsBoList.reduce((sum, good) => {
            return sum + good.buyNumber;
        }, 0);
    });
};