Ver Fonte

Merge branch 'refs/heads/master' into stable

moshaorui há 1 mês atrás
pai
commit
0bdcaf414c

+ 5 - 1
app/Admin/Controllers/DistAdminDistributorController.php

@@ -121,7 +121,11 @@ class DistAdminDistributorController extends AdminController
                 ->setTitleColumn('title')
                 ->nodes($allNodes)
                 ->exceptParentNode(false)
-                ->width(9,3);
+                ->width(9,3)
+                ->saving(function ($v) {
+                    return json_encode($v);
+                });
+
             $form->text('dist_email',admin_trans_label('email'))->width(9,3);
             $form->text('dist_contact_number',admin_trans_label('contact_number'))->width(9,3);
             $form->text('address')->width(9,3);

+ 3 - 4
app/Admin/Controllers/ImportProductController.php

@@ -31,7 +31,6 @@ class ImportProductController extends AdminController
     {
         return $content
             ->header(admin_trans( 'admin.product_import'))
-            ->description('<span style="color: red; font-weight: bold;">'.admin_trans_label('select_products_to_import').'</span>')
             ->breadcrumb(['text'=>'list','url'=>''])
             ->body($this->grid());
     }
@@ -116,9 +115,9 @@ class ImportProductController extends AdminController
                 //$batch->add(new BatchCopy()); 只能2选1
             });
 
-            $grid->tools([
-                new RpcAlbumImport(),
-            ]);
+//            $grid->tools([
+//                new RpcAlbumImport(),
+//            ]);
 
             $grid->model()->where('enabled',1)->orderBy("order",'desc')->orderBy("created_at",'desc');
         });

+ 1 - 1
app/Distributor/Actions/Extensions/DistProductImportForm.php

@@ -36,7 +36,7 @@ class DistProductImportForm extends BatchAction
         // 获取选中的ID数组
         var key = {$this->getSelectedKeysScript()}
 
-        $('#product_ids').val(key);
+        $('#album_ids').val(key);
         JS;
     }
 

+ 108 - 49
app/Distributor/Controllers/ImportProductController.php

@@ -4,19 +4,14 @@ namespace App\Distributor\Controllers;
 
 
 use App\Distributor\Actions\Extensions\DistProductImportForm;
+use App\Distributor\Repositories\RpcAlbum;
+use App\Distributor\Repositories\RpcAlbumFolder;
 use App\Distributor\Repositories\BaseProduct;
-use App\Admin\Repositories\BaseProductCategory;
-use App\Distributor\Actions\BatchCopy;
-use App\Distributor\Repositories\DistProductCategory;
 use App\Libraries\CommonHelper;
