SearchService.php 21.0 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
5
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
D
v1.2.0  
devil_gong 已提交
6
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
7
// | Licensed ( https://opensource.org/licenses/mit-license.php )
D
v1.2.0  
devil_gong 已提交
8 9 10 11 12 13
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;

use think\Db;
14
use think\facade\Hook;
15
use app\service\GoodsService;
16
use app\service\BrandService;
D
Devil 已提交
17
use app\service\ResourcesService;
D
v1.2.0  
devil_gong 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

/**
 * 搜索服务层
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class SearchService
{
    /**
     * 获取商品列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-07
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
37
    public static function GoodsList($params = [])
D
v1.2.0  
devil_gong 已提交
38
    {
D
Devil 已提交
39
        // 返回格式
D
v1.2.0  
devil_gong 已提交
40 41 42 43 44
        $result = [
            'page_total'    => 0,
            'total'         => 0,
            'data'          => [],
        ];
D
Devil 已提交
45 46 47
        
        // 搜索条件
        $where = self::SearchWhereHandle($params);
D
Devil 已提交
48
        $where_base = $where['base'];
D
Devil 已提交
49 50
        $where_keywords = $where['keywords'];
        $where_screening_price = $where['screening_price'];
D
v1.2.0  
devil_gong 已提交
51

52 53 54 55 56 57 58 59 60 61 62
        // 排序
        if(!empty($params['order_by_field']) && !empty($params['order_by_type']) && $params['order_by_field'] != 'default')
        {
            $order_by = 'g.'.$params['order_by_field'].' '.$params['order_by_type'];
        } else {
            $order_by = 'g.access_count desc, g.sales_count desc, g.id desc';
        }

        // 分页计算
        $field = 'g.*';
        $page = max(1, isset($params['page']) ? intval($params['page']) : 1);
D
Devil 已提交
63
        $n = MyC('home_search_limit_number', 20, true);
64 65 66 67 68
        $m = intval(($page-1)*$n);

        // 搜索商品列表读取前钩子
        $hook_name = 'plugins_service_search_goods_list_begin';
        Hook::listen($hook_name, [
D
Devil 已提交
69 70 71
            'hook_name'                 => $hook_name,
            'is_backend'                => true,
            'params'                    => &$params,
D
Devil 已提交
72
            'where_base'                => &$where_base,
D
Devil 已提交
73 74 75 76 77 78 79
            'where_keywords'            => &$where_keywords,
            'where_screening_price'     => &$where_screening_price,
            'field'                     => &$field,
            'order_by'                  => &$order_by,
            'page'                      => &$page,
            'm'                         => &$m,
            'n'                         => &$n,
80 81
        ]);

D
v1.2.0  
devil_gong 已提交
82
        // 获取商品总数
D
Devil 已提交
83
        $result['total'] = (int) Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->where($where_base)->where(function($query) use($where_keywords) {
D
Devil 已提交
84
            self::SearchKeywordsWhereJoinType($query, $where_keywords);
D
Devil 已提交
85 86
        })->where(function($query) use($where_screening_price) {
            $query->whereOr($where_screening_price);
D
devil 已提交
87
        })->count('DISTINCT g.id');
D
v1.2.0  
devil_gong 已提交
88 89 90 91

        // 获取商品列表
        if($result['total'] > 0)
        {
D
devil 已提交
92
            // 查询数据
D
Devil 已提交
93
            $data = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->field($field)->where($where_base)->where(function($query) use($where_keywords) {
D
Devil 已提交
94
                self::SearchKeywordsWhereJoinType($query, $where_keywords);
D
Devil 已提交
95 96
            })->where(function($query) use($where_screening_price) {
                $query->whereOr($where_screening_price);
D
devil 已提交
97 98 99 100 101 102
            })->group('g.id')->order($order_by)->limit($m, $n)->select();

            // 数据处理
            $goods = GoodsService::GoodsDataHandle($data);

            // 返回数据
D
devil_gong 已提交
103
            $result['data'] = $goods['data'];
D
v1.2.0  
devil_gong 已提交
104 105
            $result['page_total'] = ceil($result['total']/$n);
        }
D
devil_gong 已提交
106
        return DataReturn('处理成功', 0, $result);
D
v1.2.0  
devil_gong 已提交
107 108
    }

D
Devil 已提交
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
    /**
     * 关键字搜索关系类型
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-04-02
     * @desc    description
     * @param   [object]          $query          [查询对象]
     * @param   [array]           $where_keywords [搜索关键字]
     */
    public static function SearchKeywordsWhereJoinType($query, $where_keywords)
    {
        // 搜索关键字默认或的关系
        $join = 'whereOr';

        // 是否开启并且关系
        if(MyC('home_search_is_keywords_where_and') == 1)
        {
            $join = 'where';
        }

        // 条件设置
        $query->$join($where_keywords);
    }

