Browse Source

新建供应商时增加默分类

moshaorui 5 months ago
parent
commit
28e6277dc3

+ 11 - 0
app/Admin/Controllers/DistAdminUserController.php

@@ -3,6 +3,7 @@
 namespace App\Admin\Controllers;
 
 use App\Admin\Repositories\DistAdminUser;
+use App\Models\DistProductCategory;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Show;
@@ -144,11 +145,21 @@ class DistAdminUserController extends AdminController
             //保存后回调
             $form->saved(function (Form $form, $result) {
                 if ($form->isCreating()) {
+                    //添加角色
                     $newId = $form->getKey();
                     if (! $newId) {
                         return $form->response()->error('Failed to save data');
                     }
                     DistAdminUser::addRoleUser($newId, config('dictionary.dist_role_id'));//分销商角色ID 2
+                    //分配默认分类
+                    $distProductCategory = new DistProductCategory();
+                    $distProductCategory->create([
+                        'parent_id' => 0,
+                        'name' => 'Default Category',
+                        'order' => 0,
+                        'enabled' => 1,
+                        'dist_user_id'=>$newId,
+                    ]);
                 }
             });
         });

+ 1 - 1
app/Libraries/CommonHelper.php

@@ -12,7 +12,7 @@ class CommonHelper
      */
     public static function displayImage($images,$boxSize=100,$imgSize=300)
     {
-        if (empty($images) || $images[0] == null) {
+        if (empty($images) || empty($images[0])) {
             $html = "";
         } else {
             //默认用等比例缩放

+ 4 - 0
app/Models/BaseProductCategory.php

@@ -29,6 +29,10 @@ class BaseProductCategory extends Model implements Sortable
         'updated_at' => 'datetime:Y-m-d H:i:s',
     ];
 
+    protected $fillable = [
+        'name', 'parent_id', 'order','enabled','dist_user_id', // 假设已有的可填充字段
+    ];
+
     /*
      * 关联产品参数
      */

+ 4 - 0
app/Models/DistProductCategory.php

@@ -30,6 +30,10 @@ class DistProductCategory extends Model implements Sortable
         'updated_at' => 'datetime:Y-m-d H:i:s',
     ];
 
+    protected $fillable = [
+        'name', 'parent_id', 'order','enabled','dist_user_id', // 假设已有的可填充字段
+    ];
+
     /*
      * 关联产品参数
      */