Browse Source

修改thinkorm

lgy 1 week ago
parent
commit
e2c465c4d7

+ 0 - 49
jcjyhr/vendor/topthink/think-orm/src/Model.php

@@ -129,13 +129,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
      */
     protected $globalScope = [];
 
-    /**
-     * 数据字段值的变化.
-     *
-     * @var array
-     */
-    protected $change = [];
-
     /**
      * Db对象
      *
@@ -396,10 +389,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
             ->name($this->name . $this->suffix)
             ->pk($this->pk);
 
-        if (!empty($this->autoInc)) {
-            $query->autoinc(is_string($this->autoInc) ? $this->autoInc : $this->pk);
-        }
-
         if (!empty($this->table)) {
             $query->table($this->table . $this->suffix);
         }
@@ -549,36 +538,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
         return empty($this->data);
     }
 
-    /**
-     * 字段值增长
-     *
-     * @param string $field 字段名
-     * @param float  $step  增长值
-     *
-     * @return $this
-     */
-    public function inc(string $field, float $step = 1)
-    {
-        $this->setAttr($field, ['INC', $step]);
-        $this->change[$field] = $this->origin[$field] + $step;
-        return $this;
-    }
-
-    /**
-     * 字段值减少.
-     *
-     * @param string $field 字段名
-     * @param float  $step  增长值
-     *
-     * @return $this
-     */
-    public function dec(string $field, float $step = 1)
-    {
-        $this->setAttr($field, ['DEC', $step]);
-        $this->change[$field] = $this->origin[$field] - $step;
-        return $this;
-    }
-
     /**
      * 保存当前数据对象
      *
@@ -611,14 +570,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
         // 写入回调
         $this->trigger('AfterWrite');
 
-        if (!empty($this->change)) {
-            // 处理递增递减数据
-            foreach ($this->change as $field => $val) {
-                $this->data[$field] = $val;
-            }
-            $this->change = [];
-        }
-
         // 重新记录原始数据
         $this->origin   = $this->data;
         $this->get      = [];

+ 1 - 20
jcjyhr/vendor/topthink/think-orm/src/db/BaseBuilder.php

@@ -763,26 +763,7 @@ abstract class BaseBuilder
     public function select(Query $query, bool $one = false): string
     {
         $options = $query->getOptions();
-        var_dump(str_replace(
-            ['%TABLE%', '%DISTINCT%', '%EXTRA%', '%FIELD%', '%JOIN%', '%WHERE%', '%GROUP%', '%HAVING%', '%ORDER%', '%LIMIT%', '%UNION%', '%LOCK%', '%COMMENT%', '%FORCE%'],
-            [
-                $this->parseTable($query, $options['table']),
-                $this->parseDistinct($query, $options['distinct']),
-                $this->parseExtra($query, $options['extra']),
-                $this->parseField($query, $options['field'] ?? []),
-                $this->parseJoin($query, $options['join']),
-                $this->parseWhere($query, $options['where']),
-                $this->parseGroup($query, $options['group']),
-                $this->parseHaving($query, $options['having']),
-                $this->parseOrder($query, $options['order']),
-                $this->parseLimit($query, $one ? '1' : $options['limit']),
-                $this->parseUnion($query, $options['union']),
-                $this->parseLock($query, $options['lock']),
-                $this->parseComment($query, $options['comment']),
-                $this->parseForce($query, $options['force']),
-            ],
-            $this->selectSql
-        ));die;
+
         return str_replace(
             ['%TABLE%', '%DISTINCT%', '%EXTRA%', '%FIELD%', '%JOIN%', '%WHERE%', '%GROUP%', '%HAVING%', '%ORDER%', '%LIMIT%', '%UNION%', '%LOCK%', '%COMMENT%', '%FORCE%'],
             [

+ 1 - 2
jcjyhr/vendor/topthink/think-orm/src/db/BaseQuery.php

@@ -1320,7 +1320,6 @@ abstract class BaseQuery
         }
 
         $resultSet = $this->connection->select($this);
-        var_dump(2);die;
 
         // 返回结果处理
         if (!empty($this->options['fail']) && count($resultSet) == 0) {
@@ -1356,7 +1355,7 @@ abstract class BaseQuery
             $this->parsePkWhere($data);
         }
 
-        if (empty($this->options['where']) && empty($this->options['order']) && empty($this->options['sort'])) {
+        if (empty($this->options['where']) && empty($this->options['order'])) {
             $result = [];
         } else {
             $result = $this->connection->find($this);

+ 1 - 3
jcjyhr/vendor/topthink/think-orm/src/db/Connection.php

@@ -277,9 +277,7 @@ abstract class Connection implements ConnectionInterface
                     $master = '';
                 }
 
-                // $this->db->log($sql . ' [ ' . $master . 'RunTime:' . $time . 's ]');
-                // 修改日志表现形式
-                $this->db->log('[ ' . $master . 'RunTime:' . $time . 's ] '. $sql);
+                $this->db->log($sql . ' [ ' . $master . 'RunTime:' . $time . 's ]');
             };
         }
 

+ 1 - 1
jcjyhr/vendor/topthink/think-orm/src/db/Fetch.php

@@ -316,7 +316,7 @@ class Fetch
                 $this->query->setOption('soft_delete', null);
                 $this->query->setOption('data', [$field => $condition]);
                 // 生成删除SQL语句
-                $sql = $this->builder->update($this->query);
+                $sql = $this->builder->delete($this->query);
 
                 return $this->fetch($sql);
             }

+ 9 - 12
jcjyhr/vendor/topthink/think-orm/src/db/PDOConnection.php

@@ -570,12 +570,11 @@ abstract class PDOConnection extends Connection
 
         try {
             if (empty($config['dsn'])) {
-//                $config['dsn'] = $this->parseDsn($config);
-                $config['dsn'] = "dm:host=".$config['hostname'].";dbname=".$config['database'];
+                $config['dsn'] = $this->parseDsn($config);
             }
 
             $startTime = microtime(true);
-//var_dump($config);die;
+
             $this->links[$linkNum] = $this->createPdo($config['dsn'], $config['username'], $config['password'], $params);
 
             // SQL监控
@@ -724,8 +723,10 @@ abstract class PDOConnection extends Connection
             if (!$query->getOptions('force_cache')) {
                 $key = $cacheItem->getKey();
 
-                if ($this->cache->has($key)) {
-                    return $this->cache->get($key);
+                $data = $this->cache->get($key);
+
+                if (null !== $data) {
+                    return $data;
                 }
             }
         }
@@ -1251,16 +1252,14 @@ abstract class PDOConnection extends Connection
         $pdo = $this->getPDOStatement($sql, $query->getBind(), $options['master']);
 
         $result = $pdo->fetchColumn();
-        $result = false !== $result ? $result : $default;
-        $requireCache = $query->getOptions('cache_always') || !empty($result);
 
-        if (isset($cacheItem) && $requireCache) {
+        if (isset($cacheItem)) {
             // 缓存数据
             $cacheItem->set($result);
             $this->cacheData($cacheItem);
         }
 
-        return $result;
+        return false !== $result ? $result : $default;
     }
 
     /**
@@ -1375,9 +1374,7 @@ abstract class PDOConnection extends Connection
             $result = $resultSet;
         }
 
-        $requireCache = $query->getOptions('cache_always') || !empty($result);
-
-        if (isset($cacheItem) && $requireCache) {
+        if (isset($cacheItem)) {
             // 缓存数据
             $cacheItem->set($result);
             $this->cacheData($cacheItem);

+ 62 - 98
jcjyhr/vendor/topthink/think-orm/src/db/builder/Dm.php

@@ -6,11 +6,13 @@
 // +----------------------------------------------------------------------
 // | Author: liu21st <liu21st@gmail.com>
 // +----------------------------------------------------------------------
+declare (strict_types = 1);
 
 namespace think\db\builder;
 
-use think\db\BaseQuery;
 use think\db\Builder;
+use think\db\Query;
+use think\db\exception\DbException as Exception;
 use think\db\Raw;
 
 /**
@@ -18,136 +20,98 @@ use think\db\Raw;
  */
 class Dm extends Builder
 {
-    protected $insertAllSql = '%INSERT% INTO %TABLE% (%FIELD%) VALUES %DATA% %COMMENT%';
-    protected $updateSql    = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%';
+//    protected $selectSql = 'SELECT * FROM (SELECT thinkphp.*, rownum AS numrow FROM (SELECT  %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%) thinkphp ) %LIMIT%%COMMENT%';
 
     /**
-     * 生成insertall SQL
-     * @access public
-     * @param array     $dataSet 数据集
-     * @param array     $options 表达式
-     * @param bool      $replace 是否replace
+     * limit分析
+     * @access protected
+     * @param  Query $query 查询对象
+     * @param  mixed $limit
      * @return string
-     * @throws Exception
      */
-//    public function insertAll($dataSet, $options = [], $replace = false):string
-//    {
-//        // 获取合法的字段
-//        if ('*' == $options['field']) {
-//            $fields = array_keys($this->getFieldsType($options['table']));
-//        } else {
-//            $fields = $options['field'];
-//        }
-//        foreach ($dataSet as $data) {
-//            foreach ($data as $key => $val) {
-//                if (!in_array($key, $fields, true) &&  !in_array(  strtoupper($key),$fields, true)) {
-//                    if ($options['strict']) {
-//                        throw new \Exception('fields not exists:[' . $key . ']');
-//                    }
-//                    unset($data[$key]);
-//                } elseif (is_null($val)) {
-//                    $data[$key] = 'NULL';
-//                } elseif (is_scalar($val)) {
-//                    $data[$key] = $this->parseValue($val, $key);
-//                } elseif (is_object($val) && method_exists($val, '__toString')) {
-//                    // 对象数据写入
-//                    $data[$key] = $val->__toString();
-//                } else {
-//                    // 过滤掉非标量数据
-//                    unset($data[$key]);
-//                }
-//            }
-//            $value    = array_values($data);
-//            $values[] = '( ' . implode(',', $value) . ' )';
-//
-//            if (!isset($insertFields)) {
-//                $insertFields = array_map([$this, 'parseKey'], array_keys($data));
-//            }
-//        }
-//
-//        return str_replace(
-//            ['%INSERT%', '%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'],
-//            [
-//                $replace ? 'REPLACE' : 'INSERT',
-//                $this->parseTable($options['table'], $options),
-//                implode(' , ', $insertFields),
-//                implode(' , ', $values),
-//                $this->parseComment($options['comment']),
-//            ], $this->insertAllSql);
-//    }
+    protected function parseLimit(Query $query, string $limit): string
+    {
+        return (!empty($limit) && false === strpos($limit, '(')) ? ' LIMIT ' . $limit . ' ' : '';
+
+    }
 
     /**
-     * 字段和表名处理
+     * 设置锁机制
      * @access protected
-     * @param mixed  $key
-     * @param array  $options
+     * @param  Query      $query 查询对象
+     * @param  bool|false $lock
      * @return string
      */
-    public function parseKey(BaseQuery $query, string|int|Raw $key, bool $strict = false): string
+    protected function parseLock(Query $query, $lock = false): string
+    {
+        if (!$lock) {
+            return '';
+        }
+
+        return ' FOR UPDATE NOWAIT ';
+    }
+
+    /**
+     * 字段和表名处理
+     * @access public
+     * @param Query $query 查询对象
+     * @param string $key
+     * @param bool $strict
+     * @return string
+     * @throws Exception
+     */
+    public function parseKey(Query $query, $key, bool $strict = false): string
     {
-        if (is_numeric($key)) {
-            return $key;
-        } elseif ($key instanceof Expression) {
-            return $key->getValue();
+        if (is_int($key)) {
+            return (string) $key;
+        } elseif ($key instanceof Raw) {
+            return $this->parseRaw($query, $key);
         }
 
         $key = trim($key);
-        if (strpos($key, '$.') && false === strpos($key, '(')) {
+
+        if (strpos($key, '->') && false === strpos($key, '(')) {
             // JSON字段支持
-            list($field, $name) = explode('$.', $key);
-            return 'json_extract(' . $field . ', \'$.' . $name . '\')';
-        } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
-            list($table, $key) = explode('.', $key, 2);
+            [$field, $name] = explode($key, '->');
+            $key = $field . '."' . $name . '"';
+        } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) {
+            [$table, $key] = explode('.', $key, 2);
+
+            $alias = $query->getOptions('alias');
+
             if ('__TABLE__' == $table) {
-                $table =$query->getTable();
+                $table = $query->getOptions('table');
+                $table = is_array($table) ? array_shift($table) : $table;
             }
-            if (isset($options['alias'][$table])) {
-                $table = $options['alias'][$table];
+
+            if (isset($alias[$table])) {
+                $table = $alias[$table];
             }
         }
 
         if ($strict && !preg_match('/^[\w\.\*]+$/', $key)) {
             throw new Exception('not support data:' . $key);
         }
-        if ('*' != $key && ($strict || !preg_match('/[,\'\"\*\(\)`.\s]/', $key))) {
-            $key = '`' . $key . '`';
+
+        if ('*' != $key && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) {
+            $key = '"' . $key . '"';
         }
+
         if (isset($table)) {
-            if (strpos($table, '.')) {
-                $table = str_replace('.', '`.`', $table);
-            }
-            $key = '`' . $table . '`.' . $key;
+            $key = '"' . $table . '".' . $key;
         }
+
         return $key;
     }
 
     /**
      * 随机排序
      * @access protected
+     * @param  Query $query 查询对象
      * @return string
      */
-    protected function parseRand(BaseQuery $query): string
-    {
-        return 'rand()';
-    }
-    /**
-     * Partition 分析.
-     *
-     * @param BaseQuery        $query     查询对象
-     * @param string|array $partition 分区
-     *
-     * @return string
-     */
-    protected function parsePartition(BaseQuery $query, $partition): string
+    protected function parseRand(Query $query): string
     {
-        if ('' == $partition) {
-            return '';
-        }
-
-        if (is_string($partition)) {
-            $partition = explode(',', $partition);
-        }
-
-        return ' PARTITION (' . implode(' , ', $partition) . ') ';
+        return 'DBMS_RANDOM.value';
     }
 }

+ 1 - 3
jcjyhr/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php

@@ -583,9 +583,7 @@ trait ModelRelationQuery
         if (!empty($this->options['lazy_fields'])) {
             $id = $this->getKey($result);
             foreach ($this->options['lazy_fields'] as $field) {
-                if (isset($result[$field])) {
-                    $result[$field] += $this->getLazyFieldValue($field, $id);
-                }
+                $result[$field] += $this->getLazyFieldValue($field, $id);
             }
         }
 

+ 58 - 86
jcjyhr/vendor/topthink/think-orm/src/db/connector/Dm.php

@@ -1,81 +1,91 @@
 <?php
-
 // +----------------------------------------------------------------------
 // | ThinkPHP [ WE CAN DO IT JUST THINK ]
 // +----------------------------------------------------------------------
-// | Copyright (c) 2006~2023 http://thinkphp.cn All rights reserved.
+// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
 // +----------------------------------------------------------------------
 // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 // +----------------------------------------------------------------------
 // | Author: liu21st <liu21st@gmail.com>
 // +----------------------------------------------------------------------
-declare(strict_types=1);
+declare (strict_types = 1);
 
 namespace think\db\connector;
 
 use PDO;
+use think\db\exception\PDOException;
 use think\db\PDOConnection;
-use think\db\BaseQuery;
 
 /**
- * mysql数据库驱动.
+ * mysql数据库驱动
  */
 class Dm extends PDOConnection
 {
+
     /**
-     * 解析pdo连接的dsn信息.
-     *
-     * @param array $config 连接信息
-     *
+     * 解析pdo连接的dsn信息
+     * @access protected
+     * @param  array $config 连接信息
      * @return string
      */
     protected function parseDsn(array $config): string
     {
-        $dsn = 'dm:dbname=';
-        if (!empty($config['hostname'])) {
-            //  Oracle Instant Client
-            $dsn .= '//' . $config['hostname'] . ($config['hostport'] ? ':' . $config['hostport'] : '') . '/';
-        }
-        $dsn .= $config['database'];
-        if (!empty($config['charset'])) {
-            $dsn .= ';charset=' . $config['charset'];
+        $dsn = sprintf("dm:host=%s;port=%s;dbname=%s", $config['hostname'], $config['hostport'], $config['database']);
+        return  $dsn;
+    }
+    /**
+     * 连接数据库方法
+     * @access public
+     * @param array      $config         连接参数
+     * @param integer    $linkNum        连接序号
+     * @param array|bool $autoConnection 是否自动连接主数据库(用于分布式)
+     * @return PDO
+     * @throws PDOException
+     */
+    public function connect(array $config = [], $linkNum = 0, $autoConnection = false): PDO {
+        if (empty($config)) {
+            $config = $this->config;
+        } else {
+            $config = array_merge($this->config, $config);
         }
-        return $dsn;
+        
+        $PDO = parent::connect($config, $linkNum, $autoConnection);
+
+        $PDO->query(sprintf("SET SCHEMA  %s", $config['database']));
+        return $PDO;
+
     }
 
     /**
-     * 取得数据表的字段信息.
-     *
-     * @param string $tableName
-     *
+     * 取得数据表的字段信息
+     * @access public
+     * @param  string $tableName
      * @return array
      */
     public function getFields(string $tableName): array
     {
-        [$tableName] = explode(' ', $tableName);
+        $tableName = str_replace("`", "", $tableName);
 
-        if (!str_contains($tableName, '`')) {
-            if (str_contains($tableName, '.')) {
-                $tableName = str_replace('.', '`.`', $tableName);
-            }
-            $tableName = '`' . $tableName . '`';
-        }
+        $sql = $sql = sprintf("
+select a.column_name,data_type,decode(nullable,'Y',0,1) notnull,data_default,decode(a.column_name,b.column_name,1,0) pk from user_tab_columns a,(select column_name from user_constraints c,user_cons_columns col where c.constraint_name=col.constraint_name and c.constraint_type='P'and c.table_name='%s') b where table_name='%s' and a.column_name=b.column_name(+)
+", $tableName, $tableName);
 
-        $sql             = "select a.column_name,data_type,DECODE (nullable, 'Y', 0, 1) notnull,data_default, DECODE (A .column_name,b.column_name,1,0) pk from all_tab_columns a,(select column_name from all_constraints c, all_cons_columns col where c.constraint_name = col.constraint_name and c.constraint_type = 'P' and c.table_name = '" . strtoupper($tableName) . "' ) b where table_name = '" . strtoupper($tableName) . "' and a.column_name = b.column_name (+)";
-        $pdo    = $this->getPDOStatement($sql);
+        $pdo = $this->getPDOStatement($sql);
         $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
-        $info   = [];
+        $info = [];
 
         if (!empty($result)) {
             foreach ($result as $key => $val) {
-                $val                       = array_change_key_case($val);
+                $val = array_change_key_case($val);
+
                 $info[$val['column_name']] = [
-                    'name'    => $val['column_name'],
-                    'type'    => $val['data_type'],
-                    'notnull' => $val['notnull'],
+                    'name' => $val['column_name'],
+                    'type' => $val['data_type'],
+                    'notnull' => 1 == $val['notnull'],
                     'default' => $val['data_default'],
-                    'primary' => $val['pk'],
-                    'autoinc' => $val['pk'],
+                    'primary' => $val['pk'] == 1,
+                    'autoinc' => $val['pk'] == 1,
+                    'comment' => '',
                 ];
             }
         }
@@ -84,20 +94,22 @@ class Dm extends PDOConnection
     }
 
     /**
-     * 取得数据库的表信息.
-     *
-     * @param string $dbName
-     *
+     * 取得数据库的表信息
+     * @access public
+     * @param  string $dbName
      * @return array
      */
     public function getTables(string $dbName = ''): array
     {
-        $pdo    = $this->linkID->query("select table_name from all_tables");
+        $sql = " SELECT table_name FROM USER_TABLES  where TABLESPACE_NAME='MAIN'";
+        $pdo = $this->getPDOStatement($sql);
         $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
-        $info   = [];
+        $info = [];
+
         foreach ($result as $key => $val) {
             $info[$key] = current($val);
         }
+
         return $info;
     }
 
@@ -108,9 +120,8 @@ class Dm extends PDOConnection
 
     /**
      * 启动XA事务
-     *
-     * @param string $xid XA事务id
-     *
+     * @access public
+     * @param  string $xid XA事务id
      * @return void
      */
     public function startTransXa(string $xid): void
@@ -119,43 +130,4 @@ class Dm extends PDOConnection
         $this->linkID->exec("XA START '$xid'");
     }
 
-    /**
-     * 预编译XA事务
-     *
-     * @param string $xid XA事务id
-     *
-     * @return void
-     */
-    public function prepareXa(string $xid): void
-    {
-        $this->initConnect(true);
-        $this->linkID->exec("XA END '$xid'");
-        $this->linkID->exec("XA PREPARE '$xid'");
-    }
-
-    /**
-     * 提交XA事务
-     *
-     * @param string $xid XA事务id
-     *
-     * @return void
-     */
-    public function commitXa(string $xid): void
-    {
-        $this->initConnect(true);
-        $this->linkID->exec("XA COMMIT '$xid'");
-    }
-
-    /**
-     * 回滚XA事务
-     *
-     * @param string $xid XA事务id
-     *
-     * @return void
-     */
-    public function rollbackXa(string $xid): void
-    {
-        $this->initConnect(true);
-        $this->linkID->exec("XA ROLLBACK '$xid'");
-    }
 }

+ 0 - 7
jcjyhr/vendor/topthink/think-orm/src/model/concern/Attribute.php

@@ -33,13 +33,6 @@ trait Attribute
      */
     protected $pk = 'id';
 
-    /**
-     * 数据表主键自增.
-     *
-     * @var bool|null|string
-     */
-    protected $autoInc;
-
     /**
      * 数据表字段信息 留空则自动获取.
      *

+ 0 - 64
jcjyhr/vendor/topthink/think-orm/src/model/concern/AutoWriteId.php

@@ -1,64 +0,0 @@
-<?php
-
-// +----------------------------------------------------------------------
-// | ThinkPHP [ WE CAN DO IT JUST THINK ]
-// +----------------------------------------------------------------------
-// | Copyright (c) 2006~2023 http://thinkphp.cn All rights reserved.
-// +----------------------------------------------------------------------
-// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
-// +----------------------------------------------------------------------
-// | Author: liu21st <liu21st@gmail.com>
-// +----------------------------------------------------------------------
-declare (strict_types = 1);
-
-namespace think\model\concern;
-
-/**
- * 自动写入主键.
- */
-trait AutoWriteId
-{
-    /**
-     * 是否需要自动写入主键.
-     *
-     * @var false|callable
-     */
-    protected $autoWriteId = false;
-
-    /**
-     * 是否需要自动写入.
-     *
-     * @return bool
-     */
-    public function isAutoWriteId(): bool
-    {
-        return $this->autoWriteId ? true : false;
-    }
-
-    /**
-     * 设置自动写入方法.
-     *
-     * @param callable $callable
-     *
-     * @return $this
-     */
-    public function setAutoWriteId(callable $callable)
-    {
-        $this->autoWriteId = $callable;
-
-        return $this;
-    }
-
-    /**
-     * 自动写入主键.
-     *
-     * @return mixed
-     */
-    protected function autoWriteId()
-    {
-        $build = $this->autoWriteId;
-
-        return is_callable($build) ? $build() : '';
-    }
-
-}

+ 1 - 1
jcjyhr/vendor/topthink/think-orm/src/model/concern/Conversion.php

@@ -132,7 +132,7 @@ trait Conversion
                     throw new Exception('bind attr has exists:' . $key);
                 }
 
-                $this->data[$key] = $model->getAttr($attr);
+                $this->data[$key] = $model->$attr;
             }
         }
 

