Product.php 8.79 KB
<?php
/**
 * 商品详情页面展示
 * Class QLibView_Product
 */
class QLibView_Product
{
    protected $view;

    public function __construct($product_id, $goods_id)
    {
        $this->view = new stdClass();
        $this->view->goods_id = $goods_id;
        $this->view->product = $product = QINProduct_Models_Product_Client::getOneProduct($product_id, 'all');
        $goodsImage = QINProduct_Models_Goods_Images_Client::getImages($product_id, $goods_id);
        $images = array();
        if (!empty($goodsImage)) {
            foreach ($goodsImage as $v) {
                $images[] = array(
                    'big' => QINLib_Images::QFSImage($v['image_url'], 'goodsimg', '420x560', 2),
                    'small' => QINLib_Images::QFSImage($v['image_url'], 'goodsimg', '75x100', 2)
                );
            }
        }
        $this->view->shareImgURL= QINLib_Images::QFSImage($goodsImage[0]['image_url'], 'goodsimg', '420x560', 2);
        $this->view->goodsImage = $images;
        $this->view->brand = $brand = QINProduct_Models_Brand_Client::getOneBrand($product['brand_id']);
        $this->view->brandDomain = '';
        if(!empty($brand['brand_domain'])){
            $this->view->brandDomain = 'http://'.$brand['brand_domain'] . QLibConfigs_Static::$brandSiteUrl;
        }
        $this->view->brandBanner = $brandBanner = QINProduct_Models_Brand_Banner_Client::getBannerById($product['brand_id']);
        $this->view->gender = $product['gender'] == 3 || empty($product['gender']) ? '1,3' : $product['gender'] . ',3';
        $this->view->maxsort = QINProduct_Models_Sort_Client::getSortById($product['max_sort_id']);
        $this->view->middlesort = QINProduct_Models_Sort_Client::getSortById($product['middle_sort_id']);
        //舒适度等其它商品属性
        $this->view->specialAttr = QINProduct_Models_Special_Client::getSpecial($this->view->product['id']);
    }



    /**
     * 商品详情页面品牌banner
     * @param $brand_id
     * @return $this
     */
    public function brandBanner()
    {
        $this->display('brand');
        return $this;
    }

    /**
     * 商品页面mini导航条
     * @return $this
     */
    public function mininav()
    {
        $this->display('mininav');
        return $this;
    }

    /**
     * 商品页面上部商品详情
     * @return $this
     */
    public function details()
    {
        $this->display('details');
        return $this;
    }


    /**
     * 商品编码,颜色,性别,舒适度等简介
     * @return $this
     */
    public function goodsBaseDesc()
    {
        $this->display('base');
        return $this;
    }

    /**
     * 产品材质
     * @return $this
     */
    public function metarial()
    {
        $this->display('metarial');
        return $this;
    }

    /**
     * 尺码信息
     * @param $product_skn
     * @return $this|array
     */
    public function size()
    {
        $relation = QINProduct_Models_Size_Relationskn_Client::getRelation($this->view->product['erp_product_id']);
        $allSize = QINProduct_Models_Size_Client::getAllSizes();
        $this->view->allAttribute = QINProduct_Models_Size_Attribute_Client::getSizeAttribute();
        //分类尺码信息
        $size = QINProduct_Models_Size_Sortsize_Client::getSortSize($this->view->product['small_sort_id']);
        //分类属性
        $attribute = QINProduct_Models_Size_Attribute_Client::getAttributeRelationBySort($this->view->product['small_sort_id']);
        $data = array();

        foreach ($size as $sizeKey=>$sizeVal) {
            foreach ($attribute as $attributeKey=>$attributeVal) {
                foreach ($relation as $relationKey=>$relationVal) {
                    if ($relationVal['size_id'] != $sizeVal['size_id'] || $relationVal['size_attribute_id'] != $attributeVal['attribute_id']) {
                        continue;
                    }
                    $data[$sizeVal['size_id']]['size_name'] = $allSize[$sizeVal['size_id']]['size_name'];
                    $data[$sizeVal['size_id']][$attributeVal['attribute_id']] = empty($relationVal['size_value']) ? '' : $relationVal['size_value'];
                }
            }
        }
        $this->view->sizeInfo = $data;
        $this->display('size');
        return $this;
    }