D
v1.2.0  
devil_gong 已提交
134
    /**
D
Devil 已提交
135 136 137 138 139 140 141 142 143 144
     * 搜索条件处理
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-01-08
     * @desc    description
     * @param   [array]           $params [输入参数]
     */
    public static function SearchWhereHandle($params = [])
    {
D
Devil 已提交
145 146 147 148 149 150 151 152
        // 搜索商品条件处理钩子
        $hook_name = 'plugins_service_search_goods_list_where';
        Hook::listen($hook_name, [
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
        ]);

D
Devil 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165
        // 基础条件
        $where_base = [
            ['g.is_delete_time', '=', 0],
            ['g.is_shelves', '=', 1]
        ];

        // 关键字
        $where_keywords = [];
        if(!empty($params['wd']))
        {
            $keywords = explode(' ', $params['wd']);
            foreach($keywords as $kv)
            {
D
Devil 已提交
166
                $where_keywords[] = ['g.title|g.simple_desc', 'like', '%'.$kv.'%'];
D
Devil 已提交
167 168 169 170
            }
        }

        // 品牌
D
Devil 已提交
171
        // 不存在搜索品牌的时候则看是否指定品牌
D
Devil 已提交
172 173
        if(!empty($params['brand_ids']))
        {
174 175
            if(!is_array($params['brand_ids']))
            {
D
Devil 已提交
176
                $params['brand_ids'] = (substr($params['brand_ids'], 0, 1) == '{') ? json_decode(htmlspecialchars_decode($params['brand_ids']), true) : explode(',', $params['brand_ids']);
177
            }
D
Devil 已提交
178 179 180 181 182 183 184 185 186
            if(!empty($params['brand_ids']))
            {
                $where_base[] = ['g.brand_id', 'in', array_unique($params['brand_ids'])];
            }
        } else {
            if(!empty($params['brand_id']))
            {
                $where_base[] = ['g.brand_id', 'in', intval($params['brand_id'])];
            }
D
Devil 已提交
187 188 189
        }

        // 分类id
D
Devil 已提交
190
        // 不存在搜索分类的时候则看是否指定分类
D
Devil 已提交
191 192
        if(!empty($params['category_ids']))
        {
D
Devil 已提交
193 194 195 196
            if(!is_array($params['category_ids']))
            {
                $params['category_ids'] = (substr($params['category_ids'], 0, 1) == '{') ? json_decode(htmlspecialchars_decode($params['category_ids']), true) : explode(',', $params['category_ids']);
            }
D
Devil 已提交
197 198 199
            if(!empty($params['category_ids']))
            {
                $ids = GoodsService::GoodsCategoryItemsIds($params['category_ids'], 1);
D
Devil 已提交
200 201 202 203 204 205 206
                $where_base[] = ['gci.category_id', 'in', $ids];
            }
        } else {
            if(!empty($params['category_id']))
            {
                $ids = GoodsService::GoodsCategoryItemsIds([intval($params['category_id'])], 1);
                $where_base[] = ['gci.category_id', 'in', $ids];
D
Devil 已提交
207
            }
D
Devil 已提交
208 209 210 211 212 213
        }

        // 筛选价格
        $where_screening_price = [];
        if(!empty($params['screening_price_values']))
        {
D
Devil 已提交
214
            if(!is_array($params['screening_price_values']))
D
Devil 已提交
215
            {
D
Devil 已提交
216 217 218 219 220
                $params['screening_price_values'] = (substr($params['screening_price_values'], 0, 1) == '{') ? json_decode(htmlspecialchars_decode($params['screening_price_values']), true) : explode(',', $params['screening_price_values']);
            }
            if(!empty($params['screening_price_values']))
            {
                foreach($params['screening_price_values'] as $v)
D
Devil 已提交
221
                {
D
Devil 已提交
222 223 224
                    $temp = explode('-', $v);
                    if(count($temp) == 2)
                    {
D
Devil 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
                        // 最小金额等于0、最大金额大于0
                        if(empty($temp[0]) && !empty($temp[1]))
                        {
                            $where_screening_price[] = [
                                ['min_price', 'elt', $temp[1]],
                            ];

                        // 最小金额大于0、最大金额大于0
                        // 最小金额等于0、最大金额等于0
                        } elseif((!empty($temp[0]) && !empty($temp[1])) || (empty($temp[0]) && empty($temp[1])))
                        {
                            $where_screening_price[] = [
                                ['min_price', 'egt', $temp[0]],
                                ['min_price', 'elt', $temp[1]],
                            ];

                        // 最小金额大于0、最大金额等于0
                        } elseif(!empty($temp[0]) && empty($temp[1]))
                        {
                            $where_screening_price[] = [
                                ['min_price', 'egt', $temp[0]],
                            ];
                        }
D
Devil 已提交
248
                    }
D
Devil 已提交
249 250 251 252 253 254 255
                }
            }
        }

        // 商品参数、属性
        if(!empty($params['goods_params_values']))
        {
D
Devil 已提交
256
            if(!is_array($params['goods_params_values']))
D
Devil 已提交
257
            {
D
Devil 已提交
258 259 260 261
                $params['goods_params_values'] = (substr($params['goods_params_values'], 0, 1) == '{') ? json_decode(htmlspecialchars_decode($params['goods_params_values']), true) : explode(',', $params['goods_params_values']);
            }
            if(!empty($params['goods_params_values']))
            {
D
Devil 已提交
262
                $ids = Db::name('GoodsParams')->where(['value'=>$params['goods_params_values'], 'type'=>self::SearchParamsWhereTypeValue()])->column('goods_id');
D
Devil 已提交
263 264 265 266
                if(!empty($ids))
                {
                    $where_base[] = ['g.id', 'in', $ids];
                }
D
Devil 已提交
267 268 269 270 271 272
            }
        }

        // 商品规格
        if(!empty($params['goods_spec_values']))
        {
D
Devil 已提交
273
            if(!is_array($params['goods_spec_values']))
D
Devil 已提交
274
            {
D
Devil 已提交
275 276 277 278 279 280 281 282 283
                $params['goods_spec_values'] = (substr($params['goods_spec_values'], 0, 1) == '{') ? json_decode(htmlspecialchars_decode($params['goods_spec_values']), true) : explode(',', $params['goods_spec_values']);
            }
            if(!empty($params['goods_spec_values']))
            {
                $ids = Db::name('GoodsSpecValue')->where(['value'=>$params['goods_spec_values']])->column('goods_id');
                if(!empty($ids))
                {
                    $where_base[] = ['g.id', 'in', $ids];
                }
D
Devil 已提交
284
            }
D
Devil 已提交
285 286
        }

D
Devil 已提交
287 288 289 290 291 292 293
        return [
            'base'              => $where_base,
            'keywords'          => $where_keywords,
            'screening_price'   => $where_screening_price,
        ];
    }

