From f9222e1b7fa81a881809005e7c4d6808fde417d4 Mon Sep 17 00:00:00 2001
From: 15090180611 <215509543@qq.com>
Date: Tue, 31 Dec 2024 14:10:47 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../admin/controller/manystore/Index.php      |  2 +-
 .../admin/controller/school/help/Article.php  | 42 +++++++++
 .../admin/controller/school/help/Cate.php     | 13 ++-
 .../admin/lang/zh-cn/school/help/article.php  |  2 +-
 .../admin/lang/zh-cn/school/help/cate.php     | 16 +++-
 .../admin/model/school/help/Article.php       | 19 ++++-
 .../admin/view/school/help/article/add.html   | 14 +--
 .../admin/view/school/help/article/edit.html  | 14 +--
 .../admin/view/school/help/cate/index.html    |  4 +-
 application/common/controller/Backend.php     |  5 +-
 .../common/listener/manystore/ShopHook.php    |  5 +-
 public/assets/js/backend/school/help/cate.js  | 85 ++++++++++++++-----
 12 files changed, 175 insertions(+), 46 deletions(-)

diff --git a/application/admin/controller/manystore/Index.php b/application/admin/controller/manystore/Index.php
index ef5af57..2af08ea 100644
--- a/application/admin/controller/manystore/Index.php
+++ b/application/admin/controller/manystore/Index.php
@@ -483,7 +483,7 @@ class Index extends Backend
 
 
                            //调用事件
-                    $data = ['shop' => $shop];
+                    $data = ['shop' => $this->shopModel];
                   \think\Hook::listen('shop_create_after', $data);
 
                     db()->commit();
diff --git a/application/admin/controller/school/help/Article.php b/application/admin/controller/school/help/Article.php
index 89b2f05..0504a80 100644
--- a/application/admin/controller/school/help/Article.php
+++ b/application/admin/controller/school/help/Article.php
@@ -3,6 +3,8 @@
 namespace app\admin\controller\school\help;
 
 use app\common\controller\Backend;
+use think\exception\DbException;
+use think\response\Json;
 
 /**
  * 帮助文章
@@ -28,6 +30,9 @@ class Article extends Backend
 
         $this->view->assign("statusList", $this->model->getStatusList());
         $this->view->assign("hotList", $this->model->getHotList());
+
+        $this->view->assign("cateList", $this->model->getCateList());
+        $this->view->assign("cateListJson", json_encode($this->model->getCateList(), JSON_UNESCAPED_UNICODE));
     }
 
 
@@ -39,4 +44,41 @@ class Article extends Backend
      */
 
 
+
+    /**
+     * 查看
+     *
+     * @return string|Json
+     * @throws \think\Exception
+     * @throws DbException
+     */
+    public function index()
+    {
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if (false === $this->request->isAjax()) {
+            return $this->view->fetch();
+        }
+        //如果发送的来源是 Selectpage,则转发到 Selectpage
+        if ($this->request->request('keyField')) {
+            return $this->selectpage();
+        }
+        list($where, $sort, $order, $offset, $limit, $page, $alias, $bind, $excludearray) = $this->buildparams(null, null, ["cate_title"]);
+
+        if (isset($excludearray['cate_title']['value']) && $excludearray['cate_title']['value']) {
+            $help_cate_ids = $excludearray['cate_title']['value'];
+            $help_cate_ids =  implode("|",explode(',',$help_cate_ids));
+            $expireWhere = ["help_cate_ids REGEXP '({$help_cate_ids})'"];
+        } else {
+            $expireWhere = ["1=1"];
+        }
+        $list = $this->model
+            ->where($where)
+            ->whereRaw(...$expireWhere)
+            ->order($sort, $order)
+            ->paginate($limit);
+        $result = ['total' => $list->total(), 'rows' => $list->items()];
+        return json($result);
+    }
+
 }
