|
|
@@ -13,6 +13,7 @@ namespace App\Services\Api;
|
|
|
|
|
|
use App\Models\AdModel;
|
|
|
use App\Services\BaseService;
|
|
|
+use App\Services\RedisService;
|
|
|
|
|
|
/**
|
|
|
* 广告管理-服务类
|
|
|
@@ -31,28 +32,42 @@ class AdService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 添加或编辑
|
|
|
- * @return array
|
|
|
+ * 静态入口
|
|
|
+ * @return AdService|null
|
|
|
*/
|
|
|
- public function edit()
|
|
|
+ public static function make()
|
|
|
{
|
|
|
- $data = request()->all();
|
|
|
- // 图片处理
|
|
|
- $cover = trim($data['cover']);
|
|
|
- if (strpos($cover, "temp")) {
|
|
|
- $data['cover'] = save_image($cover, 'ad');
|
|
|
- } else {
|
|
|
- $data['cover'] = str_replace(IMG_URL, "", $data['cover']);
|
|
|
- }
|
|
|
- // 开始时间
|
|
|
- if ($data['start_time']) {
|
|
|
- $data['start_time'] = strtotime($data['start_time']);
|
|
|
+ return parent::make(); // TODO: Change the autogenerated stub
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取广告列表
|
|
|
+ * @param int $position 广告位置:1-首页
|
|
|
+ * @param int $listRows 返回数量
|
|
|
+ * @return array|false|mixed
|
|
|
+ */
|
|
|
+ public function getList($position=1, $listRows = 6)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:adverts:index_{$position}_{$listRows}";
|
|
|
+ if($list = RedisService::get($cacheKey)){
|
|
|
+ return $list;
|
|
|
}
|
|
|
- // 结束时间
|
|
|
- if ($data['end_time']) {
|
|
|
- $data['end_time'] = strtotime($data['end_time']);
|
|
|
+
|
|
|
+ $list = $this->model->where(['position'=> $position,'mark'=>1,'status'=>1])
|
|
|
+ ->select(['id','title','cover as image','type'])
|
|
|
+ ->orderBy('sort','desc')
|
|
|
+ ->limit($listRows)
|
|
|
+ ->get()
|
|
|
+ ->each(function($item, $k){
|
|
|
+ $item['image'] = $item['image']? get_image_url($item['image']) : '';
|
|
|
+ });
|
|
|
+
|
|
|
+ $list = $list? $list->toArray() : [];
|
|
|
+ if($list){
|
|
|
+ RedisService::set($cacheKey, $list, rand(10, 30));
|
|
|
}
|
|
|
- return parent::edit($data); // TODO: Change the autogenerated stub
|
|
|
+
|
|
|
+ return $list;
|
|
|
}
|
|
|
|
|
|
}
|