Przeglądaj źródła

Merge branch 'master' of git.huaml.com:zhh/huahuibao

shishao-home 6 lat temu
rodzic
commit
a67dfbd966

+ 4 - 0
.gitignore

@@ -1,6 +1,10 @@
 .env
 .idea
 
+#²¹»Ø shish
+.buildpath
+.project
+
 console/runtime/
 
 #ignore

+ 28 - 35
app/backend/controllers/AuthController.php

@@ -1,50 +1,43 @@
 <?php
+
 namespace backend\controllers;
+
+use biz\merchant\services\AdminService;
+use biz\platform\services\WxOpenService;
+use common\components\jwt;
 use common\services\xhAdminService;
 use common\components\util;
 use Yii;
-use yii\web\Controller;
-use common\services\xhMerchantService;
-use common\services\xhUserService;
-use common\components\weixinUtil;
-use common\components\configDict;
 use common\components\stringUtil;
-use common\services\xhWxOpenService;
 
 /**
- * 微信 oauth 授权相关
+ * 登陆验证 shish 2019.11.23
  */
-class AuthController extends PublicController{
-
-	public function actionGetUserInfo()
+class AuthController extends PublicController
+{
+	
+	//登陆并拿到token shish 2019.11.23
+	public function actionLogin()
 	{
-		$get		= Yii::$app->request->get();
-		$code		= isset($get['code']) ? $get['code'] : '';
-		if(isset($get['state']) && $get['state'] == 'authdeny'){
-			util::stop('auth fail');
+		$get = Yii::$app->request->get();
+		$mobile = isset($get['mobile']) ? $get['mobile'] : 0;
+		if (stringUtil::isMobieNumber($mobile) == false) {
+			util::fail('请填写正常的手机号');
+		}
+		$password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
+		if (empty($password)) {
+			util::fail('请输入密码');
 		}
-		$account					= '';
-		$params						= $get['params'];
-		$suffixUrl					= base64_decode($params);
-		$openMerchant				= xhWxOpenService::getMerchant();
-		$user						= [];
-		$baseInfo					= [];
-		$data						= weixinUtil::getOpenId($code,$openMerchant);//没关注公众号,用户授权获取openId
-		$openId						= $data['openid'];
-		$access_token				= $data['access_token'];
-		$admin						= xhAdminService::getByOpenId($openId);
-		if(empty($admin)){
-			if($get['authScope'] == 'snsapi_userinfo'){
-				//经测试,已经关注公众号的粉丝直接点击菜单上的链接时,不走下面的静默自动方式,走这条,也会以静默自动的方式处理获取openId;
-				$baseInfo			= weixinUtil::authGetUserInfo($openId,$access_token);//用户授权方式获取用户信息
-			}else{
-				$baseInfo			= weixinUtil::autoGetUserInfo($openId,$openMerchant);//静默自动方式获取用户信息
-			}
-			$admin					= xhAdminService::generateAdmin($baseInfo);
+		$admin = AdminService::getByCondition(['mobile' => $mobile]);
+		if ($admin['password'] != md5($password)) {
+			util::fail('密码错误');
 		}
-		xhAdminService::loginByThird($admin);
-		$url								= 'http://'.$_SERVER['HTTP_HOST'].$suffixUrl;
-		$this->redirect($url);
+		$adminId = $admin['id'];
+		//来源
+		$sourceId = WxOpenService::getSourceId();
+		//获取token
+		$token = jwt::get($sourceId, $adminId);
+		util::success(['token' => $token]);
 	}
 
 	public function actionLogout()

+ 1 - 0
app/mobile/controllers/AuthController.php

@@ -148,6 +148,7 @@ class AuthController extends PublicController
 		$token = jwt::get($sourceId, $userId);
 		$suffixUrl = strpos($suffixUrl, '?') === false ? $suffixUrl . '?token=' . $token : $suffixUrl . '&token=' . $token;
 		$url = $host . '/' . $suffixUrl;
+		echo $url;die;
 		$this->redirect($url);
 	}
 	

+ 42 - 2
app/mobile/controllers/MainController.php

@@ -5,6 +5,7 @@ namespace mobile\controllers;
 use biz\user\services\UserService;
 use common\components\jwt;
 use common\components\token;
+use common\components\tree;
 use Yii;
 use yii\db\Exception;
 use yii\web\Controller;
@@ -28,13 +29,52 @@ class MainController extends PublicController
 				}
 			}
 		}