+ 1 - 1
jcjyhr/vendor/topthink/think-orm/src/model/concern/RelationShip.php

@@ -384,7 +384,7 @@ trait RelationShip
                 throw new Exception('bind attr has exists:' . $key);
             }
 
-            $this->set($key, $relation ? $relation->getAttr($attr) : null);
+            $this->set($key, $relation ? $relation->$attr : null);
         }
 
         return $this;

+ 0 - 10
jcjyhr/vendor/topthink/think-orm/src/model/contract/EnumTransform.php

@@ -1,10 +0,0 @@
-<?php
-
-declare (strict_types = 1);
-
-namespace think\model\contract;
-
-interface EnumTransform
-{
-    public function value();
-}

+ 0 - 17
jcjyhr/vendor/topthink/think-orm/src/model/contract/FieldTypeTransform.php

@@ -1,17 +0,0 @@
-<?php
-
-declare (strict_types = 1);
-
-namespace think\model\contract;
-
-use think\Model;
-
-interface FieldTypeTransform
-{
-    public static function get(mixed $value, Model $model): ?static;
-
-    /**
-     * @return static|mixed
-     */
-    public static function set($value, Model $model) : mixed;
-}

+ 1 - 1
jcjyhr/vendor/topthink/think-orm/src/model/relation/HasMany.php

