You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.8 KiB
PHTML

<?php
namespace Admin\Event;
use Think\Controller;
class MarketEvent extends Controller
{
private $MarketDepartmentId = "1,2";
private $ManagerLevel = "4";
private $DirectorLevel = "5";
private $LevelConfig = [
'1'=>'初级',
'2'=>'中级',
'3'=>'高级',
'4'=>'经理'
];
/**
* 获取所有市场部组id
*/
public function getMarketGroupId()
{
$res = M('department','sys_')->where("id in ({$this->MarketDepartmentId})")->getField("group_ids",true);
$sendData = '';
foreach ($res as $value) {
$sendData .= $value.",";
}
return rtrim($sendData,",");
}
/**
3 years ago
* 获取市场专员gid(除了总监)
*/
public function getNoLeaderMarketGroupId()
{
$where = [
"department_id"=>['in',$this->MarketDepartmentId],
"department_level"=>['neq',$this->DirectorLevel]
];
$dbres = M('auth_group','sys_')->where($where)->getField("id",true);
return implode(",",$dbres);
}
/**
* 获取普通的市场专员初中高的gid
*/
public function getGeneralMarketGroup()
{
$where = [
"department_id"=>['in',$this->MarketDepartmentId],
"department_level"=>['LT',4]
];
$dbres = M('auth_group','sys_')->where($where)->getField("id",true);
return implode(",",$dbres);
}
/**
* 获取经理信息
*/
public function getManagerPerformanInfo()
{
$where = [
"department_id"=>['in',$this->MarketDepartmentId],
"department_level"=>['eq',$this->ManagerLevel]
];
$dbres = M('auth_group','sys_')->where($where)->getField("id",true);
$market = M("auth_group_access")
->alias("acc")
->where(["acc.group_id"=>['in',$dbres]])
->join("sys_member as mem on acc.uid = mem.uid")
->join("sys_auth_group as gro on acc.group_id = gro.id")
->getField("acc.uid,mem.nickname,mem.real_name,gro.department_id,gro.market_percentage",true);
return $market;
}
/**
* 获取配置信息
* @param [string] $key
* @return void
*/
public function getConfig($key)
{
return $this->$key;
}
/**
* 获取等级名称
*/
public function getLevelName($level)
{
return $this->LevelConfig[$level];
}
public function isMarketAdminGroup($gid)
{
$where = [
"department_id"=>['in',$this->MarketDepartmentId],
"id"=>$gid
];
return M('auth_group','sys_')->field("id,department_id,department_level")->where($where)->find();
}
public function isDepartmentLeder($department_id,$uid)
{
$gid = M("auth_group_access")->where("uid = '{$uid}'")->getField('group_id');
return M('department','sys_')->where("id = '{$department_id}' and leader_group = '$gid'")->field("id")->find();
}
public function isMarketLeder($uid)
{
$gid = M("auth_group_access")->where("uid = '{$uid}'")->getField('group_id');
return M("auth_group")->where("id = '{$gid}' and department_level = '{$this->DirectorLevel}'")->field("id")->find();
}
/**
* 添加部门总监的会长权限
* $uid,$promote_id
*/
public function addPresident($uid,$promote_id)
{
$leader_group = M("auth_group_access")
->alias("acc")
->where(['acc.uid'=>$uid])
->join("sys_auth_group as gro on acc.group_id = gro.id")
->join("sys_department as dep on gro.department_id = dep.id")
->getField("dep.leader_group",1);
if(!$leader_group){
return true;
}
$info = M('auth_group','sys_')->where(['id'=>$leader_group])->find();
$dataPresident = explode(',', $info['data_president']);
$dataPresident = array_unique(array_merge($dataPresident, array($promote_id)));
return $this->saveLeaderPresident($leader_group,$dataPresident);;
}
/**
* 移除原有权限
* @param [array] $promoteIds
* @return void
*/
public function removePresident($promoteIds)
{
if(!is_array($promoteIds)){
$promoteIds = explode(",",$promoteIds);
};
$leaderPresident = $this->getLeaderPresident();
foreach ($leaderPresident as $k => $v) {
$dataPresident = explode(',', $v);
$dataPresident = array_diff($dataPresident, $promoteIds);
$this->saveLeaderPresident($k,$dataPresident);
}
}
/**
* 添加原有权限,设计重复问题
* @param [array] $promoteIds
* @return void
*/
public function pushPresident($promoteIds)
{
if(!is_array($promoteIds)){
$promoteIds = explode(",",$promoteIds);
};
foreach ($promoteIds as $k => $v) {
$admin_id = M("Promote","tab_")->where("id = {$v}")->getField("admin_id");
$this->addPresident($admin_id,$v);
}
return true;
}
private function getLeaderPresident()
{
$where = [
"department_id"=>['in',$this->MarketDepartmentId],
"department_level"=>['eq',$this->DirectorLevel]
];
return M('auth_group','sys_')->where($where)->getField("id,data_president",true);
}
private function saveLeaderPresident($gid,$data_president)
{
if(is_array($data_president)){
$data_president = implode(",",$data_president);
};
$savedata = [
"id"=>$gid,
"data_president"=>$data_president
];
return M('auth_group','sys_')->save($savedata);
}
public function getDepartmentUserId($department_id)
{
$res = M("auth_group_access")
->alias("acc")
->field("acc.uid")
->where(['gro.department_id'=>$department_id])
->join("sys_member as mem on acc.uid = mem.uid")
->join("sys_auth_group as gro on acc.group_id = gro.id")
->select();
return array_column($res,'uid');
}
public function getAdminCompanyId()
{
if (!empty(session('user_auth_company_ids'))) {
return session('user_auth_company_ids');
}
$userAuth = session('user_auth');
$companyIds = 'all';
$userAuth['data_president']= trim($userAuth['data_president'], ",");
if (!empty($userAuth['data_empower_type'])) {//数据权限 1 全部 2 部分数据 3 自己底下的会长
//等于1默认全部数据不进行筛选
if (in_array($userAuth['data_empower_type'], [2, 3])) {
$companyIds = '';
//自己创建的会长
$myPromote_ids = M('promote', 'tab_')
->field('GROUP_CONCAT(id) as promote_ids')
->where(['admin_id' => $userAuth['uid']])
->find();
$myPromote_ids = $myPromote_ids['promote_ids'];
if ($myPromote_ids) {
if ($userAuth['data_empower_type'] == 2) {//部分会长加上自己创建的会长
// $userAuth['data_president'] .= "," . $myPromote_ids;
} elseif ($userAuth['data_empower_type'] == 3) {//自己创建的会长和底下推广员
$userAuth['data_president'] = $myPromote_ids;
}
}
$dbres = M('promote', 'tab_')
->field('company_id')
->where(['id' =>['in',$userAuth['data_president']],'level'=>1])
->group('company_id')
->getField('company_id',true);
$companyIds = implode(",",$dbres);
}
}
session('user_auth_company_ids', $companyIds);
return $companyIds;
}
}