-		$host = 'http://mobile.huaml.com/';
+		$host = 'http://mobile.huaml.com';
 		return $this->renderPartial('index', ['host' => $host, 'token' => $token]);
 	}
 
 	public function actionJwt()
 	{
-		echo jwt::create(1,12536630);
+		 $arr = array(
+	       1 => array('id'=>'1','parentid'=>0,'name'=>'一级栏目一'),
+	       2 => array('id'=>'2','parentid'=>0,'name'=>'一级栏目二'),
+	       3 => array('id'=>'3','parentid'=>1,'name'=>'二级栏目一'),
+	       4 => array('id'=>'4','parentid'=>1,'name'=>'二级栏目二'),
+	       5 => array('id'=>'5','parentid'=>2,'name'=>'二级栏目三'),
+	       6 => array('id'=>'6','parentid'=>3,'name'=>'三级栏目一'),
+	       7 => array('id'=>'7','parentid'=>3,'name'=>'三级栏目二')
+	      );
+		
+		
+		
+		$data = array(
+			array(
+				'id'=>1,
+				'name'=>'book',
+				'parent_id'=>0
+			),
+			array(
+				'id'=>2,
+				'name'=>'music',
+				'parent_id'=>0
+			),
+			array(
+				'id'=>3,
+				'name'=>'book1',
+				'parent_id'=>1
+			),
+			array(
+				'id'=>4,
+				'name'=>'book2',
+				'parent_id'=>3
+			)
+		);
+		
+		$r = tree::makeTree($data);
+		echo '<pre>';
+		print_r($r);die;
+
+//		echo jwt::create(1,12536630);
 	}
 	
 }

+ 15 - 0
app/platform/controllers/AuthController.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace platform\controllers;
+
+use Yii;
+
+class AuthController extends PlatformController
+{
+	public function actionList()
+	{
+		$get = Yii::$app->request->get();
+		$endId = isset($get['endId']) ? $get['endId'] : 1;
+	}
+
+}

+ 15 - 0
app/platform/controllers/BaseController.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace platform\controllers;
+
+use Yii;
+use yii\web\Controller;
+
+
+/**
+ * 平台次级基类,次于PublicController
+ */
+class BaseController extends PublicController
+{
+
+}

+ 13 - 0
biz/auth/classes/AuthClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\auth\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class AuthClass extends BaseClass
+{
+	
+	public static $baseFile = '\biz\auth\models\Auth';
+	
+}

+ 13 - 0
biz/auth/models/Auth.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\auth\models;
+use biz\base\models\Base;
+
+class Auth extends Base
+{
+	
+	public static function tableName()
+	{
+		return 'xhAuth';
+	}
+	
+}

+ 13 - 0
biz/auth/services/AuthService.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\auth\services;
+
+use biz\base\services\BaseService;
+use Yii;
+
+class AuthService extends BaseService
+{
+
+	public static $baseFile = '\biz\auth\classes\AuthClass';
+
+}

+ 103 - 0
common/components/tree.php

