Browse Source

分销商管理

moshaorui 5 months ago
parent
commit
d7f1a6064d

+ 2 - 8
app/Admin/Controllers/BaseProductController.php

@@ -53,10 +53,7 @@ class BaseProductController extends AdminController
                 $filter->equal('sku');
                 $filter->like('title');
                 $filter->equal('category_id','Category')->select(BaseProductCategory::selectOptions());
-                $filter->equal('enabled', 'enabled')->select([
-                    1 => 'Yes',
-                    0 => 'No',
-                ]);
+                $filter->equal('enabled', 'enabled')->select(config('dictionary.enabled'));
             });
             //排序
             $grid->model()->orderBy("is_pinned",'desc')->orderBy("order",'desc');
@@ -106,10 +103,7 @@ class BaseProductController extends AdminController
             $show->field('created_at');
             $show->field('updated_at');
             $show->field('order');
-            $show->field('enabled')->using([
-                '0' => 'No',   // 显示的状态名称
-                '1' => 'Yes',
-            ]);
+            $show->field('enabled')->using(config('dictionary.enabled'));
         });
     }
 

+ 2 - 9
app/Admin/Controllers/BaseVideoController.php

@@ -52,10 +52,7 @@ class BaseVideoController extends AdminController
                 $filter->equal('sku');
                 $filter->like('title');
                 $filter->equal('category_id','Category')->select(BaseVideoCategory::selectOptions());
-                $filter->equal('enabled', 'enabled')->select([
-                    1 => 'Yes',
-                    0 => 'No',
-                ]);
+                $filter->equal('enabled', 'enabled')->select(config('dictionary.enabled'));
             });
             //排序
             $grid->model()->orderBy("is_pinned",'desc')->orderBy("order",'desc');
@@ -73,7 +70,6 @@ class BaseVideoController extends AdminController
     protected function detail($id)
     {
         return Show::make($id, BaseVideo::with(['baseVideoCategory']), function (Show $show) {
-
             $show->field('id');
             $show->field('title');
             $show->field('base_video_category.name','Category Name');
@@ -103,10 +99,7 @@ class BaseVideoController extends AdminController
                 return $html;
             })->unescape();
             $show->field('remark')->unescape();
-            $show->field('enabled')->using([
-                '0' => 'No',   // 显示的状态名称
-                '1' => 'Yes',
-            ]);
+            $show->field('enabled')->using(config('dictionary.enabled'));
             $show->field('created_at');
             $show->field('updated_at');
         });

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

