Browse Source

feat:新增 selectMainOptions

igb 5 months ago
parent
commit
9b135e3cdd

+ 2 - 3
app/Distributor/Controllers/DistProductCategoryController.php

@@ -100,7 +100,7 @@ class DistProductCategoryController extends AdminController
         return Form::make(new DistProductCategory(), function (Form $form) {
         return Form::make(new DistProductCategory(), function (Form $form) {
             $form->display('id', 'ID');
             $form->display('id', 'ID');
             $form->select('parent_id', admin_trans_field('parent'))
             $form->select('parent_id', admin_trans_field('parent'))
-                ->options(DistProductCategory::selectOptions(function ($query) {
+                ->options(DistProductCategory::selectMainOptions(function ($query) {
                     // 在这里定义查询条件
                     // 在这里定义查询条件
                     $query->where('parent_id', 0);
                     $query->where('parent_id', 0);
                 }))
                 }))
@@ -112,9 +112,8 @@ class DistProductCategoryController extends AdminController
                 ->default(0)
                 ->default(0)
                 ->rules('numeric')
                 ->rules('numeric')
                 ->help(admin_trans_label('order_tips')); // 添加备注
                 ->help(admin_trans_label('order_tips')); // 添加备注
-
-          //  $form->select('parameter_id', 'parameter')->options(DistProductParameter::selectOptions())->required();// DIST不需要绑定 parameter
             $form->switch('enabled')->default(1);
             $form->switch('enabled')->default(1);
+          //  $form->select('parameter_id', 'parameter')->options(DistProductParameter::selectOptions())->required();// DIST不需要绑定 parameter
           //  $form->display('created_at');
           //  $form->display('created_at');
           //  $form->display('updated_at');
           //  $form->display('updated_at');
         });
         });

+ 20 - 7
app/Distributor/Repositories/DistProductCategory.php

@@ -18,7 +18,7 @@ class DistProductCategory extends EloquentRepository
 
 
 
 
     // 调用模型方法
     // 调用模型方法
-    public static function selectOptions(\Closure $closure = null)
+    public static function selectMainOptions(\Closure $closure = null)
     {
     {
 
 
         $query = Model::query();
         $query = Model::query();
@@ -44,6 +44,13 @@ class DistProductCategory extends EloquentRepository
 
 
     }
     }
 
 
+    // 调用模型方法
+    public static function selectOptions(\Closure $closure = null)
+    {
+        $selectOptions = Model::class::selectOptions($closure);
+        return $selectOptions;
+    }
+
 
 
     public static function getParameter($categoryId)
     public static function getParameter($categoryId)
     {
     {
@@ -55,6 +62,10 @@ class DistProductCategory extends EloquentRepository
         }
         }
     }
     }
 
 
+    /**
+     * @param Grid\Model|\Dcat\Admin\Grid\Model $model
+     * @return array
+     */
     public function get(Grid\Model|\Dcat\Admin\Grid\Model $model)
     public function get(Grid\Model|\Dcat\Admin\Grid\Model $model)
     {
     {
         $obj = new Model();
         $obj = new Model();
@@ -86,14 +97,17 @@ class DistProductCategory extends EloquentRepository
            }
            }
         }
         }
 
 
-
         return $model->makePaginator(
         return $model->makePaginator(
             1, // 传入总记录数
             1, // 传入总记录数
             $data // 传入数据二维数组
             $data // 传入数据二维数组
         );
         );
     }
     }
 
 
-
+    /**
+     * @param array $nodes
+     * @param $level 默认层级
+     * @return array
+     */
     function flattenTree(array $nodes, $level = 1)
     function flattenTree(array $nodes, $level = 1)
     {
     {
         $flat = [];
         $flat = [];
@@ -107,16 +121,15 @@ class DistProductCategory extends EloquentRepository
             // 根据层级在 name 字段前添加空格
             // 根据层级在 name 字段前添加空格
             $nodeCopy['name'] = str_repeat('&nbsp; ', $level * 2). ' <i class="fa fa-angle-right"></i>&nbsp; ' . $nodeCopy['name'];
             $nodeCopy['name'] = str_repeat('&nbsp; ', $level * 2). ' <i class="fa fa-angle-right"></i>&nbsp; ' . $nodeCopy['name'];
 
 
-
             // 将去除 'children' 属性的节点添加到平坦数组中
             // 将去除 'children' 属性的节点添加到平坦数组中
             $flat[] = $nodeCopy;
             $flat[] = $nodeCopy;
 
 
             // 如果存在子节点,则递归处理子节点
             // 如果存在子节点,则递归处理子节点
-            if (isset($node['children']) && is_array($node['children'])) {
-
-
+            if (isset($node['children']) && is_array($node['children']))
+            {
                 $flat = array_merge($flat, $this->flattenTree($node['children'], $level + 1));
                 $flat = array_merge($flat, $this->flattenTree($node['children'], $level + 1));
             }
             }
+
         }
         }
 
 
         return $flat;
         return $flat;