Browse Source

修改淘宝为自己的上游

mark 3 năm trước cách đây
mục cha
commit
7259b1384d

+ 55 - 0
app/Http/Controllers/BaseController.php

@@ -13,6 +13,7 @@ use App\Http\Bean\Util\Wechat\Miniprograme\GetOrderSearchParamBean;
 use App\Http\Bean\Util\Wechat\Miniprograme\GetProductGenerateParamBean;
 use App\Http\Bean\Util\Wechat\Miniprograme\GetProductListParamBean;
 use App\Http\Enum\MeiTuanLinkTypeEnum;
+use App\Http\Logic\Cron\CronLogic;
 use App\Http\Utils\BaseUtil;
 use App\Http\Utils\DianYing\DianYingUtil;
 use App\Http\Utils\HeiMaUtil;
@@ -24,6 +25,7 @@ use App\Http\Utils\Pdd\DuoDuoKeUtil;
 use App\Http\Utils\TaoBao\TaobaoLianMengUtil;
 use App\Http\Utils\Wechat\Miniprograme\MiniprogrameLianMengUtil;
 use App\Http\Utils\WechatAccountUtil;
+use App\Models\TaobaoPidModel;
 use App\Models\UserOrderCommissionModel;
 use App\Models\WechatAccountModel;
 use EasyWeChat\Kernel\Messages\Image;
@@ -131,6 +133,14 @@ class BaseController extends Controller
 
     public function test()
     {
+        CronLogic::taobaoOrdersLogic();
+        dd(1);
+        $data = TaobaoPidModel::query()
+            ->select([DB::raw("any_value(heima_app_key) as heima_app_key"),DB::raw("any_value(heima_app_secret) as heima_app_secret"),"heima_sid"])
+            ->groupBy("heima_sid")
+            ->get()->toArray();
+        $res = HeiMaUtil::getOrderList($data[0]);
+        dd($res);
 //        dd(TaobaoLianMengUtil::getGoodsInfo(621062906541));
 //        $completeOrders = UserOrderCommissionModel::query()
 //            ->where("commission_status",1)
@@ -143,7 +153,52 @@ class BaseController extends Controller
 //        return $this->success($completeOrders);
 //        return $this->success(JutuikeUtil::getActList());
 //        TaobaoLianMengUtil::taokoulingConvert("淘宝,信这于好之他而着我而天到微喜【sheii苏茵茵】大小姐~韩国真皮粗跟中筒靴女秋弹力长靴瘦腿靴");
+        $kouling = "38信有看么子他然是那年有去信 https://m.tb.cn/h.f8tCpoK?sm=67141d  骆驼男装 2021年新款羽绒服男短款加厚情侣款衣服冬季外套面包服";
+//        $info = TaobaoLianMengUtil::taokoulingConvert($kouling,70362850341);
+//        $goodsInfo = TaobaoLianMengUtil::getGoodsInfo(654351631402,70362850341);
+//        $res = TaobaoLianMengUtil::taokoulingCreate($info["click_url"],70362850341);
+//        $heimaData = HeiMaUtil::gaoYongZhuanLian(654351631402,70362850341);
+        $taobaoSid = 70362850341;
+        $info = TaobaoLianMengUtil::taokoulingConvert($kouling,$taobaoSid);
+
+        $goodsInfo = TaobaoLianMengUtil::getGoodsInfo($info["num_iid"],$taobaoSid);
+        $res = TaobaoLianMengUtil::taokoulingCreate($info["click_url"],$taobaoSid);
+        $heimaData = HeiMaUtil::gaoYongZhuanLian($info["num_iid"],$taobaoSid);
+
+
+        $goodsTitle = $goodsInfo["title"];
+        $goodsPrice = $goodsInfo["zk_final_price"];
+        $couponInfo = $heimaData["coupon_info"]??"";
+        $couponPrice = 0;
+        if (preg_match("/满\d*元减(\d*)元/",$couponInfo,$match)){
+            $couponPrice = $match[1];
+        }
+        $afterCouponPrice = $goodsPrice-$couponPrice;
+        $rebeatPrice = round($goodsInfo["zk_final_price"]*$heimaData["max_commission_rate"]/100*0.7,2);
+        $url = $res["model"];
+
+        //获取淘口令
+        $msg = <<<S
+【 $goodsTitle 】
+【原价】:$goodsPrice 元
+【优惠券】:$couponPrice 元
+【券后价】:$afterCouponPrice 元
+【返现金额】:$rebeatPrice 元
+ -------------------------
+复制这条信息:$url
+打开【手机淘宝】即可查看
+具体返现金额,以实际支付金额为准
+-------------------------
+进入公众号=>我的=>钱包,可以1:1提现哦
+S;
+        dd($msg);
+
+        dump($heimaData);
+        dump($res);
+        dump($goodsInfo);
+        dd($info);
         $res = HeiMaUtil::gaoYongZhuanLian(621062906541);
+
 //        $res = TaobaoLianMengUtil::taokoulingConvert("49嘻学上时说他然上在家去了! https://m.tb.cn/h.fjEHoGt?sm=d75195  超大浴巾成人男女学生宿舍比纯棉全棉吸水速干洗澡可穿毛巾裹巾夏");
 
         dd($res);

+ 9 - 0
app/Http/Controllers/Cron/CronController.php

@@ -34,6 +34,15 @@ class CronController extends BaseController
         return $this->success($datas);
     }
 
