rabin 3 vuotta sitten
vanhempi
commit
00496c4be8
5 muutettua tiedostoa jossa 158 lisäystä ja 31 poistoa
  1. 1 1
      assets/layadmin/html/project/database/update.html
  2. 30 0
      database/admin.php
  3. 8 0
      src/Auth.php
  4. 78 28
      src/Database.php
  5. 41 2
      src/Lib/Input.php

+ 1 - 1
assets/layadmin/html/project/database/update.html

@@ -22,7 +22,7 @@
     }
 
     .dever-color {
-      width: 100%;
+      /*width: 100%;*/
     }
 
     .dever_form_add_child {

+ 30 - 0
database/admin.php

@@ -369,6 +369,36 @@ return array
                 ),
             ),
         ),
+
+        'category'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '属性分类',
+			'default' 	=> '',
+			'desc' 		=> '分类',
+			'match' 	=> 'is_string',
+			'search'	=> 'linkage',
+			//'update'	=> $id ? false : 'linkage',
+			'update'	=> 'linkage',//这里select和radio也支持
+			'option'	=> Dever::url('category.get', 'product'),
+			'list'		=> 'Dever::load("product/category.string", "{category}")',
+			'load'		=> 'product-info_attr',
+			'tab'		=> 1,
+		),
+
+		'product-info_attr'=> array
+		(
+			'name' 		=> '属性设置',
+			'default' 	=> '',
+			'desc' 		=> '请先选择属性分类',
+			'match' 	=> 'option',
+			# 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
+			'sync'		=> array('id', 'info_id'),
+			# 根据category字段的值,获取product/attr.search接口的内容
+			'update'	=> 'load',
+			'update_load' => array('product/attr.getManageByCate', 'category'),
+			'tab'		=> 1,
+		),
 	
 		
 		#设置分割条

+ 8 - 0
src/Auth.php

