Search.php 3.85 KB
<?php
namespace Product;

use Plugin\HelperSearch;
use \LibModels\Web\Product\SearchData;

/**
 * sale首页模板数据模型
 *
 * @name SaleModel
 * @package models
 * @copyright yoho.inc
 * @version 1.0 (2015-12-17 13:54:56)
 * @author sefon
 */
class SearchModel
{

    /**
     * 根据条件获取搜索数据
     *
     * @param $condition 搜索数据的条件
     * @param $options Array([imgSize]
     *            => Array([0] => 235[1] => 314)[minImgSize] => Array([0] => 60[1] => 80)[gender] => 1[needPd] => Y[rowNum] => 5[viewNum] => 60)
     * @author sefon 2015-12-17 16:12:18
     * @return array
     */
    public static function getSearchData($condition, $options)
    {
        $data = array();
        // 调用接口查询商品数据
        $result = SearchData::searchElasticByCondition($condition);
        if (isset($result['code']) && $result['code'] === 200) {
            // 调用分类信息
            $category = SearchData::getClassesData();
            if (isset($category['code']) && $category['code'] === 200) {
                $result['data']['filter']['group_sort'] = $category['data']['sort'];
            }
            // 调用折扣区间
            $discount = SearchData::getDiscount();
            if (isset($discount['code']) && $discount['code'] === 200) {
                $result['data']['filter']['discount'] = $discount['data']['discount'];
            }
            // 调用最新上架
            $recent = SearchData::recentShelve();
            if (isset($discount['code']) && $discount['code'] === 200) {
                $result['data']['filter']['recent'] = $recent['data']['recent'];
            }
            //用户浏览记录
            $result['data']['filter']['review'] = SearchData::getRecentReview();
            // 组织模板数据
            $list = HelperSearch::getList($result, $options);
            $data = array(
                //初始化js
                'productListPage' => true,
                'list' => $list
            );
        }
        return $data;
    }

    /**
     * 搜索页面获取搜索数据
     * @param $condition
     * @param $options
     * @return array
     */
    public static function searchData($condition, $options){
        $data = self::getSearchData($condition, $options);
        //过滤频道
        if (isset($condition['gender'])) {
            unset($data['list']['filters']['channel']);
        }
        //过滤品牌
        if (isset($condition['brand'])) {
            unset($data['list']['filters']['brand']);
        }
        //过滤价格
        if (isset($condition['price'])) {
            unset($data['list']['filters']['price']);
            unset($data['list']['filters']['customPrice']);
        }
        //过滤颜色
        if (isset($condition['color'])) {
            unset($data['list']['filters']['color']);
        }
        //过滤风格
        if (isset($condition['style'])) {
            unset($data['list']['filters']['seniorChose']);
        }
        //过滤尺码
        if (isset($condition['size'])) {
            unset($data['list']['filters']['size']);
        }
        return $data;

    }
    /**
     * 根据product_sn查询产品图片信息
     * @param $product_sn
     * @param $options
     * @author sefon 2015-12-28 18:09:28
     * @return array
     */
    public static function getProductPic($product_sn, $options)
    {
        $condition['query'] = $product_sn;
        //返回搜索条件
        $condition['needFilter'] = 0;
        //获取产品数据
        $data = SearchData::searchElasticByCondition($condition);
        if (isset($data['code']) && $data['code'] === 200 && isset($data['data']['product_list']) && !empty($data['data']['product_list'])) {
            //组织数据结构
            $data = HelperSearch::getProductPic($data['data']['product_list'], $options);
        }
        echo json_encode($data);
    }
}