+    /**
+     * 定时获取淘宝订单
+     */
+    public function taobaoOrders()
+    {
+        CronLogic::taobaoOrdersLogic();
+        return $this->success();
+    }
+
     /**
      * 获取拼多多订单
      * @return \Illuminate\Http\JsonResponse

+ 74 - 0
app/Http/Logic/Cron/CronLogic.php

@@ -15,12 +15,14 @@ use App\Http\Enum\PlatformTypeEnum;
 use App\Http\Logic\BaseLogic;
 use App\Http\Logic\Order\OrderLogic;
 use App\Http\Utils\BaseUtil;
+use App\Http\Utils\HeiMaUtil;
 use App\Http\Utils\Jutuike\JutuikeUtil;
 use App\Http\Utils\LoggerFactoryUtil;
 use App\Http\Utils\Meituan\MeituanLianmengUtil;
 use App\Http\Utils\Pdd\DuoDuoKeUtil;
 use App\Http\Utils\WechatAccountUtil;
 use App\Models\CategoryModel;
+use App\Models\TaobaoPidModel;
 use App\Models\UserCashModel;
 use App\Models\UserFinanceModel;
 use App\Models\UserModel;
@@ -215,6 +217,78 @@ class CronLogic extends BaseLogic
         OrderLogic::handleOrderLogic($bean);
     }
 
+    /**
+     * 定时获取淘宝订单逻辑
+     */
+    public static function taobaoOrdersLogic()
+    {
+        //获取黑马授权账号
+        $heimaDatas = $data = TaobaoPidModel::query()
+            ->select([DB::raw("any_value(heima_app_key) as heima_app_key"),DB::raw("any_value(heima_app_secret) as heima_app_secret"),"heima_sid"])
+            ->groupBy("heima_sid")
+            ->get();
+
+        $instance = new LoggerFactoryUtil(CronLogic::class);
+
+        foreach ($heimaDatas as $heimaData){
+            //查询黑马账号下的订单
+            $orders = HeiMaUtil::getOrderList($heimaData);
+
+            if($orders){
+                BaseUtil::sendBaoJing("","获取到淘宝订单:".count($orders),"定时获取黑马淘客订单");
+            }
+            $instance->info("黑马淘客订单:".json_encode($orders));
+
+            try{
+                foreach ($orders as $orderList){
+                    switch ($orderList["tk_status"]){
+                        case 3:
+                            //订单结算
+                            $orderStatus = OrderStatusEnum::ALREADY_RECEIVE;
+                            break;
+                        case 12:
+                            //订单付款
+                            $orderStatus = OrderStatusEnum::ALREADY_PAY;
+                            break;
+                        case 13:
+                            //订单失效
+                            $orderStatus = OrderStatusEnum::ALREADY_CANCEL;
+                            break;
+                        case 14:
+                            //订单成功
+                            $orderStatus = OrderStatusEnum::ALREADY_PAY;
+                            break;
+                    }
+                    $params = [
+                        "spreadSonType" => 0,//订单子类型
+                        "orderNumber" => $orderList["trade_id"],//订单编号
+                        "payTime" => $orderList["tb_paid_time"],//支付时间
+                        "orderPrice" => $orderList["alipay_total_price"]*100,//订单金额
+                        "orderCommission" => $orderList["pub_share_pre_fee"]*100,//订单佣金
+                        "orderTitle" => $orderList["item_title"],//订单标题
+                        "orderRefundPrice" => 0,//退款金额
+                        "orderRefundTime" => null,//退款时间
+                        "orderRefundCommission" => 0,//退款佣金
+                        "orderStatus" => $orderStatus,//订单状态
+                        "orderCouponPrice" => 0,//订单优惠
+                        "productImgUrl" => $orderList["item_img"]??"",//商品图片
+                        "spreadType"=>PlatformTypeEnum::PLATFORM_TAOBAO,//订单类型
+                        "userSpreadId"=>$orderList["adzone_id"],//用户推广位
+                        "platformSpreadId"=>$orderList["adzone_id"],//平台推广位
+                        "createdAt"=>$orderList["tk_create_time"],//订单创建时间
+                    ];
+
+                    $bean = new HandleOrderParamBean($params);
+                    OrderLogic::handleOrderLogic($bean);
+                }
+            }catch (\Throwable $exception){
+                BaseUtil::sendBaoJing("","淘宝订单更新失败:".$exception->getMessage(),"定时获取黑马淘客订单");
+            }
+
+        }
+
+    }
+
     /**
      * 获取拼多多订单逻辑
      */