D
Devil 已提交
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
    /**
     * 参数搜索条件类型
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-04-11
     * @desc    description
     */
    public static function SearchParamsWhereTypeValue()
    {
        // 获取配置
        $value = MyC('home_search_params_type');
        if(empty($value))
        {
            $value = [2];
        }

        // 是否为数组
        if(!is_array($value))
        {
            $value = explode(',', $value);
        }

        return $value;
    }

D
Devil 已提交
320 321
    /**
     * 搜索记录添加
D
v1.2.0  
devil_gong 已提交
322 323 324 325 326 327
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2018-10-21T00:37:44+0800
     * @param   [array]          $params [输入参数]
     */
328
    public static function SearchAdd($params = [])
D
v1.2.0  
devil_gong 已提交
329
    {
D
Devil 已提交
330 331
        // 搜索数据结果
        if(!empty($params['search_result_data']))
D
v1.2.0  
devil_gong 已提交
332
        {
D
Devil 已提交
333 334 335 336 337
            $search_result = [
                'total'         => empty($params['search_result_data']['total']) ? 0 : $params['search_result_data']['total'],
                'data_count'    => empty($params['search_result_data']['data']) ? 0 : count($params['search_result_data']['data']),
                'page'          => empty($params['page']) ? 1 : intval($params['page']),
                'page_total'    => empty($params['search_result_data']['page_total']) ? 0 : $params['search_result_data']['page_total'],
D
v1.2.0  
devil_gong 已提交
338 339
            ];
        }
D
Devil 已提交
340 341

        // 日志数据
D
devil_gong 已提交
342
        $data = [
D
Devil 已提交
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
            'user_id'           => isset($params['user_id']) ? intval($params['user_id']) : 0,
            'keywords'          => empty($params['wd']) ? '' : $params['wd'],
            'order_by_field'    => empty($params['order_by_field']) ? '' : $params['order_by_field'],
            'order_by_type'     => empty($params['order_by_type']) ? '' : $params['order_by_type'],
            'search_result'     => empty($search_result) ? '' : json_encode($search_result, JSON_UNESCAPED_UNICODE),
            'ymd'               => date('Ymd'),
            'add_time'          => time(),
        ];

        // 参数处理
        $field_arr = [
            'brand_ids',
            'category_ids',
            'screening_price_values',
            'goods_params_values',
            'goods_spec_values',
D
devil_gong 已提交
359
        ];
D
Devil 已提交
360 361 362 363 364
        foreach($field_arr as $v)
        {
            $data[$v] = empty($params[$v]) ? '' : (is_array($params[$v]) ? json_encode($params[$v], JSON_UNESCAPED_UNICODE) : $params[$v]);
        }

D
devil_gong 已提交
365
        Db::name('SearchHistory')->insert($data);
D
v1.2.0  
devil_gong 已提交
366 367 368
    }

    /**
369 370 371 372 373 374 375
     * 搜索关键字列表
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-01-03
     * @desc    description
     * @param   [array]           $params [输入参数]
D
v1.2.0  
devil_gong 已提交
376
     */