diff --git a/application/admin/controller/school/help/Cate.php b/application/admin/controller/school/help/Cate.php
index d4fc7c6..b9e7583 100644
--- a/application/admin/controller/school/help/Cate.php
+++ b/application/admin/controller/school/help/Cate.php
@@ -33,15 +33,20 @@ class Cate extends Backend
 
         $this->view->assign("statusList", $this->model->getStatusList());
 
-        Tree::instance()->init(collection($this->model->order('weigh DESC,id ASC')->select())->toArray())->icon = ['&nbsp;&nbsp;&nbsp;&nbsp;', '&nbsp;&nbsp;&nbsp;&nbsp;', '&nbsp;&nbsp;&nbsp;&nbsp;'];
+        Tree::instance()->init(collection($this->model->order('weigh DESC,id ASC')->select())->toArray())->icon = array('&nbsp;&nbsp;&nbsp;&nbsp;│', '&nbsp;&nbsp;&nbsp;&nbsp;├', '&nbsp;&nbsp;&nbsp;&nbsp;└');
         $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
         $ruledata = [0 => __('None')];
         foreach ($this->rulelist as $k => &$v) {
+//            $v['name'] = str_replace('&nbsp;', ' ', $v['name']);
             $ruledata[$v['id']] = $v['name'];
+
         }
         unset($v);
         $this->view->assign('ruledata', $ruledata);
 
+        $this->view->assign("cateList", (new \app\admin\model\school\help\Article)->getCateList());
+        $this->view->assign("cateListJson", json_encode((new \app\admin\model\school\help\Article)->getCateList(), JSON_UNESCAPED_UNICODE));
+
     }
 
 
