Browse Source

频道删除

zqwang 1 year ago
parent
commit
79e0a6cf01

+ 6 - 1
modules/Operation/Http/Controllers/ChannelController.php

@@ -57,7 +57,7 @@ class ChannelController extends CatchController
         return ChannelServic::enableChannel($id);
     }
 
-
+    // 保存配置
     public function setting($id,Request $request){
         if ($id <  1){
             throw  new  FailedException("id不正确");
@@ -68,4 +68,9 @@ class ChannelController extends CatchController
         $set = $request->input('duanjus', []);
         return ChannelServic::setChannel($id,$set);
     }
+
+    // 删除
+    public function del($id){
+        ChannelServic::delChannel($id);
+    }
 }

+ 20 - 2
modules/Operation/Service/ChannelServic.php

@@ -38,7 +38,7 @@ class ChannelServic extends BaseService
 
     public static function getQuerySql($param)
     {
-        $sql = NavPages::query()->orderBy('status','desc')->orderBy('id','desc');
+        $sql = NavPages::query()->where('is_del','=',0)->orderBy('status','desc')->orderBy('id','desc');
         if (getProp($param,'type')){
             $sql->where('type',$param['type']);
         }
@@ -67,6 +67,7 @@ class ChannelServic extends BaseService
         self::throwErrMsg("添加失败");
     }
 
+    // 启用
     public static function enableChannel($id)
     {
         $info = NavPages::where('id',$id)->first();
@@ -77,7 +78,7 @@ class ChannelServic extends BaseService
         NavPages::where('id',$id)->update(['status'=>1]);
         return "操作成功";
     }
-
+    //  保存配置
     public static function setChannel($id, array $set)
     {
         $info = NavPages::where('id',$id)->first();
@@ -90,4 +91,21 @@ class ChannelServic extends BaseService
         }
         self::throwErrMsg("操作失败");
     }
+
+    // 删除
+    public static function delChannel($id)
+    {
+        $info = NavPages::where('id',$id)->where('is_del',0)->first();
+        if(is_empty($info)){
+            self::throwErrMsg("频道配置不存在");
+        }
+        if ($info->status = 1){
+            self::throwErrMsg("请先禁用");
+        }
+        $res = NavPages::where('id',$id)->update(['is_del' =>1,'del_at' => get_date()]);
+        if ($res){
+            return "操作成功";
+        }
+        self::throwErrMsg("操作失败");
+    }
 }

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

@@ -39,5 +39,7 @@ Route::prefix('operation')->group(function () {
         Route::post('enableStatus/{id}',[\Modules\Operation\Http\Controllers\ChannelController::class,'enableStatus']);
         // 配置
         Route::post("setting/{id}",[\Modules\Operation\Http\Controllers\ChannelController::class,"setting"]);
+        // 删除
+        Route::post("del/{id}",[\Modules\Operation\Http\Controllers\ChannelController::class,"del"]);
     });
 });