APPLE 3 лет назад
Родитель
Сommit
cb4b4fba43

+ 9 - 0
app/Http/Controllers/Admin/ArticleCateController.php

@@ -21,4 +21,13 @@ class ArticleCateController extends Backend
         parent::__construct();
         $this->service = new ArticleCateService();
     }
+
+    /**
+     * 选项列表
+     * @return mixed
+     */
+    public function options(){
+        $result = $this->service->options();
+        return message(1002,true, $result);
+    }
 }

+ 35 - 0
app/Services/Common/ArticleCateService.php

@@ -59,4 +59,39 @@ class ArticleCateService extends BaseService
         $data = request()->all();
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
+
+    /**
+     * 选项
+     * @return array
+     */
+    public function options()
+    {
+        // 获取参数
+        $param = request()->all();
+        // 用户ID
+        $keyword = getter($param, "keyword");
+        $parentId = getter($param, "parent_id");
+        $id = getter($param, "id");
+        $datas = $this->model->where(function($query) use($parentId){
+                if($parentId){
+                    $query->where(['id'=> $parentId,'mark'=>1]);
+                }else{
+                    $query->where(['status'=> 1,'mark'=>1]);
+                }
+            })
+            ->where(function($query) use($id){
+                if($id){
+                    $query->whereNotIn('id', [$id]);
+                }
+            })
+            ->where(function($query) use($keyword){
+                if($keyword){
+                    $query->where('name','like',"%{$keyword}%")->orWhere('code','like',"%{$keyword}%");
+                }
+            })
+            ->select(['id','name','status'])
+            ->get();
+
+        return $datas? $datas->toArray() : [];
+    }
 }