caviar 3 lat temu
rodzic
commit
086c0b6640

+ 4 - 4
.env

@@ -5,10 +5,10 @@ DEFAULT_TIMEZONE = Asia/Shanghai
 
 [DATABASE]
 TYPE = mysql
-HOSTNAME = 49.4.53.36
-DATABASE = erp_yzx
-USERNAME = root
-PASSWORD = Aa@@1144271187
+HOSTNAME = 8.219.191.124
+DATABASE = yuanzhongxiu
+USERNAME = yuanzhongxiu
+PASSWORD = WPDrmPREz36y6mMb
 HOSTPORT = 3306
 CHARSET = utf8
 DEBUG = true

+ 7 - 9
app/admin/controller/Admin.php

@@ -92,12 +92,11 @@ class Admin extends BaseController
             'stores'    =>  $this->storeModel->findAllStore()->toArray(),
             'all_department' => $all_department,
             'all_group' => recursion($all_groups, 0),
-            'now_group' => $all_department[0] && $all_department[0]['auth_group_ids'] != null ?$this->authGroupModel->findByIds(explode(',', $all_department[0]['auth_group_ids'])) : []
+            'now_group' => $this->authGroupModel->fetchByDepartmentId($all_department[0] ? $all_department[0]['id'] : -1 ),
         ]);
         return view();
     }
 
-
     /**
      * @return \think\response\Json|\think\response\View
      * @throws \think\db\exception\DataNotFoundException
@@ -137,22 +136,21 @@ class Admin extends BaseController
         $all_department = recursion($this->departmentModel->findAllDepartment()->toArray(),0);
         $stores = $this->storeModel->findAllStore();
         foreach ($stores as $store) $store->isChecked = in_array($store->id, explode(',', $admin->store_ids ?? ''));
-        $group_ids = $admin->department->auth_group_ids;
         View::assign([
             'stores'    =>  $stores,
             'all_department' => $all_department,
             'admin' => $admin,
-            'now_group' => $group_ids != null ? $this->authGroupModel->findByIds(explode(',', $group_ids)) : []
+            'now_group' => $this->authGroupModel->fetchByDepartmentId($admin->department_id ?? -1),
         ]);
         return view();
     }
 
 
-    public function getBindRules($department_id) {
-        $department = $this->departmentModel->findById($department_id);
-        if (!$department || $department->auth_group_ids == null)
-            return $this->ok([]);
-        return $this->ok($this->authGroupModel->findByIds(explode(',',$department->auth_group_ids)));
+    public function getBindRules($department_id = null) {
+        return $this->ok(
+                    $this->authGroupModel
+                        ->fetchByDepartmentId($department_id > 0 ? $department_id : -1 )
+        );
     }
 
     public function delete(\think\Request $request) {

+ 19 - 10
app/admin/controller/AuthGroup.php

@@ -6,7 +6,7 @@ namespace app\admin\controller;
 
 use app\admin\service\AuthService;
 use app\BaseController;
-use app\common\model\StoreModel;
+use app\common\model\DepartmentModel;
 use think\App;
 use think\facade\View;
 
@@ -14,7 +14,7 @@ use think\facade\View;
 class AuthGroup extends BaseController
 {
     private $authService;
-    private $storeModel;
+    private $departmentModel;
 
     public $reception_rules = [
         ["id" => 10001, "zh" => "客户资料", "en" => "Customer information", "icon" => ""],
@@ -33,7 +33,7 @@ class AuthGroup extends BaseController
     {
         parent::__construct($app);
         $this->authService = new AuthService();
-        $this->storeModel = new StoreModel();
+        $this->departmentModel = new DepartmentModel();
     }
 
     public function index() {
@@ -47,7 +47,7 @@ class AuthGroup extends BaseController
      * @throws \think\db\exception\ModelNotFoundException
      */
     public function add() {
-        $all_groups = $this->authService->authGroupModel->fetchAllGroups();
+        $all_department = $this->departmentModel->findAllDepartment();
 
         if ($this->request->isAjax()) {
             $params = $this->request->param();
@@ -56,13 +56,15 @@ class AuthGroup extends BaseController
                 'name' => format_string($params['name'] ?? null),
                 'rules' => format_string($params['rule_ids'] ?? null),
                 "reception_rules" =>  isset($params["reception_rules"]) ? join(',', $params['reception_rules']) : null,
+                "data_rules" =>  isset($params["data_rules"]) ? join(',', $params['data_rules']) : null,
+                "department_id" => format_string($params['department_id'] ?? null),
                 'describe' => format_string($params['describe'] ?? null),
             ]);
             return $this->ok($res);
         }
         View::assign([
             "reception_rules"    =>  $this->reception_rules,
-            "all_groups"    =>  recursion($all_groups, 0)
+            "all_department"    =>  recursion($all_department, 0)
         ]);
         return view();
     }
