Commit 8c41e667 by zhufx

公共实体增加

parent 0fb1c773
<?php
namespace Hdll\Services\Common\Controller;
use Hdll\Services\Common\Entity\User;
// use Swoft\Http\Message\Server\Request;
/**
* 活动啦啦Controller基类
......@@ -9,6 +9,18 @@ namespace Hdll\Services\Common\Controller;
*/
class BaseController
{
public function __construct()
{
User::getIns(2);
$this->init();
}
protected function init()
{
}
/**
* 业务层-错误时响应
*
......
<?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
<?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;
}
}
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