rabin 11 months ago
parent
commit
09e5b42b82

+ 2 - 0
config/base.php

@@ -68,6 +68,7 @@ $config['base'] = array
 	    4 => 'pc',
 	    5 => '微信小程序',
 	    6 => '微信公众号',
+	    100 => '手动录入',
 	),
 
 	'system_source_key' => array
@@ -78,6 +79,7 @@ $config['base'] = array
 	    'pc' => 4,
 	    'wx_applet' => 5,
 	    'wx_service' => 6,
+	    'manual' => 100,
 	),
 
 	# 全局替换

+ 11 - 6
vendor/dever-main/framework/src/Dever/Data/Model.php

@@ -450,8 +450,13 @@ class Model
             return $result;
         }
 
-        if ($method == 'insert' && isset($param[1])) {
-            $param[0]['insert_value_num'] = $param[1];
+        $call = false;
+        if (isset($param[1])) {
+            if (is_object($param[1])) {
+                $call = $param[1];
+            } elseif ($method == 'insert') {
+                $param[0]['insert_value_num'] = $param[1];
+            }
         }
 
         $param = $param ? $this->initParam($param[0], $method) : array();
@@ -466,9 +471,9 @@ class Model
         if (!isset($this->data[$key])) {
             $this->request($method, $param);
             if (isset($this->config['request'][$method]['type']) && in_array($this->config['request'][$method]['type'], array('update', 'insert'))) {
-                return $this->callData($method, $param);
+                return $this->callData($method, $param, $call);
             }
-            $this->data[$key] = $this->callData($method, $param);
+            $this->data[$key] = $this->callData($method, $param, $call);
         }
 
         return $this->data[$key];
@@ -480,10 +485,10 @@ class Model
      *
      * @return mixd
      */
-    private function callData($method, $param)
+    private function callData($method, $param, $call = false)
     {
         $param = $this->search($method, $param);
-        $handle = new Model\Handle($method, $this->config, $param);
+        $handle = new Model\Handle($method, $this->config, $param, $call);
         return $handle->get();
     }
 

+ 14 - 2
vendor/dever-main/framework/src/Dever/Data/Model/Handle.php

@@ -49,16 +49,24 @@ class Handle
      */
     protected $method;
 
+    /**
+     * call
+     *
+     * @var object
+     */
+    protected $call;
+
     /**
      * get
      *
      * @return mixed
      */
-    public function __construct($method, $config, $param)
+    public function __construct($method, $config, $param, $call = false)
     {
         $this->method = $method;
         $this->config = $config;
         $this->param = $param;
+        $this->call = $call;
         $this->request = isset($config['request'][$method]) ? $config['request'][$method] : array();
     }
 
@@ -89,7 +97,11 @@ class Handle
             if ($this->update == 1 && isset($this->param['insert_value_num'])) {
                 $data = $this->db()->$type($this->param['insert_value_num']);
             } else {
-                $data = $this->db()->$type($this->request['col']);
+                if ($type == 'all' && $this->call) {
+                    $data = $this->db()->$type($this->request['col'], $this->call);
+                } else {
+                    $data = $this->db()->$type($this->request['col']);
+                }
             }
             if ($this->update == 1 && $data) {
                 $this->save('add', $data, 20);

+ 9 - 5
vendor/dever-main/framework/src/Dever/Data/Pdo/Store.php

@@ -184,14 +184,14 @@ class Store extends Base
      *
      * @return array
      */
-    public function all($col)
+    public function all($col, $call = false)
     {
         $config = false;
         if (strpos($col, '|') !== false) {
             $config = explode('|', $col);
             $col = $config[0];
         }
-        return $this->select($col, 'fetchAll', 'select', $config);
+        return $this->select($col, 'fetchAll', 'select', $config, $call);
     }
 
     /**
@@ -320,7 +320,7 @@ class Store extends Base
      *
      * @return array
      */
-    private function select($col = '', $method = 'fetch', $type = 'select', $config = false)
+    private function select($col = '', $method = 'fetch', $type = 'select', $config = false, $call = false)
     {
         $sql = $this->sql->{$type}($this->table, $col);
 
@@ -345,10 +345,11 @@ class Store extends Base
 
             if ($this->value) {
                 $handle = $this->read->prepare($sql);
+                /*
                 if ($method == 'fetchAll') {
                     # 查询大量数据时,不缓存数据到内存,防止内存溢出
                     $this->read->set();
-                }
+                }*/
                 $handle->execute($this->value);
             } else {
                 $handle = $this->read->query($sql);
@@ -358,7 +359,10 @@ class Store extends Base
         }
 
         if ($method == 'fetchAll') {
-            $data = $this->fetchAll($handle, $config);
+            if ($call) {
+                $this->value = array();
+            }
+            $data = $this->fetchAll($handle, $config, $call);
             
         } else {
             $data = $handle->$method();

+ 25 - 8
vendor/dever-main/framework/src/Dever/Data/Store.php

@@ -138,6 +138,10 @@ class Store
         } else {
             $this->read = $this->update = $this->connect($this->config);
         }
+        # 查询大量数据时,不缓存数据到内存,防止内存溢出
+        if (Dever::config('base')->pdo_no_cache) {
+            $this->read->set();
+        }
         $this->config['link'] = false;
     }
 
@@ -690,7 +694,7 @@ class Store
      *
      * @return array
      */
-    protected function fetchAll($handle, $config = false)
+    protected function fetchAll($handle, $config = false, $call = false)
     {
         $rows = function() use ($handle) {
             while ($row = $handle->fetch()) {
@@ -701,35 +705,48 @@ class Store
         $data = $rows();
         if ($data) {
             if ($config) {
-                $result = $this->fetchSet($data, $config);
+                $result = $this->fetchSet($data, $config, $call);
             } else {
                 foreach ($data as $row) {
-                    $result[] = $row;
+                    $result[] = $this->cb($call, $row);
                 }
             }
         }
         return $result;
     }
 
+    /**
+     * call
+     *
+     * @return array
+     */
+    protected function cb($call, $data)
+    {
+        if ($call) {
+            return $call($data);
+        }
+        return $data;
+    }
+
     /**
      * fetchSet
      *
      * @return array
      */
-    protected function fetchSet($data, $config)
+    protected function fetchSet($data, $config, $call = false)
     {
         $result = array();
         $key = $config[1];
         foreach ($data as $row) {
             if (isset($row[$key])) {
                 if (isset($config[3]) && isset($row[$config[2]])) {
-                    $result[$row[$key]][$row[$config[2]]] = $row;
+                    $result[$row[$key]][$row[$config[2]]] = $this->cb($call, $row);
                 } elseif (isset($config[2]) && isset($row[$config[2]])) {
-                    $result[$row[$key]] = $row[$config[2]];
+                    $result[$row[$key]] = $this->cb($call, $row[$config[2]]);
                 } elseif (isset($config[2])) {
-                    $result[$row[$key]][] = $row;
+                    $result[$row[$key]][] = $this->cb($call, $row);
                 } else {
-                    $result[$row[$key]] = $row;
+                    $result[$row[$key]] = $this->cb($call, $row);
                 }
             }
         }