Browse Source

供应商时修改

moshaorui 5 months ago
parent
commit
97e9a28832

+ 127 - 0
app/Admin/Controllers/DistAdminDistributorController.php

@@ -0,0 +1,127 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Admin\Repositories\DistAdminDistributor;
+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 DistAdminDistributorController extends AdminController
+{
+    /**
+     * page index
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('Distro Management')
+            ->description('all')
+            ->breadcrumb(['text'=>'list','url'=>''])
+            ->body($this->grid());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        return Grid::make(new DistAdminDistributor(), function (Grid $grid) {
+            $grid->column('id')->sortable();
+            $grid->column('company_name','Company Name');
+            $grid->column('site_name');
+            $grid->column('level_domain');
+            $grid->column('country');
+            $grid->column('contact_number');
+            $grid->column('service_hotline');
+            $grid->column('enabled')->switch();
+            $grid->column('created_at');
+            $grid->column('updated_at')->sortable();
+            // 过滤
+            $grid->filter(function (Grid\Filter $filter) {
+                $filter->equal('company_name');
+                $filter->equal('site_name');
+                $filter->equal('level_domain');
+            });
+            // 排序
+            $grid->model()->orderBy("id",'desc');
+            //按钮
+            $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, new DistAdminDistributor(), function (Show $show) {
+            $show->field('id');
+            $show->field('country');
+            $show->field('contact_number');
+            $show->field('service_hotline');
+            $show->field('whats_app');
+            $show->field('facebook');
+            $show->field('instagram');
+            $show->field('youtube');
+            $show->field('linkedin');
+            $show->field('tiktok');
+            $show->field('site_name');
+            $show->field('level_domain');
+            $show->field('remark');
+            $show->field('company_address');
+            $show->field('company_name');
+            $show->field('enabled');
+            $show->field('created_at');
+            $show->field('updated_at');
+        });
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        return Form::make(new DistAdminDistributor(), function (Form $form) {
+            $form->display('id');
+            $form->text('company_name');
+            $form->text('site_name');
+            $form->text('level_domain');
+            $form->text('country');
+            $form->text('contact_number');
+            $form->text('service_hotline');
+            $form->text('whats_app');
+            $form->text('facebook');
+            $form->text('instagram');
+            $form->text('youtube');
+            $form->text('linkedin');
+            $form->text('tiktok');
+            $form->switch('enabled')->default(1);
+            $form->text('company_address');
+            $form->textarea('remark');
+            $form->display('created_at');
+            $form->display('updated_at');
+            //保存后回调
+            $form->saved(function (Form $form, $result) {
+
+
+            });
+        });
+
+    }
+}

+ 37 - 47
app/Admin/Controllers/DistAdminUserController.php

@@ -2,14 +2,13 @@
 
 namespace App\Admin\Controllers;
 
+use App\Admin\Renderable\DistDistributorTable;
 use App\Admin\Repositories\DistAdminUser;
-use App\Models\DistProductCategory;
 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
 {
@@ -19,8 +18,8 @@ class DistAdminUserController extends AdminController
     public function index(Content $content)
     {
         return $content
-            ->header('Distribution Management')
-            ->description('Distribution Management')
+            ->header('Users Management')
+            ->description('Users Management')
             ->breadcrumb(['text'=>'list','url'=>''])
             ->body($this->grid());
     }
@@ -32,20 +31,23 @@ class DistAdminUserController extends AdminController
      */
     protected function grid()
     {
-        return Grid::make(new DistAdminUser(), function (Grid $grid) {
+        return Grid::make(DistAdminUser::with(['distributor']), function (Grid $grid) {
             //指定表格视图,去掉右上角的操作按钮
             $grid->view('admin.grid.table');
             //设置列表
             $grid->column('id')->sortable();
             $grid->column('username');
-            $grid->column('name','Company Name');
+            $grid->column('name');
+            $grid->column('distributor.company_name','Company Name');
+            $grid->column('distributor.level_domain','Level Domain');
             $grid->column('language')->using(config('dictionary.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');
+                $filter->equal('name','name');
+                $filter->like('distributor.company_name', 'Company Name');
             });
             //排序
             $grid->model()->orderBy("id",'desc');
@@ -67,28 +69,29 @@ class DistAdminUserController extends AdminController
      */
     protected function detail($id)
     {
-        return Show::make($id, DistAdminUser::with(['info']), function (Show $show) {
+        return Show::make($id, DistAdminUser::with(['distributor']), function (Show $show) {
             $show->row(function (Show\Row $show) {
                 $show->width(6)->field('id');
                 $show->width(6)->field('username');
+                $show->width(6)->field('name','name');
                 $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('distributor.level_domain','Level Domain');
+                $show->width(6)->field('distributor.company_name', 'Company Name');
+                $show->width(6)->field('distributor.country','Country');
+                $show->width(6)->field('distributor.contact_number','Contact Number');
+                $show->width(6)->field('distributor.service_hotline','Service Hotline');
+                $show->width(6)->field('distributor.whats_app','whatsApp');
+                $show->width(6)->field('distributor.facebook','Facebook');
+                $show->width(6)->field('distributor.instagram','Instagram');
+                $show->width(6)->field('distributor.youtube','Youtube');
+                $show->width(6)->field('distributor.linkedin','Linkedin');
+                $show->width(6)->field('distributor.tiktok','Tiktok');
                 $show->width(6)->field('language')->using(config('dictionary.languages'));
                 $show->width(6)->field('enabled')->using(config('dictionary.enabled'));
+                $show->width(6)->field('distributor.company_address','Company Address');
                 $show->width(6)->field('created_at');
                 $show->width(6)->field('updated_at');
-                $show->width(6)->field('info.company_address','Company Address');
-                $show->width(6)->field('info.remark','Remark');
+                $show->width(6)->field('distributor.remark','Remark');
             });
         });
     }
@@ -100,31 +103,18 @@ class DistAdminUserController extends AdminController
      */
     protected function form()
     {
-        return Form::make(DistAdminUser::with(['info']), function (Form $form) {
+        return Form::make(DistAdminUser::with(['distributor']), 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->text('name','name')->required();
             $form->select('language')->options(config('dictionary.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.company_address','Company Address');
-                $form->textarea('info.remark','Remark');
-            });
+            $form->selectTable('dist_id', 'Select Distributor')
+                ->title('distId')
+                ->from(DistDistributorTable::make());
             //保存前回调
             $form->saving(function (Form $form) {
                 //判断用户名是否重复
@@ -152,14 +142,14 @@ class DistAdminUserController extends AdminController
                     }
                     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_id'=>$newId,
-                    ]);
+//                    $distProductCategory = new DistProductCategory();
+//                    $distProductCategory->create([
+//                        'parent_id' => 0,
+//                        'name' => 'Default Category',
+//                        'order' => 0,
+//                        'enabled' => 1,
+//                        'dist_id'=>$newId,
+//                    ]);
                 }
             });
         });

+ 42 - 0
app/Admin/Renderable/DistDistributorTable.php

@@ -0,0 +1,42 @@
+<?php
+namespace App\Admin\Renderable;
+
+use App\Models\DistAdminDistributor;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Grid\LazyRenderable;
+
+class DistDistributorTable extends LazyRenderable
+{
+    public function grid(): Grid
+    {
+        // 获取外部传递的参数
+        $id = $this->id;
+
+        return Grid::make(new DistAdminDistributor(), function (Grid $grid) {
+            $grid->column('id');
+            $grid->column('company_name', 'Company Name');
+            $grid->column('country', 'Country');
+            $grid->column('site_name', 'Site Name');
+            $grid->column('level_domain', 'Level Domain');
+            $grid->column('created_at');
+            $grid->column('updated_at');
+
+            // 指定行选择器选中时显示的值的字段名称
+            // 指定行选择器选中时显示的值的字段名称
+            // 指定行选择器选中时显示的值的字段名称
+            // 如果表格数据中带有 “name”、“title”或“username”字段,则可以不用设置
+            $grid->rowSelector()->titleColumn('company_name');
+
+            $grid->quickSearch(['id', 'company_name', 'level_domain']);
+
+            $grid->paginate(10);
+            $grid->disableActions();
+
+            $grid->filter(function (Grid\Filter $filter) {
+                $filter->like('company_name')->width(4);
+                $filter->like('level_domain', 'Level Domain')->width(4);
+            });
+            $grid->model()->where('enabled', 1);
+        });
+    }
+}

+ 16 - 0
app/Admin/Repositories/DistAdminDistributor.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Admin\Repositories;
+
+use App\Models\DistAdminDistributor as Model;
+use Dcat\Admin\Repositories\EloquentRepository;
+
+class DistAdminDistributor extends EloquentRepository
+{
+    /**
+     * Model.
+     *
+     * @var string
+     */
+    protected $eloquentClass = Model::class;
+}

+ 2 - 0
app/Admin/routes.php

@@ -26,6 +26,8 @@ Route::group([
     //视频管理
     $router->resource('base-video', 'BaseVideoController');
     //分销商管理
+    $router->resource('dist-admin-distributor', 'DistAdminDistributorController');
+    //分销商用户管理
     $router->resource('dist-admin-user', 'DistAdminUserController');
     //询价管理
     $router->resource('dist-inquiry', 'DistInquiryController');

+ 1 - 0
app/Models/DistAdminDistributor.php

@@ -3,6 +3,7 @@
 namespace App\Models;
 
 use Dcat\Admin\Traits\HasDateTimeFormatter;
+
 use Illuminate\Database\Eloquent\Model;
 
 class DistAdminDistributor extends Model

+ 1 - 1
app/Models/DistAdminUser.php

@@ -14,7 +14,7 @@ class DistAdminUser extends Model
     /*
      * 一对一关联
      */
-    public function info()
+    public function distributor()
     {
         return $this->hasOne(DistAdminDistributor::class, 'id', 'dist_id');
     }

+ 16 - 16
dcat_admin_ide_helper.php

@@ -51,8 +51,6 @@ namespace Dcat\Admin {
      * @property Grid\Column|Collection remark
      * @property Grid\Column|Collection video_url
      * @property Grid\Column|Collection cover_image
-     * @property Grid\Column|Collection language
-     * @property Grid\Column|Collection dist_user_id
      * @property Grid\Column|Collection country
      * @property Grid\Column|Collection contact_number
      * @property Grid\Column|Collection service_hotline
@@ -63,11 +61,13 @@ namespace Dcat\Admin {
      * @property Grid\Column|Collection linkedin
      * @property Grid\Column|Collection tiktok
      * @property Grid\Column|Collection site_name
-     * @property Grid\Column|Collection second_level_domain
+     * @property Grid\Column|Collection level_domain
      * @property Grid\Column|Collection company_address
+     * @property Grid\Column|Collection company_name
+     * @property Grid\Column|Collection language
+     * @property Grid\Column|Collection dist_id
      * @property Grid\Column|Collection describe
      * @property Grid\Column|Collection order_noumber
-     * @property Grid\Column|Collection company_name
      * @property Grid\Column|Collection customer_name
      * @property Grid\Column|Collection email
      * @property Grid\Column|Collection consulting_products
@@ -123,8 +123,6 @@ namespace Dcat\Admin {
      * @method Grid\Column|Collection remark(string $label = null)
      * @method Grid\Column|Collection video_url(string $label = null)
      * @method Grid\Column|Collection cover_image(string $label = null)
-     * @method Grid\Column|Collection language(string $label = null)
-     * @method Grid\Column|Collection dist_user_id(string $label = null)
      * @method Grid\Column|Collection country(string $label = null)
      * @method Grid\Column|Collection contact_number(string $label = null)
      * @method Grid\Column|Collection service_hotline(string $label = null)
@@ -135,11 +133,13 @@ namespace Dcat\Admin {
      * @method Grid\Column|Collection linkedin(string $label = null)
      * @method Grid\Column|Collection tiktok(string $label = null)
      * @method Grid\Column|Collection site_name(string $label = null)
-     * @method Grid\Column|Collection second_level_domain(string $label = null)
+     * @method Grid\Column|Collection level_domain(string $label = null)
      * @method Grid\Column|Collection company_address(string $label = null)
+     * @method Grid\Column|Collection company_name(string $label = null)
+     * @method Grid\Column|Collection language(string $label = null)
+     * @method Grid\Column|Collection dist_id(string $label = null)
      * @method Grid\Column|Collection describe(string $label = null)
      * @method Grid\Column|Collection order_noumber(string $label = null)
-     * @method Grid\Column|Collection company_name(string $label = null)
      * @method Grid\Column|Collection customer_name(string $label = null)
      * @method Grid\Column|Collection email(string $label = null)
      * @method Grid\Column|Collection consulting_products(string $label = null)
@@ -200,8 +200,6 @@ namespace Dcat\Admin {
      * @property Show\Field|Collection remark
      * @property Show\Field|Collection video_url
      * @property Show\Field|Collection cover_image
-     * @property Show\Field|Collection language
-     * @property Show\Field|Collection dist_user_id
      * @property Show\Field|Collection country
      * @property Show\Field|Collection contact_number
      * @property Show\Field|Collection service_hotline
@@ -212,11 +210,13 @@ namespace Dcat\Admin {
      * @property Show\Field|Collection linkedin
      * @property Show\Field|Collection tiktok
      * @property Show\Field|Collection site_name
-     * @property Show\Field|Collection second_level_domain
+     * @property Show\Field|Collection level_domain
      * @property Show\Field|Collection company_address
+     * @property Show\Field|Collection company_name
+     * @property Show\Field|Collection language
+     * @property Show\Field|Collection dist_id
      * @property Show\Field|Collection describe
      * @property Show\Field|Collection order_noumber
-     * @property Show\Field|Collection company_name
      * @property Show\Field|Collection customer_name
      * @property Show\Field|Collection email
      * @property Show\Field|Collection consulting_products
@@ -272,8 +272,6 @@ namespace Dcat\Admin {
      * @method Show\Field|Collection remark(string $label = null)
      * @method Show\Field|Collection video_url(string $label = null)
      * @method Show\Field|Collection cover_image(string $label = null)
-     * @method Show\Field|Collection language(string $label = null)
-     * @method Show\Field|Collection dist_user_id(string $label = null)
      * @method Show\Field|Collection country(string $label = null)
      * @method Show\Field|Collection contact_number(string $label = null)
      * @method Show\Field|Collection service_hotline(string $label = null)
@@ -284,11 +282,13 @@ namespace Dcat\Admin {
      * @method Show\Field|Collection linkedin(string $label = null)
      * @method Show\Field|Collection tiktok(string $label = null)
      * @method Show\Field|Collection site_name(string $label = null)
-     * @method Show\Field|Collection second_level_domain(string $label = null)
+     * @method Show\Field|Collection level_domain(string $label = null)
      * @method Show\Field|Collection company_address(string $label = null)
+     * @method Show\Field|Collection company_name(string $label = null)
+     * @method Show\Field|Collection language(string $label = null)
+     * @method Show\Field|Collection dist_id(string $label = null)
      * @method Show\Field|Collection describe(string $label = null)
      * @method Show\Field|Collection order_noumber(string $label = null)
-     * @method Show\Field|Collection company_name(string $label = null)
      * @method Show\Field|Collection customer_name(string $label = null)
      * @method Show\Field|Collection email(string $label = null)
      * @method Show\Field|Collection consulting_products(string $label = null)

+ 26 - 0
lang/en/dist-admin-distributor.php

@@ -0,0 +1,26 @@
+<?php 
+return [
+    'labels' => [
+        'DistAdminDistributor' => 'DistAdminDistributor',
+        'dist-admin-distributor' => 'DistAdminDistributor',
+    ],
+    'fields' => [
+        'country' => 'country',
+        'contact_number' => 'contact_number',
+        'service_hotline' => 'service_hotline',
+        'whats_app' => 'whats_app',
+        'facebook' => 'facebook',
+        'instagram' => 'instagram',
+        'youtube' => 'youtube',
+        'linkedin' => 'linkedin',
+        'tiktok' => 'tiktok',
+        'site_name' => 'site_name',
+        'level_domain' => 'level_domain',
+        'remark' => 'remark',
+        'company_address' => '公司地址',
+        'company_name' => '公司名称',
+        'enabled' => 'enabled',
+    ],
+    'options' => [
+    ],
+];