|
|
@@ -60,4 +60,71 @@ class AdService extends BaseService
|
|
|
return parent::edit($data); // TODO: Change the autogenerated stub
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取广告轮播列表数据
|
|
|
+ * @param $sortId 广告位ID
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function geListBySort($sortId, $num=6){
|
|
|
+ $showNum = ConfigService::make()->getConfigByCode("index_ad_{$sortId}_num");
|
|
|
+ $num = $showNum? $showNum : $num;
|
|
|
+ $cacheKey = "caches:adverts:list_sort_{$sortId}_{$num}";
|
|
|
+ $dataList = RedisService::get($cacheKey);
|
|
|
+ if($dataList){
|
|
|
+ return $dataList;
|
|
|
+ }
|
|
|
+
|
|
|
+ $dataList = $this->model::where(['ad_sort_id'=> $sortId,'mark'=> 1,'status'=> 1])
|
|
|
+ ->where(function($query){
|
|
|
+ $query->where('start_time',0)->orWhere('end_time', 0)->orWhere(function($query){
|
|
|
+ $query->where('start_time','>=', time())->where('end_time','<=', time());
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->select(['id','title','cover','type','description','url','view_num','width','height','status','sort'])
|
|
|
+ ->orderBy('sort','asc')
|
|
|
+ ->orderBy('create_time','desc')
|
|
|
+ ->limit($num)
|
|
|
+ ->get()
|
|
|
+ ->each(function($item, $k){
|
|
|
+ $item['cover'] = $item['cover']? get_image_url($item['cover']) : '';
|
|
|
+ });
|
|
|
+ $dataList = $dataList? $dataList->toArray() :[];
|
|
|
+ if($dataList){
|
|
|
+ RedisService::set($cacheKey, $dataList, rand(10, 30));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $dataList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取广告位对应单广告数据
|
|
|
+ * @param $sortId 广告位ID
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function geDataBySort($sortId){
|
|
|
+ $cacheKey = "caches:adverts:data_sort_{$sortId}";
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
+ if($data){
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->model::where(['ad_sort_id'=> $sortId,'mark'=> 1,'status'=> 1])
|
|
|
+ ->where(function($query){
|
|
|
+ $query->where('start_time',0)->orWhere('end_time', 0)->orWhere(function($query){
|
|
|
+ $query->where('start_time','>=', time())->where('end_time','<=', time());
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->select(['id','title','cover','type','description','url','view_num','width','height','status','sort'])
|
|
|
+ ->orderBy('sort','asc')
|
|
|
+ ->orderBy('create_time','desc')
|
|
|
+ ->first();
|
|
|
+ $data = $data? $data->toArray() : [];
|
|
|
+ if($data){
|
|
|
+ $data['cover'] = $data['cover']? get_image_url($data['cover']) : '';
|
|
|
+ RedisService::set($cacheKey, $data, rand(10, 30));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
}
|