heyuntao
2023-07-13 3917040b9da73089ad98acc9de91c03daae67178
application/api/logic/taoke/Search.php
@@ -10,7 +10,7 @@
use app\common\model\User as ModelUser;
use app\api\logic\taoke\device\Haodanku as LogicHaodanku;
use app\api\logic\taoke\device\Dataoke as LogicDataoke;
use think\log;
class Search extends BasicLogic
@@ -82,12 +82,23 @@
        switch($this->provider){
            case 'tb':  //淘宝
                $info = $LogicZhetaoke->zhuanlian($uri,'');
               //$info = $LogicDataoke->zhuanlian($uri,'');
               //获取宝贝详情
                $goods_id=$info["tao_id"];
                $info = $LogicDataoke->getGoodsDetail($goods_id);
                if(empty($info)) return [];
                if($info) $goods = $info;
                if(empty($info)&&isset($parse_url['host'])&&strstr($parse_url['host'],'item.taobao.com')){
                    $info = $LogicDataoke->zhuanlian($uri,'');
                    //根据宝贝标题搜索宝贝
                    $item_name=$info["title"];
                    $goods["goodsId"]="";
                    $goods["title"]=$item_name;
                }
                else if(empty($info)){
                    $goods = [];
                }
                else{
                    $goods_id=$info["tao_id"];
                    $info = $LogicDataoke->getGoodsDetail($goods_id);
                    if(empty($info)) return [];
                    if($info) $goods = $info;
                }
                break;
            case 'tm': 
                    $info = $LogicDingdanxia->superSearch($uri,'tm','t');
@@ -127,5 +138,52 @@
        }
        return $goods;
    }
    public function compare_good($content,$common_relation_id){
        //根据传入的内容调用ast方法
        $goods = $this->ast($content);
        $title = '';
        //判断goods是否为空
        if(empty($goods)){
            $title = $content;
        }
        else{
            $title = $goods['title'];
        }
        //根据$title搜索各大平台的商品天猫,淘宝,京东自营,京东POP,拼多多,唯品会,抖音
        $LogicDingdanxia = new LogicDingdanxia();
        $LogicJd = new LogicJd();
        $LogicPdd = new LogicPdd();
        $LogicHaodanku = new LogicHaodanku();
        $LogicDataoke=new LogicDataoke();
        //根据标题查询天猫商品
        $newGoods = $LogicDataoke->superSearch($title,1,5,0,1);
        //根据标题查询京东自营商品
        $newGoods =array_merge($newGoods,$LogicJd->searchGoods($title,'desc','g',0,'match',1,5));
        //根据标题查询拼多多商品
        $ppdGoodes=$LogicPdd->searchGoods($title,'',$common_relation_id,'',1,10,0,'');
        $newGoods =array_merge($newGoods,array_slice($ppdGoodes,0,5));
        //根据标题查询抖音商品
        $newGoods =array_merge($newGoods,$LogicHaodanku->getDygoodsList('',$title,0,1,5));
        if(count($newGoods)<20){
         //根据标题查询淘宝商品
        // $newGoods =array_merge($newGoods,$LogicDataoke->superSearch($title,1,5,0,0));
         //根据标题查询京东POP商品
        // $newGoods =array_merge($newGoods,$LogicJd->searchGoods($title,'desc','p',0,'match',1,5));
         //根据标题查询唯品会商品
        // $newGoods =array_merge($newGoods,$LogicDingdanxia->superSearch($goods['title'],'wph','t'));
        }
        //将newGoods按照价格排序
        $sort1 = array_column($newGoods, 'actualPrice');
        array_multisort($sort1, SORT_ASC, $newGoods);
        log::write("goodsList:".json_encode($newGoods));
        //取出前20个商品
        $goodsList = array_slice($newGoods,0,20);
        return $goodsList;
    }
    
}