Authored by hf

code review by fei.hong: do format product detail size and color data

... ... @@ -167,15 +167,15 @@ class DetailModel
$colorGroup = array();
$sizeGroup = array();
$goodsGroup = array();
$colorList = array();
$sizeList = array();
$allSizeList = array(); // 所有尺码列表
$thumbImageList = array();
$colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
$sizeStorageStr = ''; // 尺码库存总数集合, 多个之间用/分隔
$colorStorageNum = 0;
$totalStorageNum = 0; // 总库存数
foreach ($baseInfo['goodsList'] as $value) {
$colorStorageNum = 0;
$sizeStorageStr = '';
// 商品分组
if (isset($value['goodsImagesList'])) {
... ... @@ -188,10 +188,10 @@ class DetailModel
}
// 商品的尺码列表
$colorStorageGroup[$value['productSkc']] = array();
$colorStorageGroup[ $value['productSkc'] ] = array();
if (isset($value['goodsSizeBoList'])) {
foreach ($value['goodsSizeBoList'] as $size) {
$sizeList[$value['productSkc']][] = array(
$sizeList[ $value['productSkc'] ][] = array(
'id' => $size['id'],
'skuId' => $size['goodsSizeSkuId'],
'goodsId' => $size['goodsId'],
... ... @@ -199,19 +199,21 @@ class DetailModel
'name' => $size['sizeName'],
'sizeNum' => $size['goodsSizeStorageNum'],
);
// 所有尺码列表,赋值用于前端展示默认尺码的时候 判断出没有库存则显示灰色
$allSizeList[ $size['sizeName'] ] = empty($allSizeList[ $size['sizeName'] ]) ? $size['goodsSizeStorageNum'] : $allSizeList[ $size['sizeName'] ];
$colorStorageNum += intval($size['goodsSizeStorageNum']);
$sizeStorageStr .= $size['goodsSizeStorageNum'] . '/';
$colorStorageGroup[$value['productSkc']][$size['sizeName']] = $size['goodsSizeStorageNum'];
}
// 颜色分组
$colorGroup[] = array(
$colorList[] = array(
'id' => $value['colorId'],
'skcId' => $value['productSkc'],
'name' => $value['colorName'],
'goodsName' => $value['goodsName'],
'colorNum' => $colorStorageNum,
'sizeNumStr' => rtrim($sizeStorageStr, '/'),
);
}
... ... @@ -221,25 +223,30 @@ class DetailModel
// 商品库存总数
$totalStorageNum += $colorStorageNum;
}
// 遍历所有尺码,构建颜色显示数据
$i = 1;
foreach ($allSizeList as $sizeName => $value) {
// 默认尺码
$sizeGroup[0]['size'][] = array(
'name' => $sizeName, // 尺码名称
'sizeNum' => empty($value) ? false : true, // 是否有库存 (false:表示没有库存,true:表示有库存)
);
// 遍历所有尺码,统计出该尺码的每个颜色的库存量,没有时添0,不能空着,因为JS中需要判断
foreach ($sizeList as $skc => $sizeArr) {
foreach ($sizeArr as $key => $value) {
$sizeStorageStr = '';
foreach ($colorStorageGroup as $colorArr) {
if (isset($colorArr[$value['name']])) {
$sizeStorageStr .= $colorArr[$value['name']] . '/';
} else {
$sizeStorageStr .= '0/';
}
}
$sizeList[$skc][$key]['colorNumStr'] = rtrim($sizeStorageStr, '/');
// 各个颜色的尺码, 每行显示一个尺码对应的颜色
foreach ($colorList as $colorArr) {
$colorArr['colorNum'] = isset($colorStorageGroup[ $colorArr['skcId'] ][$sizeName]) ? $colorStorageGroup[ $colorArr['skcId'] ][$sizeName] : 0;
$colorGroup[$i]['color'][] = $colorArr;
}
++ $i;
}
// 格式化尺码对应的各个颜色分组
foreach ($colorGroup as $value) {
$sizeGroup[]['size'] = $sizeList[$value['skcId']];
// 遍历所有颜色, 构建尺码显示数据
foreach ($colorList as $value) {
// 各个尺码的颜色,每行显示一个颜色的对应尺码
$sizeGroup[]['size'] = $sizeList[ $value['skcId'] ];
// 默认颜色
$colorGroup[0]['color'][] = $value;
}
// 商品图: 多个
... ... @@ -563,9 +570,8 @@ class DetailModel
if (is_numeric($productId) && is_numeric($pageNum) && is_numeric($pageSize)) {
$consultList = DetailData::consultList($uid, $productId, $pageNum, $pageSize);
if (isset($consultList['code']) && $consultList['code'] === 200) {
$consultList = $consultList['data']['list'];
$build = array();
foreach ($consultList as $value) {
foreach ($consultList['data']['list'] as $value) {
$build['question'] = $value['ask'];
$build['time'] = $value['ask_time'];
$build['answer'] = $value['answer'];
... ... @@ -615,21 +621,20 @@ class DetailModel
$result = array('code' => 400, 'message' => '出错啦~');
do {
$record = DetailData::upvoteConsult($uid, $id);
if (empty($uid)) {
$result['code'] = 401;
$result['message'] = '用户id为空';
$result['data'] = Helpers::url('/signin.html', array('refer' => Helpers::url('/product/detail/consults', array('product_id' => $productId, 'total' => $total))));
break;
}
// 处理数据
if ($record && isset($record['code'])) {
$record = DetailData::upvoteConsult($uid, $id);
if (!empty($record['code'])) {
$result['code'] = $record['code'];
$result['message'] = $record['message'];
}
}while(false);
} while (false);
return $result;
}
... ... @@ -648,21 +653,20 @@ class DetailModel
$result = array('code' => 400, 'message' => '出错啦~');
do {
$record = DetailData::usefulConsult($uid, $id);
if (empty($uid)) {
$result['code'] = 401;
$result['message'] = '用户id为空';
$result['data'] = Helpers::url('/signin.html', array('refer' => Helpers::url('/product/detail/consults', array('product_id' => $productId, 'total' => $total))));
break;
}
// 处理数据
if ($record && isset($record['code'])) {
$record = DetailData::usefulConsult($uid, $id);
if (!empty($record['code'])) {
$result['code'] = $record['code'];
$result['message'] = $record['message'];
}
}while(false);
} while (false);
return $result;
}
... ...