Detail.php
6.99 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
namespace Product;
use LibModels\Wap\Product\DetailData;
use Plugin\Helpers;
/**
* 商品详情页模板相关的数据模型
*
* @name DetailModel
* @package Product
* @copyright yoho.inc
* @version 1.0 (2015-11-19 10:49:36)
* @author fei.hong <fei.hong@yoho.cn>
*/
class DetailModel
{
/**
* 商品基本信息
*
* @param int $productId 商品ID
* @param int $goodsId 某个颜色的商品
* @param int $uid 当前登录用户ID, 未登录为0
* @return array
*/
public static function getBaseInfo($productId, $goodsId, $uid)
{
$result = array();
if (is_numeric($productId) && is_numeric($goodsId)) {
// 调用接口
$baseInfo = DetailData::baseInfo($productId, $uid);
// 商品名称
if (isset($baseInfo['productName'])) {
$result['goodsName'] = $baseInfo['productName'];
}
// 商品价格
if (isset($baseInfo['productPriceBo'])) {
$result['goodsPrice'] = array();
$result['goodsPrice']['currentPrice'] = $baseInfo['productPriceBo']['formatSalesPrice'];
if ($baseInfo['productPriceBo']['formatMarketPrice'] !== $baseInfo['productPriceBo']['formatSalesPrice']) {
$result['goodsPrice']['previousPrice'] = $baseInfo['productPriceBo']['formatMarketPrice'];
}
}
// VIP商品价格
if (isset($baseInfo['productPriceBo']['vipPrices'])) {
$build = array();
foreach ($baseInfo['productPriceBo']['vipPrices'] as $value) {
$build['level'] = $value['vipLevel'];
$build['text'] = $value['vipPrice'];
$result['vipLevel']['list'][] = $build;
}
}
// 上市期
if (isset($baseInfo['expectArrivalTime'])) {
$result['periodOfMarket'] = date('n', $baseInfo['firstShelveTime']) . '月';
}
// 促销信息
if (isset($baseInfo['promotionBoList'])) {
$build = array();
foreach ($baseInfo['promotionBoList'] as $value) {
$build['title'] = $value['promotionTitle'];
$build['type'] = $value['promotionType'];
$result['goodsDiscount']['list'][] = $build;
}
}
// 商品咨询和商品评价
$result['feedbacks'] = array();
if (!empty($baseInfo['consultBoWrapper'])) {
$result['feedbacks']['consultNum'] = $baseInfo['consultBoWrapper']['consultTotal'];
$result['feedbacks']['consults'] = array();
$build = array();
foreach ($baseInfo['consultBoWrapper']['consultBoList'] as $value) {
$build['question'] = $value['ask'];
$build['time'] = $value['askTime'];
$build['answer'] = $value['answer'];
$result['feedbacks']['consults'][] = $build;
}
}
if (!empty($baseInfo['commentBoWrapper'])) {
$result['feedbacks']['commentNum'] = $baseInfo['commentBoWrapper']['commentTotal'];
$result['feedbacks']['comments'] = array();
$build = array();
foreach ($baseInfo['commentBoWrapper']['commentBoList'] as $value) {
$build['userName'] = $value['nickName'];
$build['desc'] = $value['colorName'] . $value['sizeName'];
$build['content'] = $value['content'];
$build['time'] = $value['createTime'];
$result['feedbacks']['comments'][] = $build;
}
}
// 品牌信息
if (!empty($baseInfo['brand'])) {
$result['enterStore'] = array(
'img' => Helpers::getImageUrl($baseInfo['brand']['brandIco'], 47, 47),
'storeName' => $baseInfo['brand']['brandName'],
'url' => Helpers::url('', array(), $baseInfo['brand']['brandDomain'])
);
}
// 商品信息
if (!empty($baseInfo['goodsList'])) {
$colorGroup = array();
$sizeGroup = array();
$goodsList = array();
$goodsGroup = array();
$colorId = 0;
foreach ($baseInfo['goodsList'] as $value) {
$colorId = intval($value['colorId']);
// 商品按颜色进行分类分组
foreach ($value['goodsImagesList'] as $goods) {
$goodsList[ $goods['goodsId'] ] = $colorId;
$goodsGroup[$colorId][] = array(
'goodsId' => $goods['goodsId'],
'img' => $goods['imageUrl'],
);
$colorGroup[$colorId] = array(
'colorId' => $colorId,
'colorName' => $value['colorName'],
'colorImage' => Helpers::getImageUrl($value['colorImage'], 60, 60),
);
}
// 商品的尺码列表
foreach ($value['goodsSizeBoList'] as $size) {
$sizeGroup[ $colorId ] = array(
'sizeName' => $size['sizeName'],
'sizeSku' => $size['goodsSizeSkuId'],
'sizeStorage' => $size['goodsSizeStorageNum'],
);
}
}
// 商品图
$goodsId = intval($goodsId);
if (isset($goodsList[$goodsId])) {
$colorId = $goodsList[$goodsId];
// 多个
if (isset($goodsGroup[$colorId][1])) {
foreach ($goodsGroup[$colorId] as $value) {
$result['bannerTop']['list'][] = array(
'img' => Helpers::getImageUrl($value['img'], 450, 600)
);
}
}
// 单个
elseif (isset($goodsGroup[$colorId][0])) {
$result['bannerTop'] = array(
'img' => Helpers::getImageUrl($goodsGroup[$colorId][0]['img'], 450, 600)
);
}
}
}
// 调用尺码需要的SKN号
if (isset($baseInfo['erpProductId'])) {
$result['skn'] = $baseInfo['erpProductId'];
}
}
return $result;
}
/**
* 商品尺码信息
*
* @param int $productSkn
* @return array
*/
public static function getSizeInfo($productSkn)
{
$sizeInfo = DetailData::sizeInfo($productSkn);
var_dump($sizeInfo);
}
}