Detail.php 30.4 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
<?php

namespace Product;

use LibModels\Web\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 SKN 和 ID 只需要传一个
     * @param int $goodsId 某个颜色的商品
     * @param int $uid 当前登录用户ID, 未登录为0
     * @param int $productSkn SKN 和 ID 只需要传一个
     * @return array
     */
    public static function getBaseInfo($productId, $goodsId, $uid, $vipLevel, $productSkn = null)
    {
        $result = array();

        $baseInfo = array();
        // 通过ID获取
        if (is_numeric($productId) && is_numeric($goodsId)) {
            $baseInfo = DetailData::baseInfo($productId, $uid);
        }
        // 通过SKN获取
        elseif (is_numeric($productSkn)) {
            $baseInfo = DetailData::baseInfo(null, $uid, $productSkn);
        }
        // 商品名称
        if (empty($baseInfo['productName'])) {
            return $result;
        }
        
        // 面包屑导航
        $result['pathNav'] = array(
            array(
                'href' => '/boys',
                'name' => 'BOYS首页'
            ),
            array(
                'href' => '/boys?sort=1',
                'name' => '服配'
            ),
            array(
                'href' => '/boys?sort=1&msort=232',
                'name' => '手表'
            ),
            array(
                'name' => $baseInfo['productName'],
            )
        );
                            
        // 商品促销短语
        if (!empty($baseInfo['salesPhrase'])) {
            $result['goodsSubtitle'] = $baseInfo['salesPhrase'];
        }

        // 商品标签
        if (!empty($baseInfo['productTagBoList'])) {
            foreach ($baseInfo['productTagBoList'] as $value) {
                switch ($value['tagLabel']) {
                    case 'is_soon_sold_out': // 即将售磬
                        $result['tags']['is_soon_sold_out'] = true;
                        break;
                    case 'is_new': // 新品NEW
                        $result['tags']['is_new'] = true;
                        break;
                    case 'is_discount': // SALE
                        $result['tags']['is_discount'] = true;
                        break;
                    case 'is_limited': // 限量
                        $result['tags']['is_limited'] = true;
                        break;
                    case 'is_yohood': // YOHOOD
                        $result['tags']['is_yohood'] = true;
                        break;
                    case 'is_advance': // 再到着
                        $result['tags']['is_advance'] = true;
                        break;
                }
            }
        }

        // 商品价格
        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'];
                $build['currentLevel'] = ($value['vipLevel'] == $vipLevel) ? true : false;
                $result['vipLevel']['list'][] = $build;
            }
        }

        // 上市期
        if (isset($baseInfo['expectArrivalTime']) && !empty($baseInfo['expectArrivalTime'])) {
            $result['periodOfMarket'] = $baseInfo['expectArrivalTime'] . '月';
        }

        // 促销信息
        if (isset($baseInfo['promotionBoList'])) {
            $build = array();
            foreach ($baseInfo['promotionBoList'] as $value) {
                $build['text'] = '【' . $value['promotionType'] . '】' . $value['promotionTitle'];
                $result['goodsDiscount']['list'][] = $build;
            }
        }

        // 没有商品ID, 则取一次
        if (empty($productId)) {
            $productId = isset($baseInfo['id']) ? $baseInfo['id'] : 0;
        }

        $result['feedbacks'] = array();

        // 商品咨询
        $result['feedbacks']['consultsNum'] = 0;
        if (!empty($baseInfo['consultBoWrapper'])) {
            $result['feedbacks']['consultsNum'] = $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;
            }
            $result['feedbacks']['consultsUrl'] = Helpers::url('/product/detail/consults', array('product_id' => $productId, 'total' => $result['feedbacks']['consultsNum']));
        }
        // 暂无咨询
        else {
            $result['feedbacks']['consultsUrl'] = Helpers::url('/product/detail/consultform', array('product_id' => $productId));
        }

        // 商品评价
        $result['feedbacks']['commentsNum'] = 0;
        if (!empty($baseInfo['commentBoWrapper'])) {
            $result['feedbacks']['commentsNum'] = $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'] = isset($value['content']) ? $value['content'] : '';
                $build['time'] = $value['createTime'];
                $result['feedbacks']['comments'][] = $build;
            }
            $result['feedbacks']['commentsUrl'] = Helpers::url('/product/detail/comments', array('product_id' => $productId, 'total' => $result['feedbacks']['commentsNum']));
        }

        // 品牌信息
        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'])
            );
            // 为你优选的链接
            $result['preferenceUrl'] = Helpers::url('/product/detail/preference', array('productSkn' => $baseInfo['erpProductId'], 'brandId' => $baseInfo['brand']['id']), '');
        }

        // 商品信息
        if (!empty($baseInfo['goodsList'])) {
            $colorGroup = array();
            $sizeGroup = array();
            $goodsGroup = array();
            $sizeName = '';
            $colorList = array();
            $sizeList = array();
            $allSizeList = array(); // 所有尺码列表
            $thumbImageList = array();
            $colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
            $colorStorageNum = 0;
            $totalStorageNum = 0; // 总库存数
            foreach ($baseInfo['goodsList'] as $value) {
                // 如果status为0,即skc下架时就跳过该商品
                if ($value['status'] === 0) {
                    continue;
                }

                $colorStorageNum = 0;

                // 商品分组
                if (isset($value['goodsImagesList'])) {
                    foreach ($value['goodsImagesList'] as $goods) {
                        $goodsGroup[] = array(
                            'goodsId' => $goods['goodsId'],
                            'img' => $goods['imageUrl'],
                        );
                    }
                }

                // 商品的尺码列表
                $colorStorageGroup[ $value['productSkc'] ] = array();
                if (isset($value['goodsSizeBoList'])) {
                    $sizeName = '';
                    foreach ($value['goodsSizeBoList'] as $size) {
                        $sizeList[ $value['productSkc'] ][] = array(
                            'id' => $size['id'],
                            'skuId' => $size['goodsSizeSkuId'],
                            'goodsId' => $size['goodsId'],
                            'colorId' => $value['colorId'],
                            'name' => $size['sizeName'],
                            'sizeNum' => $size['goodsSizeStorageNum'],
                        );
                        $sizeName = $size['sizeName'];
                        
                        // 所有尺码列表,赋值用于前端展示默认尺码的时候 判断出没有库存则显示灰色
                        $allSizeList[$sizeName] = empty($allSizeList[$sizeName]['storage']) 
                                                          ? array('storage' => $size['goodsSizeStorageNum'], 'id' => $size['id']) 
                                                          : $allSizeList[$sizeName];
                        $colorStorageNum += intval($size['goodsSizeStorageNum']);
                        $colorStorageGroup[ $value['productSkc'] ][$sizeName] = intval($size['goodsSizeStorageNum']);
                    }

                    // 颜色分组
                    $colorList[] = array(
                        'id' => $value['colorId'],
                        'skcId' => $value['productSkc'],
                        'name' => $value['colorName'],
                        'goodsName' => $value['goodsName'],
                        'colorNum' => $colorStorageNum,
                    );
                }

                // 缩略图
                $thumbImageList[] = array('img' => Helpers::getImageUrl($value['colorImage'], 60, 60));

                // 商品库存总数
                $totalStorageNum += $colorStorageNum;
            }
            
            // 遍历所有尺码,构建颜色显示数据
            $i = 1;
            foreach ($allSizeList as $sizeName => $value) {
                // 默认尺码
                $sizeGroup[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;
                    $colorGroup[$i]['color'][] = $colorArr;
                }
                $colorGroup[$i]['id'] = $value['id'];
                
                ++ $i;
            }
            // 遍历所有颜色, 构建尺码显示数据
            $i = 1;
            foreach ($colorList as $value) {
                // 各个尺码的颜色,每行显示一个颜色的对应尺码
                $sizeGroup[$i]['size'] = $sizeList[ $value['skcId'] ];
                $sizeGroup[$i]['colorId'] = $value['skcId'];
                // 默认颜色
                $colorGroup[0]['color'][] = $value;
                
                ++ $i;
            }

            // 商品图: 多个
            if (isset($goodsGroup[1])) {
                foreach ($goodsGroup as $value) {
                    $result['bannerTop']['list'][] = array(
                        'img' => Helpers::getImageUrl($value['img'], 450, 600)
                    );
                }
            }
            // 商品图: 单个
            elseif (isset($goodsGroup[0])) {
                $result['bannerTop'] = array(
                    'img' => Helpers::getImageUrl($goodsGroup[0]['img'], 450, 600)
                );
            }
        }

        // 悬浮的购物车信息
        $result['cartInfo'] = array(
            'cartUrl' => Helpers::url('/cart/index/index', null), // 购物车链接
            'numInCart' => 0,
            'goodsInstore' => $baseInfo['storage'], // 库存量
        );
        $soldOut = ($baseInfo['storage'] == 0) || ($baseInfo['status'] == 0 || $totalStorageNum === 0);
        $notForSale = $baseInfo['attribute'] == 2;
        // 显示加入购物车链接
        if (!$soldOut && !$notForSale) {
            ksort($colorGroup, SORT_NUMERIC);
            
            $result['cartInfo']['addToCartUrl'] = Helpers::url('/product/buy_' . $productId . '_' . $goodsId . '.html');
            $result['cartInfo']['productId'] = $productId;
            $result['cartInfo']['thumbs'] = $thumbImageList;
            $result['cartInfo']['name'] = isset($result['goodsName']) ? $result['goodsName'] : '';
            $result['cartInfo']['price'] = isset($result['goodsPrice']['previousPrice']) ? $result['goodsPrice']['previousPrice'] : '';
            $result['cartInfo']['salePrice'] = isset($result['goodsPrice']['currentPrice']) ? $result['goodsPrice']['currentPrice'] : '';
            $result['cartInfo']['totalNum'] = $totalStorageNum;
            $result['cartInfo']['colors'] = $colorGroup;
            $result['cartInfo']['sizes'] = $sizeGroup;
        }
        // 非卖品
        elseif ($notForSale) {
            $result['cartInfo']['notForSale'] = true;
        }
        // 已售磬
        elseif ($soldOut) {
            $result['cartInfo']['soldOut'] = true;
        }

        // 是否收藏
        $result['isCollect'] = false;
        if (isset($baseInfo['isCollect']) && $baseInfo['isCollect'] === 'Y') {
            $result['isCollect'] = true;
        }

        // 底部简介的URL链接
        $result['introUrl'] = Helpers::url('/product/intro_' . $baseInfo['erpProductId'] . '/' . $baseInfo['cnAlphabet'] . '.html', null, '');
        $result['id'] = $productId;

        // 清空变量,释放内存
        $baseInfo = array();
        $goodsGroup = array();
        $sizeGroup = array();
        $colorGroup = array();
        $sizeList = array();

        return $result;
    }

    /**
     * 商品尺码信息
     *
     * @param int $productSkn
     * @return array
     */
    public static function getSizeInfo($productSkn)
    {
        $result = array();

        if (is_numeric($productSkn)) {
            // 调用服务
            $sizeInfo = DetailData::sizeInfo($productSkn);

            // 商品信息
            if (isset($sizeInfo['productDescBo']['erpProductId'])) {
                $sex = '通用';
                switch ($sizeInfo['productDescBo']['gender']) {
                    case 1:
                        $sex = '男款';
                        break;
                    case 2:
                        $sex = '女款';
                        break;
                }
                $result['goodsDescription'] = array(
                    'title' => '商品信息',
                    'enTitle' => 'DESCRIPTION',
                    'detail' => array(
                        'list' => array(
                            array('param' => '编号:' . $sizeInfo['productDescBo']['erpProductId']),
                            array('param' => '颜色:' . $sizeInfo['productDescBo']['colorName']),
                            array('param' => '性别:' . $sex),
                        )
                    ),
                );
            }
            if (!empty($sizeInfo['productDescBo']['standardBos'])) {
                foreach ($sizeInfo['productDescBo']['standardBos'] as $value) {
                    $result['goodsDescription']['detail']['list'][] = array('param' => $value['standardName'] . ':' . $value['standardVal']);
                }
            }
            if (isset($sizeInfo['phrase'])) {
                $result['goodsDescription']['desc'] = $sizeInfo['phrase'];
            }

            // 尺码信息
            if (!empty($sizeInfo['sizeInfoBo'])) {
                $result['sizeInfo'] = array(
                    'title' => '尺码信息',
                    'enTitle' => 'SIZE INFO',
                    'detail' => array('list' => array()),
                );
                /* 参考尺码 */
                $boyReference = !empty($sizeInfo['productExtra']['boyReference']);
                $girlReference = !empty($sizeInfo['productExtra']['girlReference']);
                $gender = isset($sizeInfo['productDescBo']['gender']) ? $sizeInfo['productDescBo']['gender'] : 3;
                $referenceName = '参考尺码';
                if (($gender == 1 && $boyReference) || ($gender == 2 && $girlReference)) {
                    $referenceName = '参考尺码';
                } elseif ($gender == 3 && $boyReference) {
                    $referenceName = '参考尺码(男)';
                } elseif ($gender == 3 && $girlReference) {
                    $referenceName = '参考尺码(女)';
                }

                $referenceList = array();
                // 判断是否显示参考尺码
                $showReference = ($boyReference && !empty($sizeInfo['sizeInfoBo']['sizeBoList'][0]['boyReferSize'])) || ($girlReference && !empty($sizeInfo['sizeInfoBo']['sizeBoList'][0]['girlReferSize']) );
                if ($showReference) {
                    $referenceList[0] = array('param' => $referenceName);
                }

                if (!empty($sizeInfo['sizeInfoBo']['sizeAttributeBos'])) {
                    $sizeNameList = array(0 => array('param' => '吊牌尺码')); // 尺码名称
                    $sizeBoGroup = array(); // 尺码按ID分组
                    foreach ($sizeInfo['sizeInfoBo']['sizeAttributeBos'] as $attr) {
                        $sizeBoGroup[$attr['id']][0] = array('param' => empty($attr['attributeName']) ? ' ' : $attr['attributeName']);
                    }
                    $item = array();
                    foreach ($sizeInfo['sizeInfoBo']['sizeBoList'] as $value) {
                        $item = array();
                        $sizeNameList[] = array('param' => $value['sizeName']);
                        if ($boyReference && ($gender == 1 || $gender == 3)) {
                            $referenceList[] = array('param' => empty($value['boyReferSize']['referenceName']) ? ' ' : $value['boyReferSize']['referenceName']);
                        } elseif ($girlReference && ($gender == 2 || $gender == 3)) {
                            $referenceList[] = array('param' => empty($value['girlReferSize']['referenceName']) ? ' ' : $value['girlReferSize']['referenceName']);
                        } else {
                            $showReference = false;
                        }
                        foreach ($value['sortAttributes'] as $attr) {
                            $sizeBoGroup[$attr['id']][] = array('param' => empty($attr['sizeValue']) ? ' ' : $attr['sizeValue']);
                        }
                    }

                    // 根据模板页面的显示,按表格一列一列来显示
                    $result['sizeInfo']['detail']['list'][0]['params'] = $sizeNameList;
                    if ($showReference) {
                        $result['sizeInfo']['detail']['list'][1]['params'] = $referenceList;
                    }
                    foreach ($sizeBoGroup as $value) {
                        $result['sizeInfo']['detail']['list'][]['params'] = $value;
                    }
                } else {
                    $result['sizeInfo']['detail']['list'][0]['params'] = array(0 => array('param' => ''));
                }
            }

            // 测量方式
            if (!empty($sizeInfo['sizeImage'])) {
                $result['measurementMethod'] = array(
                    'title' => '测量方式',
                    'enTitle' => 'MEASUREMENT METHOD',
                    'img' => $sizeInfo['sizeImage'],
                );
            }

            // 模特试穿, 竖着输出排列显示
            if (!empty($sizeInfo['modelBos'])) {
                $result['reference'] = array(
                    'title' => '模特试穿',
                    'enTitle' => 'REFERENCE',
                    'detail' => array('list' => array()),
                );

                // 控制是否显示备注
                $showRemark = false;
                $remarkList = array(0 => array('param' => '备注'));

                $result['reference']['detail']['list'][0]['params'] = array(0 => array('param' => '')); // 头像列表
                $result['reference']['detail']['list'][1]['params'] = array(0 => array('param' => '模特')); // 模特名字列表
                $result['reference']['detail']['list'][2]['params'] = array(0 => array('param' => '身高')); // 身高列表
                $result['reference']['detail']['list'][3]['params'] = array(0 => array('param' => '体重')); // 体重列表
                $result['reference']['detail']['list'][4]['params'] = array(0 => array('param' => '三围')); // 三围列表
                $result['reference']['detail']['list'][5]['params'] = array(0 => array('param' => '吊牌尺码')); // 吊牌尺码
                $result['reference']['detail']['list'][6]['params'] = array(0 => array('param' => '试穿描述')); // 试穿描述

                foreach ($sizeInfo['modelBos'] as $value) {
                    $result['reference']['detail']['list'][0]['params'][] = array('param' => $value['avatar']);
                    $result['reference']['detail']['list'][1]['params'][] = array('param' => $value['modelName']);
                    $result['reference']['detail']['list'][2]['params'][] = array('param' => $value['height']);
                    $result['reference']['detail']['list'][3]['params'][] = array('param' => $value['weight']);
                    $result['reference']['detail']['list'][4]['params'][] = array('param' => $value['vitalStatistics']);
                    $result['reference']['detail']['list'][5]['params'][] = array('param' => $value['fitModelBo']['fit_size']);
                    $result['reference']['detail']['list'][6]['params'][] = array('param' => $value['fitModelBo']['feel']);
                    if (!empty($value['fitModelBo']['fit_remark'])) {
                        $showRemark = true;
                        $remarkList[] = array('param' => $value['fitModelBo']['fit_remark']);
                    } else {
                        $remarkList[] = array('param' => '');
                    }
                }

                // 显示模特备注
                if ($showRemark) {
                    $result['reference']['detail']['list'][7]['params'] = $remarkList;
                }
            }

            // 商品材质
            if (!empty($sizeInfo['productMaterialList'])) {
                $result['materials'] = array(
                    'title' => '商品材质',
                    'enTitle' => 'MATERIALS',
                    'list' => array(),
                );
                foreach ($sizeInfo['productMaterialList'] as $value) {
                    $result['materials']['list'][] = array(
                        'img' => $value['imageUrl'],
                        'desc' => $value['remark'],
                    );
                }
            }

            // 洗涤提示
            if (!empty($sizeInfo['washTipsBoList'])) {
                $result['washTips']['list'] = array();
                foreach ($sizeInfo['washTipsBoList'] as $value) {
                    $result['washTips']['list'][] = $value;
                }
            }

            // 详情配图
            if (isset($sizeInfo['productIntroBo']['productIntro'])) {
                $productIntro = '';
                if (!empty($sizeInfo['productDescBo']['phrase'])) {
                    $productIntro .= $sizeInfo['productDescBo']['phrase'] . '<br/>';
                }
                $productIntro .= $sizeInfo['productIntroBo']['productIntro'];
                if ($productIntro) {
                    $result['productDetail'] = array(
                        'title' => '商品详情',
                        'enTitle' => 'DETAILS',
                        'desc' => strtr($productIntro, array(
                            '\r\n\t' => '',
                            '</p>' => '',
                            '<img src=' => "<img class=\"lazy\" src=\"data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==\" data-original=",
                            '<img border="0" src=' => "<img border=\"0\" class=\"lazy\" src=\"data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==\" data-original=",
                            '.jpg' => '.jpg?imageMogr2/thumbnail/750x/quality/90',
                        )),
                    );
                }
            }

            // 清空变量,释放内存
            $sizeInfo = array();
        }

        return $result;
    }

    /**
     * 获取评价列表
     *
     * @param int $productId 产品ID
     * @param int $pageNum 页码数
     * @param int $pageSize 每页显示个数
     * @return array
     */
    public static function getComments($productId, $pageNum = 1, $pageSize = 300)
    {
        $result = array();

        if (is_numeric($productId) && is_numeric($pageNum) && is_numeric($pageSize)) {
            $commentList = DetailData::commentList($productId, $pageNum, $pageSize);
            if (!empty($commentList['data'])) {
                $build = array();
                foreach ($commentList['data'] as $value) {
                    $build['userName'] = $value['nickname'];
                    $build['desc'] = $value['color_name'] . '/' . $value['size_name'];
                    $build['content'] = $value['content'];
                    $build['time'] = $value['create_time'];
                    $result[] = $build;
                }
            }
        }

        return $result;
    }

    /**
     * 获取咨询列表
     *
     * @param int $uid 用户ID
     * @param int $productId 产品ID
     * @param int $pageNum 页码数
     * @param int $pageSize 每页显示个数
     * @return array
     */
    public static function getConsults($uid, $productId, $pageNum = 1, $pageSize = 300)
    {
        $result = array();

        if (is_numeric($productId) && is_numeric($pageNum) && is_numeric($pageSize)) {
            $consultList = DetailData::consultList($uid, $productId, $pageNum, $pageSize);
            if (isset($consultList['code']) && $consultList['code'] === 200) {
                $build = array();
                foreach ($consultList['data']['list'] as $value) {
                    $build['question'] = $value['ask'];
                    $build['time'] = $value['ask_time'];
                    $build['answer'] = $value['answer'];
                    $build['id'] = $value['id'];
                    $build['isLike'] = $value['is_like'] === 'Y';
                    $build['like'] = intval($value['like']);
                    $build['isUseful'] = $value['is_useful'] === 'Y';
                    $build['useful'] = intval($value['useful']);
                    $result[] = $build;
                }
            }
            $consultList = array();
        }

        return $result;
    }

    /**
     * 获取常见问题列表
     *
     * @return array
     */
    public static function getCommonConsults()
    {
        $result = array();

        $consults = DetailData::commonConsultList();
        if (isset($consults['code']) && $consults['code'] === 200) {
            $result['commonConsults'] = $consults['data'];
            $consults = array();
        }

        return $result;
    }

    /**
     * 咨询点赞
     *
     * @param int $uid 用户ID
     * @param int $id 咨询ID
     * @param int $productId 商品ID
     * @param int $total 购买咨询总数
     * @return array
     */
    public static function upvoteConsult($uid, $id, $productId, $total)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            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;
            }
            
            // 处理数据
            $record = DetailData::upvoteConsult($uid, $id);
            if (!empty($record['code'])) {
                $result['code'] = $record['code'];
                $result['message'] = $record['message'];
            }
        } while (false);

        return $result;
    }

    /**
     * 咨询有用
     *
     * @param int $uid 用户ID
     * @param int $id 咨询ID
     * @param int $productId 商品ID
     * @param int $total 购买咨询总数
     * @return array
     */
    public static function usefulConsult($uid, $id, $productId, $total)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            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;
            }
            
            // 处理数据
            $record = DetailData::usefulConsult($uid, $id);
            if (!empty($record['code'])) {
                $result['code'] = $record['code'];
                $result['message'] = $record['message'];
            }
        } while (false);

        return $result;
    }

    /**
     * 获取为你优选的商品
     *
     * @param int $productSkn 商品SKN
     * @return array
     */
    public static function getPreference($productSkn, $channel, $brandId)
    {
        $result = array();

        if (is_numeric($productSkn)) {
            $preference = DetailData::preference($productSkn, $channel, $brandId);
            if (!empty($preference)) {
                foreach ($preference as $value) {
                    $value = Helpers::formatProduct($value, false, true, true, 299, 388, false, false);
                    if (false !== $value) {
                        $result['recommendList'][] = $value;
                    }
                }
            }
        }

        return $result;
    }

}