NewSaleProcess.php
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Plugin\DataProcess;
use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;
/**
* 新品到着、折扣专区数据处理类
*/
class NewSaleProcess
{
/**
* 处理新品到着、折扣专区数据
*
* @param array $products 接口传回的数据
* @return array 处理之后的数据
*/
public static function newSaleData($products)
{
$result = array();
// 处理Tabs
if (isset($products['tabs'])) {
$result['tabs'] = array();
foreach ($products['tabs'] as $key => $one) {
$tabItem = array();
$tabItem['title'] = $one;
$tabItem['dataId'] = $key;
if ($key === 1) {
$tabItem['focus'] = true;
}
$result['tabs'][] = $tabItem;
}
}
// 处理Filter
if(isset($products['filter'])) {
$result['filter'] = ListProcess::getFilterData($products['filter']);
}
// 处理商品
if (isset($products['product_list'])) {
foreach ($products['product_list'] as $single) {
$result['goods'][] = Helpers::formatProduct($single, true, false, false, 290, 388);
}
}
return $result;
}
/**
* 处理热销排行榜数据
*
* @param array $products 接口传回的数据
* @param boolean $notab 是否传回tab数据
* @param int $limit 查询返回的最大限制数
* @param int $page 分页第几页
* @return array 处理之后的数据
*/
public static function topData($products, $notab, $limit, $page)
{
$result = array();
// 处理Tabs
if (!$notab && isset($products['tabs'])) {
$result['tabs'] = array();
foreach ($products['tabs'] as $key => $one) {
$tabItem = array();
$tabItem['title'] = $one;
$tabItem['dataId'] = $key;
if ($key === 0) {
$tabItem['focus'] = true;
}
$result['tabs'][] = $tabItem;
}
}
// 处理商品
if (isset($products['product_list'])) {
$count = count($products['product_list']);
$one = array();
foreach ($products['product_list'] as $key => $single) {
$one = Helpers::formatProduct($single, true, false, false, 75, 114);
$one['rank'] = $limit * ($page -1) + $key + 1;
!empty($single['sales_phrase']) && $one['sales_phrase'] = $single['sales_phrase'];
$result['goods'][] = $one;
}
}
return $result;
}
}