90 lines
2.0 KiB
PHP
90 lines
2.0 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Organization_model extends HD_Model
|
|
{
|
|
private $table_name = 'lc_organization';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct($this->table_name, 'default');
|
|
}
|
|
|
|
/**
|
|
* @param $id
|
|
* @return int
|
|
*/
|
|
public function getLevel($id)
|
|
{
|
|
$level = 0;
|
|
while ($id) {
|
|
$row = $this->get(['id' => $id]);
|
|
$id = $row['parentId'] ?: 0;
|
|
if ($id) {
|
|
$level++;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
return $level;
|
|
}
|
|
|
|
/**
|
|
* 获取团队有几级
|
|
* @param $teamId
|
|
* @return int
|
|
*/
|
|
public function getTeamLevel($teamId)
|
|
{
|
|
$level = 0;
|
|
$id = $teamId;
|
|
while ($id > 0) {
|
|
$row = $this->get(['parentId' => $id]);
|
|
$id = $row['id'] ?: 0;
|
|
if ($id) {
|
|
$level++;
|
|
}
|
|
}
|
|
return $level;
|
|
}
|
|
|
|
/**
|
|
* @param $ids
|
|
* @param $fileds
|
|
* @param $map_key
|
|
* @param $map_name
|
|
* @return array
|
|
*/
|
|
public function get_map_by_ids($ids, $fileds = '', $map_key = 'id', $map_name = '')
|
|
{
|
|
$rows = [];
|
|
$ids = array_unique($ids);
|
|
if ($ids) {
|
|
$cf_ids = implode(',', $ids);
|
|
$where = [
|
|
"id in ($cf_ids)" => null
|
|
];
|
|
$rows = $this->map($map_key, $map_name, $where, '', '', '', $fileds);
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
/**
|
|
* 根据团队id获取来源id
|
|
* @param $teamId
|
|
* @return int[]
|
|
*/
|
|
public function getCfIdByTeamId($teamId)
|
|
{
|
|
$result = ['cfId' => 0, 'cf2Id' => 0];
|
|
$row = $this->get(['id' => $teamId]);
|
|
if ($row) {
|
|
$result['cf2Id'] = $row['cfId'] ?: 0;
|
|
if ($row['parentId'] > 0) {
|
|
$pRow = $this->get(['id' => $row['parentId']]);
|
|
$result['cfId'] = $pRow['cfId'] ?: 0;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
} |