shish пре 6 година
родитељ
комит
0908936602

+ 41 - 1
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;
@@ -34,7 +35,46 @@ class MainController extends PublicController
 
 	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;
+	}
+}
+
+
+?>