Browse Source

获取广告

15313670163 1 month ago
parent
commit
b3b054b70a
3 changed files with 35 additions and 15 deletions
  1. 10 14
      app/JsonRpc/WebsiteService.php
  2. 1 1
      runtime/hyperf.pid
  3. 24 0
      runtime/logs/hyperf.log

+ 10 - 14
app/JsonRpc/WebsiteService.php

@@ -488,24 +488,20 @@ class WebsiteService implements WebsiteServiceInterface
         $where = [
             'website_id' => $data['website_id'],
             'ad_place.status' => 1,
-            'ad.status' => 1,
+            // 'ad.status' => 1,
         ];
         if(isset($data['ad_tag']) && !empty($data['ad_tag'])){
             $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
-            $where[] = ['ad_tag','like','%'.$data['ad_tag'].'%'];
-            $result = AdPlace::where($where)
-            ->leftJoin("ad","ad.pid","ad_place.id")
-            ->select("ad_place.*","ad.*",'ad.name as ad_name','ad.id as ad_id')
-            ->where('ad.fromtime', '<=', $now)
-            ->where('ad.totime', '>=', $now)
-            // ->whereBetween('ad.fromtime', [$now, 'ad.totime'])
+            $where[] = ['ad_place.ad_tag','like','%'.$data['ad_tag'].'%'];
+            $result =  AdPlace::where($where)
+            ->leftJoin("ad", function ($join) use ($now) {
+                $join->on("ad.pid", "=", "ad_place.id")
+                     ->where('ad.status', 1)
+                     ->where('ad.fromtime', '<=', $now)
+                     ->where('ad.totime', '>=', $now);
+            })
+            ->select("ad_place.*")
             ->get()->all();
-            if(empty($result)){
-               $result = AdPlace::where('website_id',$data['website_id'])
-               ->where('status',1)
-                ->where('ad_tag','like','%'.$data['ad_tag'].'%')
-                ->get()->all(); 
-            }
             if(empty($result)){
                 return Result::error("此广告位不存在!",0);
             } 

+ 1 - 1
runtime/hyperf.pid

@@ -1 +1 @@
-38982
+14988

+ 24 - 0
runtime/logs/hyperf.log

@@ -451,3 +451,27 @@
 [2025-02-21T16:00:22.301592+08:00] sql.INFO: [5.5] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
 [2025-02-21T16:00:23.285935+08:00] sql.INFO: [3.3] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
 [2025-02-21T16:00:24.041032+08:00] sql.INFO: [8.76] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:58:51.683789+08:00] sql.INFO: [14.91] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:58:53.402045+08:00] sql.INFO: [3.34] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:58:54.583738+08:00] sql.INFO: [3.17] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:59:01.313507+08:00] sql.INFO: [3.17] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:59:02.196142+08:00] sql.INFO: [3.51] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:59:02.999062+08:00] sql.INFO: [4.3] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:59:07.958195+08:00] sql.INFO: [18.87] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:59:08.274804+08:00] sql.INFO: [3.61] select `ad_place`.* from `ad_place` where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad_tag` like '%INDEDX%') [] []
+[2025-03-03T17:59:27.479081+08:00] sql.INFO: [13.77] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T17:59:27.687398+08:00] sql.INFO: [2.95] select `ad_place`.* from `ad_place` left join `ad` on `ad`.`pid` = `ad_place`.`id` and `ad`.`fromtime` <= '2025-03-03 17:59:27' and `ad`.`totime` >= '2025-03-03 17:59:27' where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad_tag` like '%INDEDX%') [] []
+[2025-03-03T18:00:15.883312+08:00] sql.INFO: [14.14] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T18:00:16.217887+08:00] sql.INFO: [3.75] select `ad_place`.* from `ad_place` left join `ad` on `ad`.`pid` = `ad_place`.`id` and `ad`.`fromtime` <= '2025-03-03 18:00:16' and `ad`.`totime` >= '2025-03-03 18:00:16' where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad`.`status` = '1' and `ad_tag` like '%INDEDX%') [] []
+[2025-03-03T18:01:54.326547+08:00] sql.INFO: [14.32] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T18:01:54.556291+08:00] sql.INFO: [3.46] select `ad_place`.* from `ad_place` left join `ad` on `ad`.`pid` = `ad_place`.`id` and `ad`.`fromtime` <= '2025-03-03 18:01:54' and `ad`.`totime` >= '2025-03-03 18:01:54' where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad`.`status` = '1' and `ad_tag` like '%INDEDX%') [] []
+[2025-03-03T18:01:55.576805+08:00] sql.INFO: [2.96] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T18:01:55.582539+08:00] sql.INFO: [2.84] select `ad_place`.* from `ad_place` left join `ad` on `ad`.`pid` = `ad_place`.`id` and `ad`.`fromtime` <= '2025-03-03 18:01:55' and `ad`.`totime` >= '2025-03-03 18:01:55' where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad`.`status` = '1' and `ad_tag` like '%INDEDX%') [] []
+[2025-03-03T18:01:59.784113+08:00] sql.INFO: [14.99] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T18:02:00.078287+08:00] sql.INFO: [3.08] select `ad_place`.* from `ad_place` left join `ad` on `ad`.`pid` = `ad_place`.`id` and `ad`.`fromtime` <= '2025-03-03 18:02:00' and `ad`.`totime` >= '2025-03-03 18:02:00' where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad`.`status` = '1' and `ad_place`.`ad_tag` like '%INDEDX%') [] []
+[2025-03-03T18:02:49.553286+08:00] sql.INFO: [13.64] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T18:02:49.765528+08:00] sql.INFO: [3.03] select `ad_place`.* from `ad_place` where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad_place`.`ad_tag` like '%INDEDX%') [] []
+[2025-03-03T18:03:09.371614+08:00] sql.INFO: [17.43] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T18:03:09.657222+08:00] sql.INFO: [3.51] select `ad_place`.* from `ad_place` left join `ad` on `ad`.`pid` = `ad_place`.`id` and `ad`.`fromtime` <= '2025-03-03 18:03:09' and `ad`.`totime` >= '2025-03-03 18:03:09' where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad`.`status` = '1' and `ad_place`.`ad_tag` like '%INDEDX%') [] []
+[2025-03-03T18:03:30.195167+08:00] sql.INFO: [14.04] select * from `website` where json_contains(`website_url`, '"localhost:3000"') limit 1 [] []
+[2025-03-03T18:03:30.424665+08:00] sql.INFO: [3.38] select `ad_place`.* from `ad_place` left join `ad` on `ad`.`pid` = `ad_place`.`id` and `ad`.`status` = '1' and `ad`.`fromtime` <= '2025-03-03 18:03:30' and `ad`.`totime` >= '2025-03-03 18:03:30' where (`website_id` = '2' and `ad_place`.`status` = '1' and `ad_place`.`ad_tag` like '%INDEDX%') [] []