+ 26 - 11
app/Http/Logic/WechatLogic.php

@@ -10,6 +10,7 @@ use App\Http\Enum\MeiTuanLinkTypeEnum;
 use App\Http\Enum\PlatformTypeEnum;
 use App\Http\Enum\WechatAccountMenuTypeEnum;
 use App\Http\Utils\BaseUtil;
+use App\Http\Utils\HeiMaUtil;
 use App\Http\Utils\Jutuike\JutuikeUtil;
 use App\Http\Utils\LoggerFactoryUtil;
 use App\Http\Utils\Meituan\MeituanLianmengUtil;
@@ -489,20 +490,34 @@ S;
 
             //默认是认为淘宝链接
                 $instance->info("匹配到淘宝链接");
-                $goodsInfo = TaobaoLianMengUtil::taokoulingConvert($message["Content"]);
-                $instance->info("淘宝返回数据:".json_encode($goodsInfo));
+            $info = TaobaoLianMengUtil::taokoulingConvert($message["Content"],$taobaoSid);
+            $instance->info("淘宝返回数据:".json_encode($info));
+
+            $goodsInfo = TaobaoLianMengUtil::getGoodsInfo($info["num_iid"],$taobaoSid);
+            $res = TaobaoLianMengUtil::taokoulingCreate($info["click_url"],$taobaoSid);
+            $heimaData = HeiMaUtil::gaoYongZhuanLian($info["num_iid"],$taobaoSid);
+
+
+            $goodsTitle = $goodsInfo["title"];
+            $goodsPrice = $goodsInfo["zk_final_price"];
+            $couponInfo = $heimaData["coupon_info"]??"";
+            $couponPrice = 0;
+            if (preg_match("/满\d*元减(\d*)元/",$couponInfo,$match)){
+                $couponPrice = $match[1];
+            }
+            $afterCouponPrice = $goodsPrice-$couponPrice;
+            $rebeatPrice = round($goodsInfo["zk_final_price"]*$heimaData["max_commission_rate"]/100*0.7,2);
+            $url = $res["model"];
 
-                //获取商品详情
-//                $goodsItem = TaobaoLianMengUtil::getGoodsInfo($goodsInfo["num_iid"]);
                 //获取淘口令
 
-                $tuiguangRes = JutuikeUtil::convert($goodsInfo["num_iid"],$jutuikeSid);
-                $goodsTitle = $tuiguangRes["goodsName"];
-                $goodsPrice = $tuiguangRes["marketPrice"];
-                $couponPrice = $tuiguangRes["couponInfo"]["fav"];
-                $afterCouponPrice = $tuiguangRes["price"];
-                $rebeatPrice = round($tuiguangRes["commission"]*0.7,2);
-                $url = $tuiguangRes["url"];
+//                $tuiguangRes = JutuikeUtil::convert($goodsInfo["num_iid"],$jutuikeSid);
+//                $goodsTitle = $tuiguangRes["goodsName"];
+//                $goodsPrice = $tuiguangRes["marketPrice"];
+//                $couponPrice = $tuiguangRes["couponInfo"]["fav"];
+//                $afterCouponPrice = $tuiguangRes["price"];
+//                $rebeatPrice = round($tuiguangRes["commission"]*0.7,2);
+//                $url = $tuiguangRes["url"];
                 $msg = <<<S
 【 $goodsTitle 】
 【原价】:$goodsPrice 元