@@ -76,25 +78,32 @@ class AuthGroup extends BaseController
     public function edit() {
         $params = $this->request->param();
         $id = $params['id'];
-        $all_groups = $this->authService->authGroupModel->fetchAllGroups();
         $group = $this->authService->authGroupModel->findById($id);
+        $all_department = $this->departmentModel->findAllDepartment();
         if ($this->request->isAjax()) {
             $res = $this->authService->authGroupModel->where('id', $params['id'])->save([
                 'pid' => 0,
                 'name' => $params['name'] ?? $group->name,
                 'rules' => !isset($params['rule_ids']) ? null : $params['rule_ids'],
                 "reception_rules" =>  isset($params["reception_rules"]) ? join(',', $params['reception_rules']) : null,
+                "data_rules" =>  isset($params["data_rules"]) ? join(',', $params['data_rules']) : null,
+                "department_id" => format_string($params['department_id'] ?? null),
                 'describe' => $params['describe'] ?? $group->describe,
                 'update_time' => time()
             ]);
             return $this->ok($res);
         }
-        $reception_rules = $group->reception_rules ? explode(',',$group->reception_rules) : [];
-        foreach ($this->reception_rules as &$item) $item['isChecked'] = in_array($item['id'], $reception_rules);
+        $reception_rule_ids = $group->reception_rules ? explode(',',$group->reception_rules) : [];
+        $reception_rules = array_merge([],$this->reception_rules);
+        foreach ($reception_rules as &$item) $item['isChecked'] = in_array($item['id'], $reception_rule_ids);
+        $data_rule_ids = $group->data_rules ? explode(',', $group->data_rules) : [];
+        $data_rules = array_merge([], $this->reception_rules);
+        foreach ($data_rules as &$item) $item['isChecked'] = in_array($item['id'], $data_rule_ids);
         View::assign([
             'group' => $group,
-            "all_groups" => recursion($all_groups, 0),
-            "reception_rules"    =>  $this->reception_rules,
+            "reception_rules"    =>  $reception_rules,
+            "data_rules"    =>  $data_rules,
+            "all_department"    =>  recursion($all_department, 0)
         ]);
         return view();
     }

+ 9 - 9
app/admin/controller/Department.php

@@ -32,7 +32,7 @@ class Department extends BaseController
      */
     public function add() {
         $all_department = $this->departmentModel->fetchAllDepartment();
-        $all_group = $this->authGroupModel->fetchAllGroups();
+//        $all_group = $this->authGroupModel->fetchAllGroups();
         if ($this->request->isAjax()) {
             $params = $this->request->param();
             $db_department = $this->departmentModel->findByName(format_string($params['name'] ?? null));
@@ -43,16 +43,16 @@ class Department extends BaseController
                 'name' => format_string($params['name'] ?? null),
                 'describe' => format_string($params['describe'] ?? null),
             ];
-            if($params['pid'] == 0) {
-                $auth_group_ids = array_merge($params['auth_group_ids'] ?? []);
-                $department['auth_group_ids'] = count($auth_group_ids) > 0 ? join(',', $auth_group_ids) : null;
-            }
+//            if($params['pid'] == 0) {
+//                $auth_group_ids = array_merge($params['auth_group_ids'] ?? []);
+//                $department['auth_group_ids'] = count($auth_group_ids) > 0 ? join(',', $auth_group_ids) : null;
+//            }
             $res = $this->departmentModel->save($department);
             return $this->ok($res);
         }
         View::assign([
             "all_department"    =>  recursion($all_department, 0),
-            "all_group" =>  $all_group
+//            "all_group" =>  $all_group
         ]);
         return view();
     }
