优化会长添加或者换绑引起的市场变化

master
chenzhi 3 years ago
parent aae58f024b
commit 3d215d57aa

@ -763,10 +763,15 @@ class OldCountController extends \Think\Controller
}
return $time_arr;
}
public function eventTest($event,$action)
public function eventTest($event,$action,$arg = false)
{
$Event = A($event,"Event");
$res = $Event->$action();
if(!$arg){
$res = $Event->$action();
}else{
$res = call_user_func_array(array($Event, $action), explode(":",$arg));
}
dd($res);
}

@ -1436,15 +1436,12 @@ class PromoteCompanyController extends ThinkController
M("Promote","tab_")->where("company_id = '{$company_id}'")->save($savedata);
// 权限跟随
if($is_change_belong){
$authGroup = M('auth_group',"sys_")->where(['title'=>'市场总监'])->find();
$subPromoteIds = M('promote', 'tab_')->where(['level' => 1, 'company_id' => $company_id])->getField('id', true);
$dataPresident = explode(',', $authGroup['data_president']);
if ($save['company_belong'] == 1 || $save['company_belong'] == 2) {
$dataPresident = array_unique(array_merge($dataPresident, $subPromoteIds));
A("Market","Event")->pushPresident($subPromoteIds);
} else {
$dataPresident = array_diff($dataPresident, $subPromoteIds);
A("Market","Event")->removePresident($subPromoteIds);
}
M('auth_group',"sys_")->where(['title'=>'市场总监'])->save(['data_president'=>implode(',', $dataPresident)]);
resetUserAuth();
}
}

@ -78,6 +78,9 @@ class MarketEvent extends Controller
{
return $this->$key;
}
/**
* 获取等级名称
*/
public function getLevelName($level)
{
return $this->LevelConfig[$level];
@ -112,7 +115,64 @@ class MarketEvent extends Controller
return true;
}
$info = M('auth_group','sys_')->where(['id'=>$leader_group])->find();
return M('auth_group','sys_')->where(['id'=>$leader_group])->save(['data_president'=>$info['data_president'].",".$promote_id]);
$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)

@ -43,12 +43,10 @@ class MarketService
M('promote', 'tab_')->where($map)->save(['admin_id' => $toId]);
M('promote', 'tab_')->where(['chain' => ['like', $promote['chain'] . $promote['id'] . '/%']])->save(['admin_id' => $toId]);
$authGroup = M('auth_group', 'sys_')->where(['title'=>'市场总监'])->find();
$dataPresident = explode(',', $authGroup['data_president']);
if (!in_array($promote['id'], $dataPresident)) {
M('auth_group', 'sys_')->where(['title'=>'市场总监'])->save(['data_president' => $authGroup['data_president'] . ',' . $promote['id']]);
resetUserAuth();
}
$marketEvent = A("Market","Event");
$marketEvent->removePresident($promote['id']);
$marketEvent->addPresident($toId,$promote['id']);
resetUserAuth();
}
public function shiftSpend($promoteIds, $fromId, $toId, $time = null)

@ -272,15 +272,13 @@ class PromoteCompanyService
// 权限跟随
if($isChangeBelong){
$authGroup = M('auth_group', 'sys_')->where(['title'=>'市场总监'])->find();
$subPromoteIds = M('promote', 'tab_')->where(['level' => 1, 'company_id' => $companyId])->getField('id', true);
$dataPresident = explode(',', $authGroup['data_president']);
if ($companyInfo['company_belong'] == 1 || $companyInfo['company_belong'] == 2) {
$dataPresident = array_unique(array_merge($dataPresident, $subPromoteIds));
A("Market","Event")->pushPresident($subPromoteIds);
} else {
$dataPresident = array_diff($dataPresident, $subPromoteIds);
A("Market","Event")->removePresident($subPromoteIds);
}
M('auth_group', 'sys_')->where(['title' => '市场总监'])->save(['data_president' => implode(',', $dataPresident)]);
resetUserAuth();
}
}

@ -1124,8 +1124,6 @@ class PromoteService {
if ($data['level'] == 1 && in_array($data['company_belong'], [1, 2])) {
$id = M('promote', 'tab_')->getLastInsID();
A('Market','Event')->addPresident($data['admin_id'],$id);
// $info = M('sys_auth_group')->where(['title'=>'市场总监'])->find();
// M('sys_auth_group')->where(['title'=>'市场总监'])->save(['data_president'=>$info['data_president'].",".$id]);
resetUserAuth();
}

Loading…
Cancel
Save