浏览代码

更新轮播图

zqwang 1 年之前
父节点
当前提交
49ff48f712

+ 20 - 3
modules/Common/Services/BaseService.php

@@ -13,9 +13,26 @@ use Catch\Exceptions\FailedException;
 
 class BaseService
 {
-    protected static  function  throwErrMsg($msg,$code = ""){
-        if ($code){
-            throw  new FailedException($msg,$code);
+    public static function getMiniProgramType()
+    {
+        return [
+            ['value' => 1, 'name' => "微信小程序"],
+            ['value' => 2, 'name' => "抖音小程序"],
+        ];
+    }
+
+    public static function getNavPagesType()
+    {
+        return [
+            ['value' => 1, 'name' => "排行榜"],
+            ['value' => 2, 'name' => "最新"],
+        ];
+    }
+
+    protected static function throwErrMsg($msg, $code = "")
+    {
+        if ($code) {
+            throw  new FailedException($msg, $code);
         }
         throw  new FailedException($msg);
     }

+ 39 - 0
modules/Operation/Http/Controllers/ChannelController.php

@@ -0,0 +1,39 @@
+<?php
+/**
+ *
+ * @file:ChannelController.php
+ * @Date: 2023/6/8
+ * @Time: 11:16
+ */
+
+
+namespace Modules\Operation\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Contracts\Pagination\LengthAwarePaginator;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Http\Request;
+use Modules\Operation\Service\ChannelServic;
+
+class ChannelController extends CatchController
+{
+    /**
+     *   频道列表
+     * name: list
+     * @param Request $request
+     * @return LengthAwarePaginator|Builder[]|Collection
+     * date 2023/06/08 14:03
+     */
+    public function list(Request $request)
+    {
+        $param = $request->all();
+        return ChannelServic::ChannelList($param);
+    }
+
+    public function add(Request $request)
+    {
+
+    }
+
+}

+ 16 - 8
modules/Operation/Service/BannerService.php

@@ -35,20 +35,25 @@ class BannerService extends BaseService
         if (!$list->isEmpty()){
             $types = self::getMiniProgramType();
             $types = array_column($types,null,'value');
+            $videoIds = array_unique(array_column($list->items(),'video_id'));
+            $videoInfo = DB::table('videos')->whereIn('id',$videoIds)->select('id','name','cover_image')->get();
+
+            if ($videoInfo){
+                $videoInfo  = json_decode(json_encode($videoInfo),true);
+
+                $videoInfo = array_column($videoInfo,null,'id');
+            }else{
+                $videoInfo = [];
+            }
+
             foreach ($list as $value){
                 $value->miniprogram_type_text = $types[$value->miniprogram_type]['name'] ?? "-";
+                $value->videoInfo = $videoInfo[$value->video_id] ?? [];
             }
         }
         return $list;
     }
 
-    public  static  function  getMiniProgramType(){
-        return [
-            ['value' => 1,'name' =>"微信小程序"],
-            ['value' => 2,'name' =>"抖音小程序"],
-        ];
-    }
-
     /**
      *  查询构建
      * name: getQuery
@@ -62,6 +67,9 @@ class BannerService extends BaseService
         if (getProp($param,'title')){
             $sql->where("title","like","%{$param['title']}%");
         }
+        if (getProp($param,'miniprogram_type')){
+            $sql->where("miniprogram_type",$param['miniprogram_type']);
+        }
         return $sql;
     }
 
@@ -118,7 +126,7 @@ class BannerService extends BaseService
        if (is_empty($info)){
            return  "操作成功";
        }
-       
+
         $other = DuanJuBanner::where('id','<>',$id)->where('miniprogram_type',$info->miniprogram_type)->where('status',1)->value('id');
         if (empty($other)){
             self::throwErrMsg("此类型小程序应最少保障一张可用轮播图");

+ 6 - 0
modules/Operation/routes/route.php

@@ -28,4 +28,10 @@ Route::prefix('operation')->group(function () {
         // 快速状态
         Route::post('editStatus/{id}',[\Modules\Operation\Http\Controllers\BannerController::class,'updateStatus']);
     });
+
+    // 频道管理
+    Route::prefix('channel')->group(function (){
+        Route::any('list',[\Modules\Operation\Http\Controllers\ChannelController::class,'list']);
+        Route::post('add',[\Modules\Operation\Http\Controllers\ChannelController::class,'add']);
+    });
 });