@@ -265,7 +265,7 @@ class HasMany extends Relation
         // 保存关联表数据
         $data[$this->foreignKey] = $this->parent->{$this->localKey};
 
-        return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
+        return new $this->model($data);
     }
 
     /**

+ 1 - 1
jcjyhr/vendor/topthink/think-orm/src/model/relation/MorphMany.php

@@ -325,7 +325,7 @@ class MorphMany extends Relation
         $data[$this->morphKey]  = $this->parent->$pk;
         $data[$this->morphType] = $this->type;
 
-        return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
+        return new $this->model($data);
     }
 
     /**

+ 2 - 2
jcjyhr/vendor/topthink/think-orm/src/model/relation/MorphOne.php

@@ -300,7 +300,7 @@ class MorphOne extends Relation
         $data[$this->morphKey]  = $this->parent->$pk;
         $data[$this->morphType] = $this->type;
 
-        return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
+        return new $this->model($data);
     }
 
     /**
@@ -365,7 +365,7 @@ class MorphOne extends Relation
                 throw new Exception('bind attr has exists:' . $key);
             }
 
-            $result->setAttr($key, $model?->getAttr($attr));
+            $result->setAttr($key, $model?->$attr);
         }
     }
 }

+ 10 - 12
jcjyhr/vendor/topthink/think-orm/src/model/relation/MorphTo.php

@@ -243,20 +243,18 @@ class MorphTo extends Relation
             foreach ($range as $key => $val) {
                 // 多态类型映射
                 $model = $this->parseModel($key);
+                $obj = new $model();
+                if (!is_null($closure)) {
+                    $obj = $closure($obj);
+                }
+                $pk = $obj->getPk();
+                $list = $obj->with($subRelation)
+                    ->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
+                    ->select($val);
                 $data = [];
-                if (class_exists($model)) {
-                    $obj = new $model();
-                    if (!is_null($closure)) {
-                        $obj = $closure($obj);
-                    }
-                    $pk = $obj->getPk();
-                    $list = $obj->with($subRelation)
-                        ->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
-                        ->select($val);
 
-                    foreach ($list as $k => $vo) {
-                        $data[$vo->$pk] = $vo;
-                    }
+                foreach ($list as $k => $vo) {
+                    $data[$vo->$pk] = $vo;
                 }
 
                 foreach ($resultSet as $result) {

+ 9 - 9
jcjyhr/vendor/topthink/think-orm/src/model/relation/OneToOne.php

@@ -90,9 +90,9 @@ abstract class OneToOne extends Relation
         }
 
         // 预载入封装
-        $joinTable  = $this->query->getTable();
-        $joinAlias  = $relation;
-        $joinType   = $joinType ?: $this->joinType;
+        $joinTable = $this->query->getTable();
+        $joinAlias = $relation;
+        $joinType = $joinType ?: $this->joinType;
 
         $query->via($joinAlias);
 
@@ -232,7 +232,7 @@ abstract class OneToOne extends Relation
         // 保存关联表数据
         $data[$this->foreignKey] = $this->parent->{$this->localKey};
 
-        return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
+        return new $this->model($data);
     }
 
     /**
@@ -274,8 +274,8 @@ abstract class OneToOne extends Relation
         foreach ($result->getData() as $key => $val) {
             if (str_contains($key, '__')) {
                 [$name, $attr] = explode('__', $key, 2);
-                if ($name == $relation) {
-                    $list[$name][$attr] = $val;
+                if ($name === strtolower($relation)) {
+                    $list[$relation][$attr] = $val;
                     unset($result->$key);
                 }
             }
@@ -315,14 +315,14 @@ abstract class OneToOne extends Relation
     protected function bindAttr(Model $result, Model $model = null): void
     {
         foreach ($this->bindAttr as $key => $attr) {
-            $key    = is_numeric($key) ? $attr : $key;
-            $value  = $result->getOrigin($key);
+            $key = is_numeric($key) ? $attr : $key;
+            $value = $result->getOrigin($key);
 
             if (!is_null($value)) {
                 throw new Exception('bind attr has exists:' . $key);
             }
 
-            $result->setAttr($key, $model?->getAttr($attr));
+            $result->setAttr($key, $model?->$attr);
         }
     }