You've already forked qlg.tsgz.moe
购物车分类
This commit is contained in:
69
hyhproject/app/controller/UserLevel.php
Normal file
69
hyhproject/app/controller/UserLevel.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\app\controller;
|
||||
|
||||
use wstmart\app\model\Users;
|
||||
use wstmart\common\model\UserLevel as UL;
|
||||
use wstmart\common\model\UserTrees as UT;
|
||||
|
||||
use think\Collection;
|
||||
|
||||
/**
|
||||
* ============================================================================
|
||||
* 用户控制器
|
||||
*/
|
||||
class UserLevel extends Base
|
||||
{
|
||||
|
||||
protected $beforeActionList = [
|
||||
'checkAuth' => ['except'=>'']// 访问这些except下的方法不需要执行前置操作
|
||||
];
|
||||
|
||||
/**
|
||||
* index
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author 倪苍华 <canghua.cc@gmail.com>
|
||||
* Date 2019/9/10 10:37
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$userId = get_my_id();
|
||||
$User = UT::getMyLevel($userId);
|
||||
return $User;
|
||||
}
|
||||
|
||||
/**
|
||||
* TreeList
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author 倪苍华 <canghua.cc@gmail.com>
|
||||
* Date 2019/9/10 11:18
|
||||
*/
|
||||
public function TreeList()
|
||||
{
|
||||
$userId = get_my_id();
|
||||
$count = UL::where(['uid' => $userId])->group("level")->count();
|
||||
$treeArr = [];
|
||||
$newLevel = 1;
|
||||
do {
|
||||
if ($newLevel > 10) break;
|
||||
$treeArr[$newLevel]['level'] = UT::$level[$newLevel];
|
||||
$ptree = UT::where(['uid' => $userId])->find();// 找到我的层级
|
||||
$userId = $ptree->pid;// 上级uid
|
||||
if ($userId == 0) $userId = 1;// 上级uid
|
||||
$plevel = UL::where(['uid' => $userId, 'level' => $newLevel])->find();// 查看上级是否有权限助购
|
||||
if ($plevel) {// 如果有,则使用上级信息
|
||||
$treeArr[$newLevel]['userId'] = $userId;
|
||||
$user = Users::where(['userId' => $plevel->uid])->find();
|
||||
$treeArr[$newLevel]['userName'] = $user->userName ?: $user->loginName;
|
||||
$newLevel++;
|
||||
}
|
||||
// 如果没有,则递归查询上级信息
|
||||
} while ($newLevel < ($count + 2));
|
||||
// pd($treeArr);
|
||||
return $treeArr;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user