377
    public static function SearchKeywordsList($params = [])
D
v1.2.0  
devil_gong 已提交
378
    {
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
        // 搜索框下热门关键字
        $data = [];
        switch(intval(MyC('home_search_keywords_type', 0)))
        {
            case 1 :
                $data = Db::name('SearchHistory')->where([['keywords', '<>', '']])->group('keywords')->limit(10)->column('keywords');
                break;
            case 2 :
                $keywords = MyC('home_search_keywords', '', true);
                if(!empty($keywords))
                {
                    $data = explode(',', $keywords);
                }
                break;
        }
        return $data;
D
v1.2.0  
devil_gong 已提交
395
    }
D
Devil 已提交
396 397 398 399 400 401 402 403 404 405 406 407

    /**
     * 分类下品牌列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-08-29
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function CategoryBrandList($params = [])
    {
D
Devil 已提交
408 409 410 411 412 413 414
        $data = [];
        if(MyC('home_search_is_brand', 0) == 1)
        {
            // 基础条件
            $brand_where = [
                ['is_enable', '=', 1],
            ];
D
Devil 已提交
415

D
Devil 已提交
416 417
            // 搜索条件
            $where = self::SearchWhereHandle($params);
D
Devil 已提交
418
            $where_base = $where['base'];
D
Devil 已提交
419 420
            $where_keywords = $where['keywords'];
            $where_screening_price = $where['screening_price'];
D
Devil 已提交
421

D
Devil 已提交
422
            // 一维数组、参数值去重
D
Devil 已提交
423
            if(!empty($where_base) || !empty($where_keywords) || !empty($where_screening_price))
D
Devil 已提交
424
            {
D
Devil 已提交
425
                $ids = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->where($where_base)->where(function($query) use($where_keywords) {
D
Devil 已提交
426
                    self::SearchKeywordsWhereJoinType($query, $where_keywords);
D
Devil 已提交
427 428 429 430 431 432 433
                })->where(function($query) use($where_screening_price) {
                    $query->whereOr($where_screening_price);
                })->group('g.brand_id')->column('g.brand_id');
                if(!empty($ids))
                {
                    $brand_where[] = ['id', 'in', array_unique($ids)];
                }
D
Devil 已提交
434 435
            }

D
Devil 已提交
436 437 438 439 440 441 442 443 444 445 446
            // 获取品牌列表
            $data_params = [
                'field'     => 'id,name,logo,website_url',
                'where'     => $brand_where,
                'm'         => 0,
                'n'         => 0,
            ];
            $ret = BrandService::BrandList($data_params);
            $data = empty($ret['data']) ? [] : $ret['data'];
        }
        return $data;
D
Devil 已提交
447 448 449 450 451 452 453 454 455 456 457 458 459
    }

    /**
     * 根据分类id获取下级列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-08-29
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function GoodsCategoryList($params = [])
    {
D
Devil 已提交
460 461 462 463 464 465 466
        $data = [];
        if(MyC('home_search_is_category', 0) == 1)
        {
            $pid = empty($params['category_id']) ? 0 : intval($params['category_id']);
            $data = GoodsService::GoodsCategoryList(['where'=>['pid'=>$pid], 'field'=>'id,name']);
        }
        return $data;
D
Devil 已提交
467 468 469 470 471 472 473 474 475 476 477 478 479
    }

    /**
     * 获取商品价格筛选列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-07
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function ScreeningPriceList($params = [])
    {
D
Devil 已提交
480 481 482 483 484 485
        $data = [];
        if(MyC('home_search_is_price', 0) == 1)
        {
            $data = Db::name('ScreeningPrice')->field('id,name,min_price,max_price')->where(['is_enable'=>1])->order('sort asc')->select();
        }
        return $data;
D
Devil 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498
    }

    /**
     * 搜索商品参数列表、去重
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-01-08
     * @desc    description
     * @param   [array]           $params [输入参数]
     */
    public static function SearchGoodsParamsValueList($params = [])
    {
D
Devil 已提交
499 500 501 502 503
        $data = [];
        if(MyC('home_search_is_params', 0) == 1)
        {
            // 搜索条件
            $where = self::SearchWhereHandle($params);
D
Devil 已提交
504
            $where_base = $where['base'];
D
Devil 已提交
505 506 507
            $where_keywords = $where['keywords'];
            $where_screening_price = $where['screening_price'];

D
Devil 已提交
508
            // 仅搜索基础参数
D
Devil 已提交
509
            $where_base[] = ['gp.type', 'in', self::SearchParamsWhereTypeValue()];
D
Devil 已提交
510

D
Devil 已提交
511
            // 一维数组、参数值去重
D
Devil 已提交
512
            $data = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->join(['__GOODS_PARAMS__'=>'gp'], 'g.id=gp.goods_id')->where($where_base)->where(function($query) use($where_keywords) {
D
Devil 已提交
513
                self::SearchKeywordsWhereJoinType($query, $where_keywords);
D
Devil 已提交
514 515 516 517 518
            })->where(function($query) use($where_screening_price) {
                $query->whereOr($where_screening_price);
            })->group('gp.value')->field('gp.value')->select();
        }
        return $data;
D
Devil 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531
    }

    /**
     * 搜索商品规格列表、去重
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-01-08
     * @desc    description
     * @param   [array]           $params [输入参数]
     */
    public static function SearchGoodsSpecValueList($params = [])
    {
D
Devil 已提交
532 533 534 535 536
        $data = [];
        if(MyC('home_search_is_spec', 0) == 1)
        {
            // 搜索条件
            $where = self::SearchWhereHandle($params);
D
Devil 已提交
537
            $where_base = $where['base'];
D
Devil 已提交
538 539 540 541
            $where_keywords = $where['keywords'];
            $where_screening_price = $where['screening_price'];

            // 一维数组、参数值去重
D
Devil 已提交
542
            $data = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->join(['__GOODS_SPEC_VALUE__'=>'gsv'], 'g.id=gsv.goods_id')->where($where_base)->where(function($query) use($where_keywords) {
D
Devil 已提交
543
                self::SearchKeywordsWhereJoinType($query, $where_keywords);
D
Devil 已提交
544 545 546 547 548
            })->where(function($query) use($where_screening_price) {
                $query->whereOr($where_screening_price);
            })->group('gsv.value')->field('gsv.value')->select();
        }
        return $data;
D
Devil 已提交
549
    }
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565

    /**
     * 搜索条件基础数据
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-01-11
     * @desc    description
     * @param   [array]           $params [输入参数]
     */
    public static function SearchMapInfo($params = [])
    {
        // 分类
        $category = empty($params['category_id']) ? [] : GoodsService::GoodsCategoryRow(['id'=>intval($params['category_id']), 'field'=>'name,vice_name,describe,seo_title,seo_keywords,seo_desc']);

        // 品牌
D
Devil 已提交
566
        $brand = null;
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
        if(!empty($params['brand_id']))
        {
            $data_params = [
                'field'     => 'id,name,describe,logo,website_url',
                'where'     => ['id'=>intval($params['brand_id'])],
                'm'         => 0,
                'n'         => 1,
            ];
            $ret = BrandService::BrandList($data_params);
            if(!empty($ret['data']) && !empty($ret['data'][0]))
            {
                $brand = $ret['data'][0];
            }
        }

        return [
D
Devil 已提交
583 584
            'category'  => empty($category) ? null : $category,
            'brand'     => empty($brand) ? null : $brand,
585 586 587
        ];
        
    }
D
v1.2.0  
devil_gong 已提交
588 589
}
?>