rabin 6 месяцев назад
Родитель
Сommit
b6c4fc8423
6 измененных файлов с 167 добавлено и 30 удалено
  1. 2 1
      api/Page/Data.php
  2. 51 15
      api/Page/Update.php
  3. 1 1
      lib/Auth.php
  4. 42 0
      lib/Common.php
  5. 42 11
      lib/Page.php
  6. 29 2
      manage/admin.php

+ 2 - 1
api/Page/Data.php

@@ -89,6 +89,7 @@ class Data extends Page
 
     public function handleData($k, $v)
     {
+        $result['index'] = $k+1*Dever::input('pg', '', '', 1);
         $button = $this->button('data_button', $v);
         if ($button) {
             $result['button'] = $button;
@@ -106,7 +107,7 @@ class Data extends Page
             if (isset($v[$key])) {
                 $result[$key] = $this->getValue($key, $v[$key], $v, $value);
             } elseif (strpos($key, '/')) {
-                $other = $this->getOther($key, $value['where'], $v);
+                $other = $this->getOther($key, $value, $v);
                 if ($other) {
                     $otherName = array();
                     foreach ($other as $k1 => $v1) {

+ 51 - 15
api/Page/Update.php

@@ -178,13 +178,18 @@ class Update extends Page
                 }
                 if (isset($remote[$k])) {
                     $data['update'][$remote[$k][0]]['remote'] = Dever::url($remote[$k][1]);
-                    $result = Dever::call($remote[$k][1], array($v), 'api');
-                    if ($result) {
-                        $this->setUpdate($info, $data, $result);
+                    if ($field[$k]['type'] == 'cascader' && !isset($field[$k]['option'])) {
+                        
+                    } else {
+                        $result = Dever::call($remote[$k][1], array($v), 'api');
+                        if ($result) {
+                            $this->setUpdate($info, $data, $result);
+                        }
                     }
                 }
                 if (isset($show[$k])) {
                     $data['update'][$show[$k][0]]['show'] = $this->getShow($show[$k][1], $info);
+                    $info[$k] = $data['update'][$show[$k][0]]['show'];
                 }
             }
             if (isset($field[$k]) && isset($field[$k]['index'])) {
@@ -196,7 +201,7 @@ class Update extends Page
         if ($default) {
             foreach ($default as $k => $v) {
                 $data['update'][$v[0]]['value'] = $this->getShow($v[1], $info);
-                $data['field'][$k] = $this->getShow($v[1], $info);
+                $info[$k] = $data['field'][$k] = $data['update'][$v[0]]['value'];
             }
         }
     }
@@ -354,8 +359,25 @@ class Update extends Page
                             $sku[$v['key']] = array($v['where'], $v['content']['field'], $v['spec'], $v['spec_field'], $input[$v['key'] . '_spec'], $input[$v['key']]);
                         }
                         
-                    } elseif (strpos($v['key'], '/')) {
-                        $other[$v['key']] = array($v['where'], $v['content']['field'], $v['content']['drag'], $input[$v['key']]);
+                    } elseif (strpos($v['key'], '/') && $v['type'] != 'hidden') {
+                        if (isset($v['field'])) {
+                            $value = $input[$v['key']] ?? false;
+                            if (strpos($v['key'], '#')) {
+                                $v['key'] = str_replace('#', '', $v['key']);
+                            }
+                            $other_id = $input[$v['key'] . '_id'] ?? 0;
+                            $value = array
+                            (
+                                0 => array('id' => $other_id, $v['field'] => $value)
+                            );
+                            if (isset($other[$v['key']])) {
+                                $other[$v['key']][3][0] += $value[0];
+                            } else {
+                                $other[$v['key']] = array($v['where'], false, false, $value);
+                            }
+                        } else {
+                            $other[$v['key']] = array($v['where'], $v['content']['field'], $v['content']['drag'], $input[$v['key']]);
+                        }
                     } else {
                         $this->doData($data, $v['key'], $input[$v['key']], $this->config['field']);
                     }
@@ -430,7 +452,7 @@ class Update extends Page
             $where = array();
             $name = array();
             foreach ($check as $k => $v) {
-                if (isset($data[$v])) {
+                if (isset($data[$v]) && $data[$v]) {
                     if (isset($field[$v]) && isset($field[$v]['name'])) {
                         $n = $field[$v]['name'];
                     } elseif (isset($this->db->config['struct'][$v])) {
@@ -459,7 +481,17 @@ class Update extends Page
     {
         if (isset($this->config['start']) && $this->config['start']) {
             $data['id'] = $id;
-            $data = Dever::call($this->config['start'], array($this->db, $data));
+            if (is_array($this->config['start'])) {
+                $result = $data;
+                foreach ($this->config['start'] as $k => $v) {
+                    $result = Dever::call($v, array($this->db, $result));
+                }
+            } else {
+                $result = Dever::call($this->config['start'], array($this->db, $data));
+            }
+            if ($result) {
+                $data = $result;
+            }
         }
     }
 
@@ -469,7 +501,7 @@ class Update extends Page
             $data['id'] = $id;
             if (is_array($this->config['end'])) {
                 foreach ($this->config['end'] as $k => $v) {
-                    Dever::call($v, array($data));
+                    Dever::call($v, array($this->db, $data));
                 }
             } else {
                 Dever::call($this->config['end'], array($this->db, $data));
@@ -491,7 +523,7 @@ class Update extends Page
                 $input = $v[3];
                 $value = array();
                 foreach ($input as $k1 => $v1) {
-                    if (isset($v1['id'])) {
+                    if (isset($v1['id']) && $v1['id']) {
                         $value['id'] = $v1['id'];
                     }
                     foreach ($common as $k2 => $v2) {
@@ -505,12 +537,16 @@ class Update extends Page
                             }
                         }
                     }
-                    foreach ($update as $k2 => $v2) {
-                        if (isset($v1[$k2])) {
-                            $this->doData($value, $k2, $v1[$k2], $set->config['field']);
-                        } else {
-                            $value[$k2] = '';
+                    if ($update) {
+                        foreach ($update as $k2 => $v2) {
+                            if (isset($v1[$k2])) {
+                                $this->doData($value, $k2, $v1[$k2], $set->config['field']);
+                            } else {
+                                $value[$k2] = '';
+                            }
                         }
+                    } else {
+                        $value += $v1;
                     }
                     if ($drag) {
                         $value[$drag] = $k1+1;

+ 1 - 1
lib/Auth.php

@@ -18,7 +18,7 @@ class Auth
             $info['extend']['info_id'] = 1;
             $info['extend']['module_id'] = 1;
             $info['extend']['data_id'] = 1;
-            Dever::error('请先登录');
+            #Dever::error('请先登录');
         }
         $this->system = Dever::db('system', 'manage')->find($info['extend']['system_id']);
         if (!$this->system) {

+ 42 - 0
lib/Common.php

@@ -126,6 +126,48 @@ class Common
         return hash('sha256', $password . $salt);
     }
 
+    # 自动更新key
+    public function updateKey($db, $data)
+    {
+        if ($data['name'] && !$data['key']) {
+            if (Dever::project('pinyin')) {
+                $where = array();
+                if (isset($data['id']) && $data['id']) {
+                    $where['id'] = array('!=', $data['id']);
+                }
+                $data['key'] = Dever::load('convert', 'pinyin')->getPinyin($data['name']);
+
+                # 检查是否存在
+                $where['key'] = $data['key'];
+                $info = $db->find($where);
+                if ($info) {
+                    $data['key'] .= '-' . date('YmdHis');
+                }
+            }
+        }
+        return $data;
+    }
+
+    # 设置联动
+    public function cascader($total, $func)
+    {
+        $total = Dever::input('total', 'is_numeric', '联动总数', $total);
+        $level = Dever::input('level', 'is_numeric', '联动级别', 1);
+        $parent = Dever::input('parent', 'is_numeric', '联动ID', 0);
+        if ($parent < 0) {
+            Dever::error('error');
+        }
+        $data = $func($level, $parent);
+        if ($level >= $total) {
+            foreach ($data as &$v) {
+                $v['leaf'] = true;
+            }
+        }
+        $result['total'] = $total;
+        $result['list'] = $data;
+        return $result;
+    }
+
     # 根据load获取db
     public function db($load)
     {

+ 42 - 11
lib/Page.php

@@ -90,16 +90,21 @@ class Page extends Auth
     # 获取关联数据
     public function getOther($key, $set, $data)
     {
-        $where = array();
-        foreach ($set as $k => $v) {
-            if (!is_array($v) && isset($data[$v])) {
-                $where[$k] = $data[$v];
-            } else {
-                $where[$k] = $v;
+        $where = $config = array();
+        if (isset($set['where'])) {
+            foreach ($set['where'] as $k => $v) {
+                if (!is_array($v) && isset($data[$v])) {
+                    $where[$k] = $data[$v];
+                } else {
+                    $where[$k] = $v;
+                }
             }
         }
+        if (isset($set['col'])) {
+            $config['col'] = $set['col'];
+        }
         if ($where) {
-            return Dever::db($key)->select($where);
+            return Dever::db($key)->select($where, $config);
         }
         return array();
     }
@@ -270,13 +275,37 @@ class Page extends Auth
             }
         }
         if (strpos($key, '/') && $this->key == 'update') {
-            $this->setType($value, 'array');
+            $this->setType($value, 'table');
             $this->setShow($value);
             if (strpos($key, '#')) {
                 $key = str_replace('#', '', $key);
             }
             $sku = $value['type'] == 'sku' ? true : false;
-            $value['value'] = $this->getOther($key, $value['where'], $this->info);
+            $value['value'] = $this->getOther($key, $value, $this->info);
+            if (isset($value['default'])) {
+                $value['value'] += $value['default'];
+            }
+            if (isset($value['field'])) {
+                list($app, $table) = explode('/', $key);
+                $set = Dever::project($app);
+                $manage = @include($set['path'] . 'manage/'.$table.'.php');
+                if (isset($manage['update']['field'][$value['field']])) {
+                    $value = array_merge($value, $manage['update']['field'][$value['field']]);
+                }
+                if ($value['value']) {
+                    $data[$key . '_id'] = array
+                    (
+                        'key' => $key . '_id',
+                        'type' => 'hidden',
+                        'value' => $value['value'][0]['id'],
+                    );
+                    $value['value'] = $value['value'][0][$value['field']];
+                }
+                $this->setRules($value);
+                $this->setForm($value);
+                $data[] = $value;
+                return $value['name'] ?? 'test';
+            }
             $update = new \Manage\Api\Page\Update($key, false);
             $value['option'] = array();
             $value['content'] = $update->get($value['value'], $value['option'], $sku);
@@ -316,7 +345,7 @@ class Page extends Auth
             }
             $this->setForm($value);
             $data[] = $value;
-            return $value['name'];
+            return $value['name'] ?? 'test';
         }
     }
 
@@ -396,7 +425,9 @@ class Page extends Auth
 
     private function setForm(&$value)
     {
-        $value['value'] = Dever::input('search')[$value['key']] ?? '';
+        if (empty($value['value'])) {
+            $value['value'] = Dever::input('search')[$value['key']] ?? '';
+        }
         if (is_array($value['value'])) {
             foreach ($value['value'] as &$v) {
                 $v = (float) $v;

+ 29 - 2
manage/admin.php

@@ -473,8 +473,35 @@ return array
                 'type' => 'tree',
                 'desc' => '',
             ),
-            # 定义另外一个表或者方法里的字段,带有"."就是方法,调用manage/role里的upload配置,这里也可以自行配置
-            //'manage/role' => 'upload',
+            # 调用另外一个manage下update字段定义,如api/api_notify,就是调用api/manage/api_notify.php里的update
+            /*
+            #也可以这样设置
+            'api/api_notify#' => array
+            (
+                'field' => 'sign_arg',
+                'name' => '签名参数',
+                'where'  => array('api_id' => 'id'),
+            ),
+            'api/api_notify##' => array
+            (
+                'field' => 'sign_id',
+                'name' => '签名',
+                'where'  => array('api_id' => 'id'),
+            ),
+            'api/api_notify' => array
+            (
+                'name' => '基本设置',
+                'where'  => array('api_id' => 'id'),
+                'default' => array(array('type' => 2)),
+                # 默认使用表格形式展示,可以改成每行展示
+                'type' => 'line',
+            ),
+            'api/api_notify_body' => array
+            (
+                'name' => '参数设置',
+                'where'  => array('api_id' => 'id'),
+            ),
+            */
         ),
 
         # 是否开启控制功能