@@ -60,6 +65,12 @@ class Cate extends Backend
     public function index()
     {
         if ($this->request->isAjax()) {
+            //如果发送的来源是 Selectpage,则转发到 Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+
+
             $list = $this->rulelist;
             $total = count($this->rulelist);
             $result = array("total" => $total, "rows" => $list);
diff --git a/application/admin/lang/zh-cn/school/help/article.php b/application/admin/lang/zh-cn/school/help/article.php
index ac6957e..f472a1a 100644
--- a/application/admin/lang/zh-cn/school/help/article.php
+++ b/application/admin/lang/zh-cn/school/help/article.php
@@ -1,7 +1,7 @@
 <?php
 
 return [
-    'Help_cate_ids' => '平台帮助分类ids',
+    'Help_cate_ids' => '平台帮助分类',
     'Title'         => '标题',
     'Content'       => '文章详情',
     'Status'        => '状态',
diff --git a/application/admin/lang/zh-cn/school/help/cate.php b/application/admin/lang/zh-cn/school/help/cate.php
index d7c75b1..bf35fd9 100644
--- a/application/admin/lang/zh-cn/school/help/cate.php
+++ b/application/admin/lang/zh-cn/school/help/cate.php
@@ -1,7 +1,7 @@
 <?php
 
 return [
-    'Pid'        => 'pid',
+    'Pid'        => '上级分类',
     'Name'       => '帮助分类名',
     'Status'     => '状态',
     'Status 1'   => '上架',
@@ -11,5 +11,17 @@ return [
     'Weigh'      => '权重',
     'Createtime' => '创建时间',
     'Updatetime' => '修改时间',
-    'Deletetime' => '删除时间'
+    'Deletetime' => '删除时间',
+
+        'Help_cate_ids' => '平台帮助分类',
+    'Title'         => '标题',
+    'Content'       => '文章详情',
+
+    'Hot'           => '平台热门',
+    'Hot 0'         => '否',
+    'Hot 1'         => '是',
+    'Start_time'    => '更新时间',
+    'Toggle all'    => '展开',
+    'Views'         => '浏览量',
+
 ];
diff --git a/application/admin/model/school/help/Article.php b/application/admin/model/school/help/Article.php
index bfd5dd9..477a214 100644
--- a/application/admin/model/school/help/Article.php
+++ b/application/admin/model/school/help/Article.php
@@ -27,9 +27,20 @@ class Article extends Model
     protected $append = [
         'status_text',
         'hot_text',
-        'start_time_text'
+        'start_time_text',
+        'cate_title',
     ];
-    
+
+    public function getCateTitleAttr($value, $data)
+    {
+        $classes_cate_ids =  (isset($data['help_cate_ids']) ? $data['help_cate_ids'] : '');
+        if(!$classes_cate_ids) return '';
+        //$classes_cate_ids 查询分类表 names 已逗号拼接返回
+        $classes_cate_title = Cate::where('id','in',$classes_cate_ids)->column('name');
+        return implode(',',$classes_cate_title);
+    }
+
+
 
     protected static function init()
     {
@@ -80,5 +91,9 @@ class Article extends Model
         return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
     }
 
+    public function getCateList(){
+        return Cate::column("name", 'id');
+    }
+
 
 }
diff --git a/application/admin/view/school/help/article/add.html b/application/admin/view/school/help/article/add.html
index c38c373..a452e73 100644
--- a/application/admin/view/school/help/article/add.html
+++ b/application/admin/view/school/help/article/add.html
@@ -3,7 +3,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Help_cate_ids')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-help_cate_ids" data-rule="required" data-source="school/help/cate/index"  data-max-select-limit="3" data-multiple="true"  data-params='{"custom[status]":"1"}' class="form-control selectpage" name="row[help_cate_ids]" type="text" value="{$q_help_cate_ids}">
+            <input id="c-help_cate_ids" data-rule="required" data-source="school/help/cate/index"  data-max-select-limit="3" data-multiple="true"  data-params='{"custom[status]":"1","isTree":1}' class="form-control selectpage" name="row[help_cate_ids]" type="text" value="{$q_help_cate_ids}">
         </div>
     </div>
     <div class="form-group">
@@ -54,12 +54,12 @@
             <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="0">
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Views')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-views" class="form-control" name="row[views]" type="number" value="0">
-        </div>
-    </div>
+<!--    <div class="form-group">-->
+<!--        <label class="control-label col-xs-12 col-sm-2">{:__('Views')}:</label>-->
+<!--        <div class="col-xs-12 col-sm-8">-->
+<!--            <input id="c-views" class="form-control" name="row[views]" type="number" value="0">-->
+<!--        </div>-->
+<!--    </div>-->
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
diff --git a/application/admin/view/school/help/article/edit.html b/application/admin/view/school/help/article/edit.html
index 059684c..da01661 100644
--- a/application/admin/view/school/help/article/edit.html
+++ b/application/admin/view/school/help/article/edit.html
@@ -3,7 +3,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Help_cate_ids')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-help_cate_ids" data-rule="required" data-source="school/help/cate/index" data-max-select-limit="3" data-multiple="true"  data-params='{"custom[status]":"1"}'  class="form-control selectpage" name="row[help_cate_ids]" type="text" value="{$row.help_cate_ids|htmlentities}">
+            <input id="c-help_cate_ids" data-rule="required" data-source="school/help/cate/index" data-max-select-limit="3" data-multiple="true"  data-params='{"custom[status]":"1","isTree":1}'  class="form-control selectpage" name="row[help_cate_ids]" type="text" value="{$row.help_cate_ids|htmlentities}">
         </div>
     </div>
     <div class="form-group">
@@ -54,12 +54,12 @@
             <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Views')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-views" class="form-control" name="row[views]" type="number" value="{$row.views|htmlentities}">
-        </div>
-    </div>
+<!--    <div class="form-group">-->
+<!--        <label class="control-label col-xs-12 col-sm-2">{:__('Views')}:</label>-->
+<!--        <div class="col-xs-12 col-sm-8">-->
+<!--            <input id="c-views" class="form-control" name="row[views]" type="number" value="{$row.views|htmlentities}">-->
+<!--        </div>-->
+<!--    </div>-->
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
diff --git a/application/admin/view/school/help/cate/index.html b/application/admin/view/school/help/cate/index.html
index 09e2a49..3e28ae5 100644
--- a/application/admin/view/school/help/cate/index.html
+++ b/application/admin/view/school/help/cate/index.html
@@ -92,4 +92,6 @@
 
     </div>
 </div>
-
+<script>
+    var cateListJson ={$cateListJson};
+</script>
diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php
index dcf9093..e66e7f7 100644
--- a/application/common/controller/Backend.php
+++ b/application/common/controller/Backend.php
@@ -764,11 +764,12 @@ class Backend extends Controller
             }
             if ($istree && !$primaryvalue) {
                 $tree = Tree::instance();
-                $tree->init(collection($list)->toArray(), 'pid');
+                $tree->init(collection($list)->toArray(), 'pid')->icon = array('&nbsp;&nbsp;&nbsp;&nbsp;│', '&nbsp;&nbsp;&nbsp;&nbsp;├', '&nbsp;&nbsp;&nbsp;&nbsp;└');
+
                 $list = $tree->getTreeList($tree->getTreeArray(0), $field);
                 if (!$ishtml) {
                     foreach ($list as &$item) {
-                        $item = str_replace('&nbsp;', ' ', $item);
+//                        $item = str_replace('&nbsp;', ' ', $item);
                     }
                     unset($item);
                 }
diff --git a/application/common/listener/manystore/ShopHook.php b/application/common/listener/manystore/ShopHook.php
index 2094a94..a093a71 100644
--- a/application/common/listener/manystore/ShopHook.php
+++ b/application/common/listener/manystore/ShopHook.php
@@ -15,7 +15,8 @@ class ShopHook
         ["shop"=>$shop] = $params;
 
 
-
+        //机构初始化数据
+        ManystoreShop::initData($shop->id);
 
 
     }
@@ -76,8 +77,6 @@ class ShopHook
         ManystoreShop::initData($shop->id);
 
 
-
-
     }
 
 
diff --git a/public/assets/js/backend/school/help/cate.js b/public/assets/js/backend/school/help/cate.js
index ac7035e..1bed1c7 100644
--- a/public/assets/js/backend/school/help/cate.js
+++ b/public/assets/js/backend/school/help/cate.js
@@ -43,18 +43,38 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
 // 过滤偶数,然后将其乘以10,最后求和
                             let sumOfDoubledEvens = numbers.map(item => item.id).join(","); // 求和
 
-                            $("#myTabContent2 .form-commonsearch input[name='help_cate_ids']").val(sumOfDoubledEvens);
+                            $("#myTabContent2 .form-commonsearch input[name='cate_title']").val(sumOfDoubledEvens);
                             $("#myTabContent2 .btn-refresh").trigger("click");
 
 
                         });
