Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
9e7121ac
Commit
9e7121ac
authored
Jul 25, 2018
by
zhufx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.重构设置实体表名代码
2.订单错误码更新
parent
b8d02185
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
27 deletions
+62
-27
src/Common/Entity/CommonEntity.php
+62
-21
src/Order/Enum/OrderError.php
+0
-6
No files found.
src/Common/Entity/CommonEntity.php
View file @
9e7121ac
...
...
@@ -8,9 +8,11 @@
namespace
Hdll\Services\Common\Entity
;
use
Swoft\App
;
use
Swoft\Core\RequestContext
;
use
Swoft\Db\Bean\Collector\EntityCollector
;
use
Swoft\Db\Model
;
use
Swoft\Exception\Exception
;
use
Swoole\Http\Request
;
class
CommonEntity
extends
Model
{
...
...
@@ -23,20 +25,16 @@ class CommonEntity extends Model
//获取注解里的table
$res
=
new
\ReflectionClass
(
static
::
class
);
self
::
$commentString
=
$res
->
getDocComment
();
if
(
false
!==
strpos
(
self
::
$commentString
,
"
{
split
}
"
)
)
{
$dbNum
=
self
::
getDbNum
();
self
::
setTableName
(
$dbNum
);
}
//分表逻辑
$this
->
split
();
$this
->
init
();
}
/**
* 初始化
*/
public
function
init
()
{
...
...
@@ -48,23 +46,68 @@ class CommonEntity extends Model
$res
=
new
\ReflectionClass
(
static
::
class
);
self
::
$commentString
=
$res
->
getDocComment
();
if
(
false
!==
strpos
(
self
::
$commentString
,
"
{
split
}
"
)
)
{
$dbNum
=
self
::
getDbNum
();
self
::
setTableName
(
$dbNum
);
//分表逻辑
self
::
split
();
return
new
static
;
}
/**
* 设置分表表名
* @throws Exception
*/
protected
function
split
()
{
$request
=
RequestContext
::
getRequest
();
if
(
empty
(
$request
)
)
{
//初始化不做处理
return
;
}
return
new
static
();
$testFlag
=
$request
->
query
(
'flag'
);
if
(
false
===
strpos
(
self
::
$commentString
,
"
{
split
}
"
)
||
$testFlag
==
'hdllTest'
)
{
return
;
}
$dbNum
=
self
::
getDbNum
();
$tableName
=
self
::
getTableName
();
self
::
setTableName
(
$tableName
.
'_'
.
$dbNum
);
}
/**
* 获取分库表明
* 获取分库表名
*
* @return string|void
* @throws Exception
* @throws \ReflectionException
*/
public
static
function
tableName
()
{
$num
=
self
::
getDbNum
();
return
self
::
getTableName
()
.
'_'
.
$num
;
$request
=
RequestContext
::
getRequest
();
if
(
empty
(
$request
)
)
{
//初始化不做处理
return
;
}
$testFlag
=
$request
->
query
(
'flag'
);
//获取注解里的table
$res
=
new
\ReflectionClass
(
static
::
class
);
self
::
$commentString
=
$res
->
getDocComment
();
if
(
false
!==
strpos
(
self
::
$commentString
,
"
{
split
}
"
)
&&
$testFlag
!=
'hdllTest'
)
{
$dbNum
=
self
::
getDbNum
();
$tableName
=
self
::
getTableName
()
.
'_'
.
$dbNum
;
self
::
setTableName
(
$tableName
);
return
$tableName
;
}
else
{
return
self
::
getTableName
();
}
}
/**
...
...
@@ -89,13 +132,11 @@ class CommonEntity extends Model
* 设置表名
* @param $dbNum
*/
pr
ivate
static
function
setTableName
(
$dbNum
)
pr
otected
static
function
setTableName
(
$tableName
)
{
$tableName
=
self
::
getTableName
();
EntityCollector
::
collect
(
static
::
class
,
new
\Swoft\Db\Bean\Annotation\Table
([
'name'
=>
$tableName
.
'_'
.
$dbNum
])
new
\Swoft\Db\Bean\Annotation\Table
([
'name'
=>
$tableName
])
);
}
...
...
@@ -104,7 +145,7 @@ class CommonEntity extends Model
* 获取原始表名
* @return string
*/
pr
ivate
static
function
getTableName
()
pr
otected
static
function
getTableName
()
{
preg_match
(
'/(?<=Table\(name=").*(?="\))/'
,
self
::
$commentString
,
$matches
);
return
$tableName
=
isset
(
$matches
[
0
])
?
$matches
[
0
]
:
''
;
...
...
src/Order/Enum/OrderError.php
View file @
9e7121ac
...
...
@@ -43,12 +43,6 @@ class OrderError
const
DB_ERROR
=
[
"msg"
=>
"数据库操作错误"
,
"code"
=>
500
,
"errorCode"
=>
22118
];
public
static
function
atranslate
(
$message
,
$param
)
{
if
(
empty
(
$param
)
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment