|
@@ -18,40 +18,39 @@ class DistProductCategory extends EloquentRepository
|
|
|
|
|
|
|
|
|
|
|
|
- public static function selectOptions(\Closure $closure = null)
|
|
|
+ public static function selectMainOptions(\Closure $closure = null)
|
|
|
{
|
|
|
- $selectOptions = Model::class::selectOptions($closure);
|
|
|
|
|
|
-
|
|
|
- $headings = [];
|
|
|
+ $query = Model::query();
|
|
|
|
|
|
-
|
|
|
- foreach ($selectOptions as $key => $value) {
|
|
|
-
|
|
|
- if (strpos($value, '├─') === 0 || strpos($value, '└─') === 0) {
|
|
|
+ if ($closure) {
|
|
|
+ $closure($query);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- $headings[$key] = $value;
|
|
|
- }
|
|
|
+
|
|
|
+ if (!$query) {
|
|
|
+ return [];
|
|
|
}
|
|
|
|
|
|
- return $headings;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ $results = $query->orderBy('name')->orderBy('order')->pluck('name', 'id');
|
|
|
+
|
|
|
+
|
|
|
+ $results = $results->map(function ($name) {
|
|
|
+ return '├─' . $name;
|
|
|
+ });
|
|
|
+
|
|
|
+ return $results->all();
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static function selectOptions(\Closure $closure = null)
|
|
|
+ {
|
|
|
+ $selectOptions = Model::class::selectOptions($closure);
|
|
|
+ return $selectOptions;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static function getParameter($categoryId)
|
|
|
{
|
|
@@ -63,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)
|
|
|
{
|
|
|
$obj = new Model();
|
|
@@ -94,15 +97,17 @@ class DistProductCategory extends EloquentRepository
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
return $model->makePaginator(
|
|
|
1,
|
|
|
$data
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * @param array $nodes
|
|
|
+ * @param $level 默认层级
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
function flattenTree(array $nodes, $level = 1)
|
|
|
{
|
|
|
$flat = [];
|
|
@@ -116,14 +121,15 @@ class DistProductCategory extends EloquentRepository
|
|
|
|
|
|
$nodeCopy['name'] = str_repeat(' ', $level * 2). ' <i class="fa fa-angle-right"></i> ' . $nodeCopy['name'];
|
|
|
|
|
|
-
|
|
|
|
|
|
$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));
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return $flat;
|