ads = $ads; $this->adCategory = $adCategory; } public function model() { return Ad::class; } public function getFilterAds($where, $whereIn = array()) { $today_time = strtotime(date('Y-m-d', strtotime("+1 day")))-1; /* if ($whereIn) { $res = $this->ads->select('ads.id','ads.category_id','ads.type_id','ads.title','ads.content','ads.url','ads.text_color','ads.uid','c.org','c.is_float','c.float_left','c.float_right','c.float_top','c.width','c.height','c.alias') ->leftjoin($this->adCategory->getTable().' as c', 'ads.category_id', '=', 'c.id') ->where($where) ->where(function ($query) { $today = strtotime(date('Y-m-d', time())); $query->where('ended_at', '>=', $today)->orWhere('ended_at', '=', 0); }) ->where('started_at', '<=', $today_time) ->whereIn('c.alias', $whereIn) ->orderBy('list_order', 'asc') ->orderBy('id', 'desc') ->get(); } else { $res = $this->ads->select('ads.id','ads.category_id','ads.type_id','ads.title','ads.content','ads.url','ads.text_color','ads.uid','c.org','c.is_float','c.float_left','c.float_right','c.float_top','c.width','c.height','c.alias') ->leftjoin($this->adCategory->getTable().' as c', 'ads.category_id', '=', 'c.id') ->where($where) ->where(function ($query) { $today = strtotime(date('Y-m-d', time())); $query->where('ended_at', '>=', $today)->orWhere('ended_at', '=', 0); }) ->where('started_at', '<=', $today_time) ->orderBy('list_order', 'asc') ->orderBy('id', 'desc') ->get(); } */ $res = $this->ads ->select('ads.id','ads.category_id','ads.type_id','ads.title','ads.content','ads.url','ads.text_color','ads.uid','c.org','c.is_float','c.float_left','c.float_right','c.float_top','c.width','c.height','c.alias','ads.target') ->leftjoin($this->adCategory->getTable().' as c', 'ads.category_id', '=', 'c.id') ->where($where) ->where(function ($query) { $today = strtotime(date('Y-m-d', time())); $query->where('ended_at', '>=', $today)->orWhere('ended_at', '=', 0); }) ->where('started_at', '<=', $today_time); if ($whereIn) { $res->whereIn('c.alias', $whereIn); } /*$res->when(get_subsite_id()>0, function ($query) { $query->whereHas('subsites', function ($query) { $query->where('subsite_id', get_subsite_id());}); });*/ $res->whereHas('subsites', function ($query) { $query->where('subsite_id', get_subsite_id()); }); $rst = $res->orderBy('list_order', 'desc')->orderBy('ads.created_at', 'desc')->get(); $res_new = $this->get_html($rst); return $res_new; } public function getAds($where, $limit) { $today_time = strtotime(date('Y-m-d', strtotime("+1 day")))-1; $res = $this->ads->select('ads.id','ads.category_id','ads.type_id','ads.title','ads.content','ads.url','ads.text_color','ads.uid','c.org','c.is_float','c.float_left','c.float_right','c.float_top','c.width','c.height') ->leftjoin($this->adCategory->getTable().' as c', 'ads.category_id', '=', 'c.id') ->where($where) ->where(function ($query) { $today = strtotime(date('Y-m-d', time())); $query->where('ended_at', '>=', $today)->orWhere('ended_at', '=', 0); }) ->where('started_at', '<=', $today_time) ->when(get_subsite_id()>0, function ($query) { $query->whereHas('subsites', function ($query) { $query->where('subsite_id', get_subsite_id()); }); }) ->orderBy('list_order', 'asc') ->orderBy('ads.created_at', 'desc') ->limit($limit) ->get(); $res_new = $this->get_html($res); return $res_new; } /* * 处理广告数据 * _get_html方法用于根据不同的广告类型生成对应的模板文件代码 * 广告类型(1:文字,2:图片,3:代码,4:flash,5:视频) */ private function get_html($ads) { if ($ads->ToArray()) { foreach ($ads as $k => $v) { if ($v->alias == 'AIX_index_five_recommend' && $v->uid ==0) { unset($ads[$k]); continue; } $html = ''; $size_html = ''; $href = ''; $v->width && $size_html .= 'width="'.$v->width.'"'; $v->height && $size_html .= ' height="'.$v->height.'"'; if ($v->url) { $href = $v->url; } elseif ($v->uid) { //企业信息查看页面 $href = route(url_rewrite('AIX_companyshow'), array('id'=>$v->uid)); } !$href && $href = 'javascript:;'; switch ($v->type_id) { case 1: $v->text_color && $style="color:{{$v->text_color}};"; $v->width && $style.="width:{{$v->width}};"; $v->height && $style.="height:{{$v->height}}"; $html = ''.$v->content.''; break; case 2://生成广告为图片类型的代码 $html = ''; $html .= ''.$v->title.''; $html .= ''; break; case 3: $html = $v->content; break; case 4://生成广告为flash类型的代码 $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; break; case 5://生成视频广告 if (preg_match("/^.+\.(flv|f4v)$/i", $v->content)) { $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } else { //通用代码 $v->content = preg_replace('/((width)[=]?[:]?[\"]?[0-9]+[\"]?)/i', 'width="'.$v->width.'"', $v->content);//宽 $v->content = preg_replace('/((height)[=]?[:]?[\'"]?[0-9]+[\'"]?)/i', 'height="'.$v->height.'"', $v->content);//高 $html = ''.$v->content.''; } break; } $v->html = $html; $v->href = $href; } } return $ads; } }