@@ -76,7 +76,7 @@ class Department extends BaseController
             $res = $this->departmentModel->where('id', $params['id'])->save([
                 'pid' => $params['pid'] ?? $department->pid,
                 'name' => $params['name'] ?? $department->name,
-                "auth_group_ids" =>  isset($params["auth_group_ids"]) ? join(',', array_merge($params['auth_group_ids'])) : null,
+//                "auth_group_ids" =>  isset($params["auth_group_ids"]) ? join(',', array_merge($params['auth_group_ids'])) : null,
                 'describe' => $params['describe'] ?? $department->describe,
                 'update_time' => time()
             ]);
@@ -87,7 +87,7 @@ class Department extends BaseController
         View::assign([
             'department' => $department,
             "all_department"    =>  recursion($all_department, 0),
-            "all_group" =>  $all_group
+//            "all_group" =>  $all_group
         ]);
         return view();
     }
@@ -114,7 +114,7 @@ class Department extends BaseController
                 'field'     =>  $data['name'],
                 'spread'    =>  true,
                 'checked'   =>  false,
-                'disabled'  =>  $data['id'] == 1
+                'disabled'  =>  $data['id'] == 5
             ];
         }, $groups);
         return $this->ok(recursion($format_groups));

+ 19 - 3
app/admin/controller/Store.php

@@ -5,6 +5,7 @@ namespace app\admin\controller;
 
 
 use app\BaseController;
+use app\common\model\DepartmentModel;
 use app\common\model\StoreModel;
 use think\App;
 use think\facade\View;
@@ -14,10 +15,12 @@ class Store extends BaseController
 {
 
     private $storeModel;
+    private $departmentModel;
 
     public function __construct(App $app)
     {
         $this->storeModel = new StoreModel();
+        $this->departmentModel = new DepartmentModel();
         parent::__construct($app);
     }
 
@@ -37,12 +40,20 @@ class Store extends BaseController
             $store = $this->storeModel->doesItExist($abbr);
             if ($store)
                 return $this->fail(lang('Fail to add. Data duplication'));
-            $res = $this->storeModel->save([
+            $last_id = $this->storeModel->insert([
                 'name'  =>  $name,
                 'abbr'  =>  $abbr,
-                'address'   =>  $address
+                'address'   =>  $address,
+                'update_time' => time(),
+                'create_time' => time()
+            ],true);
+            $this->departmentModel->save([
+                'name' => $name,
+                'store_id' => $last_id,
+                'pid' => 5,
+                'describe' => $name
             ]);
-            return $this->ok($res);
+            return $this->ok($last_id);
         }
         return view();
     }
@@ -64,6 +75,10 @@ class Store extends BaseController
                 'address'   =>  $params['address'],
                 'update_time'   =>  time()
             ]);
+            $this->departmentModel->where('store_id', $store->id)->update([
+                'name' => $params['name'],
+                'describe' => $params['name']
+            ]);
             return $this->ok($res);
         }
         View::assign('store', $store);
@@ -75,6 +90,7 @@ class Store extends BaseController
         if(!isset($params['ids']))
             return $this->fail(lang("Please select the data you want to delete"));
         $this->storeModel->deleteByIds(explode(',', $params['ids']));
+        $this->departmentModel->where('store_id', 'in', $params['ids'])->delete();
         return $this->ok(true);
     }
 

+ 2 - 0
app/admin/lang/zh-cn.php

@@ -155,6 +155,8 @@ return [
     "Enter the product name or number and press Enter to select the product" => "输入商品名称或者编号后按回车选择商品",
     "Reception rules"   =>  "前台权限",
     "Backstage permission"  =>  "后台权限",
+    "Relevance department"  => "关联部门",
+    "Data rules"    =>  "数据权限"
 ];
 
 

+ 2 - 1
app/admin/view/admin/add.html

@@ -65,6 +65,7 @@
                           </select>
                         </div>
                     </div>
+
                     <div class="layui-form-item" id="store" {if $stores.0.id == 5} hidden {/if}>
                         <label class="layui-form-label">{:lang("Store")}</label>
                         <div class="layui-input-block">
@@ -105,7 +106,7 @@
 </div>
 <script>
 
-  layui.use(['laydate','form','upload'], () => {
+  layui.use(['form'], () => {
     const form = layui.form;
       form.on('select(department)', function (data) {
           let id = data.value;

+ 24 - 2
app/admin/view/admin/edit.html

@@ -55,7 +55,7 @@
                                     <div class="layui-form-item">
                                         <label class="layui-form-label">{:lang('Department')}</label>
                                         <div class="layui-input-block">
-                                            <select name="group_id" lay-filter="required">
+                                            <select name="department_id" lay-filter="department">
                                                 {volist name="all_department" id="item"}
                                                 <option value="{$item.id}"  {if $admin.department_id == $item.id} selected {/if} >{$item.name}</option>
                                                 {volist name='$item.children' id='first'}
@@ -113,8 +113,30 @@
     </div>
 </div>
 <script>
-    layui.use(['laydate','form','upload'], () => {
+    layui.use(['form'], () => {
         const form = layui.form;
+        form.on('select(department)', function (data) {
+            let id = data.value;
+            request("{:url('admin/admin/getBindRules')}", {department_id: id}).then(res => {
+                console.log(res)
+                if(res.code  == 200) {
+                    let options = "";
+                    let templates = res.data;
+                    for (let template of templates) {
+                        console.log(template)
+                        options += `<option value="${template.id}">${template.name}</option>`;
+                    }
+                    $("#rule").html(options);
+                    form.render('select');
+                }
+            });
+            if(data.value == 5) {
+                $('#store').css('display','block');
+            } else {
+                $('#store').css('display','none');
+            }
+
+        });
 
         form.on('submit(caviar_submit_btn)', (data) => {
             const response = request('{:url("admin/admin/edit")}', data.field)

+ 19 - 23
app/admin/view/auth_group/add.html

@@ -31,29 +31,25 @@
                                             {/volist}
                                         </div>
                                     </div>
-<!--                                    <div class="layui-form-item">-->
-<!--                                        <label class="layui-form-label">上级角色</label>-->
-<!--                                        <div class="layui-input-block">-->
-<!--                                            <select name="pid" lay-filter="required">-->
-<!--                                                <option value="0" selected>{:lang("Unknown")}</option>-->
-<!--                                                {volist name="all_groups" id="item"}-->
-<!--                                                <option value="{$item.id}"  >{$item.name}</option>-->
-<!--                                                {volist name='$item.children' id='first'}-->
-<!--                                                <option value="{$first.id}">&nbsp;&nbsp;| &#45;&#45;&nbsp;{$first.name}</option>-->
-<!--                                                {volist name='$first.children' id='second'}-->
-<!--                                                <option value="{$second.id}">&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;{$second.name}</option>-->
-<!--                                                {volist name='$second.children' id='thirdly'}-->
-<!--                                                <option value="{$thirdly.id}">&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;{$thirdly.name}</option>-->
-<!--                                                {volist name='$thirdly.children' id='fourthly'}-->
-<!--                                                <option value="{$fourthly.id}">&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;{$fourthly.name}</option>-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                            </select>-->
-<!--                                        </div>-->
-<!--                                    </div>-->
+                                    <div class="layui-form-item">
+                                        <label class="layui-form-label">{:lang("Data rules")}</label>
+                                        <div class="layui-input-block">
+                                            {volist name="reception_rules" id="item"}
+                                            <input type="checkbox" name="data_rules[]" value="{$item.id}" title={$item.zh}>
+                                            {/volist}
+                                        </div>
+                                    </div>
+
+                                    <div class="layui-form-item">
+                                        <label class="layui-form-label">{:lang("Relevance department")}</label>
+                                        <div class="layui-input-block">
+                                            <select name="department_id" lay-filter="required">
+                                                {volist name="all_department" id="item"}
+                                                <option value="{$item.id}">{$item.name}</option>
+                                                {/volist}
+                                            </select>
+                                        </div>
+                                    </div>
                                     <div class="layui-form-item">
                                         <label class="layui-form-label">{:lang("Backstage permission")}</label>
                                         <div class="layui-input-block">

+ 20 - 23
app/admin/view/auth_group/edit.html

@@ -31,29 +31,26 @@
                                             {/volist}
                                         </div>
                                     </div>
-<!--                                    <div class="layui-form-item">-->
-<!--                                        <label class="layui-form-label">{:lang('Superior department')}</label>-->
-<!--                                        <div class="layui-input-block">-->
-<!--                                            <select name="pid" lay-filter="required">-->
-<!--                                                <option value="0" selected>{:lang("Unknown")}</option>-->
-<!--                                                {volist name="all_groups" id="item"}-->
-<!--                                                <option value="{$item.id}"  {if $group.pid == $item.id} selected {/if} >{$item.name}</option>-->
-<!--                                                {volist name='$item.children' id='first'}-->
-<!--                                                <option value="{$first.id}"  {if $group.pid == $first.id} selected {/if}>&nbsp;&nbsp;| &#45;&#45;&nbsp;{$first.name}</option>-->
-<!--                                                {volist name='$first.children' id='second'}-->
-<!--                                                <option value="{$second.id}"  {if $group.pid == $second.id} selected {/if}>&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;{$second.name}</option>-->
-<!--                                                {volist name='$second.children' id='thirdly'}-->
-<!--                                                <option value="{$thirdly.id}"  {if $group.pid == $thirdly.id} selected {/if}>&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;{$thirdly.name}</option>-->
-<!--                                                {volist name='$thirdly.children' id='fourthly'}-->
-<!--                                                <option value="{$fourthly.id}"  {if $group.pid == $fourthly.id} selected {/if}>&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;&nbsp;| &#45;&#45;&nbsp;{$fourthly.name}</option>-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                                {/volist}-->
-<!--                                            </select>-->
-<!--                                        </div>-->
-<!--                                    </div>-->
+
+                                    <div class="layui-form-item">
+                                        <label class="layui-form-label">{:lang("Data rules")}</label>
+                                        <div class="layui-input-block">
+                                            {volist name="data_rules" id="item"}
+                                            <input type="checkbox" name="data_rules[]" value="{$item.id}" title={$item.zh} {if $item.isChecked} checked {/if}>
+                                            {/volist}
+                                        </div>
+                                    </div>
+
+                                    <div class="layui-form-item">
+                                        <label class="layui-form-label">{:lang("Relevance department")}</label>
+                                        <div class="layui-input-block">
+                                            <select name="department_id" lay-filter="required">
+                                                {volist name="all_department" id="item"}
+                                                <option value="{$item.id}" {if $item.id == $group.department_id} selected {/if}>{$item.name}</option>
+                                                {/volist}
+                                            </select>
+                                        </div>
+                                    </div>
                                     <div class="layui-form-item">
                                         <label class="layui-form-label">{:lang("Backstage permission")}</label>
                                         <div class="layui-input-block">

+ 0 - 14
app/admin/view/department/add.html

@@ -46,14 +46,6 @@
                                         </div>
                                     </div>
 
-                                    <div class="layui-form-item" id="group_role">
-                                        <label class="layui-form-label">{:lang("Relevance role")}</label>
-                                        <div class="layui-input-block">
-                                            {volist name="all_group" id="item"}
-                                            <input type="checkbox" name="auth_group_ids[]" value="{$item.id}" title="{$item.name}">
-                                            {/volist}
-                                        </div>
-                                    </div>
                                     <div class="layui-form-item">
                                         <div class="layui-input-block">
                                             <button type="button" class="layui-btn" lay-submit="" lay-filter="caviar_submit_btn">{:lang('Submit')}</button>
@@ -72,12 +64,6 @@
     </div>
 </div>
 <script>
-    // function show_role() {
-    //     if($("#pid").val() == 0) {
-    //         $('#group_role').css('display', 'block');
-    //     }
-    // }
-
     layui.use(['tree', 'util'], async function(){
         const layer = layui.layer
             ,form = layui.form;

+ 0 - 9
app/admin/view/department/edit.html

@@ -46,15 +46,6 @@
                                             </select>
                                         </div>
                                     </div>
-
-                                    <div class="layui-form-item" id="group_role">
-                                        <label class="layui-form-label">{:lang("Relevance role")}</label>
-                                        <div class="layui-input-block">
-                                            {volist name="all_group" id="item"}
-                                            <input type="checkbox" name="auth_group_ids[]" value="{$item.id}" title="{$item.name}" {if $item.isChecked } checked {/if}>
-                                            {/volist}
-                                        </div>
-                                    </div>
                                     <div class="layui-form-item">
                                         <div class="layui-input-block">
                                             <button type="button" class="layui-btn" lay-submit="" lay-filter="caviar_submit_btn">{:lang('Submit')}</button>

+ 6 - 0
app/common/model/AuthGroupModel.php

@@ -31,6 +31,12 @@ class AuthGroupModel extends BaseModel
         return $this->where('is_delete',0)->select();
     }
 
+    public function fetchByDepartmentId($d_id) {
+        return $this->where([
+            ['is_delete', '=', 0],
+            ['department_id', '=', $d_id]
+        ])->select();
+    }