@@ -0,0 +1,155 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Admin\Repositories\DistAdminUser;
+use Dcat\Admin\Form;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Show;
+use Dcat\Admin\Http\Controllers\AdminController;
+use Dcat\Admin\Layout\Content;
+use Dcat\Admin\Admin;
+
+class DistAdminUserController extends AdminController
+{
+    /**
+     * page index
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('Distribution Management')
+            ->description('Distribution Management')
+            ->breadcrumb(['text'=>'list','url'=>''])
+            ->body($this->grid());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        return Grid::make(new DistAdminUser(), function (Grid $grid) {
+            //指定表格视图,去掉右上角的操作按钮
+            $grid->view('admin.grid.table');
+            //设置列表
+            $grid->column('id')->sortable();
+            $grid->column('username');
+            $grid->column('name','Company Name');
+            $grid->column('language')->using(config('app.languages'));
+            $grid->column('enabled')->switch();
+            $grid->column('created_at');
+            $grid->column('updated_at')->sortable();
+            $grid->filter(function (Grid\Filter $filter) {
+                $filter->equal('username');
+                $filter->equal('name','company name');
+            });
+            //排序
+            $grid->model()->orderBy("id",'desc');
+            //按钮
+            $grid->disableViewButton();
+            $grid->showQuickEditButton();
+            $grid->enableDialogCreate();
+            $grid->disableEditButton();
+            $grid->disableDeleteButton();
+            $grid->disableBatchDelete();
+        });
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     *
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        return Show::make($id, DistAdminUser::with(['info']), function (Show $show) {
+            $show->row(function (Show\Row $show) {
+                $show->width(6)->field('id');
+                $show->width(6)->field('username');
+                $show->width(6)->field('info.site_name','Site Name');
+                $show->width(6)->field('name','Company Name');
+                $show->width(6)->field('info.country','Country');
+                $show->width(6)->field('info.contact_number','Contact Number');
+                $show->width(6)->field('info.service_hotline','Service Hotline');
+                $show->width(6)->field('info.whats_app','whatsApp');
+                $show->width(6)->field('info.facebook','Facebook');
+                $show->width(6)->field('info.instagram','Instagram');
+                $show->width(6)->field('info.youtube','Youtube');
+                $show->width(6)->field('info.linkedin','Linkedin');
+                $show->width(6)->field('info.tiktok','Tiktok');
+                $show->width(6)->field('info.second_level_domain','Second Level Domain');
+                $show->width(6)->field('language')->using(config('app.languages'));
+                $show->width(6)->field('enabled')->using(config('dictionary.enabled'));
+                $show->width(6)->field('created_at');
+                $show->width(6)->field('updated_at');
+                $show->width(6)->field('info.remark','Remark');
+            });
+        });
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        return Form::make(DistAdminUser::with(['info']), function (Form $form) {
+            $form->display('id');
+            $form->text('username')->required();
+            $form->password('password')->customFormat(function ($v) {
+                return "";
+            });
+            $form->text('name','Company Name')->required();
+            $form->text('info.site_name','Site Name')->required();
+            $form->text('info.second_level_domain','Second Level Domain')->required();
+            $form->select('language')->options(config('app.languages'))->required();
+            $form->switch('enabled')->default(1);
+
+            $form->fieldset('Contact Information', function (Form $form) {
+                $form->text('info.country','Country');
+                $form->text('info.contact_number','Contact Number');
+                $form->text('info.service_hotline','Service Hotline');
+                $form->text('info.whats_app','WhatsApp');
+                $form->text('info.facebook','Facebook');
+                $form->text('info.instagram','Instagram');
+                $form->text('info.youtube','Youtube');
+                $form->text('info.linkedin','Linkedin');
+                $form->text('info.tiktok','Tiktok');
+                $form->textarea('info.remark','Remark');
+            });
+            //保存前回调
+            $form->saving(function (Form $form) {
+                //判断用户名是否重复
+                $count = DistAdminUser::findCountByUsername($form->getKey(), $form->username);
+                if ($count > 0) {
+                    return $form->response()->error('Username already exists');
+                }
+                if($form->isCreating() && ($form->password === null || $form->password === '')) {
+                    return $form->response()->error('Password cannot be empty');
+                }
+                //密码加密
+                if ($form->password) {
+                    $form->password = bcrypt($form->password);
+                } else {
+                    $form->deleteInput('password');
+                }
+            });
+            //保存后回调
+            $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('app.dist_role_id'));//分销商角色ID 2
+                }
+            });
+        });
+    }
+}

+ 2 - 10
app/Admin/Controllers/TestController.php

@@ -18,17 +18,14 @@ class TestController extends AdminController
      */
     protected function grid()
     {
-
-
         return Grid::make(new Test(), function (Grid $grid) {
+            $grid->view('admin.grid.table');
             $grid->column('id')->sortable();
             $grid->column('name');
             $grid->column('created_at');
             $grid->column('updated_at')->sortable();
-
             $grid->filter(function (Grid\Filter $filter) {
                 $filter->equal('id');
-
             });
         });
     }
@@ -60,12 +57,7 @@ class TestController extends AdminController
         return Form::make(new Test(), function (Form $form) {
             $form->display('id');
 
-            $form->multipleImage('name')->saving(function ($paths) {
-                return json_encode($paths);
-            })->dir('images/product/'.date("Ymd").'/')
-                ->uniqueName()
-                ->autoUpload()
-                ->accept('jpg,png,gif,jpeg,webp');
+            $form->text('name')->default("123");
 
             $form->display('created_at');
             $form->display('updated_at');

+ 41 - 0
app/Admin/Repositories/DistAdminUser.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Admin\Repositories;
+
+use App\Models\DistAdminUser as Model;
+use Dcat\Admin\Repositories\EloquentRepository;
+use App\Models\DistAdminRoleUser;
+class DistAdminUser extends EloquentRepository
+{
+    /**
+     * Model.
+     *
+     * @var string
+     */
+    protected $eloquentClass = Model::class;
+
+
+    /*
+     * 增加角色用户色关系
+     */
+    public static function addRoleUser($userId,$roleId) {
+        $distAdminRoleUser = new DistAdminRoleUser();
+        $distAdminRoleUser->role_id = $roleId;
+        $distAdminRoleUser->user_id = $userId;
+        $distAdminRoleUser->save();
+    }
+
+    /*
+     * 判断用户名是否存在
+     */
+    public static function findCountByUsername($id,$username)
+    {
+        $instance = new self();
+        if ($id) {
+            $count = $instance->Model()::where('username', $username)->where('id', '!=', $id)->count();
+        } else {
+            $count = $instance->Model()::where('username', $username)->count();
+        }
+        return $count;
+    }
+}

+ 3 - 2
app/Admin/routes.php

@@ -23,8 +23,9 @@ Route::group([
     $router->resource('product-parameter', 'BaseProductParameterController');
     //视频分类
     $router->resource('video-category', 'BaseVideoCategoryController');
-
-    $router->resource('language', 'LanguageController');
     //视频管理
     $router->resource('base-video', 'BaseVideoController');
+    //分销商管理
+    $router->resource('dist-admin-user', 'DistAdminUserController');
+    //分销商等级管理
 });

+ 14 - 0
app/Models/DistAdminRoleUser.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+use Illuminate\Database\Eloquent\Model;
+
+class DistAdminRoleUser extends Model
+{
+	use HasDateTimeFormatter;
+    protected $table = 'dist_admin_role_users';
+
+
+}

+ 21 - 0
app/Models/DistAdminUser.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+
+use Illuminate\Database\Eloquent\Model;
+
+class DistAdminUser extends Model
+{
+	use HasDateTimeFormatter;
+    protected $table = 'dist_admin_users';
+
+    /*
+     * 一对一关联
+     */
+    public function info()
+    {
+        return $this->hasOne(DistAdminUserInfo::class, 'dist_user_id', 'id');
+    }
+}

+ 17 - 0
app/Models/DistAdminUserInfo.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+use Illuminate\Database\Eloquent\Model;
+
+class DistAdminUserInfo extends Model
+{
+	use HasDateTimeFormatter;
+    protected $table = 'dist_admin_users_info';
+
+    public function user()
+    {
+        return $this->belongsTo(DistAdminUser::class, 'id', 'dist_user_id');
+    }
+}

+ 3 - 0
config/app.php

@@ -222,5 +222,8 @@ return [
     //默认语言
     'default_language' => 'en',
 
+    //分销商角色ID
+    'dist_role_id' => '2',
+
 
 ];

+ 16 - 0
config/dictionary.php

@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Support\Facades\Facade;
+
+/*
+ * 数据字典 dictionary
+ */
+
+return [
+    //是否启用
+    'enabled' => [
+        '0' => 'No',
+        '1' => 'Yes',
+    ],
+
+];

+ 18 - 0
lang/en/dist-admin-user.php

@@ -0,0 +1,18 @@
+<?php
+return [
+    'labels' => [
+        'DistAdminUser' => 'DistAdminUser',
+        'dist-admin-user' => 'DistAdminUser',
+    ],
+    'fields' => [
+        'username' => 'username',
+        'password' => 'password',
+        'name' => 'name',
+        'avatar' => 'avatar',
+        'remember_token' => 'remember_token',
+        'language' => 'language',
+        'enabled' => 'enabled',
+    ],
+    'options' => [
+    ],
+];

+ 1 - 1
resources/views/admin/grid/dropdown-actions.blade.php

@@ -21,4 +21,4 @@
         @endif
     </ul>
 </div>
-@endif
+@endif

+ 3 - 1
resources/views/admin/grid/table-toolbar.blade.php

@@ -20,7 +20,9 @@
                     {!! $grid->renderTools() !!}  {!! $grid->renderQuickSearch() !!}
 
                     <div class="pull-right" data-responsive-table-toolbar="{{$tableId}}">
+                        <!--
                         {!! $grid->renderRightTools() !!}
+                        -->
                         {!! $grid->renderColumnSelector() !!}
                         {!! $grid->renderCreateButton() !!}
                         {!! $grid->renderExportButton() !!}
@@ -29,4 +31,4 @@
             </div>
         </div>
     </div>
-@endif
+@endif

+ 1 - 1
resources/views/admin/grid/table.blade.php

@@ -2,7 +2,7 @@
 <div class="dcat-box">
 
     <div class="d-block pb-0">
-        @include('admin::grid.table-toolbar')
+        @include('admin.grid.table-toolbar')
     </div>
 
     {!! $grid->renderFilter() !!}