فهرست منبع

前端-三农资讯网修改获取广告

15313670163 2 ماه پیش
والد
کامیت
b91794979a
1فایلهای تغییر یافته به همراه27 افزوده شده و 35 حذف شده
  1. 27 35
      app/JsonRpc/WebsiteService.php

+ 27 - 35
app/JsonRpc/WebsiteService.php

@@ -486,45 +486,37 @@ class WebsiteService implements WebsiteServiceInterface
      */
     public function getWebsiteAdvertisement(array $data): array
     {
-
         $where = [
-            'website_id' => 1,
-            'id' => $data['ad_placeid'],
+            'website_id' => $data['website_id'],
+            'status' => 1,
         ];
+        if(isset($data['place_id']) && !empty($data['place_id'])){
+            $where['id'] = $data['place_id']; 
+            $result = AdPlace::where($where)->first();    
+            var_dump("==========",$result['id']);
+            // return Result::success($ad_place['id']);
+            if(empty($result->toArray())){
+                return Result::error("此广告位不存在!",0);
+            }else{
+                //查找有没有广告
+                $now = Carbon::now();       
+                $ad=Ad::where('pid',$result->id)
+                ->where('status',1)
+                ->where('fromtime', '<=', $now)
+                ->where('totime', '>=', $now)
+                ->orderBy('id','asc')
+                ->first();
+                if(!empty($ad)){
+                    // return Result::success($ad->toArray());
+                    $result = $ad->toArray();
+                }   
+            } 
+        return Result::success($result);
+        }else{
+            // $result = AdPlace::where($where)->get()->all(); 
+        }
 
-        //查询这个广告位是否存在
-        $ad_place = AdPlace::where($where)->orderBy('id', 'asc')->first();
 
-        var_dump("==========", $ad_place);
-        if (empty($ad_place)) {
-            return Result::error("error", 0);
-        } else {
-            $adplaceid = $ad_place['id'];
-            //查找有没有广告
-            $ad = Ad::where('pid', $adplaceid['id'])->where('status', 1)->orderBy('id', 'asc')->get();
-            if (empty($ad)) {
-                //若没有生效的广告,则显示默认的缩略图
-                $result = $adplaceid;
-                return Result::success($result);
-            } else {
-                //查找在生效时间的广告
-                $today = Carbon::now();
-                foreach ($ad as $i) {
-                    $starttime = Carbon::parse($i['fromtime']);
-                    $endtime = Carbon::parse($i['totime']);
-                    $time = $today->between($starttime, $endtime);
-                    if ($time) {
-                        $result = $i;
-                    }
-                }
-                if (empty($result)) {
-                    $result = $ad;
-                    return Result::success($result);
-                } else {
-                    return Result::success($result);
-                }
-            }
-        }
     }
 
     /**