    /**
     * 测量示意图
     * @return $this
     */
    public function cateImage()
    {
        $this->display('cateimage');
        return $this;
    }


    /**
     * 试穿报告
     * @return $this
     */
    public function tryon()
    {
        $this->display('tryon');
        return $this;
    }


    /**
     * 模特卡
     * @return $this
     */
    public function modelcard()
    {
        $this->display('modelcard');
        return $this;
    }


    /**
     * 商品详情介绍
     * @return $this
     */
    public function description()
    {
        //搭配
        $list = QINProduct_Models_Collocation_Client::getCollocation($this->view->product['id']);
        foreach ($list as $key => $v) {
            if (empty($v['info'])) {
                continue;
            }
            $list[$key]['info'] = $info = json_decode($v['info'], true);
            foreach ($info as $k => $val) {
                $list[$key]['info'][$k]['product'] = $this->getProductInfo($val['id']);
            }
        }
        $this->view->collocation = $list;
        $this->display('description');
        return $this;
    }
    
    /**
     * 穿搭配数据组合
     * @param int $product_id
     * @return array
     */
    private function  getProductInfo($product_skn)
    {
        $data = QINProduct_Models_Product_Client::getFullProductBySkn($product_skn);
        if(empty($data)) {
            return array();
        }
        $product ['id'] = $data ['id'];
        $product_id = $data['id'];
        $product ['product_name'] = $data ['product_name'];
        $product ['cn_alphabet'] = $data ['cn_alphabet'];
        $product ['erp_product_id'] = $data ['erp_product_id'];
        $product ['brand_id'] = $data ['brand_id'];
        $product ['sales_phrase'] = isset($data ['sales_phrase']) ? $data ['sales_phrase'] :'';
        $product ['shelve_time'] = isset($data ['shelve_time']) ? $data ['shelve_time'] : 0;
        $product ['is_outlets'] = isset($data['is_outlets']) ? 'N' : $data['is_outlets'];
        $product ['phrase'] = empty($data['phrase']) ? '' : $data['phrase'];
        $product ['style'] = empty($data['style']) ? '' : $data['style'];
        $product['status'] = 0;
        if(isset($data['status']))
        {
        	$product['status'] = $data['status'];
        }

        $goods_list = QINProduct_Models_Goods_Client::getGoodsByProduct($product_id);
        foreach ($goods_list as $k => $v) {
            if(empty($v['color_image']))
            {
                unset($goods_list[$k]);
                continue;
            }
            $goods_list[$k]['url'] = 'http://item.yohobuy.com/product/pro_' . $product_id . '_' . $v['id'] . '/' . $product['cn_alphabet'] . '.html';
        }
        if(empty($goods_list))
        {
            return array();
        }
        $product['goods'] = $goods_list;
        
        $goods = array_shift ( $goods_list );
        $product['url'] = $goods ['url'];
        
        $product['default_pic'] = $goods ['color_image'];
        $price = QINProduct_Models_Price_Client::getPriceByProduct($product_id);
        $product['price'] = array(
            'market_price' => $price['market_price'],
            'sales_price' => $price['sales_price'],
            'special_price' => $price['special_price'],
            'yoho_coin_num' => $price['yoho_coin_num'],
            'vip_discount_type' => $price['vip_discount_type'],
            'vip_discount' => $price['vip_discount'],
            'list_sales_price' => number_format($price['sales_price'], 2),
            'list_market_price' => number_format($price['market_price'],2),
            'vip_price' => $price['vip_price']
        );
        return $product;
    }


    /**
     * 售后服务
     * @return $this
     */
    public function aftersale()
    {
        $this->display('aftersale');
        return $this;
    }

    /**
     * 咨询评论
     * @return $this
     */
    public function comment()
    {
        $this->display('comment');
        return $this;
    }


    /**
     * 选择模板
     * @param $template
     * @return bool|mixed
     */
    protected function display($template)
    {
        if (empty($template)) {
            return false;
        }
        return include __DIR__ . '/Template/Product/' . $template . '.phtml';
    }

    /**
     * 模板变量获取
     * @param $name
     * @return mixed
     */
    public function __get($name)
    {
        return $this->view->$name;
    }

    /**
     * 模板变量获取
     * @param $name
     * @return mixed
     */
    public function __isset($name)
    {
        return empty($this->view->$name);
    }
}