+ 32 - 13
app/Http/Utils/HeiMaUtil.php

@@ -5,6 +5,7 @@ namespace App\Http\Utils;
 
 use App\Exceptions\CommonException;
 use App\Http\Enum\ErrorEnum;
+use App\Models\TaobaoPidModel;
 use Tool\ShanTaoTool\HttpCurl;
 
 /**
@@ -21,15 +22,19 @@ class HeiMaUtil extends BaseUtil
      * 根据商品ID获取商品的佣金信息
      * @param $goodsId
      */
-    public static function gaoYongZhuanLian($goodsId)
+    public static function gaoYongZhuanLian($goodsId,$pid)
     {
+        //根据pid找到黑马授权的账号密钥
+        $taobao = TaobaoPidModel::query()
+            ->where("adzone_id",$pid)
+            ->first();
+
         $url = self::$baseUrl."api-zhuanlian";
         $params = [
-            "appkey"=>"611653348",
-            "appsecret"=>"4f660e85e93bc45012591d0a314997d6",
-            "sid"=>"4463",
-            "pid"=>"mm_101807570_250550471_102348550452",
-//            "pid"=>"mm_34231311_452000065_108585250029",
+            "appkey"=>$taobao["heima_app_key"],
+            "appsecret"=>$taobao["heima_app_secret"],
+            "sid"=>$taobao["heima_sid"],
+            "pid"=>$taobao["adzone_code"],
             "num_iid"=>$goodsId,
             "signurl"=>1
         ];
@@ -50,19 +55,33 @@ class HeiMaUtil extends BaseUtil
     /**
      * 获取订单列表
      */
-    public static function getOrderList()
+    public static function getOrderList($heima)
     {
         $url = self::$baseUrl."api-order";
         $params = [
-            "appkey"=>"",
-            "appsecret"=>"",
-            "sid"=>"",
-            "start_time"=>"mm_34231311_452000065_108585250029",
-            "end_time"=>"",
+            "appkey"=>$heima["heima_app_key"],
+            "appsecret"=>$heima["heima_app_secret"],
+            "sid"=>$heima["heima_sid"],
+            "start_time"=>date("Y-m-d H:i:s",time()-20*60),
+            "end_time"=>date("Y-m-d H:i:s"),
+//            "start_time"=>"2021-12-17 13:40:00",
+//            "end_time"=>"2021-12-17 15:40:00",
             "page_no"=>1,
             "page_size"=>100,
             "signurl"=>1,
-            "query_type"=>2
+            "query_type"=>4
         ];
+        $res = HttpCurl::getCurl($url,$params);
+        if(isset($res["error"])){
+            //存在错误则报警
+            BaseUtil::sendBaoJing("获取订单失败",$res,"定时获取黑马淘客订单");
+        }
+        $url = $res["url"];
+        $response = HttpCurl::getCurl($url);
+        if(!isset($response["tbk_sc_order_details_get_response"])){
+            //存在错误则报警
+            BaseUtil::sendBaoJing("获取订单失败",$response,"定时获取黑马淘客订单");
+        }
+        return $response["tbk_sc_order_details_get_response"]["data"]["results"]["publisher_order_dto"];
     }
 }

+ 58 - 8
app/Http/Utils/TaoBao/TaobaoLianMengUtil.php

@@ -7,6 +7,7 @@ namespace App\Http\Utils\TaoBao;
 use App\Exceptions\TaobaoException;
 use App\Http\Utils\BaseUtil;
 use App\Http\Utils\LoggerFactoryUtil;
