mark 2 years ago
parent
commit
605bfe640b
1 changed files with 32 additions and 13 deletions
  1. 32 13
      app/Http/Logic/WechatLogic.php

+ 32 - 13
app/Http/Logic/WechatLogic.php

@@ -313,6 +313,16 @@ S;
         $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));
@@ -322,20 +332,11 @@ S;
                 $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>";
+//                $link = "<a href='".$url."'>点我购买,即刻拿优惠</a>";
             }else{
                 //未备案,使用自己已备案的pid调用商品搜索接口获取goods_sign
-                $bean = new GoodsSearchParamBean(
-                    [
-                        "keyword"=>$message["Content"],
-                        "pid"=>"23985775_220421267"
-                    ]
-                );
-                $data = DuoDuoKeUtil::goodsSearch($bean);
-                $instance->info("拼多多返回商品详情数据:".json_encode($data));
-
                 //获取到goods_sign
-                $goods_sign = $data["goods_search_response"]["goods_list"][0]["goods_sign"];
+                $goods_sign = $goodsData["goods_search_response"]["goods_list"][0]["goods_sign"];
                 $beanData = [
                     "p_id"=>$platformSid,
                     "goods_sign_list"=>json_encode([$goods_sign]),
@@ -346,10 +347,28 @@ S;
                 $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>";
+//                $link = "<a href='".$url."'>点击备案之后,直接购买</a>";
             }
 
-            $wenti = new Text($link);
+            $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/100000,2);
+            $goodsTitle = $goodsData["goods_search_response"]["goods_list"][0]["goods_name"];
+            $msg = <<<S
+            【 $goodsTitle 】
+            【原价】:$goodsPrice 元
+            【优惠券】:$couponPrice 元
+            【券后价】:$afterCouponPrice 元
+            【返现金额】:$rebeatPrice
+            -------------------------
+            点击链接购买:$url
+            具体返现金额,以实际支付金额为准
+            -------------------------
+S;
+
+
+            $wenti = new Text($msg);
             $app->customer_service->message($wenti)->to($officialOpenId)->send();
 
         }