+
+
+                        $("#table1").on("change", "input:checkbox[name='btSelectAll']", function (e) {
+                            // var ids = $(this).data("index");       //数据id
+                            // var checked = $(this).prop('checked'); //选中状态
+                            // Layer.alert(JSON.stringify(Table.api.selecteddata(table)));
+
+
+                            let numbers = Table.api.selecteddata(table);
+
+// 过滤偶数,然后将其乘以10,最后求和
+                            let sumOfDoubledEvens = numbers.map(item => item.id).join(","); // 求和
+
+                            $("#myTabContent2 .form-commonsearch input[name='cate_title']").val(sumOfDoubledEvens);
+                            $("#myTabContent2 .btn-refresh").trigger("click");
+
+
+                        });
+
+
                     },
                     columns: [
                         [
                             {checkbox: true},
                             {field: 'id', title: __('Id')},
                             {field: 'pid', title: __('Pid'),visible:false},
-                            {field: 'name', title: __('Name') , align: 'left', formatter: Controller.api.formatter.name, clickToSelect: !false},
+                            {field: 'name', title: __('Name') ,width:180, align: 'left',  formatter: Controller.api.formatter.name, clickToSelect: !false},
                             {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.toggle},
                             {field: 'weigh', title: __('Weigh'), operate: false},
                             {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
@@ -83,17 +103,32 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
                                         //     return row.status == '2'||row.status == '3';
                                         // }
                                     },
+                                    // {
+                                    //     name: 'article',
+                                    //     title: '文章列表',
+                                    //     text: '文章列表',
+                                    //     icon: 'fa fa-list',
+                                    //     classname: 'btn btn-primary btn-xs btn-click',
+                                    //     click: function (e, data) {
+                                    //         $("#myTabContent2 .form-commonsearch input[name='help_cate_ids']").val(data.id);
+                                    //         $("#myTabContent2 .btn-refresh").trigger("click");
+                                    //     }
+                                    // },
                                     {
                                         name: 'article',
-                                        title: '文章列表',
-                                        text: '文章列表',
-                                        icon: 'fa fa-list',
-                                        classname: 'btn btn-primary btn-xs btn-click',
-                                        click: function (e, data) {
-                                            $("#myTabContent2 .form-commonsearch input[name='help_cate_ids']").val(data.id);
-                                            $("#myTabContent2 .btn-refresh").trigger("click");
-                                        }
-                                    }
+                                        text: __('添加文章'),
+                                        title: __('添加文章'),
+                                        classname: 'btn btn-danger btn-xs btn-dialog',
+                                        icon: 'fa fa-files-o',
+                                        // dropdown : '更多',
+                                        url: article_url,
+                                        callback: function (data) {
+
+                                        },
+                                        // visible: function (row) {
+                                        //     return row.status == '2'||row.status == '3';
+                                        // }
+                                    },
                                 ], events: Table.api.events.operate, formatter: Table.api.formatter.operate},
 
 
