Commit 8af01f20 by feixiang

实体分表逻辑修改

parent 488d0b21
...@@ -93,12 +93,17 @@ class CommonEntity extends Model ...@@ -93,12 +93,17 @@ class CommonEntity extends Model
//获取注解里的table //获取注解里的table
$res = new \ReflectionClass(static::class); $res = new \ReflectionClass(static::class);
self::$commentString = $res->getDocComment(); $commentString = $res->getDocComment();
if ( false !== strpos(self::$commentString,"{split}") && !App::$isInTest) { if (
(
false !== strpos($commentString,"{split}")
|| false !== strpos($commentString,"@Split()")
)
&& !App::$isInTest) {
$dbNum = self::getDbNum(); $dbNum = self::getDbNum();
$tableName = self::getTableName().'_'.$dbNum; $tableName = self::getTableName($commentString).'_'.$dbNum;
self::setTableName($tableName); //self::setTableName($tableName);
return $tableName; return $tableName;
} else { } else {
...@@ -143,9 +148,10 @@ class CommonEntity extends Model ...@@ -143,9 +148,10 @@ class CommonEntity extends Model
* 获取原始表名 * 获取原始表名
* @return string * @return string
*/ */
protected static function getTableName() protected static function getTableName($commentString = '')
{ {
preg_match('/(?<=Table\(name=").*(?="\))/', self::$commentString, $matches); $commentString = $commentString === ''?self::$commentString:$commentString;
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
return $tableName = isset($matches[0])?$matches[0]:''; return $tableName = isset($matches[0])?$matches[0]:'';
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment