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
8c41e667
Commit
8c41e667
authored
Jul 13, 2018
by
zhufx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公共实体增加
parent
0fb1c773
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
185 additions
and
1 deletions
+185
-1
src/Common/Controller/BaseController.php
+13
-1
src/Common/Entity/CommonEntity.php
+55
-0
src/Common/Entity/User.php
+117
-0
No files found.
src/Common/Controller/BaseController.php
View file @
8c41e667
<?php
<?php
namespace
Hdll\Services\Common\Controller
;
namespace
Hdll\Services\Common\Controller
;
use
Hdll\Services\Common\Entity\User
;
// use Swoft\Http\Message\Server\Request;
/**
/**
* 活动啦啦Controller基类
* 活动啦啦Controller基类
...
@@ -9,6 +9,18 @@ namespace Hdll\Services\Common\Controller;
...
@@ -9,6 +9,18 @@ namespace Hdll\Services\Common\Controller;
*/
*/
class
BaseController
class
BaseController
{
{
public
function
__construct
()
{
User
::
getIns
(
2
);
$this
->
init
();
}
protected
function
init
()
{
}
/**
/**
* 业务层-错误时响应
* 业务层-错误时响应
*
*
...
...
src/Common/Entity/CommonEntity.php
0 → 100644
View file @
8c41e667
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/2
* Time: 13:49
*/
namespace
Hdll\Services\Common\Entity
;
use
Swoft\Db\Bean\Collector\EntityCollector
;
use
Swoft\Db\Model
;
class
CommonEntity
extends
Model
{
public
function
__construct
(
array
$attributes
=
[])
{
parent
::
__construct
(
$attributes
);
$user
=
User
::
getIns
();
$dbNum
=
$user
->
getStoreId
()
%
100
;
//获取注解里的table
$res
=
new
\ReflectionClass
(
static
::
class
);
$commentString
=
$res
->
getDocComment
();
preg_match
(
'/(?<=Table\(name=").*(?="\))/'
,
$commentString
,
$matches
);
$tableName
=
isset
(
$matches
[
0
])
?
$matches
[
0
]
:
''
;
EntityCollector
::
collect
(
static
::
class
,
new
\Swoft\Db\Bean\Annotation\Table
([
'name'
=>
$tableName
.
'_'
.
$dbNum
])
);
}
public
static
function
getDb
()
{
$user
=
User
::
getIns
();
$dbNum
=
$user
->
getStoreId
()
%
100
;
//获取注解里的table
$res
=
new
\ReflectionClass
(
static
::
class
);
$commentString
=
$res
->
getDocComment
();
preg_match
(
'/(?<=Table\(name=").*(?="\))/'
,
$commentString
,
$matches
);
$tableName
=
isset
(
$matches
[
0
])
?
$matches
[
0
]
:
''
;
EntityCollector
::
collect
(
static
::
class
,
new
\Swoft\Db\Bean\Annotation\Table
([
'name'
=>
$tableName
.
'_'
.
$dbNum
])
);
return
new
static
();
}
}
\ No newline at end of file
src/Common/Entity/User.php
0 → 100644
View file @
8c41e667
<?php
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://doc.swoft.org
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace
Hdll\Services\Common\Entity
;
use
Swoft\Db\Bean\Annotation\Id
;
use
Swoft\Db\Bean\Annotation\Required
;
use
Swoft\Db\Bean\Annotation\Table
;
use
Swoft\Db\Bean\Annotation\Column
;
use
Swoft\Db\Bean\Annotation\Entity
;
use
Swoft\Db\Model
;
use
Swoft\Db\Types
;
/**
* 用户实体
*
* @uses User
* @version 2017年08月23日
* @author stelin <phpcrazy@126.com>
* @copyright Copyright 2010-2016 Swoft software
* @license PHP Version 7.x {@link http://www.php.net/license/3_0.txt}
*/
class
User
{
private
$id
;
private
$nick_name
;
private
$store_id
;
private
$head_img
;
private
$token
;
private
static
$ins
;
final
private
function
__construct
(
$token
=
''
)
{
$this
->
setHeadImg
(
"test"
);
$this
->
setId
(
1
);
$this
->
setNickName
(
"zhangsan"
);
$this
->
setStoreId
(
"2"
);
$this
->
setToken
(
$token
);
}
public
static
function
getIns
(
$token
=
''
)
{
if
(
self
::
$ins
instanceof
self
)
{
return
self
::
$ins
;
}
return
new
self
(
$token
);
}
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getNickName
()
{
return
$this
->
nick_name
;
}
public
function
getStoreId
()
{
return
$this
->
store_id
;
}
public
function
getHeadImg
()
{
return
$this
->
head_img
;
}
public
function
getToken
()
{
return
$this
->
token
;
}
public
function
setId
(
$value
)
{
return
$this
->
id
=
$value
;
}
public
function
setNickName
(
$value
)
{
return
$this
->
nick_name
=
$value
;
}
public
function
setStoreId
(
$value
)
{
return
$this
->
store_id
=
$value
;
}
public
function
setHeadImg
(
$value
)
{
return
$this
->
head_img
=
$value
;
}
public
function
setToken
(
$value
)
{
return
$this
->
token
=
$value
;
}
}
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