@@ -200,10 +235,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
                 });
 
 
-                // 获取选中项
-                $(document).on("click", "#table1 .btn-selected", function () {
-                    Layer.alert(JSON.stringify(Table.api.selecteddata(table)));
-                });
+                // // 获取选中项
+                // $(document).on("click", "#table1 .btn-selected", function () {
+                //     Layer.alert(JSON.stringify(Table.api.selecteddata(table)));
+                // });
 
             },
             second: function () {
@@ -230,8 +265,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
                         [
                             {checkbox: true},
                             {field: 'id', title: __('Id')},
-                            {field: 'help_cate_ids', title: __('Help_cate_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
-                            {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
+                            // {field: 'help_cate_ids', title: __('Help_cate_ids'),  operate: 'LIKE', table: table, class: 'autocontent', searchList: cateListJson, formatter: Table.api.formatter.flag},
+
+                            {field: 'cate_title', title: __('Help_cate_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
+                            {field: 'title', title: __('Title'), operate: '=', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                             {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                             {field: 'hot', title: __('Hot'), searchList: {"0":__('Hot 0'),"1":__('Hot 1')}, formatter: Table.api.formatter.normal},
                             {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
@@ -317,9 +354,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
         api: {
             formatter: {
                 name: function (value, row, index) {
-                    value = value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
+                    // value = value.toString().replace(/(&|&amp;)nbsp;/g, '  ');
+                    value = htmlDecode(value);
                     var caret = row.haschild == 1 || row.ismenu == 1 ? '<i class="fa fa-caret-right"></i>' : '';
-                    value = value.indexOf("&nbsp;") > -1 ? value.replace(/(.*)&nbsp;/, "$1" + caret) : caret + value;
+                    value =  caret + value;
 
                     value = !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value;
                     return '<a href="javascript:;" data-id="' + row.id + '" data-pid="' + row.pid + '" class="'
@@ -336,10 +374,19 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
         }
     };
 
+    function htmlDecode(input) {
+        var doc = new DOMParser().parseFromString(input, 'text/html');
+        return doc.documentElement.textContent;
+    }
 
     var add_url = function (row,dom) {
         return 'school/help/cate/add?pid='+row.id;
     }
 
+    var article_url = function (row,dom) {
+        console.log(row);
+        return 'school/help/article/add?help_cate_ids='+row.id;
+    }
+
     return Controller;
 });