Detail.php 13.9 KB
<?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'];
            } else {
                return $result;
            }

            // 商品价格
            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']['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;
                }
            }
            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'] = $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)
                        );
                    }
                }
            }

            // 悬浮的购物车信息
            $result['cartInfo'] = array(
                'numInCart' => 0,
                'goodsInstore' => $baseInfo['storage'],
            );
            
            // 底部简介的URL链接
            $result['introUrl'] = Helpers::url('/product/intro_' . $baseInfo['erpProductId'] . '/' . $baseInfo['cnAlphabet'] . '.html');
        }

        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'])) {
                $result['goodsDescription'] = array(
                    'title' => '商品信息',
                    'enTitle' =>  'PRODUCT INFO',
                    'detail' => array(
                        array('param' => '编号:' . $sizeInfo['productDescBo']['erpProductId']),
                        array('param' => '颜色:' . $sizeInfo['productDescBo']['colorName']),
                    ),
                );
            }
            if (!empty($sizeInfo['productDescBo']['standardBos'])) {
                foreach ($sizeInfo['productDescBo']['standardBos'] as $value) {
                    $result['goodsDescription']['detail'][] = $value['standardName'] . ':' . $value['standardVal'];
                }
            }
            if (isset($sizeInfo['phrase'])) {
                $result['goodsDescription']['desc'] = $sizeInfo['phrase'];
            }
            
            // 尺码信息
            if (!empty($sizeInfo['productIntroBo']['sizeInfoBo'])) {
                $result['sizeInfo'] = array(
                    'title' => '尺码信息',
                    'enTitle' => 'SIZE INFO',
                    'detail' => array('list' => array()),
                );
                $sizeNameList = array(0 => array('param' => '吊牌尺码') ); // 尺码名称
                $sizeBoGroup = array(); // 尺码按ID分组
                foreach ($sizeInfo['productIntroBo']['sizeInfoBo']['sizeAttributeBos'] as $attr) {
                    $sizeBoGroup[ $attr['id'] ][0] = array('param' => $value['attributeName']);
                }
                foreach ($sizeInfo['productIntroBo']['sizeInfoBo']['sizeBoList'] as $value) {
                    foreach ($value['sortAttributes'] as $attr) {
                        $sizeBoGroup[ $attr['id'] ][] = array('param' => $attr['sizeValue']);
                        $sizeNameList[] = array('param' => $value['sizeName']);
                    }
                }
                
                // 根据模板页面的显示,按表格一列一列来显示
                $result['detail']['list'][0] = $sizeNameList;
                foreach ($sizeBoGroup as $value) {
                    $result['detail']['list'][] = $value;
                }
            }
            
            // 测量方式
            if (isset($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()),
                );
                $result['reference']['detail']['list'][0] = array(0 => array('param' => '')); // 头像列表
                $result['reference']['detail']['list'][1] = array(0 => array('param' => '模特')); // 模特名字列表
                $result['reference']['detail']['list'][2] = array(0 => array('param' => '身高')); // 身高列表
                $result['reference']['detail']['list'][3] = array(0 => array('param' => '体重')); // 体重列表
                $result['reference']['detail']['list'][4] = array(0 => array('param' => '三围')); // 三围列表
                $result['reference']['detail']['list'][5] = array(0 => array('param' => '吊牌尺码')); // 吊牌尺码
                $result['reference']['detail']['list'][6] = array(0 => array('param' => '试穿描述')); // 试穿描述
                foreach ($sizeInfo['modelBos'] as $value) {
                    $result['reference']['detail']['list'][0][] = array('param' => $value['avatar']);
                    $result['reference']['detail']['list'][1][] = array('param' => $value['modelName']);
                    $result['reference']['detail']['list'][2][] = array('param' => $value['height']);
                    $result['reference']['detail']['list'][3][] = array('param' => $value['weight']);
                    $result['reference']['detail']['list'][4][] = array('param' => $value['vitalStatistics']);
                    $result['reference']['detail']['list'][5][] = array('param' => $value['fitModelBo']['fit_size']);
                    $result['reference']['detail']['list'][6][] = array('param' => $value['fitModelBo']['feel']);
                }
            }
            
            // 商品材质
            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 = strstr($sizeInfo['productIntroBo']['productIntro'], '<br />');
                if ($productIntro) {
                    $result['productDetail'] = array(
                        'title' => '商品详情',
                        'enTitle' => 'DETAILS',
                        'desc' => strtr($productIntro, array(
                            '\r\n\t' => '',
                            '</p>' => '',
                            '<br />' => "\r\n",
                            '<img src=' => "<img class=\"lazy\" src=\"data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==\" data-original=",
                        )),
                    );
                }
            }
            
        }
        
        return $result;
    }

    /**
     * 获取评价列表
     */
    public static function getComments()
    {
        
    }
    
    /**
     * 获取咨询列表
     */
    public static function getConsults()
    {
        
    }
    
}