heyuntao
2023-07-18 a62ebe0d1b9ea896cdba7bd4ec6e1d0d142b3b84
application/api/logic/taoke/Search.php
@@ -139,7 +139,7 @@
        return $goods;
    }
    public function compare_good($content,$common_relation_id){
    public function compare_good($content,$common_relation_id,$exclude_tb=0,$exclude_jd=0,$exclude_pdd=0,$exclude_dy=0){
        //根据传入的内容调用ast方法
        $goods = $this->ast($content);
        $title = '';
@@ -188,6 +188,7 @@
        array_multisort($sort1, SORT_ASC, $jdGoods);
        $ppdGoodes=[];
        $common_relation_id='168369887871568';
        //根据标题查询拼多多商品
        if(!empty($common_relation_id)){
            $ppdGoodes=$LogicPdd->searchGoods($title,'',$common_relation_id,'',1,20,0,'');
@@ -214,38 +215,61 @@
        if($goodscount<20){
            //如果goodscount不满足20则从天猫商品里补足20
            $needcount=20-$goodscount+5;
            $newGoods =array_merge($newGoods,array_slice($tmGoods,0,5));
            $newGoods =array_merge($newGoods,array_slice($tmcsGoods,0,5));
            $newGoods =array_merge($newGoods,array_slice($jdGoods,0,5));
            if($exclude_tb==0){
                $newGoods =array_merge($newGoods,array_slice($tmGoods,0,5));
                $newGoods =array_merge($newGoods,array_slice($tmcsGoods,0,5));
            }
            if($exclude_jd==0){
                $newGoods =array_merge($newGoods,array_slice($jdGoods,0,5));
            }
            //按照价格排序
            $sort1 = array_column($newGoods, 'actualPrice');
            array_multisort($sort1, SORT_ASC, $newGoods);
            $newGoods =array_merge($newGoods,array_slice($taobaoGoods,0,$needcount));
            $newGoods =array_merge($newGoods,array_slice($ppdGoodes,0,5));
            $newGoods =array_merge($newGoods,array_slice($dyGoods,0,5));
            if(count($newGoods)>0){
                $sort1 = array_column($newGoods, 'actualPrice');
                array_multisort($sort1, SORT_ASC, $newGoods);
            }
            if($exclude_pdd==0){
                $newGoods =array_merge($newGoods,array_slice($ppdGoodes,0,5));
            }
            if($exclude_tb==0){
                $newGoods =array_merge($newGoods,array_slice($taobaoGoods,0,$needcount));
            }
            if($exclude_dy==0){
                $newGoods =array_merge($newGoods,array_slice($dyGoods,0,5));
            }
        }
        else{
            $newGoods =array_merge($newGoods,array_slice($tmGoods,0,5));
            $newGoods =array_merge($newGoods,array_slice($tmcsGoods,0,5));
            $newGoods =array_merge($newGoods,array_slice($jdGoods,0,5));
            if($exclude_tb==0){
                $newGoods =array_merge($newGoods,array_slice($tmGoods,0,5));
                $newGoods =array_merge($newGoods,array_slice($tmcsGoods,0,5));
            }
            if($exclude_jd==0){
                $newGoods =array_merge($newGoods,array_slice($jdGoods,0,5));
            }
            //按照价格排序
            $sort1 = array_column($newGoods, 'actualPrice');
            array_multisort($sort1, SORT_ASC, $newGoods);
            $newGoods =array_merge($newGoods,array_slice($ppdGoodes,0,5));
            $newGoods =array_merge($newGoods,array_slice($dyGoods,0,5));
            if(count($newGoods)>0){
                $sort1 = array_column($newGoods, 'actualPrice');
                array_multisort($sort1, SORT_ASC, $newGoods);
            }
            if($exclude_pdd==0){
                $newGoods =array_merge($newGoods,array_slice($ppdGoodes,0,5));
            }
            if($exclude_dy==0){
                $newGoods =array_merge($newGoods,array_slice($dyGoods,0,5));
            }
        }
        //如果还是不满足20则从淘宝商品里补足20
        if(count($newGoods)<20){
            $tbGoods = $LogicDataoke->superSearch($title,1,20,0,0);
            //去除销量为0的商品并按照价格排序
            $tbGoods = array_filter($tbGoods,function($v){
                return $v['monthSales'] > 0&&$v['shopType']=='淘宝';
            });
            //按照价格排序
            $sort1 = array_column($tbGoods, 'actualPrice');
            array_multisort($sort1, SORT_ASC, $tbGoods);
            $newGoods =array_merge($newGoods,array_slice($tbGoods,0,20));
            if($exclude_tb==0){
                $tbGoods = $LogicDataoke->superSearch($title,1,20,0,0);
                //去除销量为0的商品并按照价格排序
                $tbGoods = array_filter($tbGoods,function($v){
                    return $v['monthSales'] > 0&&$v['shopType']=='淘宝';
                });
                //按照价格排序
                $sort1 = array_column($tbGoods, 'actualPrice');
                array_multisort($sort1, SORT_ASC, $tbGoods);
                $newGoods =array_merge($newGoods,array_slice($tbGoods,0,20));
            }
        }
        //取出前20个商品