Commit 46326144 authored by 郭勇志's avatar 郭勇志

分库

parent b224a28d
...@@ -17,5 +17,12 @@ return [ ...@@ -17,5 +17,12 @@ return [
'password' => '', 'password' => '',
'charset' => 'utf8', 'charset' => 'utf8',
], ],
'db-101' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=weishopdbt',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
] ]
]; ];
...@@ -4,7 +4,8 @@ namespace app\models\v1\user; ...@@ -4,7 +4,8 @@ namespace app\models\v1\user;
use Yii; use Yii;
use yii\web\IdentityInterface; use yii\web\IdentityInterface;
use app\models\v1\BaseModel; use app\models\v1\BaseModel;
use yii\web\HttpException;
/** /**
* This is the model class for table "shop_rbac_user". * This is the model class for table "shop_rbac_user".
* *
...@@ -33,7 +34,6 @@ use app\models\v1\BaseModel; ...@@ -33,7 +34,6 @@ use app\models\v1\BaseModel;
* @property string $WX_OPENID 小程序OPENID * @property string $WX_OPENID 小程序OPENID
* @property int $AGE 年龄 * @property int $AGE 年龄
* @property string $SHARE_NO 分享码 * @property string $SHARE_NO 分享码
* @property string $ACCESS_TOKEN 验证TOKEN
*/ */
class ShopRbacUser extends BaseModel implements IdentityInterface class ShopRbacUser extends BaseModel implements IdentityInterface
{ {
...@@ -54,7 +54,7 @@ class ShopRbacUser extends BaseModel implements IdentityInterface ...@@ -54,7 +54,7 @@ class ShopRbacUser extends BaseModel implements IdentityInterface
[['GUID', 'CODE'], 'required'], [['GUID', 'CODE'], 'required'],
[['CREATE_DATE', 'UPDATE_DATE'], 'safe'], [['CREATE_DATE', 'UPDATE_DATE'], 'safe'],
[['IS_FORBID', 'CONTACTSEX', 'IS_UPLOAD_HX', 'IS_BELONG', 'AGE'], 'integer'], [['IS_FORBID', 'CONTACTSEX', 'IS_UPLOAD_HX', 'IS_BELONG', 'AGE'], 'integer'],
[['GUID', 'CODE', 'PASSWORD', 'ORG_GUID', 'EMPLOYEE_GUID', 'CREATE_GUID', 'UPDATE_GUID', 'MOBILEPHONE', 'USER_GUID', 'REMARK', 'ALIPAY_UID', 'WX_UNIONID', 'WX_OPENID', 'SHARE_NO', 'ACCESS_TOKEN'], 'string', 'max' => 50], [['GUID', 'CODE', 'PASSWORD', 'ORG_GUID', 'EMPLOYEE_GUID', 'CREATE_GUID', 'UPDATE_GUID', 'MOBILEPHONE', 'USER_GUID', 'REMARK', 'ALIPAY_UID', 'WX_UNIONID', 'WX_OPENID', 'SHARE_NO'], 'string', 'max' => 50],
[['NAME', 'CREATE_NAME', 'UPDATE_NAME'], 'string', 'max' => 100], [['NAME', 'CREATE_NAME', 'UPDATE_NAME'], 'string', 'max' => 100],
[['DESCRIPTION'], 'string', 'max' => 255], [['DESCRIPTION'], 'string', 'max' => 255],
[['GUID'], 'unique'], [['GUID'], 'unique'],
...@@ -92,7 +92,6 @@ class ShopRbacUser extends BaseModel implements IdentityInterface ...@@ -92,7 +92,6 @@ class ShopRbacUser extends BaseModel implements IdentityInterface
'WX_OPENID' => 'Wx Openid', 'WX_OPENID' => 'Wx Openid',
'AGE' => 'Age', 'AGE' => 'Age',
'SHARE_NO' => 'Share No', 'SHARE_NO' => 'Share No',
'ACCESS_TOKEN' => 'Access Token',
]; ];
} }
/** /**
...@@ -112,8 +111,8 @@ class ShopRbacUser extends BaseModel implements IdentityInterface ...@@ -112,8 +111,8 @@ class ShopRbacUser extends BaseModel implements IdentityInterface
*/ */
public function generateAccessToken() public function generateAccessToken()
{ {
$this->ACCESS_TOKEN= Yii::$app->security->generateRandomString(); $accessToken= Yii::$app->security->generateRandomString();
return $this->ACCESS_TOKEN; return $accessToken;
} }
/** /**
* 根据给到的ID查询身份。 * 根据给到的ID查询身份。
...@@ -133,7 +132,6 @@ class ShopRbacUser extends BaseModel implements IdentityInterface ...@@ -133,7 +132,6 @@ class ShopRbacUser extends BaseModel implements IdentityInterface
*/ */
public static function findIdentityByAccessToken($token, $type = null) public static function findIdentityByAccessToken($token, $type = null)
{ {
// return static::findOne(['ACCESS_TOKEN' => $token]);
// 取得reids中用户信息 // 取得reids中用户信息
$redis = Yii::$app->redis; $redis = Yii::$app->redis;
$model = new ShopRbacUser; $model = new ShopRbacUser;
...@@ -141,12 +139,14 @@ class ShopRbacUser extends BaseModel implements IdentityInterface ...@@ -141,12 +139,14 @@ class ShopRbacUser extends BaseModel implements IdentityInterface
if ($rtnGet) { if ($rtnGet) {
$userInfo=json_decode($rtnGet,true); $userInfo=json_decode($rtnGet,true);
$db=DB_PREFIX.$userInfo['ORG_GUID']; $db=DB_PREFIX.$userInfo['ORG_GUID'];
$dbObj = \Yii::$app->$db; $dbObj = \Yii::$app->$db;
$query = new \yii\db\Query(); $query = new \yii\db\Query();
$temp=$query->where(array('GUID'=>$userInfo['USER_GUID']))->from('shop_rbac_user')->limit(1)->one($dbObj); $temp=$query->where(array('GUID'=>$userInfo['USER_GUID']))->from('shop_rbac_user')->limit(1)->one($dbObj);
$model->attributes = $temp; if (!empty($temp)) {
return $model; $model->attributes = $temp;
return $model;
}
throw new HttpException('404','用户存在');
} }
return false; return false;
......
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