Kaynağa Gözat

根据多个banner id获取banner数据

duqinya 5 yıl önce
ebeveyn
işleme
627a737b25

+ 35 - 0
app/Http/Controllers/V2/BannerController.php

@@ -0,0 +1,35 @@
+<?php
+namespace App\Http\Controllers\V2;
+use App\Http\Controllers\BaseController;
+use App\Repositories\BannerRepository;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Http\Request;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/15
+ * Time: 下午5:21
+ */
+
+class BannerController extends BaseController
+{
+    public function __construct(BannerRepository $bannerRepository)
+    {
+        $this->bannerRepository = $bannerRepository;
+    }
+    //根据多个banner ID获取banner数据
+    public function lists(Request $request)
+    {
+        $data = $request->only('ids');
+        $validator = Validator::make($data, [
+            'ids' => 'required|string'
+        ]);
+        if ($validator->fails()) {
+            return $this->jsonError($validator->errors()->first());
+        }
+        $data['ids'] = urldecode($data['ids']);
+        $bannerLists = $this->bannerRepository->bannerData($data);
+        return $this->jsonSuccess($bannerLists);
+    }
+}

+ 24 - 0
app/Models/Banner.php

@@ -0,0 +1,24 @@
+<?php
+namespace App\Models;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/15
+ * Time: 下午5:19
+ */
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class Banner extends BaseModel
+{
+    use SoftDeletes;
+
+    protected $dates = ['deleted_at'];
+    protected  $table = 'config_banner';
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['tpl_id','rule','status','area_type','name','link_content_id','image','type','is_open','use_background'];
+
+
+}

+ 36 - 0
app/Repositories/BannerRepository.php

@@ -0,0 +1,36 @@
+<?php
+namespace App\Repositories;
+use App\Models\Banner;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/15
+ * Time: 下午5:39
+ */
+
+class BannerRepository
+{
+    public function __construct(Banner $banner)
+    {
+        $this->banner = $banner;
+    }
+
+    public function bannerData($request)
+    {
+        $where = [];
+        $ids = explode(",", $request['ids']);
+        $bannerLists = $this->banner
+            ->where($where)
+            ->get();
+        $banner_data =  [];
+        foreach ($ids as $v){
+            foreach ($bannerLists as $value){
+                if($v == $value['id']){
+                    $banner_data[] = $value;
+                }
+            }
+        }
+        return $banner_data;
+    }
+
+}

+ 14 - 0
routes/api.php

@@ -44,4 +44,18 @@ $api->version('v1', [
 
     //获取某自提点
     $api->get('/pickupNode/getPickupNode','ConfigPickupNodeController@getPickupNode');
+});
+
+$api->version('v1', [
+    'namespace' => 'App\Http\Controllers\V2',
+], function ($api) {
+
+    $api->group([
+        'prefix' => 'v2'
+    ], function ($api) {
+        $api->group(['middleware' => 'jwt.chxq_auth'], function ($api) {
+            //根据多个ID获取banner
+            $api->get('/bannerSet/lists', 'BannerController@lists');
+        });
+    });
 });