...
|
...
|
@@ -647,47 +647,58 @@ class CartModel |
|
|
if (isset($productData['goods_list'])) {
|
|
|
$goodsList = $productData['goods_list'];
|
|
|
|
|
|
$sizeName = '';
|
|
|
$colors = array();
|
|
|
$colorList = array();
|
|
|
$oneColor = array();
|
|
|
$sizes = array();
|
|
|
$oneSize = array();
|
|
|
$sizeList = array();
|
|
|
$allSizeList = array(); // 所有尺码列表
|
|
|
$thumbImageList = array();
|
|
|
$colorNum = 0;
|
|
|
$totalStorageNum = 0; // 总库存数
|
|
|
$colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
|
|
|
foreach ($goodsList as $val) {
|
|
|
$colorNum = 0;
|
|
|
$sizeStorageStr = '';
|
|
|
|
|
|
// 尺码
|
|
|
foreach ($val['size_list'] as $one) {
|
|
|
$oneSize = array();
|
|
|
$oneSize['id'] = $one['size_id'];
|
|
|
$oneSize['skuId'] = $one['product_sku'];
|
|
|
$oneSize['goodsId'] = $val['goods_id'];
|
|
|
$oneSize['colorId'] = $val['color_id'];
|
|
|
$oneSize['name'] = $one['size_name'];
|
|
|
$oneSize['sizeNum'] = $one['storage_number'];
|
|
|
|
|
|
$colorNum += $one['storage_number'];
|
|
|
$sizeStorageStr .= $one['storage_number'] . '/';
|
|
|
|
|
|
$sizeList[$val['product_skc']][] = $oneSize;
|
|
|
$sizeName = '';
|
|
|
|
|
|
// 商品的尺码列表
|
|
|
$colorStorageGroup[ $val['product_skc'] ] = array();
|
|
|
if (isset($val['size_list'])) {
|
|
|
// 尺码
|
|
|
foreach ($val['size_list'] as $one) {
|
|
|
$sizeName = $one['size_name'];
|
|
|
$oneSize = array();
|
|
|
|
|
|
$oneSize['id'] = $one['size_id'];
|
|
|
$oneSize['skuId'] = $one['product_sku'];
|
|
|
$oneSize['goodsId'] = $val['goods_id'];
|
|
|
$oneSize['colorId'] = $val['color_id'];
|
|
|
$oneSize['name'] = $sizeName;
|
|
|
$oneSize['sizeNum'] = $one['storage_number'];
|
|
|
$sizeList[$val['product_skc']][] = $oneSize;
|
|
|
|
|
|
// 所有尺码列表,赋值用于前端展示默认尺码的时候 判断出没有库存则显示灰色
|
|
|
$allSizeList[$sizeName] = empty($allSizeList[$sizeName]['storage_number'])
|
|
|
? array('storage' => $one['storage_number'], 'id' => $one['size_id'])
|
|
|
: $allSizeList[$sizeName];
|
|
|
|
|
|
$colorNum += intval($one['storage_number']);
|
|
|
|
|
|
$colorStorageGroup[$val['product_skc']][$one['size_name']] = $one['storage_number'];
|
|
|
}
|
|
|
|
|
|
$colorStorageGroup[$val['product_skc']][$one['size_name']] = $one['storage_number'];
|
|
|
// 颜色分组
|
|
|
$oneColor = array();
|
|
|
$oneColor['id'] = $val['color_id'];
|
|
|
$oneColor['skcId'] = $val['product_skc'];
|
|
|
$oneColor['name'] = $val['color_name'];
|
|
|
$oneColor['goodsName'] = $productData['product_name'];
|
|
|
$oneColor['colorNum'] = $colorNum;
|
|
|
$colorList[] = $oneColor;
|
|
|
}
|
|
|
|
|
|
// 颜色
|
|
|
$oneColor = array();
|
|
|
$oneColor['id'] = $val['color_id'];
|
|
|
$oneColor['skcId'] = $val['product_skc'];
|
|
|
$oneColor['name'] = $val['color_name'];
|
|
|
$oneColor['goodsName'] = $productData['product_name'];
|
|
|
$oneColor['colorNum'] = $colorNum;
|
|
|
$oneColor['sizeNumStr'] = rtrim($sizeStorageStr, '/');
|
|
|
$colors[] = $oneColor;
|
|
|
|
|
|
// 缩略图
|
|
|
foreach ($val['images_list'] as $image) {
|
|
|
$thumbImageList[] = array(
|
...
|
...
|
@@ -699,25 +710,38 @@ class CartModel |
|
|
$totalStorageNum += $colorNum;
|
|
|
}
|
|
|
|
|
|
// 遍历所有尺码,统计出该尺码的每个颜色的库存量,没有时添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, '/');
|
|
|
// 遍历所有尺码,构建颜色显示数据
|
|
|
$i = 1;
|
|
|
foreach ($allSizeList as $sizeName => $value) {
|
|
|
// 默认尺码
|
|
|
$sizes[0]['size'][] = array(
|
|
|
'name' => $sizeName, // 尺码名称
|
|
|
'sizeNum' => empty($value['storage']) ? false : true, // 是否有库存 (false:表示没有库存,true:表示有库存)
|
|
|
'id' => $value['id'],
|
|
|
);
|
|
|
|
|
|
// 各个颜色的尺码, 每行显示一个尺码对应的颜色
|
|
|
foreach ($colorList as $colorArr) {
|
|
|
$colorArr['colorNum'] = isset($colorStorageGroup[ $colorArr['skcId'] ][$sizeName]) ? $colorStorageGroup[ $colorArr['skcId'] ][$sizeName] : 0;
|
|
|
$colors[$i]['color'][] = $colorArr;
|
|
|
}
|
|
|
$colors[$i]['id'] = $value['id'];
|
|
|
|
|
|
++ $i;
|
|
|
}
|
|
|
|
|
|
// 格式化尺码对应的各个颜色分组
|
|
|
foreach ($colors as $color) {
|
|
|
$sizes[]['size'] = $sizeList[$color['skcId']];
|
|
|
// 遍历所有颜色, 构建尺码显示数据
|
|
|
$i = 1;
|
|
|
foreach ($colorList as $value) {
|
|
|
// 各个尺码的颜色,每行显示一个颜色的对应尺码
|
|
|
$sizes[$i]['size'] = $sizeList[ $value['skcId'] ];
|
|
|
$sizes[$i]['colorId'] = $value['skcId'];
|
|
|
// 默认颜色
|
|
|
$colors[0]['color'][] = $value;
|
|
|
|
|
|
++ $i;
|
|
|
}
|
|
|
ksort($colors, SORT_NUMERIC);
|
|
|
|
|
|
$data['thumbs'] = $thumbImageList;
|
|
|
$data['colors'] = $colors;
|
...
|
...
|
|