@@ -187,13 +187,20 @@ class Auth
      */
     public function real($info, $state = true)
     {
+        if (!$info) {
+            return;
+        }
         if ($state == true && Dever::config('base')->getAdmin && $info && isset($info['id'])) {
             $admin = Dever::db('manage/admin')->one($info['id']);
+            if ($admin['status'] != 1) {
+                echo '管理账户已被封禁';die;
+            }
             if ($admin['top']) {
                 $info['top'] = $admin['top'];
             }
         }
 
+
         if (!$info) {
             $info = $this->auth();
             if ($info) {
@@ -201,6 +208,7 @@ class Auth
                 Dever::location(Dever::url(''));
             }
         }
+        $info = $this->role($info);
 
         if (isset($info['role']) && $info['role']) {
             $info['role_info'] = Dever::db('manage/role')->one($info['role']);

+ 78 - 28
src/Database.php

@@ -3245,8 +3245,11 @@ class Database
         return $result;
     }
 
-    private function update_struct($config, $col, $data, $tab = -1, $prefix = '')
+    public function update_struct($config, $col, $data, $tab = -1, $prefix = '', $layadmin = false)
     {
+        if (!$layadmin) {
+            $layadmin = layadmin();
+        }
         $result = array();
         $upload_call = '';
         if (isset($config['manage']['upload'])) {
@@ -3292,7 +3295,7 @@ class Database
                 if ($v['update'] == 'hidden') {
                     $style = 'style="display:none"';
                 }
-                if (layadmin()) {
+                if ($layadmin) {
                     $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div classs="layui-col-lg6">';
 
                     if (is_array($v['update'])) {
@@ -3449,7 +3452,7 @@ class Database
      */
     public function update_html($param, $key, $index, $data, &$result, $prefix = '')
     {
-        if (isset($param['name']) && $param['update'] != 'hidden' && isset($param['update'])) {
+        if (isset($param['name']) && isset($param['update']) && $param['update'] != 'hidden' && $param['update'] != 'load') {
             $result .= Html::pageLeft($param);
         }
 
@@ -3495,7 +3498,7 @@ class Database
             }
 
             # 处理同步
-            if (isset($param['sync']) && strpos($key, '-')) {
+            if (isset($param['sync']) && strpos($key, '-') && $param['update'] != 'load') {
                 $temp = explode('-', $key);
                 if (isset($data[$param['sync'][0]])) {
                     if (isset($temp[2])) {
@@ -3514,10 +3517,20 @@ class Database
                         $param['value'] = $load;
                     }
                 }
-                if (!isset($temp[2])) {
+                if (!isset($temp[2]) && is_array($param['update'])) {
                     $order = false;
-                    $config = Dever::db($temp[0] . '/' . $temp[1])->config;
-                    $param['update'] = $config['struct'];
+                    if (isset($param['update'][0]) && is_string($param['update'][0]) && strstr($param['update'][0], '.')) {
+                        if (isset($param['update'][1]) && $param['update'][1]) {
+                            $param['update_load'] = $param['update'][0];
+                            $param['update'] = 'load';
+                        } else {
+                            $param['update'] = Dever::load($param['update'][0]);
+                        }
+                    } else {
+                        $config = Dever::db($temp[0] . '/' . $temp[1])->config;
+                        $param['update'] = $config['struct']; 
+                    }
+                    
                     if (isset($config['manage']['tab'])) {
                         $param['prefix'] = $prefix;
                         $param['tab'] = $config['manage']['tab'];
@@ -3641,6 +3654,10 @@ class Database
                     $param['upload_search_value'] = $this->value($param['upload_search_value'], $data + $param);
                 }
 
+                if ($param['update'] == 'load') {
+                    $param['where_id'] = $this->id;
+                }
+
                 $result .= Html::$method($param);
             }
 
@@ -3883,9 +3900,9 @@ class Database
                                 $index = $t[0] . '/' . $t[1];
 
                                 $update_col[$i][$index] = $m_col;
-                                $update_set[$i][$index][$num][$temp[1]] = $v;
-                                $update_add[$i][$index][$num][$temp[1]] = $v;
-                                $update_add[$i][$index][$num][$m_col] = $s_value;
+                                $update_set[$i][$index][$num]['set_' . $temp[1]] = $v;
+                                $update_add[$i][$index][$num]['add_' . $temp[1]] = $v;
+                                $update_add[$i][$index][$num]['add_' . $m_col] = $s_value;
                                 $update_id[$i][$index][$num][$m_col] = $s_value;
                                 if ($this->id && $temp[1] == 'id') {
                                     $update_id[$i][$index][$num]['id'] = $v;
@@ -3938,14 +3955,40 @@ class Database
 
                                 if (isset($temp[2])) {
                                     $update_col[$i][$index] = $m_col;
-                                    $update_set[$i][$index][0][$temp[2]] = $v;
-                                    //$update_set[$i][$index][0][$m_col] = $s_value;
+                                    $update_set[$i][$index][0]['set_' . $temp[2]] = $v;
+                                    //$update_set[$i][$index][0]['set_' . $m_col] = $s_value;
 
-                                    $update_add[$i][$index][0][$temp[2]] = $v;
-                                    $update_add[$i][$index][0][$m_col] = $s_value;
+                                    $update_add[$i][$index][0]['add_' . $temp[2]] = $v;
+                                    $update_add[$i][$index][0]['add_' . $m_col] = $s_value;
 
                                     $update_id[$i][$index][0][$m_col] = $s_value;
                                 }
+                            } else {
+                                $temp = explode('-', $k);
+                                if (isset($temp[2])) {
+                                    $k = $temp[0] . '-' . $temp[1];
+                                    if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
+                                        $s_col = $config['struct'][$k]['sync'][0];
+                                        $m_col = $config['struct'][$k]['sync'][1];
+                                        if ($s_col == 'id') {
+                                            $s_value = $this->id;
+                                        } else {
+                                            $s_one = $this->load('one', $this->id);
+                                            $s_value = $s_one[$s_col];
+                                        }
+
+                                        $index = $temp[0] . '/' . $temp[1];
+                                        $temp[2] = ltrim($temp[2], '_');
+                                        $temp = explode('_', $temp[2]);
+                                        $update_col[$i][$index] = $m_col;
+                                        $up = array();
+                                        $up['add_' . $temp[0] . '_id'] = $temp[1];
+                                        $up['add_' . $temp[0] . '_value'] = $v;
+                                        $up['add_' . $m_col] = $s_value;
+                                        $update_add[$i][$index][] = $up;
+                                        $update_delete[$i][$index][][$m_col] = $s_value;
+                                    }
+                                }
                             }
                         } else {
                             if (is_array($v)) {
@@ -3976,8 +4019,7 @@ class Database
             }
             //print_r($update_set);
             //print_r($update_id);
-            //print_r($update_add);
-            //print_r($update_set);die;
+            //print_r($update_add);die;
             //print_r($input);
             //print_r($update_other);
             //print_r($config['struct']);die;
@@ -4024,26 +4066,34 @@ class Database
                         }
                     }
 
-                    if (isset($update_id[$k]) && $update_id[$k]) {
-                        foreach ($update_set[$k] as $k1 => $v1) {
+                    if (isset($update_add[$k]) && $update_add[$k]) {
+                        foreach ($update_add[$k] as $k1 => $v1) {
                             $col = $update_col[$k][$k1];
                             foreach ($v1 as $k2 => $v2) {
-                                if (isset($update_id[$k][$k1][$k2][$col])) {
-                                    $update_id[$k][$k1][$k2][$col] = $id;
-                                }
-                                if (isset($update_add[$k][$k1][$k2][$col])) {
-                                    $update_add[$k][$k1][$k2][$col] = $id;
+                                if (isset($update_set[$k][$k1][$k2][$col])) {
+                                    $update_set[$k][$k1][$k2][$col] = $id;
                                 }
                                 if (isset($v2[$col])) {
                                     $v2[$col] = $id;
                                 }
-                                $check = Dever::load($k1 . '-one', $update_id[$k][$k1][$k2]);
+
+                                $check = false;
+                                if (isset($update_id[$k][$k1][$k2])) {
+                                    if (isset($update_id[$k][$k1][$k2][$col])) {
+                                        $update_id[$k][$k1][$k2][$col] = $id;
+                                    }
+                                    $check = Dever::load($k1 . '-one', $update_id[$k][$k1][$k2]);
+                                } elseif (isset($update_delete[$k][$k1][$k2])) {
+                                    # 清理
+                                    Dever::load($k1 . '-delete', $update_delete[$k][$k1][$k2]);
+                                }
+                                
                                 if ($check) {
-                                    unset($v2['id']);
-                                    $v2['where_id'] = $check['id'];
-                                    Dever::load($k1 . '-update', $v2);
+                                    unset($update_set[$k][$k1][$k2]['set_id']);
+                                    $update_set[$k][$k1][$k2]['where_id'] = $check['id'];
+                                    Dever::load($k1 . '-update', $update_set[$k][$k1][$k2]);
                                 } else {
-                                    Dever::load($k1 . '-insert', $update_add[$k][$k1][$k2]);
+                                    Dever::load($k1 . '-insert', $v2);
                                 }
                             }
                         }

+ 41 - 2
src/Lib/Input.php

@@ -745,6 +745,9 @@ class Input
                 if (isset($param['control']) && is_string($param['control'])) {
                     //print_r($param);die;
                     $js = ' show_id="' . $param['control'] . '" onclick="inputShow($(this), \'' . $param['control'] . '\', \'input\')"';
+                } elseif (isset($param['load'])) {
+                    $js = ' onchange="loadChange($(this), \'' . $param['load'] . '\')" ';
+                    $js .= ' onload="loadChange($(this), \'' . $param['load'] . '\')" ';
                 } elseif (isset($param['bind'])) {
                     $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
                     $js = $param['bind'][0] . '="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
@@ -908,7 +911,12 @@ class Input
             
         }
 
-        $html .= '<script>function linkage_' . $param['name'] . '(level){select_linkage(level, "' . $id . '","' . $param['option'] . '", "' . $param['name'] . '", \'' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '\', "' . (isset($param['valid']) ? $param['valid'] : '') . '", "' . $w . '", false, "'.$param['search_state'].'", "'.$level_param.'", "'.$col.'", "'.$api.'", "'.$type.'", "'.$title.'", "'.$open.'")};';
+        $load = '';
+        if (isset($param['load'])) {
+            $load = $param['load'];
+        }
+
+        $html .= '<script>function linkage_' . $param['name'] . '(level){select_linkage(level, "' . $id . '","' . $param['option'] . '", "' . $param['name'] . '", \'' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '\', "' . (isset($param['valid']) ? $param['valid'] : '') . '", "' . $w . '", false, "'.$param['search_state'].'", "'.$level_param.'", "'.$col.'", "'.$api.'", "'.$type.'", "'.$title.'", "'.$open.'", "'.$load.'")};';
 
         $html .= '$(document).ready(function(){linkage_' . $param['name'] . '(' . $level . ');'.$script.'});</script>';
 
@@ -937,6 +945,7 @@ class Input
         $html = $class ? '<div class="' . $class . '">' : '';
 
         $child_class = '';
+        $style = '';
         if (isset($param['child'])) {
             $child_param['name'] = 'update_' . $param['child_name'];
             isset($param['value']) && $param['value'] = $param['value'];
@@ -950,6 +959,13 @@ class Input
         if (isset($param['control']) && is_string($param['control'])) {
             //print_r($param);die;
             $change = ' show_id="' . $param['control'] . '" onchange="inputShow($(this), \'' . $param['control'] . '\')"';
+        } elseif (isset($param['option_add'])) {
+            $change = ' onchange="addChange($(this))" ';
+            $style = 'width:25%';
+            $child_class .= ' change';
+        } elseif (isset($param['load'])) {
+            $change = ' onchange="loadChange($(this), \'' . $param['load'] . '\')" ';
+            $child_class .= ' change';
         } elseif (isset($param['bind'])) {
             $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
             $change = $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
@@ -1005,12 +1021,18 @@ class Input
             }
         }
         
-        $html .= $hidden . '<select '.$xm.' class="update_value form-control ' . $child_class . '  ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '"  ' . $change . '>';
+        $html .= $hidden . '<select '.$xm.' class="update_value form-control ' . $child_class . '  ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '"  ' . $change . '  style="' . $style . '">';
 
         if (isset($param['option'])) {
+
             if (!isset($param['option'][-100]) && isset($param['lang']) && $param['lang']) {
                 $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
             }
+
+            if (isset($param['option_add'])) {
+                $html .= '<option value="0" data-type="add" data-url="'.Dever::url($param['option_add'][1]).'">' . $param['option_add'][0] . '</option>';
+            }
+
             foreach ($param['option'] as $k => $v) {
                 if (is_array($v)) {
                     if (isset($v['lang']) && $v['lang']) {
@@ -1357,4 +1379,21 @@ class Input
         }
         return $result;
     }
+
+    /**
+     * _load
+     *
+     * @return string
+     */
+    public static function _load($param)
+    {
+        $cate = '';
+        $load = $param['update_load'];
+        if (is_array($load)) {
+            $cate = $load[1];
+            $load = $load[0];
+        }
+        $html = '<div class="update_load" id="'.$param['name'].'" data-load="'.Dever::url($load).'" data-cate="'.$cate.'" data-id="'.$param['where_id'].'"></div>';
+        return $html;
+    }
 }