+use App\Models\TaobaoPidModel;
 use ETaobao\Factory;
 /**
  * 淘宝联盟工具类
@@ -32,7 +33,19 @@ class TaobaoLianMengUtil extends BaseUtil
      */
     public static function getActivityInfo($adzone_id,$activity_material_id)
     {
-        $app = self::getApp();
+        //根据pid找到淘宝信息
+        $taobao = TaobaoPidModel::query()
+            ->where("adzone_id",$adzone_id)
+            ->first();
+        $config = [
+            "appkey"=>$taobao["taobao_app_key"],//淘宝客appKey
+            "secretKey"=>$taobao["taobao_app_secret"],//secretKey
+            "format"=>"json",//返回的数据格式
+            "session"=>"",//授权接口(sc类的接口)需要带上
+            "sandbox"=>false,
+        ];
+
+        $app = Factory::tbk($config);
         $params = [
             "adzone_id"=>$adzone_id,
             "activity_material_id"=>$activity_material_id
@@ -142,10 +155,22 @@ class TaobaoLianMengUtil extends BaseUtil
     /**
      * 获取淘口令接口
      * @param $url string 地址
+     * @param $adzone_id string 推广位
      */
-    public static function taokoulingCreate($url)
+    public static function taokoulingCreate($url,$adzone_id)
     {
-        $app = self::getApp();
+        //根据pid找到淘宝信息
+        $taobao = TaobaoPidModel::query()
+            ->where("adzone_id",$adzone_id)
+            ->first();
+        $config = [
+            "appkey"=>$taobao["taobao_app_key"],//淘宝客appKey
+            "secretKey"=>$taobao["taobao_app_secret"],//secretKey
+            "format"=>"json",//返回的数据格式
+            "session"=>"",//授权接口(sc类的接口)需要带上
+            "sandbox"=>false,
+        ];
+        $app = Factory::tbk($config);
         $params = [
             "url"=>$url
         ];
@@ -160,13 +185,26 @@ class TaobaoLianMengUtil extends BaseUtil
     /**
      * 淘口令解析&转链
      * @param $kouling 淘口令
+     * @param $adzone_id 推广位
      */
-    public static function taokoulingConvert($kouling)
+    public static function taokoulingConvert($kouling,$adzone_id)
     {
-        $app = self::getApp();
+        //根据pid找到淘宝信息
+        $taobao = TaobaoPidModel::query()
+            ->where("adzone_id",$adzone_id)
+            ->first();
+        $config = [
+            "appkey"=>$taobao["taobao_app_key"],//淘宝客appKey
+            "secretKey"=>$taobao["taobao_app_secret"],//secretKey
+            "format"=>"json",//返回的数据格式
+            "session"=>"",//授权接口(sc类的接口)需要带上
+            "sandbox"=>false,
+        ];
+        $app = Factory::tbk($config);
+
         $params = [
             "password_content"=>$kouling,
-            "adzone_id"=>"70362850341"
+            "adzone_id"=>$adzone_id
         ];
         $res = $app->tpwd->httpPost("taobao.tbk.tpwd.convert",$params);
         $instance = new LoggerFactoryUtil(TaobaoLianMengUtil::class);
@@ -184,9 +222,21 @@ class TaobaoLianMengUtil extends BaseUtil
      * @return mixed
      * @throws TaobaoException
      */
-    public static function getGoodsInfo($goodsId)
+    public static function getGoodsInfo($goodsId,$adzone_id)
     {
-        $app = self::getApp();
+        //根据pid找到淘宝信息
+        $taobao = TaobaoPidModel::query()
+            ->where("adzone_id",$adzone_id)
+            ->first();
+        $config = [
+            "appkey"=>$taobao["taobao_app_key"],//淘宝客appKey
+            "secretKey"=>$taobao["taobao_app_secret"],//secretKey
+            "format"=>"json",//返回的数据格式
+            "session"=>"",//授权接口(sc类的接口)需要带上
+            "sandbox"=>false,
+        ];
+        $app = Factory::tbk($config);
+
         $params = [
             "num_iids"=>$goodsId,
         ];

+ 2 - 0
routes/api.php

@@ -45,6 +45,8 @@ Route::prefix("cron")->namespace("Cron")->group(function (){
     Route::get("meituan/orders","CronController@meituanOrders");
     //获取聚推客订单
     Route::get("jutuike/orders","CronController@jutuikeOrders");
+    //定时获取淘宝订单
+    Route::get("taobao/orders","CronController@taobaoOrders");
     //获取拼多多订单
     Route::get("pdd/orders","CronController@pddOrders");
     //下单提醒