感觉很累赘~~
目的:
1、通过分析订单,统计出每款产品,每天的销量; 2、订单来源于:正常订单和品牌特买两个渠道; 3、区分显示各渠道的数值,”特买“为橙色字体; 4、如果同时存在,则显示综合,通过 tooltip 提示构成;
数据:
{
12372336825 => {
:name => 'WR574AGD',
:sale => {:num => 1, :payment => 383.3}
},
12661562424 => {
:name => 'AWHF0330',
:total => {:num => 1, :payment => 80.0}
},
12818935599 => {
:name => 'AWAT1114',
:sale => {:num => 2, :payment => 160.0},
:total => {:num => 1, :payment => 80.0}
},
}
代码:
def parse_sales(data, field = :num, round = 0)
if data.has_key?(:sale) # 品牌特买
sale = data[:sale][field].round(round)
sale_tag = content_tag(:font, sale, style: 'color: #F89406;')
end
# 普通订单
total = data[:total][field].round(round) if data.has_key?(:total)
case
when (sale && total)
content_tag(:a, (sale + total), rel: 'tooltip', title: "#{total} + 特买(#{sale})")
when sale
sale_tag
else
total
end
end
输出成: