mark 2 роки тому
батько
коміт
fddc03bc82
1 змінених файлів з 91 додано та 84 видалено
  1. 91 84
      app/Http/Logic/WechatLogic.php

+ 91 - 84
app/Http/Logic/WechatLogic.php

@@ -310,53 +310,57 @@ S;
         $daogoUser = UserModel::query()->where("user_open_id",$officialOpenId)->first();
         $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$daogoUser->id);
         $instance->info("pid:".$platformSid);
-        //1.判断是否匹配上拼多多商品链接
-        $res = preg_match("/https\:\/\/mobile\.yangkeduo\.com/",$message["Content"],$match);
-        if($res){
-            $instance->info("匹配到拼多多链接");
-            //获取商品详情
-            $bean = new GoodsSearchParamBean(
-                [
-                    "keyword"=>$message["Content"],
-                    "pid"=>"23985775_220421267"
-                ]
-            );
-            $goodsData = DuoDuoKeUtil::goodsSearch($bean);
-            $instance->info("拼多多返回商品详情数据:".json_encode($goodsData));
-
-            //1.判断推广位是否备案
-            $oauthRes = DuoDuoKeUtil::memberAuthorityQuery($platformSid);
-            $instance->info("备案信息:".json_encode($oauthRes));
-            //2.未备案这授权,已备案则直接获取推广链接
-            if($oauthRes["authority_query_response"]["bind"]){
-                //已备案
-                $data = DuoDuoKeUtil::goodsZsUnitUrlGen($platformSid,$message["Content"]);
-                $instance->info("拼多多返回数据:".json_encode($data));
-                $url = $data["goods_zs_unit_generate_response"]["short_url"];
+        $wenti = new Text("稍等");
+        $app->customer_service->message($wenti)->to($officialOpenId)->send();
+
+        try{
+            //1.判断是否匹配上拼多多商品链接
+            $res = preg_match("/https\:\/\/mobile\.yangkeduo\.com/",$message["Content"],$match);
+            if($res){
+                $instance->info("匹配到拼多多链接");
+                //获取商品详情
+                $bean = new GoodsSearchParamBean(
+                    [
+                        "keyword"=>$message["Content"],
+                        "pid"=>"23985775_220421267"
+                    ]
+                );
+                $goodsData = DuoDuoKeUtil::goodsSearch($bean);
+                $instance->info("拼多多返回商品详情数据:".json_encode($goodsData));
+
+                //1.判断推广位是否备案
+                $oauthRes = DuoDuoKeUtil::memberAuthorityQuery($platformSid);
+                $instance->info("备案信息:".json_encode($oauthRes));
+                //2.未备案这授权,已备案则直接获取推广链接
+                if($oauthRes["authority_query_response"]["bind"]){
+                    //已备案
+                    $data = DuoDuoKeUtil::goodsZsUnitUrlGen($platformSid,$message["Content"]);
+                    $instance->info("拼多多返回数据:".json_encode($data));
+                    $url = $data["goods_zs_unit_generate_response"]["short_url"];
 //                $link = "<a href='".$url."'>点我购买,即刻拿优惠</a>";
-            }else{
-                //未备案,使用自己已备案的pid调用商品搜索接口获取goods_sign
-                //获取到goods_sign
-                $goods_sign = $goodsData["goods_search_response"]["goods_list"][0]["goods_sign"];
-                $beanData = [
-                    "p_id"=>$platformSid,
-                    "goods_sign_list"=>json_encode([$goods_sign]),
-                    "generate_authority_url"=>"true",
-                ];
-
-                $generateBean = new GoodsPromotionUrlGenerateParamBean($beanData);
-                $res = DuoDuoKeUtil::goodsPromotionUrlGenerate($generateBean);
-                $instance->info("生成备案信息:".json_encode($res));
-                $url = $res["goods_promotion_url_generate_response"]["goods_promotion_url_list"][0]["short_url"];
+                }else{
+                    //未备案,使用自己已备案的pid调用商品搜索接口获取goods_sign
+                    //获取到goods_sign
+                    $goods_sign = $goodsData["goods_search_response"]["goods_list"][0]["goods_sign"];
+                    $beanData = [
+                        "p_id"=>$platformSid,
+                        "goods_sign_list"=>json_encode([$goods_sign]),
+                        "generate_authority_url"=>"true",
+                    ];
+
+                    $generateBean = new GoodsPromotionUrlGenerateParamBean($beanData);
+                    $res = DuoDuoKeUtil::goodsPromotionUrlGenerate($generateBean);
+                    $instance->info("生成备案信息:".json_encode($res));
+                    $url = $res["goods_promotion_url_generate_response"]["goods_promotion_url_list"][0]["short_url"];
 //                $link = "<a href='".$url."'>点击备案之后,直接购买</a>";
-            }
+                }
 
-            $goodsPrice = round($goodsData["goods_search_response"]["goods_list"][0]["min_group_price"]/100,2);
-            $couponPrice = round($goodsData["goods_search_response"]["goods_list"][0]["coupon_discount"]/100,2);
-            $afterCouponPrice = $goodsPrice-$couponPrice;
-            $rebeatPrice = round($goodsData["goods_search_response"]["goods_list"][0]["promotion_rate"]*$afterCouponPrice*0.7/1000,2);
-            $goodsTitle = $goodsData["goods_search_response"]["goods_list"][0]["goods_name"];
-            $msg = <<<S
+                $goodsPrice = round($goodsData["goods_search_response"]["goods_list"][0]["min_group_price"]/100,2);
+                $couponPrice = round($goodsData["goods_search_response"]["goods_list"][0]["coupon_discount"]/100,2);
+                $afterCouponPrice = $goodsPrice-$couponPrice;
+                $rebeatPrice = round($goodsData["goods_search_response"]["goods_list"][0]["promotion_rate"]*$afterCouponPrice*0.7/1000,2);
+                $goodsTitle = $goodsData["goods_search_response"]["goods_list"][0]["goods_name"];
+                $msg = <<<S
 【 $goodsTitle 】
 【原价】:$goodsPrice 元
 【优惠券】:$couponPrice 元
@@ -367,28 +371,26 @@ S;
 具体返现金额,以实际支付金额为准
 -------------------------
 S;
+                $wenti = new Text($msg);
+                $app->customer_service->message($wenti)->to($officialOpenId)->send();
+                return;
+            }
 
-
-            $wenti = new Text($msg);
-            $app->customer_service->message($wenti)->to($officialOpenId)->send();
-            return;
-        }
-
-        //2.判断是否匹配上淘宝链接
-        $res = preg_match("/https\:\/\/m\.tb\.cn/",$message["Content"],$match);
-        //获取聚推客的推广位ID
-        $jutuikeSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$daogoUser->id);
-        if($res){
-            $instance->info("匹配到淘宝链接");
-            $goodsInfo = JutuikeUtil::transferGoodsLink($message["Content"]);
-            $tuiguangRes = JutuikeUtil::convert($goodsInfo["goodsId"],$jutuikeSid);
-            $goodsTitle = $tuiguangRes["goodsName"];
-            $goodsPrice = $tuiguangRes["marketPrice"];
-            $couponPrice = $tuiguangRes["couponInfo"]["fav"];
-            $afterCouponPrice = $tuiguangRes["price"];
-            $rebeatPrice = round($tuiguangRes["commissionRate"]*0.7,2);
-            $url = $tuiguangRes["url"];
-            $msg = <<<S
+            //2.判断是否匹配上淘宝链接
+            $res = preg_match("/https\:\/\/m\.tb\.cn/",$message["Content"],$match);
+            //获取聚推客的推广位ID
+            $jutuikeSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$daogoUser->id);
+            if($res){
+                $instance->info("匹配到淘宝链接");
+                $goodsInfo = JutuikeUtil::transferGoodsLink($message["Content"]);
+                $tuiguangRes = JutuikeUtil::convert($goodsInfo["goodsId"],$jutuikeSid);
+                $goodsTitle = $tuiguangRes["goodsName"];
+                $goodsPrice = $tuiguangRes["marketPrice"];
+                $couponPrice = $tuiguangRes["couponInfo"]["fav"];
+                $afterCouponPrice = $tuiguangRes["price"];
+                $rebeatPrice = round($tuiguangRes["commissionRate"]*0.7,2);
+                $url = $tuiguangRes["url"];
+                $msg = <<<S
 【 $goodsTitle 】
 【原价】:$goodsPrice 元
 【优惠券】:$couponPrice 元
@@ -400,23 +402,23 @@ S;
 具体返现金额,以实际支付金额为准
 -------------------------
 S;
-            $wenti = new Text($msg);
-            $app->customer_service->message($wenti)->to($officialOpenId)->send();
-            return;
-        }
-        //3.判断是否匹配到维品会链接
-        $res = preg_match("/https\:\/\/m\.vip\.com/",$message["Content"],$match);
-        if($res){
-            $instance->info("匹配到维品会链接");
-            $goodsInfo = JutuikeUtil::transferGoodsLink($message["Content"]);
-            $tuiguangRes = JutuikeUtil::convert($goodsInfo["goodsId"],$jutuikeSid,$goodsInfo["source"]);
-            $goodsTitle = $tuiguangRes["goodsName"];
-            $goodsPrice = $tuiguangRes["marketPrice"];
-            $couponPrice = $tuiguangRes["couponInfo"]["fav"];
-            $afterCouponPrice = $tuiguangRes["price"];
-            $rebeatPrice = round($tuiguangRes["commissionRate"]*0.7,2);
-            $url = $tuiguangRes["url"];
-            $msg = <<<S
+                $wenti = new Text($msg);
+                $app->customer_service->message($wenti)->to($officialOpenId)->send();
+                return;
+            }
+            //3.判断是否匹配到维品会链接
+            $res = preg_match("/https\:\/\/m\.vip\.com/",$message["Content"],$match);
+            if($res){
+                $instance->info("匹配到维品会链接");
+                $goodsInfo = JutuikeUtil::transferGoodsLink($message["Content"]);
+                $tuiguangRes = JutuikeUtil::convert($goodsInfo["goodsId"],$jutuikeSid,$goodsInfo["source"]);
+                $goodsTitle = $tuiguangRes["goodsName"];
+                $goodsPrice = $tuiguangRes["marketPrice"];
+                $couponPrice = $tuiguangRes["couponInfo"]["fav"];
+                $afterCouponPrice = $tuiguangRes["price"];
+                $rebeatPrice = round($tuiguangRes["commissionRate"]*0.7,2);
+                $url = $tuiguangRes["url"];
+                $msg = <<<S
 【 $goodsTitle 】
 【原价】:$goodsPrice 元
 【优惠券】:$couponPrice 元
@@ -427,10 +429,15 @@ S;
 具体返现金额,以实际支付金额为准
 -------------------------
 S;
-            $wenti = new Text($msg);
+                $wenti = new Text($msg);
+                $app->customer_service->message($wenti)->to($officialOpenId)->send();
+                return;
+            }
+        }catch (\Throwable $exception){
+            $wenti = new Text("请换个商品,该商品没有返利");
             $app->customer_service->message($wenti)->to($officialOpenId)->send();
-            return;
         }
+
     }
 
     /**