moshaorui 4 luni în urmă
părinte
comite
409a1154b8

+ 1 - 4
app/Admin/Controllers/BaseProductCategoryController.php

@@ -73,10 +73,7 @@ class BaseProductCategoryController extends AdminController
     {
         return Form::make(new BaseProductCategory(), function (Form $form) {
             $form->select('parent_id', admin_trans_field('parent'))
-                ->options(BaseProductCategory::selectMainOptions(function ($query) {
-                    // 在这里定义查询条件
-                    $query->where('parent_id', 0);
-                }))
+                ->options(BaseProductCategory::selectMainOptions())
                 ->saving(function ($v) {
                     return (int) $v;
                 });

+ 15 - 21
app/Admin/Repositories/BaseProductCategory.php

@@ -28,7 +28,7 @@ class BaseProductCategory extends EloquentRepository
         if (!$closure) {
             $closure = function ($query) {
                 $query = $query->where('enabled', 1);
-                $query =  $query->orderBy('order', 'asc');
+                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
                 return $query;
             };
         }
@@ -39,28 +39,20 @@ class BaseProductCategory extends EloquentRepository
 
     public static function selectMainOptions(\Closure $closure = null)
     {
-        $query = Model::query();
-
-        //通过传入条件限制
-        if ($closure) {
-            $closure($query);
+        if (!$closure) {
+            $closure = function ($query) {
+                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
+                return $query;
+            };
         }
-
-        // 确保查询构造器不为空
-        if (!$query) {
-            return [];
+        $selectOptions =  Model::class::selectOptions($closure);
+        //只显示2层
+        foreach ($selectOptions as $key => $value) {
+            if (substr_count($value,' ') > 8) {
+                unset($selectOptions[$key]);
+            }
         }
-
-        // 返回键值对数组,并按 'name' 和 'order' 字段排序
-        $results = $query->orderBy('order', 'asc')->pluck('name', 'id');
-
-        // 在每个 name 前面加上 '├─'
-        $results = $results->map(function ($name) {
-            return '├─' . $name;
-        });
-
-        $all = array_replace([0 => admin_trans_label('root')],$results->all());
-        return $all;
+        return $selectOptions;
     }
 
 
@@ -96,4 +88,6 @@ class BaseProductCategory extends EloquentRepository
         );
     }
 
+
+
 }

+ 1 - 1
app/Admin/Repositories/BaseVideoCategory.php

@@ -20,7 +20,7 @@ class BaseVideoCategory extends EloquentRepository
         if (!$closure) {
             $closure = function ($query) {
                 $query = $query->where('enabled', 1);
-                $query =  $query->orderBy('order', 'asc');
+                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
                 return $query;
             };
         }

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

@@ -54,6 +54,8 @@ class DistProductCategoryController extends AdminDistController
                 return $prefix . ' ' . html_entity_decode($name); // 拼接加号和名称
             });
             $grid->column('parent_id');
+            $grid->column('order');
+            $grid->column('enabled')->switch();
             $grid->column('created_at');
             $grid->column('updated_at');//->sortable();
             $grid->disableViewButton();

+ 0 - 3
app/Distributor/Controllers/SitePagesController.php

@@ -90,9 +90,6 @@ class SitePagesController extends AdminDistController
                 $filter->like('title')->width(2);
                 $filter->equal('pagesTag.id',admin_trans_label('tags'))->select('api/tag')->width(2);
             });
-            //增加JS,使新增与编辑带location
-            $paramsUrl = 'type='.$pageType;
-            CommonHelper::replaceAddEditerUrl('.tree-quick-create', '.tree-quick-edit', $paramsUrl);
             //权限与条件
             $grid->model()->where('dist_id', getDistributorId())->where('page_type', $pageType)->orderBy('id', 'desc');
         });

+ 2 - 2
app/Distributor/Repositories/DistProductCategory.php

@@ -53,7 +53,7 @@ class DistProductCategory extends EloquentRepository
         $query->where('dist_id', getDistributorId());
 
         // 返回键值对数组,并按 'name' 和 'order' 字段排序
-        $results = $query->orderBy('order', 'asc')->pluck('name', 'id');
+        $results = $query->orderBy('order', 'desc')->orderBy('id', 'desc')->pluck('name', 'id');
 
         // 在每个 name 前面加上 '├─'
         $results = $results->map(function ($name) {
@@ -71,7 +71,7 @@ class DistProductCategory extends EloquentRepository
             $closure = function ($query) {
                 $query = $query->where('dist_id', getDistributorId());
                 $query = $query->where('enabled', 1);
-                $query =  $query->orderBy('order', 'asc');
+                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
                 return $query;
             };
         }

+ 1 - 1
app/Distributor/Repositories/DistVideoCategory.php

@@ -23,7 +23,7 @@ class DistVideoCategory extends EloquentRepository
             $closure = function ($query) {
                 $query = $query->where('dist_id', getDistributorId());
                 $query = $query->where('enabled', 1);
-                $query =  $query->orderBy('order', 'asc');
+                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
                 return $query;
             };
         }

+ 1 - 1
app/Distributor/Repositories/SitePagesTag.php

@@ -37,7 +37,7 @@ class SitePagesTag extends EloquentRepository
      */
     public static function all()
     {
-        $result =  Model::where('dist_id', getDistributorId())->get();
+        $result =  Model::where('dist_id', getDistributorId())->orderBy('created_at', 'desc')->get();
         return $result;
     }
 

+ 6 - 6
app/Models/BaseProductCategory.php

@@ -30,7 +30,7 @@ class BaseProductCategory extends Model
     ];
 
     protected $fillable = [
-        'name', 'parent_id', 'order','enabled','dist_user_id', // 假设已有的可填充字段
+        'name', 'parent_id', 'order','enabled','parameter_id', // 假设已有的可填充字段
     ];
 
     /*
@@ -42,9 +42,9 @@ class BaseProductCategory extends Model
     }
 
 
-    public static function selectOptions(\Closure $closure = null)
-    {
-        $options = (new static())->withQuery($closure)->buildSelectOptions();
-        return collect($options)->all();
-    }
+//    public static function selectOptions(\Closure $closure = null)
+//    {
+//        $options = (new static())->withQuery($closure)->buildSelectOptions();
+//        return collect($options)->all();
+//    }
 }

+ 0 - 40
app/Models/DistProductCategory.php

@@ -42,46 +42,6 @@ class DistProductCategory extends Model implements Sortable
     protected $distributor = null;
 
 
-    public function __construct()
-    {
-
-//        // 获取当前登录的分销商/经销商
-//        $distributor=Session::get('distributor');
-//
-//
-//
-//            // 过滤分销商
-//        if ($distributor) {
-//
-//                $this->dist_id =$distributor->id;
-//        }
-//
-
-
-    }
-
-    protected static function boot()
-    {
-        var_dump('ufoxguo');
-        parent::boot();
-
-        static::addGlobalScope(new VerifiedDistId());
-    }
-
-//    protected static function booted()
-//    {
-//
-//        static::addGlobalScope('dist_id', function (Builder $builder) {
-//            // 获取当前登录的分销商/经销商
-//            $distributor=Session::get('distributor');
-//
-//            // 过滤分销商
-//            if (!$distributor) {
-//                $builder->where('dist_id', $distributor->id); // 替换为你的条件
-//            }
-//        });
-//
-//    }
 
     /*
      * 关联产品参数