-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 ImportProductController extends AdminDistController
 {
     /**
@@ -59,34 +54,46 @@ class ImportProductController extends AdminDistController
      */
     protected function grid()
     {
-        return Grid::make(BaseProduct::with(['baseProductCategory','images']), function (Grid $grid) {
+        return Grid::make(new RpcAlbum(), function (Grid $grid) {
+            $lang = config('app.locale');//当前语言
             $grid->view('admin.grid.table');
             $grid->column('id')->display(function () {
                 return $this->_index+1;
             })->width('8%');
-            $grid->column('title')->width('20%');
-            $grid->column('sku')->width('10%');
-            $grid->column('images')->display(function ($images) {
-                $images = $images->toArray();
-                $dataImages = array_column($images, 'image_url');
+            $grid->column('cover')->display(function ($images) {
+                $images = json_decode($images);
                 // 限制最多显示2个缩略图
-                $dataImages = array_slice($dataImages, 0, 1);
-                return CommonHelper::displayImage($dataImages,100);
+                $dataImages = array_slice($images, 0, 1);
+                return CommonHelper::displayImage($dataImages,100,1024,2);
+            });
+            if ($lang == 'en') {
+                $grid->column('title_en');
+            } else {
+                $grid->column('title');
+            }
+            $grid->column('model');
+            $grid->column('missing_content')->display(function ($missing_content) {
+                $missing_content = [];
+                if ($this->cover == '[]') {$missing_content[] = '主图';}
+                if ($this->en_detail == '[]') {$missing_content[] = '英文详情';}
+                if ($this->cn_detail == '[]') {$missing_content[] = '中文详情';}
+                if ($this->video == '[]') {$missing_content[] = '视频';}
+                if ($this->poster == '[]') {$missing_content[] = '海报';}
+                if ($this->cert == '[]') {$missing_content[] = '证书';}
+                if ($this->pdf == '[]') {$missing_content[] = 'PDF';}
+                return implode(' / ', $missing_content);
             });
-            $grid->column('base_product_category.name',admin_trans_label('category_name'));
 
-           // $grid->column('keywords');
-           // $grid->column('description');
-            //$grid->column('created_at')->sortable();
-            //$grid->column('issuance_date');
+            $grid->column('created_at')->sortable();
+            $grid->column('updated_at')->sortable();
+
             // 筛选
             $grid->filter(function (Grid\Filter $filter) {
                 $filter->panel();
                 $filter->expand();
-                $filter->equal('sku')->width(2);
-                $filter->like('title')->width(2);
-                $filter->equal('category_id',admin_trans_label('category'))->select(BaseProductCategory::selectOptions())->width(2);
-                //$filter->equal('enabled', admin_trans_label('enabled'))->select(admin_trans_array( config('dictionary.enabled')))->width(2);
+                $filter->equal('model')->width(2);
+                $lang = config('app.locale');//当前语言
+                $filter->equal('folder_id',admin_trans_label('product_category'))->select(RpcAlbumFolder::selectOptions($lang))->width(3);
             });
             // 删除新增按钮
             $grid->disableCreateButton();
@@ -107,29 +114,25 @@ class ImportProductController extends AdminDistController
         });
     }
 
-    /**
-     * Make a show builder.
-     *
-     * @param mixed $id
-     *
-     * @return Show
-     */
     protected function detail($id)
     {
-        return Show::make($id, BaseProduct::with(['baseProductCategory','images']), function (Show $show) {
-           // $show->field('id');
-            $show->field('title');
-            $show->field('sku');
-            $show->field('base_product_category.name',admin_trans_label('category_name'));
-            $show->field('keywords');
-            $show->field('description');
-            $show->field('issuance_date');
+        return Show::make($id, new \App\Admin\Repositories\RpcAlbum(), function (Show $show) {
+            $lang = config('app.locale');//当前语言
+            if ($lang == 'en') {
+                $show->field('title_en');
+            } else {
+                $show->field('title');
+            }
+
+            $show->field('model');
             $show->field('parameters',admin_trans_label('attribute'))->as(function ($items) {
+                $items = json_decode($items);
                 if (is_array($items)) {
                     // 创建表格的表头
                     $table = '<table class="table table-bordered table-condensed">';
                     // 遍历数组并将数据填充到表格中
                     foreach ($items as $item) {
+                        $item = (array)$item;
                         $table .= '<tr>';
                         $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>';    // 商品名称
                         $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>'; // 数量
@@ -140,20 +143,76 @@ class ImportProductController extends AdminDistController
                 }
                 return ''; // 当没有数组数据时
             })->unescape();
-            $show->field('images')->as(function ($images) {
-                // 开始生成 HTML
-                $dataImages = array_column($images, 'image_url');
-                return CommonHelper::displayImage($dataImages,150);
+            $show->field('cover')->as(function ($images) {
+                $images = json_decode($images);
+                return CommonHelper::displayImage($images,150,1024,2);
+            })->unescape();
+
+            $show->field('en_detail')->as(function ($images) {
+                $images = json_decode($images);
+                $html = '<div style="text-align: center">';
+                foreach ($images as $key => $image) {
+                    $url = CommonHelper::albumUrl($image);
+                    $html .= '<img src="' . $url . '" style="max-width:90%;margin-bottom:10px">';
+                }
+                $html .= '</div>';
+                return $html;
+            })->unescape();
+
+            $show->field('cn_detail')->as(function ($images) {
+                $images = json_decode($images);
+                $html = '<div style="text-align: center">';
+                foreach ($images as $key => $image) {
+                    $url = CommonHelper::albumUrl($image);
+                    $html .= '<img src="' . $url . '" style="max-width:90%;margin-bottom:10px">';
+                }
+                $html .= '</div>';
+                return $html;
+            })->unescape();
+
+            $show->field('video')->as(function ($items) {
+                $items = json_decode($items);
+                return CommonHelper::displayVideo($items,'cover','video_src','150',2);
+            })->unescape();
+
+            $show->field('poster')->as(function ($images) {
+                $images = json_decode($images);
+                return CommonHelper::displayImage($images,150,1024,2);
+            })->unescape();
+
+            $show->field('cert')->as(function ($images) {
+                $images = json_decode($images);
+                return CommonHelper::displayImage($images,150,1024,2);
+            })->unescape();
+
+            $show->field('cert')->as(function ($images) {
+                $images = json_decode($images);
+                return CommonHelper::displayImage($images,150,1024,2);
             })->unescape();
-            $show->field('content')->unescape();
-            $show->field('seo_title');
-            $show->field('seo_keywords');
-            $show->field('seo_description');
-            $show->field('created_at');
-            //$show->field('updated_at');
+
+            $show->field('pdf')->as(function ($items) {
+                $items = json_decode($items);
+                if (is_array($items)) {
+                    // 创建表格的表头
+                    $table = '<table class="table table-bordered table-condensed">';
+                    // 遍历数组并将数据填充到表格中
+                    foreach ($items as $item) {
+                        $table .= '<tr>';
+                        $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item->pdf_title . '</td>';    // 商品名称
+                        $table .= '<td style="vertical-align: middle !important;"><a target="_blank" href="' . CommonHelper::albumUrl($item->pdf_src). '">查看</a></td>'; // 数量
+                        $table .= '</tr>';
+                    }
+                    $table .= '</table>';
+                    return $table;
+                }
+                return ''; // 当没有数组数据时
+            })->unescape();
+
             // 禁用操作
             $show->disableEditButton();
             $show->disableDeleteButton();
+
+
         });
     }
 

+ 2 - 2
app/Distributor/Controllers/SettingsController.php

@@ -80,8 +80,8 @@ class SettingsController extends Controller
             $form->text('seo_title')->value($distInfo->seo_title)->required();
             $form->text('seo_keywords')->value($distInfo->seo_keywords);
             $form->textarea('seo_description')->value($distInfo->seo_description);
-            $form->cutImage("logo")
-                ->aspectRatio(130/50)// 设置裁剪框比例
+            $form->image("logo")
+                //->aspectRatio(130/50)// 设置裁剪框比例
                 ->retainable()//禁止删OSS图
                 ->autoUpload()
                 ->uniqueName()

+ 45 - 49
app/Distributor/Forms/ImportProduct.php

@@ -1,7 +1,9 @@
 <?php
 
 namespace App\Distributor\Forms;
+use App\Distributor\Repositories\RpcAlbum;
 use App\Distributor\Repositories\DistProductCategory;
+use App\Libraries\CommonHelper;
 use App\Models\DistProduct;
 use App\Models\BaseProductImage;
 use App\Models\DistProductImage;
@@ -10,93 +12,87 @@ use Dcat\Admin\Widgets\Form;
 
 class ImportProduct extends Form
 {
-    /**
-     * Handle the form request.
-     *
-     * @param array $input
-     *
-     * @return mixed
-     */
     public function handle(array $input)
     {
-        // dump($input);
-
-        // return $this->response()->error('Your error message.');
-
-
-        // 获取输入的 product_ids 和 category_id
-        $productIds = explode(',', $input['product_ids']);
+        $albumIds = explode(',', $input['album_ids']);
         $categoryId = $input['category_id'];
 
-        // 检查 product_ids 是否为空
-
-        if (empty($input['product_ids'])) {
+        if (empty($input['album_ids'])) {
             return $this
                 ->response()
                 ->error('请选择要导入的产品');
         }
-
-
         try {
-            foreach ($productIds as $productId) {
-                // 从 BaseProduct 获取产品数据
-                $baseProduct = BaseProduct::findById($productId);
+            //RPC读取相册
+            $rpcAlbum = new RpcAlbum();
+            $albumResult = $rpcAlbum->getByids($albumIds);
 
-                if (!$baseProduct) {
-                    throw new \Exception("Product with ID $productId not found in BaseProduct.");
-                }
-// 获取 base_product_image 表中与当前 base_product 相关的图片记录
-                $baseProductImages = BaseProductImage::where('product_id', $baseProduct->id)->get();
+            if ($albumResult['status']= false) {
+                return $this
+                    ->response()
+                    ->error('RPC获取相册失败:'. $albumResult['msg']);
+            }
 
+            foreach ($albumResult['data'] as $item) {
+                $title = isset($item['title']) ? $item['title'] : $item['model'];
+                $content = empty($item['text_detail']) ? $this->changeToimagesHTML($item['en_detail']) : $item['text_detail'];
                 // 创建新的 DistProduct 记录
                 $distProduct = DistProduct::create([
                     'category_id' => $categoryId,
-                    'title' => $baseProduct->title,
-                    'sku' => $baseProduct->sku, // 假设 $baseProduct 也有 sku 字段
-                    'issuance_date' => $baseProduct->issuance_date, // 假设 $baseProduct 也有 issuance_date 字段
+                    'title' => $title,
+                    'sku' => $item['model'], // 假设 $baseProduct 也有 sku 字段
+                    'issuance_date' => null, // 假设 $baseProduct 也有 issuance_date 字段
                     'order' => 0, // 假设 $baseProduct 也有 order 字段
-                    'enabled' => $baseProduct->enabled, // 假设 $baseProduct 也有 enabled 字段
-                    'content' => $baseProduct->content, // 假设 $baseProduct 也有 content 字段
-                    'parameters' => $baseProduct->parameters, // 假设 $baseProduct 也有 parameters 字段
-                    'seo_title'=> $baseProduct->seo_title,
-                    'seo_keywords' => $baseProduct->seo_keywords,
-                    'seo_description' => $baseProduct->seo_description,
+                    'enabled' => 1, // 假设 $baseProduct 也有 enabled 字段
+                    'content' => $content, // 假设 $baseProduct 也有 content 字段
+                    'parameters' => $item['parameters'], // 假设 $baseProduct 也有 parameters 字段
+                    'seo_title'=> $title,
+                    'seo_keywords' => '',
+                    'seo_description' => '',
+                    'status' => 2,
                     'dist_id' => getDistributorId(),
                     'created_at' => now(), // 自动填充创建时间
                     'updated_at' => now(), // 自动填充更新时间
-                    'status' => 2,
-                    'review_reply' => '',
                 ]);
                 DistProduct::where('id', $distProduct->id)->update(['slug' => $distProduct->id]);
+                //DistProduct::where('id', $distProduct->id)->update(['slug' => $distProduct->id]);
                 // 遍历 base_product_image 表中的记录,并插入到 dist_product_image 表中
-                foreach ($baseProductImages as $baseImage) {
+                $cover = json_decode($item['cover'], true);
+                foreach ($cover as $baseImage) {
+                    $i = 1;
                     DistProductImage::create([
-                        'image_url' => $baseImage->image_url,
+                        'image_url' => CommonHelper::albumUrl($baseImage),
                         'product_id' => $distProduct->id, // 使用新创建的 DistProduct 的 ID
-                        'order' => $baseImage->order,
+                        'order' => $i,
                         'created_at' => now(), // 自动填充创建时间
                         'updated_at' => now(), // 自动填充更新时间
                     ]);
+                    $i++;
                 }
             }
-
             return $this
                 ->response()
                 ->success('导入成功')
                 ->refresh();
         } catch (\Exception $e) {
-
+            throw $e;
             return $this
                 ->response()
                 ->error('导入失败: ' . $e->getMessage());
         }
-//
-//        return $this
-//				->response()
-//				->success('导入成功')
-//				->refresh();
     }
 
+    public function changeToimagesHTML($content) {
+        $content = json_decode($content, true);
+        $html = '';
+        foreach ($content as $item) {
+            $item = CommonHelper::albumUrl($item);
+            $html.= '<img src="'. $item. '">';
+        }
+        return $html;
+    }
+
+
     /**
      * Build a form here.
      */
@@ -108,7 +104,7 @@ class ImportProduct extends Form
         $this->select('category_id', admin_trans_label('category_name'))
             ->options(DistProductCategory::selectOptions())
             ->required();
-        $this->hidden('product_ids')->attribute('id', 'product_ids');
+        $this->hidden('album_ids')->attribute('id', 'album_ids');
     }
 
     /**

+ 11 - 0
app/Distributor/Repositories/RpcAlbum.php

@@ -32,6 +32,7 @@ class RpcAlbum extends EloquentRepository
         $this->albumFolder = $albumFolder;
     }
 
+
     /*
      * 执行RPC调用
      */
@@ -40,6 +41,16 @@ class RpcAlbum extends EloquentRepository
         return RpcClient::albumExecute($method, $params);
     }
 
+    /*
+     * 通过IDS获取相册详情
+     */
+    public function getByids($ids)
+    {
+        return $this->execute('siteAlbumGetByIds', [
+            'ids' => $ids,
+        ]);
+    }
+
     /*
      * 获取相册列表
      */

+ 1 - 1
app/helpers.php

@@ -249,7 +249,7 @@ if (!function_exists('generateSlug')) {
         // 2. 将空格替换为短横线(-)
         $slug = str_replace(' ', '-', $slug);
         // 3. 将不合法的字符(!@#$%^&*?=+)替换为空
-        $slug = preg_replace('/[::^!@#$%^&*()?=+]+/', '', $slug);
+        $slug = preg_replace('/[::^!@#$%^&*()?=+]+/u', '', $slug);
         // 4. 清理多余的短横线
         $slug = preg_replace('/-+/', '-', $slug);
         // 5. 去除开头和结尾的短横线

+ 162 - 0
app/repair/dcat-plus/laravel-admin/src/Form/Field/Editor.php

@@ -0,0 +1,162 @@
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+use Dcat\Admin\Form\Field;
+use Dcat\Admin\Support\Helper;
+
+/**
+ * TinyMCE editor.
+ *
+ * @see https://www.tiny.cloud/docs
+ * @see http://tinymce.ax-z.cn/
+ */
+class Editor extends Field
+{
+    protected $options = [
+        'plugins' => [
+            'advlist',
+            'autolink',
+            'link',
+            'image',
+            'media',
+            'lists',
+            'preview',
+            'code',
+            'help',
+            'fullscreen',
+            'table',
+            'autoresize',
+            'codesample',
+        ],
+        'toolbar' => [
+            'undo redo | preview fullscreen | styleselect | fontsizeselect bold italic underline strikethrough forecolor backcolor | link image media blockquote removeformat codesample',
+            'alignleft aligncenter alignright  alignjustify| indent outdent bullist numlist table subscript superscript | code',
+        ],
+        'min_height' => 400,
+        'save_enablewhendirty' => true,
+        'convert_urls' => false,
+
+        // 图片上传后,把长与宽设为空
+        'image_dimensions' =>  false,
+        'image_prepend_dimensions' => false,
+        'object_resizing' => false,
+    ];
+
+    protected $disk;
+
+    protected $imageUploadDirectory = 'tinymce/images';
+
+    /**
+     * 设置文件上传存储配置.
+     *
+     * @param  string  $disk
+     * @return $this
+     */
+    public function disk(string $disk)
+    {
+        $this->disk = $disk;
+
+        return $this;
+    }
+
+    /**
+     * 设置图片上传文件夹.
+     *
+     * @param  string  $dir
+     * @return $this
+     */
+    public function imageDirectory(string $dir)
+    {
+        $this->imageUploadDirectory = $dir;
+
+        return $this;
+    }
+
+    /**
+     * 自定义图片上传接口.
+     *
+     * @param  string  $url
+     * @return $this
+     */
+    public function imageUrl(string $url)
+    {
+        return $this->mergeOptions(['images_upload_url' => $this->formatUrl(admin_url($url))]);
+    }
+
+    /**
+     * 设置语言包url.
+     *
+     * @param  string  $url
+     * @return $this
+     */
+    public function languageUrl(string $url)
+    {
+        return $this->mergeOptions(['language_url' => $url]);
+    }
+
+    /**
+     * 设置编辑器高度.
+     *
+     * @param  int  $height
+     * @return $this
+     */
+    public function height(int $height)
+    {
+        return $this->mergeOptions(['min_height' => $height]);
+    }
+
+    /**
+     * @return array
+     */
+    protected function formatOptions()
+    {
+        $this->options['language'] = config('app.locale');
+        $this->options['readonly'] = ! empty($this->attributes['readonly']) || ! empty($this->attributes['disabled']);
+
+        if (empty($this->options['images_upload_url'])) {
+            $this->options['images_upload_url'] = $this->defaultImageUploadUrl();
+        }
+
+        $this->options['image_dimensions'] = true;
+
+
+        return $this->options;
+    }
+
+    /**
+     * @return string
+     */
+    protected function defaultImageUploadUrl()
+    {
+        return $this->formatUrl(route(admin_api_route_name('tinymce.upload')));
+    }
+
+    /**
+     * @param  string  $url
+     * @return string
+     */
+    protected function formatUrl(string $url)
+    {
+        return Helper::urlWithQuery(
+            $url,
+            [
+                '_token' => csrf_token(),
+                'disk'   => $this->disk,
+                'dir'    => $this->imageUploadDirectory,
+            ]
+        );
+    }
+
+    /**
+     * @return string
+     */
+    public function render()
+    {
+        $this->addVariables([
+            'options' => $this->formatOptions(),
+        ]);
+
+        return parent::render();
+    }
+}

+ 2 - 1
composer.json

@@ -28,7 +28,8 @@
             "App\\": "app/",
             "Database\\Factories\\": "database/factories/",
             "Database\\Seeders\\": "database/seeders/",
-            "Dcat\\Admin\\Http\\Middleware\\": "app/repair/dcat-plus/laravel-admin/src/Http/Middleware/"
+            "Dcat\\Admin\\Http\\Middleware\\": "app/repair/dcat-plus/laravel-admin/src/Http/Middleware/",
+            "Dcat\\Admin\\Form\\Field\\": "app/repair/dcat-plus/laravel-admin/src/Form/Field/"
         }
     },
     "autoload-dev": {