m0_70156489 1 tuần trước cách đây
mục cha
commit
4b6f8ad662

+ 3 - 0
application/admin/controller/Procuremen.php

@@ -7187,6 +7187,9 @@ class Procuremen extends Backend
      */
     public function export_month_outward()
     {
+        if (!$this->hasProcuremenPerm(['export_month_outward', 'exportMonthOutward'])) {
+            $this->error(__('You have no permission'));
+        }
         $this->request->filter(['strip_tags', 'trim']);
         $ym = trim((string)$this->request->get('ym', date('Y-m')));
         if (!preg_match('/^\d{4}-\d{2}$/', $ym)) {

+ 53 - 2
application/admin/controller/Procuremenexport.php

@@ -19,12 +19,63 @@ class Procuremenexport extends Backend
     public function _initialize()
     {
         parent::_initialize();
+        $canExport = $this->hasProcuremenSiblingPerm(['export_month_outward', 'exportMonthOutward']);
+        $canDetails = $this->hasProcuremenSiblingPerm(['details']);
+        $this->view->assign('canExportMonthOutward', $canExport);
         $this->assignconfig('procuremenAuth', [
-            'details'             => $this->auth->check('procuremen/details'),
-            'export_month_outward' => $this->auth->check('procuremen/export_month_outward'),
+            'details'              => $canDetails,
+            'export_month_outward' => $canExport,
         ]);
     }
 
+    /**
+     * 月度导出页引用的采购子权限(规则名在 procuremen 控制器下)
+     *
+     * @param string[] $actions
+     */
+    protected function hasProcuremenSiblingPerm(array $actions): bool
+    {
+        foreach ($actions as $action) {
+            $action = strtolower(trim((string)$action));
+            if ($action === '') {
+                continue;
+            }
+            if (strpos($action, 'procuremen/') !== 0) {
+                $action = 'procuremen/' . $action;
+            }
+            if ($this->auth->check($action)) {
+                return true;
+            }
+        }
+        $suffixes = [];
+        foreach ($actions as $action) {
+            $action = strtolower(trim((string)$action));
+            $action = preg_replace('#^procuremen/#', '', $action);
+            if ($action !== '') {
+                $suffixes[$action] = true;
+            }
+        }
+        if ($suffixes === []) {
+            return false;
+        }
+        try {
+            foreach ($this->auth->getRuleList() as $rule) {
+                $rule = strtolower((string)$rule);
+                if (strpos($rule, 'procuremen/') !== 0) {
+                    continue;
+                }
+                foreach (array_keys($suffixes) as $suffix) {
+                    if ($rule === 'procuremen/' . $suffix || strpos($rule, 'procuremen/' . $suffix . '/') === 0) {
+                        return true;
+                    }
+                }
+            }
+        } catch (\Throwable $e) {
+        }
+
+        return false;
+    }
+
     public function index()
     {
         $this->relationSearch = false;

+ 31 - 0
application/admin/controller/Procuremenmenu.php

@@ -123,6 +123,37 @@ class Procuremenmenu extends Backend
                 ]);
                 $added++;
             }
+            if ($m['name'] === 'procuremenexport/index') {
+                $exportChildren = [
+                    ['name' => 'procuremen/export_month_outward', 'title' => '导出'],
+                    ['name' => 'procuremen/details', 'title' => '详情'],
+                ];
+                foreach ($exportChildren as $cr) {
+                    $exists = Db::name('auth_rule')->where('name', $cr['name'])->find();
+                    if ($exists) {
+                        Db::name('auth_rule')->where('name', $cr['name'])->update([
+                            'pid'        => $menuId,
+                            'title'      => $cr['title'],
+                            'status'     => 'normal',
+                            'ismenu'     => 0,
+                            'updatetime' => $t,
+                        ]);
+                        continue;
+                    }
+                    Db::name('auth_rule')->insert([
+                        'type'       => 'file',
+                        'pid'        => $menuId,
+                        'name'       => $cr['name'],
+                        'title'      => $cr['title'],
+                        'icon'       => 'fa fa-circle-o',
+                        'ismenu'     => 0,
+                        'status'     => 'normal',
+                        'createtime' => $t,
+                        'updatetime' => $t,
+                    ]);
+                    $added++;
+                }
+            }
         }
         \think\Cache::rm('__menu__');
         $this->success('菜单安装完成,新增节点 ' . $added . ' 个。请刷新后台并到「权限管理」为角色勾选新菜单。');

+ 1 - 5
application/admin/view/procuremenexport/index.html

@@ -5,7 +5,7 @@
         <div class="widget-body no-padding">
             <div id="toolbar" class="toolbar">
                 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}"><i class="fa fa-refresh"></i> 刷新</a>
-                {if $auth->check('procuremen/export_month_outward')}
+                {if $canExportMonthOutward}
                 <a href="javascript:;" class="btn btn-success" id="btn-export-month-outward" title="导出当前所选月份的协助明细 Excel"><i class="fa fa-download"></i> 导出 Excel</a>
                 {/if}
                 <span class="procuremen-export-ym-wrap" style="display:inline-block;margin-left:12px;vertical-align:middle;">
@@ -14,10 +14,6 @@
                 </span>
             </div>
             <table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%"></table>
-            <div class="procuremen-export-help" style="padding:8px 12px 10px;">
-                <p class="help-block" style="margin:0 0 8px;">显示所选月份内<strong>已完结</strong>的协助订单(月份按<strong>采购确认通过</strong>时间统计,同一订单号合并为一行)。</p>
-                <p class="help-block" style="margin:0;">点击「导出 Excel」下载该月协助明细(单个工作表):上方为<strong>中标汇总</strong>;下方为<strong>供应商报价明细</strong>,列出各订单下发供应商的单价、交货期及是否中标。</p>
-            </div>
         </div>
     </div>
 </div>

+ 4 - 0
public/assets/js/backend/procuremenexport.js

@@ -96,6 +96,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             });
 
             $(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
+                if (!exportCan('export_month_outward')) {
+                    Toastr.error('无导出权限');
+                    return;
+                }
                 var ym = ($('#export-preview-ym').val() || '').trim();
                 if (!/^\d{4}-\d{2}$/.test(ym)) {
                     Toastr.warning('请选择有效月份');