Detail.php 4.09 KB
<?php

namespace Product;

use LibModels\Wap\Product\DetailData;

/**
 * 商品详情页模板相关的数据模型
 * 
 * @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 $uid 当前登录用户ID, 未登录为0
     * @return array
     */
    public static function getBaseInfo($productId, $uid)
    {
        $result = array();
        
        if (is_numeric($productId)) {
            // 调用接口
            $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']) . '月';
            }
            // 商品咨询和商品评价
            $result['feedbacks'] = array();
            if (isset($baseInfo['consultBoWrapper'])) {
                $result['feedbacks']['consultTotal'] = $baseInfo['consultBoWrapper']['consultTotal'];
                $result['feedbacks']['consults'] = array();
            }
            if (isset($baseInfo['commentBoWrapper'])) {
                $result['feedbacks']['commentTotal'] = $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['goodsList'])) {
                foreach ($baseInfo['goodsList'] as $value) {
                    foreach ($value['goodsImagesList'] as $image) {
                        
                    }
                    
                    foreach ($value['goodsSizeBoList'] as $size) {
                        
                    }
                }
                
                // 多个
                if (isset($baseInfo['goodsList'][1])) {
                    $result['bannerTop']['list'] = array();
                    foreach ($baseInfo['goodsList'][1] as $value) {
                        
                    }
                } 
                // 单个
                else {
                    $result['bannerTop'] = array();
                    $result['bannerTop']['img'] = '';
                }
            }

        }
        
        return $result;
        var_dump($baseInfo);
        
    }

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

}