Pārlūkot izejas kodu

Merge branch 'zhucj' of iqiyoo:zhuishuyun_wap into zhucj

wangzq 2 gadi atpakaļ
vecāks
revīzija
c947c3eb93
1 mainītis faili ar 63 papildinājumiem un 7 dzēšanām
  1. 63 7
      app/Http/Controllers/QuickApp/Book/BookController.php

+ 63 - 7
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\QuickApp\Book;
 
 use App\Consts\BaseConst;
 use App\Libs\Utils;
+use App\Modules\Book\Models\RecoBanner;
 use App\Modules\Book\Services\BookAuditService;
 use App\Modules\Channel\Models\ChannelAdvert;
 use App\Modules\Channel\Services\ChannelAdvertService;
@@ -12,6 +13,7 @@ use App\Modules\Channel\Services\ChannelRecommendBooksService;
 use App\Modules\RecommendBook\Services\QappRecommendService;
 use App\Modules\RecommendBook\Services\RecommendService;
 use App\Modules\Book\Services\RecoBannerService;
+use App\Modules\Subscribe\Models\Order;
 use App\Modules\Trade\Services\OrderService;
 use App\Modules\User\Models\ChannelAdUser;
 use App\Modules\User\Models\QappPackage;
@@ -1035,15 +1037,69 @@ class BookController extends BaseController
         if(empty($order_id)){
             return response()->error();
         }
+        $channel_ad_id = 0;
+
         if(Redis::exists($cacheKey)){
-            $channel_ad_id = Redis::get($cacheKey);
-            $type = ($channel_ad_id > 0) ? 1 : 0;
-            $created_at = $updated_at = date('Y-m-d H:i:s');
-            DB::table('channel_advert_orders')->insert(compact('order_id','uid','distribution_id','channel_ad_id','type','created_at','updated_at'));
-            return response()->success();
-        }else{
-            return response()->success();
+            try {
+                //获取广告id
+                $channel_ad_id = Redis::get($cacheKey);
+                //判断订单跟广告是否有关系
+                $order = Order::find($order_id);
+                if(!$order){
+                    return response()->error();
+                }
+
+                if($channel_ad_id > 0){
+                    //新版
+                    $type = 1;
+                    $advert = ChannelAdvert::find($channel_ad_id);
+                    if(!$advert){
+                        return response()->error();
+                    }
+
+                    if($advert->type == '2' && $advert->activity_id != 0){
+                        //广告类型为活动
+                        if($order->activity_id != $advert->activity_id){
+                            return response()->error();
+                        }
+                    }else{
+                        //广告类型为书籍
+                        $content = explode(';',$advert->content);
+                        if(!isset($content[2])){
+                            return response()->error();
+                        }
+                        if($order->from_bid == 0 || $order->from_bid != Hashids::decode($content[2])[0]){
+                            return response()->error();
+                        }
+                    }
+                }else{
+                    //旧版
+                    $type = 0;
+                    $advert = RecoBanner::find(abs($channel_ad_id));
+                    if(!$advert){
+                        return response()->error();
+                    }
+                    $result = $this->getBidCidFromUrl($advert->redirect_url);
+                    $bid = $result['bid'];
+                    $cid = $result['cid'];
+                    if($cid){
+                        if($order->from_bid == 0 || $order->from_bid != Hashids::decode($bid)[0]){
+                            return response()->error();
+                        }
+                    }else{
+                        if($order->activity_id == 0 || $order->from_bid != Hashids::decode($bid)[0]){
+                            return response()->error();
+                        }
+                    }
+                }
+                $created_at = $updated_at = date('Y-m-d H:i:s');
+                DB::table('channel_advert_orders')->insert(compact('order_id','uid','distribution_id','channel_ad_id','type','created_at','updated_at'));
+            } catch (\Exception $e) {
+                \Log::info('绑定广告和订单失败'.$e->getMessage());
+                \Log::info('order_id:'.$order_id.' uid:'.$uid.' distribution_id:'.$distribution_id.' channel_ad_id:'.$channel_ad_id);
+            }
         }
+        return response()->success();
     }
 
 }