@@ -0,0 +1,103 @@
+<?php
+namespace common\components;
+/**
+ * @name PHPTree
+ * @author crazymus < QQ:291445576 >
+ * @des PHP生成树形结构,无限多级分类
+ * @version 1.2.0
+ * @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+ * @updated 2015-08-26
+ 
+ */
+class tree{
+	
+	protected static $config = array(
+		/* 主键 */
+		'primary_key' 	=> 'id',
+		/* 父键 */
+		'parent_key'  	=> 'parent_id',
+		/* 展开属性 */
+		'expanded_key'  => 'expanded',
+		/* 叶子节点属性 */
+		'leaf_key'      => 'leaf',
+		/* 孩子节点属性 */
+		'children_key'  => 'children',
+		/* 是否展开子节点 */
+		'expanded'    	=> false
+	);
+	
+	/* 结果集 */
+	protected static $result = array();
+	
+	/* 层次暂存 */
+	protected static $level = array();
+	/**
+	 * @name 生成树形结构
+	 * @param array 二维数组
+	 * @return mixed 多维数组
+	 */
+	public static function makeTree($data,$options=array() ){
+		$dataset = self::buildData($data,$options);
+		$r = self::makeTreeCore(0,$dataset,'normal');
+		return $r;
+	}
+	
+	/* 生成线性结构, 便于HTML输出, 参数同上 */
+	public static function makeTreeForHtml($data,$options=array()){
+		
+		$dataset = self::buildData($data,$options);
+		$r = self::makeTreeCore(0,$dataset,'linear');
+		return $r;
+	}
+	
+	/* 格式化数据, 私有方法 */
+	private static function buildData($data,$options){
+		$config = array_merge(self::$config,$options);
+		self::$config = $config;
+		extract($config);
+		
+		$r = array();
+		foreach($data as $item){
+			$id = $item[$primary_key];
+			$parent_id = $item[$parent_key];
+			$r[$parent_id][$id] = $item;
+		}
+		
+		return $r;
+	}
+	
+	/* 生成树核心, 私有方法  */
+	private static function makeTreeCore($index,$data,$type='linear')
+	{
+		extract(self::$config);
+		foreach($data[$index] as $id=>$item)
+		{
+			if($type=='normal'){
+				if(isset($data[$id]))
+				{
+					$item[$expanded_key]= self::$config['expanded'];
+					$item[$children_key]= self::makeTreeCore($id,$data,$type);
+				}
+				else
+				{
+					$item[$leaf_key]= true;
+				}
+				$r[] = $item;
+			}else if($type=='linear'){
+				$parent_id = $item[$parent_key];
+				self::$level[$id] = $index==0?0:self::$level[$parent_id]+1;
+				$item['level'] = self::$level[$id];
+				self::$result[] = $item;
+				if(isset($data[$id])){
+					self::makeTreeCore($id,$data,$type);
+				}
+				
+				$r = self::$result;
+			}
+		}
+		return $r;
+	}
+}
+
+
+?>

+ 1 - 1
common/config/main-local.php

@@ -16,7 +16,7 @@ $config = [
 			'class' => 'yii\db\Connection',
 			'dsn' => 'mysql:host=127.0.0.1;dbname=huahuibao',
 			'username' => 'root',
-			'password' => '353167',
+			'password' => 'zt20152008',
 			'charset' => 'utf8',
 		],
 	],

+ 30 - 0
sql.txt

@@ -1,3 +1,33 @@
+shish 2019.11.23
+DROP TABLE IF EXISTS xhAuth;
+CREATE TABLE xhAuth(
+id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+endId TINYINT NOT NULL DEFAULT 0 COMMENT '业务端,零售1',
+parentId INT NOT NULL DEFAULT 0 COMMENT '权限父id',
+authName VARCHAR(30) NOT NULL DEFAULT '' COMMENT '权限名称',
+front_url VARCHAR(30) NOT NULL DEFAULT '' COMMENT '前端路由',
+back_url VARCHAR(30) NOT NULL DEFAULT '' COMMENT '后端路由',
+`addTime` INT(11) NOT NULL DEFAULT '0' COMMENT '添加时间'
+)COMMENT='各业务端的权限';
+DROP TABLE IF EXISTS xhSetAuth;
+CREATE TABLE xhSetAuth(
+id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+setId TINYINT NOT NULL DEFAULT 0 COMMENT '套餐id',
+endId TINYINT NOT NULL DEFAULT 0 COMMENT '业务端id',
+auth VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '权限',
+`addTime` INT(11) NOT NULL DEFAULT '0' COMMENT '添加时间'
+)COMMENT='套餐在各业务端的权限';
+CREATE TABLE xhAdminRoleAuth(
+id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+roleId INT NOT NULL DEFAULT 0 COMMENT '角色id',
+auth VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '权限',
+`addTime` INT(11) NOT NULL DEFAULT '0' COMMENT '添加时间'
+)COMMENT='员工角色权限'
+
+
+shish 2019.11.23
+jwt的过期时间要设置得短点
+
 shish 2019.11.22
 !!注意要将成积分移到成长值里