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.

151 lines
5.0 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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,",");
}
/**
* 获取所有市场部组id
*/
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 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;
}
}