117 lines
3.8 KiB
PHP
117 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
|
|
namespace addon\saas\model;
|
|
|
|
use app\model\BaseModel;
|
|
|
|
class ManageNode extends BaseModel
|
|
{
|
|
|
|
/***
|
|
* 添加节点
|
|
* @param $param
|
|
* @return bool
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function addNode($param)
|
|
{
|
|
if (isset($param['manage_id']) && isset($param['parent'])) {
|
|
$manage_id = $param['manage_id'];
|
|
$depth_level = 1;
|
|
$district = 1;
|
|
$chain = '#' . $manage_id . '#';
|
|
$grand_parent = 0;
|
|
if (isset($param['parent']) && $param['parent']) {
|
|
$pidInfo = model('manage_user')->getInfo(['id' => $param['parent']], 'chain,district,depth_level,parent,grand_parent');
|
|
if ($pidInfo) {
|
|
$depth_level = $pidInfo['depth_level'] + 1;
|
|
$district = $pidInfo['district'] + 1;
|
|
$chain = $pidInfo['chain'] . $param['manage_id'] . '#';
|
|
$grand_parent = $pidInfo['grand_parent'];
|
|
}
|
|
}
|
|
$data = [
|
|
'parent' => $param['parent'],
|
|
'grand_parent' => $grand_parent,
|
|
'district' => $param['district'] ?? $district,
|
|
'depth_level' => $depth_level,
|
|
'chain' => $chain,
|
|
];
|
|
return $data;
|
|
}
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 移动节点
|
|
* @param $id 移动会员iD
|
|
* @param $pid 所属ID
|
|
*/
|
|
public function moveNode($manage_id, $pid)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
/***
|
|
* 获取上级节点
|
|
* @param $id 管理ID
|
|
* @param $depth_level 层级深度
|
|
* @param $depth_group 分组
|
|
*/
|
|
public function getUpUserNode($id, $field = '*', $depth_level = '', $ext_where = [])
|
|
{
|
|
$where[] = ['id', '=', $id];
|
|
$chain = model('manage_user')->getvalue($where, 'chain');
|
|
$uids = array_filter(explode('#', $chain));
|
|
arsort($uids);
|
|
$w[] = ['id', 'in', $uids];
|
|
$w[] = ['id', '<>', $id];
|
|
$userInfo = model('manage_user')->getList($w, $field, 'depth_level desc,create_time desc');
|
|
return $userInfo;
|
|
}
|
|
|
|
|
|
/***
|
|
* 获取下级全部用户
|
|
* @param $id
|
|
* @param string $depth_group
|
|
* @param string $field
|
|
* @param string $depth_level
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getUserNodeDownALL($id, $depth_group = '', $field = '*', $depth_level = '')
|
|
{
|
|
$where = [];
|
|
if ($depth_group) {
|
|
$where[] = ['depth_group', '=', $depth_group];
|
|
}
|
|
if ($depth_level) {
|
|
if (!is_numeric($depth_level)) {
|
|
$depth_level = $this->where('id', $id)->value('depth_level') + 1;
|
|
}
|
|
$where[] = ['depth_level', '>', $depth_level];
|
|
}
|
|
$where[] = ['id', '<>', $id];
|
|
$where[] = ['chain', 'like', "%#{$id}-%"];
|
|
$info = $this->where($where)->field($field)->select()->toArray();
|
|
return $info;
|
|
}
|
|
}
|