Sfoglia il codice sorgente

update:
商品管理页面,支持点击修改商品图片时,自动定位到图片窗口中的分类目录

joe 4 anni fa
parent
commit
71c583a191

+ 9 - 0
app/admin/controller/widget/Images.php

@@ -3,6 +3,7 @@
 namespace app\admin\controller\widget;
 
 use app\admin\controller\AuthController;
+use app\admin\controller\store\StoreProduct;
 use think\facade\Route as Url;
 use app\admin\model\system\{
     SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
@@ -27,8 +28,16 @@ class Images extends AuthController
         if ($pid === NULL) {
             $pid = session('pid') ? session('pid') : 0;
         }
+        $productId = request()->param('productId');
         session('pid', $pid);
         $this->assign('pid', $pid);
+        
+        if ($productId) {
+            $res = SystemAttachmentModel::getPidByProductId($productId);
+            $this->assign('pid', $res['pid']);
+            $this->assign('ppid', $res['ppid']);
+        }
+       
 ////       //TODO 分类标题
 //       $typearray = Category::getAll();
 //       $this->assign(compact('typearray'));

+ 28 - 0
app/admin/model/system/SystemAttachment.php

@@ -9,6 +9,7 @@ namespace app\admin\model\system;
 use crmeb\services\upload\Upload;
 use crmeb\traits\ModelTrait;
 use crmeb\basic\BaseModel;
+use app\models\store\StoreProduct as StoreProductModel;
 
 /**
  * 文件检验model
@@ -160,4 +161,31 @@ class SystemAttachment extends BaseModel
             return true;
         }
     }
+
+    /**
+    根据 商品 ID 找到商品图片,再根据任意一张图片找到商品图片的分类ID和父ID
+     select esa.pid as id, esac.pid from eb_system_attachment esa 
+left join eb_system_attachment_category esac 
+on esa.pid = esac.id 
+where esa.att_dir = 'http://twongpicd.shotshock.shop/606882670534/澳乐月亮围栏6+2_1.jpg'
+    
+        @return: ['pid'=>int, 'ppid'=>int]
+     */
+    public static function getPidByProductId($productId) 
+    {
+        $model = new self;
+        $res = StoreProductModel::where('id', $productId)->field('image,slider_image')->select()->toArray();
+        if ($res) {
+            $image=$res[0]['image'];
+            if(!$image){
+                $arr = $res[0]['slider_image'];
+                if($arr) {
+                    $image = $arr[0];
+                }
+            }
+        }
+        $ids = $model::alias('a')->field('a.pid, c.pid as ppid')->join('SystemAttachmentCategory c', 'c.id=a.pid')
+            ->where('a.att_dir', $image)->find();
+        return $ids ? $ids->toArray() : ['pid'=>0, 'ppid'=>0];
+    }
 }

+ 1 - 1
app/admin/view/store/store_product/create.php

@@ -1291,7 +1291,7 @@
                 return this.rule[name] || {};
             },
             uploadImage: function (name) {
-                return this.createFrame('选择图片',this.U({c:"widget.images",a:'index',p:{fodder:name}}),{h:545,w:900});
+                return this.createFrame('选择图片',this.U({c:"widget.images",a:'index',p:{fodder:name,productId:this.id}}),{h:545,w:900});
             },
             uploadVideo: function () {
                 if (this.videoLink) {

+ 12 - 1
app/admin/view/widget/images.php

@@ -158,7 +158,7 @@
 <script src="{__ADMIN_PATH}js/layuiList.js?id=dsfwef"></script>
 <script>
     var pid = {$pid},small = {$Request.param.small ? : 0} ,parentinputname = '{$Request.param.fodder}';//当前图片分类ID
-
+    var ppid = {$ppid};
     new Vue({
         el: "#app",
         data: {
@@ -355,6 +355,17 @@
                 var that=this;
                 layList.baseGet(that.U({a:'get_image_cate',q:{name:this.searchTitle}}),function (res) {
                     that.$set(that,'categoryList',res.data);
+                    for(var i=0; i<that.categoryList.length; i++) {
+                        if(that.categoryList[i].id == this.pid || that.categoryList[i].id == ppid) {
+                            that.OpenTree(that.categoryList[i], i);
+                        }
+                        for(var j=0; j<that.categoryList[i].child.length; j++) {
+                            if(that.categoryList[i].child[j].id == this.pid) {
+                                that.OpenTree(that.categoryList[i].child[j], j);
+                                break;
+                            }
+                        }
+                    }
                 });
             },
             //鼠标移入显示图标