市场专员业绩管理优化

master
zhengyongxing 4 years ago
parent 06bd0bf848
commit 83717b64ae

@ -2469,7 +2469,7 @@ function is_sendBonus($pay_time = '',$admin_id = '') {
->where(['pay_time'=>$pay_time,'admin_id'=>$admin_id])
->find();
if ($market_altogether) {
if ($market_altogether['wait_commission'] != '0.00' && $market_altogether['wait_commission']) {
return '已发放';
} else {
return '未发放';

@ -81,7 +81,7 @@ class MarketPercentageController extends ThinkController
} else if ($value['company_belong'] == 1) {
$data[$key]['company_belong'] = '外团';
} else if ($value['company_belong'] == 2) {
$data[$key]['company_belong'] = '分发联盟';
$data[$key]['company_belong'] = '外团-分发联盟';
} else {
$data[$key]['company_belong'] = '无';
}
@ -146,6 +146,50 @@ class MarketPercentageController extends ThinkController
->select();
}
$all_data = M("settleup_marketorder","tab_")
->field("pay_time,promote_account,company_belong,member.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,admin_id,
sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses")
->join("left join sys_auth_group_access access on admin_id=access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->join("left join sys_member member on access.uid=member.uid")
->where(['group_id'=>['in','11,12,21']])
->group("admin_id,pay_time")
->order("pay_time DESC")
->select();
$wait_amount = [];
foreach ($all_data as $key => $value) {
$sum_amount = $value['performance_revenue'] + $value['appraisal_bonuses'];
$market_percentage = json_decode($value['market_percentage'],true);
//业绩提成
$all_data[$key]['performance_commission'] =
number_format($value['company_profit']*($market_percentage['develop_commission_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_commission_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['performance_revenue'] ? ($all_data[$key]['performance_commission'] = 0):"";
//绩效考核奖金
$all_data[$key]['achievement_bonus'] =
number_format($value['company_profit']*($market_percentage['appraisal_bonuses_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_appraisal_bonuses_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['appraisal_bonuses'] ? ($all_data[$key]['achievement_bonus'] = 0):"";
//总提成
$all_data[$key]['commission'] = number_format($all_data[$key]['performance_commission']+$all_data[$key]['achievement_bonus'], 2, '.', '');
//应发金额
$all_data[$key]['extend_commission'] =
substr(number_format($all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
//待发金额
$all_data[$key]['wait_commission'] = substr(number_format($all_data[$key]['commission'] - ( $all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100) ), 4, '.', ''),0,-2);
$wait_amount[$value['admin_id'].$value['pay_time']] = $all_data[$key]['wait_commission'];
}
$all_data = [];
$count = M("settleup_marketorder","tab_")
->field("pay_time,promote_account,company_belong,real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage")
@ -162,8 +206,6 @@ class MarketPercentageController extends ThinkController
}
$this->checkListOrCountAuthRestMap($map,[]);
$wait_amount = [];
foreach ($data as $key => $value) {
if ($value['group_id'] == 21) {
@ -197,8 +239,8 @@ class MarketPercentageController extends ThinkController
$data[$key]['commission'] = number_format($data[$key]['performance_commission']+$data[$key]['achievement_bonus'], 2, '.', '');
//应发金额
$data[$key]['extend_commission'] =
number_format($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 2, '.', '');
substr(number_format($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
$month = date("m",strtotime($value['pay_time']));
@ -222,29 +264,31 @@ class MarketPercentageController extends ThinkController
$wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
}
} elseif($market_percentage['time'] == 3) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'01'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'02'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'03'] +
$wait_amount[$value['admin_id'].($yes-1).'-'.'04'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'05'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'06'] +
$wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
$wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
if ($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '01'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '02'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '03'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '04'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '05'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '06'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '07'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '08'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '09'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '10'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '11'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '12'];
}
} else {
$data[$key]['extend_commission'] += $wait_amount[date("Y-m",strtotime("last month",strtotime($value['pay_time'])))];
}
//待发金额
$data[$key]['wait_commission'] = number_format($data[$key]['commission'] - $data[$key]['extend_commission'], 2, '.', '');
$wait_amount[$value['admin_id'].$value['pay_time']] = $data[$key]['wait_commission'];
$data[$key]['wait_commission'] = substr(number_format($data[$key]['commission'] - ( $data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100) ), 4, '.', ''),0,-2);
if ($market_percentage['remain_time'] == 1) {
if ($month == '07') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
$data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
} elseif($month == '10') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'07'] + $wait_amount[$value['admin_id'].$yes.'-'.'08'] + $wait_amount[$value['admin_id'].$yes.'-'.'09'];
$data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'07'] + $wait_amount[$value['admin_id'].$yes.'-'.'08'] + $wait_amount[$value['admin_id'].$yes.'-'.'09'];
} elseif($month == '04') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'];
$data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'];
} elseif($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
$data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
}
} elseif($market_percentage['remain_time'] == 2) {
// } elseif($market_percentage['remain_time'] == 2) {
// if ($month == '07') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'] +
// $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
@ -252,7 +296,7 @@ class MarketPercentageController extends ThinkController
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
// $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
// }
} elseif($market_percentage['remain_time'] == 3) {
// } elseif($market_percentage['remain_time'] == 3) {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'01'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'02'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'03'] +
// $wait_amount[$value['admin_id'].($yes-1).'-'.'04'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'05'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'06'] +
// $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
@ -262,6 +306,9 @@ class MarketPercentageController extends ThinkController
}
// dump($market_percentage);
// dump($wait_amount);die();
if ($_REQUEST['export']) {
$title = ['pay_time' => '时间',
@ -321,6 +368,51 @@ class MarketPercentageController extends ThinkController
->select();
}
// $all_data = M("settleup_marketorder","tab_")
// ->field("tab_settleup_marketorder.id,pay_time,promote_account,company_belong,member.real_name,develop_type,game_name,
// sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname,admin_id,
// sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses")
// ->join("left join sys_auth_group_access access on admin_id=access.uid")
// ->join("left join sys_auth_group auth on access.group_id=auth.id")
// ->join("left join sys_member member on access.uid=member.uid")
// ->where(['group_id'=>['in','11,12,21']])
// ->group("admin_id,pay_time")
// ->select();
//
// $wait_amount = [];
// foreach ($all_data as $key => $value) {
//
// $sum_amount = $value['performance_revenue'] + $value['appraisal_bonuses'];
//
// $market_percentage = json_decode($value['market_percentage'],true);
// //业绩提成
// $all_data[$key]['performance_commission'] =
// number_format($value['company_profit']*($market_percentage['develop_commission_ratio']/100) +
// $value['company_profit']*($market_percentage['maintain_commission_ratio']/100), 2, '.', '');
//
// $sum_amount <$market_percentage['performance_revenue'] ? ($all_data[$key]['performance_commission'] = 0):"";
// //绩效考核奖金
// $all_data[$key]['achievement_bonus'] =
// number_format($value['company_profit']*($market_percentage['appraisal_bonuses_ratio']/100) +
// $value['company_profit']*($market_percentage['maintain_appraisal_bonuses_ratio']/100), 2, '.', '');
// $sum_amount <$market_percentage['appraisal_bonuses'] ? ($all_data[$key]['achievement_bonus'] = 0):"";
// //总提成
// $all_data[$key]['commission'] = number_format($all_data[$key]['performance_commission']+$all_data[$key]['achievement_bonus'], 2, '.', '');
// //应发金额
// $all_data[$key]['extend_commission'] =
// number_format($all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
// $all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 2, '.', '');
//
// //待发金额
// $all_data[$key]['wait_commission'] = number_format($all_data[$key]['commission'] - ( $all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
// $all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100) ), 2, '.', '');
// $wait_amount[$value['admin_id'].$value['pay_time']] = $all_data[$key]['wait_commission'];
//
// }
// dump($data);die();
$all_data = [];
$count = M("settleup_marketorder","tab_")
->field("pay_time,promote_account,company_belong,tab_settleup_marketorder.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname")
@ -338,8 +430,6 @@ class MarketPercentageController extends ThinkController
}
$this->checkListOrCountAuthRestMap($map,[]);
// dump($data);die();
$sum['performance_commission'] = 0;
$sum['achievement_bonus'] = 0;
@ -364,8 +454,7 @@ class MarketPercentageController extends ThinkController
$data[$key]['is_send'] = is_sendBonus($value['pay_time'],$value['admin_id']);
$market_percentage = json_decode($value['market_percentage'],true);
// $data[$key]['performance_revenue'] = number_format($market_percentage['performance_revenue'], 2, '.', '');
// $data[$key]['appraisal_bonuses'] = number_format($market_percentage['appraisal_bonuses'], 2, '.', '');
//业绩提成
$data[$key]['performance_commission'] =
number_format($value['company_profit']*($market_percentage['develop_commission_ratio']/100) +
@ -383,16 +472,86 @@ class MarketPercentageController extends ThinkController
$sum['commission'] += $data[$key]['commission'];
//应发金额
$data[$key]['extend_commission'] =
number_format($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 2, '.', '');
substr(number_format($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
$sum['extend_commission'] += $data[$key]['extend_commission'];
$month = date("m",strtotime($value['pay_time']));
$yes = date("Y",strtotime($value['pay_time']));
if ($market_percentage['time'] == 1) {
if ($month == '07') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'];
$data[$key]['is_send_use'] = 1;
} elseif($month == '10') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
$data[$key]['is_send_use'] = 1;
} elseif($month == '04') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
$data[$key]['is_send_use'] = 1;
} elseif($month == '01') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'];
$data[$key]['is_send_use'] = 1;
}
} elseif($market_percentage['time'] == 2) {
// dump($wait_amount);die();
if ($month == '07') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'] +
// $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
$data[$key]['is_send_use'] = 1;
} elseif($month == '01') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
// $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
$data[$key]['is_send_use'] = 1;
}
} elseif($market_percentage['time'] == 3) {
if ($month == '01') {
// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '01'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '02'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '03'] +
// $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '04'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '05'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '06'] +
// $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '07'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '08'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '09'] +
// $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '10'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '11'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '12'];
$data[$key]['is_send_use'] = 1;
}
} else {
$data[$key]['is_send_use'] = 1;
}
//待发金额
$data[$key]['wait_commission'] = number_format($data[$key]['commission'] - $data[$key]['extend_commission'], 2, '.', '');
$data[$key]['wait_commission'] = substr(number_format($data[$key]['commission'] - ($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100)), 4, '.', ''),0,-2);
$sum['wait_commission'] += $data[$key]['wait_commission'];
// $wait_amount[$value['admin_id'].$value['pay_time']] = $data[$key]['wait_commission'];
// if ($market_percentage['remain_time'] == 1) {
// if ($month == '07') {
// $data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
// } elseif($month == '10') {
// $data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'07'] + $wait_amount[$value['admin_id'].$yes.'-'.'08'] + $wait_amount[$value['admin_id'].$yes.'-'.'09'];
// } elseif($month == '04') {
// $data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'];
// } elseif($month == '01') {
// $data[$key]['wait_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
// }
//// } elseif($market_percentage['remain_time'] == 2) {
//// if ($month == '07') {
//// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'] +
//// $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
//// } elseif($month == '01') {
//// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
//// $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
//// }
//// } elseif($market_percentage['remain_time'] == 3) {
//// $data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'01'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'02'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'03'] +
//// $wait_amount[$value['admin_id'].($yes-1).'-'.'04'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'05'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'06'] +
//// $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
//// $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
// }
// $sum['wait_commission'] += $data[$key]['wait_commission'];
$sum['company_profit'] += $value['company_profit'];
}
// dump($data);die();
$this->assign("sum",$sum);
if ($_REQUEST['export']) {
@ -433,9 +592,57 @@ class MarketPercentageController extends ThinkController
$this->ajaxReturn(['status'=>0,'msg'=>'数据错误']);
}
$group_config = M("auth_group_access access")
->field("market_percentage")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->where(['uid'=>$_REQUEST['admin_id']])
->find();
$group_config = json_decode($group_config['market_percentage'],true);
$month = date("m",strtotime($_REQUEST['pay_time']));
$yes = date("Y",strtotime($_REQUEST['pay_time']));
if ($group_config['time'] == 1) {
if ($month == '07') {
$where = [$yes.'-'.'01',$yes.'-'.'02',$yes.'-'.'03'];
if ($_REQUEST['all']) {
$where = array_merge($where,[$yes.'-'.'04',$yes.'-'.'05',$yes.'-'.'06']);
}
} elseif($month == '10') {
$where = [$yes.'-'.'04',$yes.'-'.'05',$yes.'-'.'06'];
if ($_REQUEST['all']) {
$where = array_merge($where,[$yes.'-'.'07',$yes.'-'.'08',$yes.'-'.'09']);
}
} elseif($month == '04') {
$where = [($yes-1).'-'.'10',($yes-1).'-'.'11',($yes-1).'-'.'12'];
if ($_REQUEST['all']) {
$where = array_merge($where,[$yes.'-'.'01',$yes.'-'.'02',$yes.'-'.'03']);
}
} elseif($month == '01') {
$where = [($yes-1).'-'.'07',($yes-1).'-'.'08',($yes-1).'-'.'09'];
if ($_REQUEST['all']) {
$where = array_merge($where,[$yes.'-'.'10',$yes.'-'.'11',$yes.'-'.'12']);
}
}
} elseif($group_config['time'] == 2) {
if ($month == '07') {
$where = [$yes.'-'.'01',$yes.'-'.'02',$yes.'-'.'03',$yes.'-'.'04',$yes.'-'.'05',$yes.'-'.'06'];
} elseif($month == '01') {
$where = [($yes-1).'-'.'07',($yes-1).'-'.'08',($yes-1).'-'.'09',($yes-1).'-'.'10',($yes-1).'-'.'11',($yes-1).'-'.'12'];
}
} elseif($group_config['time'] == 3) {
if ($month == '01') {
$where = [($yes-1).'-'.'01',($yes-1).'-'.'02',($yes-1).'-'.'03',($yes-1).'-'.'04',($yes-1).'-'.'05',($yes-1).'-'.'06',
($yes-1).'-'.'07',($yes-1).'-'.'08',($yes-1).'-'.'09',($yes-1).'-'.'10',($yes-1).'-'.'11',($yes-1).'-'.'12'];
}
}
$where = array_merge($where,[$_REQUEST['pay_time']]);
$map['pay_time'] = ['in',$where];
$data = M("settleup_marketorder","tab_")
->field("tab_settleup_marketorder.id,pay_time,promote_account,company_belong,tab_settleup_marketorder.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname,admin_id")
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname,admin_id,
sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses")
->join("left join sys_auth_group_access access on admin_id=access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->join("left join sys_member member on access.uid=member.uid")
@ -443,6 +650,47 @@ class MarketPercentageController extends ThinkController
->group("admin_id,pay_time")
->select();
$all_data = M("settleup_marketorder","tab_")
->field("tab_settleup_marketorder.id,pay_time,promote_account,company_belong,member.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname,admin_id,
sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses")
->join("left join sys_auth_group_access access on admin_id=access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->join("left join sys_member member on access.uid=member.uid")
->where(['group_id'=>['in','11,12,21']])
->group("admin_id,pay_time")
->select();
$wait_amount = [];
foreach ($all_data as $key => $value) {
$sum_amount = $value['performance_revenue'] + $value['appraisal_bonuses'];
$market_percentage = json_decode($value['market_percentage'],true);
//业绩提成
$all_data[$key]['performance_commission'] =
number_format($value['company_profit']*($market_percentage['develop_commission_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_commission_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['performance_revenue'] ? ($all_data[$key]['performance_commission'] = 0):"";
//绩效考核奖金
$all_data[$key]['achievement_bonus'] =
number_format($value['company_profit']*($market_percentage['appraisal_bonuses_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_appraisal_bonuses_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['appraisal_bonuses'] ? ($all_data[$key]['achievement_bonus'] = 0):"";
//总提成
$all_data[$key]['commission'] = number_format($all_data[$key]['performance_commission']+$all_data[$key]['achievement_bonus'], 2, '.', '');
//应发金额
$all_data[$key]['extend_commission'] =
substr(number_format($all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
//待发金额
$all_data[$key]['wait_commission'] = substr(number_format($all_data[$key]['commission'] - ( $all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100) ), 4, '.', ''),0,-2);
$wait_amount[$value['admin_id'].$value['pay_time']] = $all_data[$key]['wait_commission'];
}
foreach ($data as $key => $value) {
@ -453,54 +701,124 @@ class MarketPercentageController extends ThinkController
} else if ($value['group_id'] == 12) {
$data[$key]['level'] = '高级';
}
$sum_amount = $value['performance_revenue'] + $value['appraisal_bonuses'];
$market_percentage = json_decode($value['market_percentage'],true);
$data[$key]['performance_revenue'] = number_format($market_percentage['performance_revenue'], 2, '.', '');
$data[$key]['appraisal_bonuses'] = number_format($market_percentage['appraisal_bonuses'], 2, '.', '');
// $data[$key]['performance_revenue'] = number_format($market_percentage['performance_revenue'], 2, '.', '');
// $data[$key]['appraisal_bonuses'] = number_format($market_percentage['appraisal_bonuses'], 2, '.', '');
//业绩提成
$data[$key]['performance_commission'] =
number_format($value['company_profit']*($market_percentage['develop_commission_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_commission_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['performance_revenue'] ? ($data[$key]['performance_commission'] = 0):"";
//绩效考核奖金
$data[$key]['achievement_bonus'] =
number_format($value['company_profit']*($market_percentage['appraisal_bonuses_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_appraisal_bonuses_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['appraisal_bonuses'] ? ($data[$key]['achievement_bonus'] = 0):"";
//总提成
$data[$key]['commission'] = number_format($data[$key]['performance_commission']+$data[$key]['achievement_bonus'], 2, '.', '');
//应发金额
$data[$key]['extend_commission'] =
number_format($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['performance_commission'] * ($market_percentage['month_bonus_ratio']/100), 2, '.', '');
substr(number_format($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
//待发金额
$data[$key]['wait_commission'] = number_format($data[$key]['commission'] - $data[$key]['extend_commission'], 2, '.', '');
}
$data[$key]['wait_commission'] = substr(number_format($data[$key]['commission'] - ($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100)), 4, '.', ''),0,-2);
$insert['pay_time'] = $data[0]['pay_time'];
$insert['admin_id'] = $data[0]['admin_id'];
$insert['real_name'] = $data[0]['real_name'];
$insert['nickname'] = $data[0]['nickname'];
$insert['level'] = $data[0]['level'];
$insert['pay_amount'] = $data[0]['pay_amount'];
$insert['extend_commission'] = $data[0]['extend_commission'];
$insert['wait_commission'] = $data[0]['wait_commission'];
$insert['remark'] = "{$data[0]['nickname']}发起提成发放";
$insert['create_time'] = time();
$is_hav = M("market_altogether","tab_")
->where(['pay_time'=>$data[0]['pay_time'],'admin_id'=>$data[0]['admin_id']])
->find();
if ($is_hav) {
$this->ajaxReturn(['status'=>1,'msg'=>'已经发放过']);
}
$month = date("m",strtotime($value['pay_time']));
$yes = date("Y",strtotime($value['pay_time']));
$is_add = M("market_altogether","tab_")->add($insert);
if ($market_percentage['time'] == 1) {
//跨级发放验证当前发放月份
$check_month = date("m",strtotime($_REQUEST['pay_time']));
if ($month == '07') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] +
$wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'] + $data[$key]['wait_commission'];
}
} elseif($month == '10') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'07'] +
$wait_amount[$value['admin_id'].$yes.'-'.'08'] + $wait_amount[$value['admin_id'].$yes.'-'.'09'] + $data[$key]['wait_commission'];
}
} elseif($month == '04') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] +
$wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'] + $data[$key]['wait_commission'];
}
} elseif($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] +
$wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'] + $data[$key]['wait_commission'];
}
}
} elseif($market_percentage['time'] == 2) {
if ($month == '07') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'] +
$wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
} elseif($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
$wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
}
} elseif($market_percentage['time'] == 3) {
if ($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '01'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '02'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '03'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '04'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '05'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '06'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '07'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '08'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '09'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '10'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '11'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '12'];
}
}
// else {
// $data[$key]['is_send_use'] = 1;
// }
$insert['pay_time'] = $data[$key]['pay_time'];
$insert['admin_id'] = $data[$key]['admin_id'];
$insert['real_name'] = $data[$key]['real_name'];
$insert['nickname'] = $data[$key]['nickname'];
$insert['level'] = $data[$key]['level'];
$insert['pay_amount'] = $data[$key]['pay_amount'];
$insert['extend_commission'] = $data[$key]['extend_commission'];
$insert['wait_commission'] = $data[$key]['wait_commission'];
$insert['remark'] = "{$data[$key]['nickname']}发起提成发放";
if ($_REQUEST['all']) {
$insert['remark'] = '离职发放';
$insert['type'] = 1;
}
$insert['create_time'] = time();
$is_hav = M("market_altogether","tab_")
->where(['pay_time'=>$data[$key]['pay_time'],'admin_id'=>$data[$key]['admin_id']])
->find();
if ($is_hav) {
// $this->ajaxReturn(['status'=>1,'msg'=>'已经发放过']);
$is_add = M("market_altogether","tab_")
->where(['pay_time'=>$data[$key]['pay_time'],'admin_id'=>$data[$key]['admin_id']])
->save($insert);
} else {
$is_add = M("market_altogether","tab_")->add($insert);
}
// $is_add = M("market_altogether","tab_")->add($insert);
if (!$is_add) {
$this->ajaxReturn(['status'=>0,'msg'=>'发放失败']);
}
if ($is_add) {
$this->ajaxReturn(['status'=>1,'msg'=>'发放成功']);
} else {
$this->ajaxReturn(['status'=>0,'msg'=>'发放失败']);
}
$this->ajaxReturn(['status'=>1,'msg'=>'发放成功']);
}
public function reCaculateBonus() {
@ -508,8 +826,8 @@ class MarketPercentageController extends ThinkController
$pay_time = $_REQUEST['pay_time'];
if (!$pay_time) {
// $pay_time = "all";
$pay_time = date("Y-m",strtotime('-1 month'));
$pay_time = "all";
// $pay_time = date("Y-m",strtotime('-1 month'));
}
exec("php cli.php timing/caculateMarketStream/time/{$pay_time} > /dev/null &");
@ -519,6 +837,7 @@ class MarketPercentageController extends ThinkController
public function showBonusList($row = 10, $p = 1) {
// echo date("Y-m",strtotime("last month",strtotime("2020-07")));die();
$map = [];
$_REQUEST['pay_time']?$map['pay_time'] = $_REQUEST['pay_time']:'';
@ -527,7 +846,8 @@ class MarketPercentageController extends ThinkController
$_REQUEST['level']?$map['level'] = $_REQUEST['level']:'';
$data = M("market_altogether","tab_")
->field("real_name,admin_id,nickname,level,sum(pay_amount) pay_amount,sum(extend_commission) extend_commission, sum(wait_commission) wait_commission,remark")
->field("max(pay_time) pay_time,real_name,admin_id,nickname,level,sum(pay_amount) pay_amount,sum(extend_commission) extend_commission, sum(wait_commission) wait_commission,remark,group_id,max(type) type")
->join("left join sys_auth_group_access access on admin_id=access.uid")
->where($map);
if ($_REQUEST['export']) {
$data = $data
@ -536,10 +856,117 @@ class MarketPercentageController extends ThinkController
->select();
} else {
$data = $data->page($p, $row)
->order("pay_time DESC")
->order("id DESC")
->group("admin_id")
->select();
}
// dump($data);die();
foreach($data as $key => $value) {
if ($value['group_id'] == 21) {
$data[$key]['level'] = '初级';
} else if ($value['group_id'] == 11) {
$data[$key]['level'] = '中级';
} else if ($value['group_id'] == 12) {
$data[$key]['level'] = '高级';
}
$group_config = M("auth_group_access access")
->field("market_percentage")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->where(['uid'=>$value['admin_id']])
->find();
$group_config = json_decode($group_config['market_percentage'],true);
$month = date("m",strtotime($value['pay_time']));
$yes = date("Y",strtotime($value['pay_time']));
$where = [$value['pay_time']];
if ($group_config['time'] == 1) {
//到季发放剩余金额条件
if ($month == '07') {
$where = [$yes.'-'.'04',$yes.'-'.'05',$yes.'-'.'06'];
} elseif($month == '10') {
$where = [$yes.'-'.'07',$yes.'-'.'08',$yes.'-'.'09'];
} elseif($month == '04') {
$where = [$yes.'-'.'01',$yes.'-'.'11',$yes.'-'.'12'];
} elseif($month == '01') {
$where = [($yes-1).'-'.'07',($yes-1).'-'.'08',($yes-1).'-'.'09'];
}
//未到季发放剩余金额条件
if ($month == '02') {
$where = [$yes.'-'.'01'];
} elseif($month == '03') {
$where = [$yes.'-'.'01',$yes.'-'.'02'];
} elseif($month == '05') {
$where = [$yes.'-'.'04'];
} elseif($month == '06') {
$where = [$yes.'-'.'04',$yes.'-'.'05'];
} elseif($month == '08') {
$where = [$yes.'-'.'07'];
} elseif($month == '09') {
$where = [$yes.'-'.'07',$yes.'-'.'08'];
} elseif($month == '11') {
$where = [$yes.'-'.'10'];
} elseif($month == '12') {
$where = [$yes.'-'.'10',$yes.'-'.'11'];
}
$where = array_merge($where,[$value['pay_time']]);
}
// var_dump($where);die();
$surplus_data = M("settleup_marketorder","tab_")
->field("tab_settleup_marketorder.id,pay_time,promote_account,company_belong,tab_settleup_marketorder.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname,admin_id,
sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses")
->join("left join sys_auth_group_access access on admin_id=access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->join("left join sys_member member on access.uid=member.uid")
->where(['pay_time'=>['in',$where],'admin_id'=>$value['admin_id']])
->group("admin_id,pay_time")
->select();
// $paytime = $value['pay_time'];
// $surplus_data = M()->table("({$surplus_data}) a")
// ->field("a.*")
// ->join("left join tab_market_altogether market on a.admin_id=market.admin_id and a.pay_time=market.pay_time")
// ->where("(market.admin_id is null) or (a.pay_time = '{$paytime}')")
// ->select();
$data[$key]['wait_commission'] = 0;
foreach($surplus_data as $k => $v) {
$sum_amount = $v['performance_revenue'] + $v['appraisal_bonuses'];
$market_percentage = json_decode($v['market_percentage'],true);
//业绩提成
$surplus_data[$k]['performance_commission'] =
number_format($v['company_profit']*($market_percentage['develop_commission_ratio']/100) +
$v['company_profit']*($market_percentage['maintain_commission_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['performance_revenue'] ? ($surplus_data[$k]['performance_commission'] = 0):"";
//绩效考核奖金
$surplus_data[$k]['achievement_bonus'] =
number_format($v['company_profit']*($market_percentage['appraisal_bonuses_ratio']/100) +
$v['company_profit']*($market_percentage['maintain_appraisal_bonuses_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['appraisal_bonuses'] ? ($surplus_data[$k]['achievement_bonus'] = 0):"";
//总提成
$surplus_data[$k]['commission'] = number_format($surplus_data[$k]['performance_commission']+$surplus_data[$k]['achievement_bonus'], 2, '.', '');
//应发金额
$surplus_data[$k]['extend_commission'] =
substr(number_format($surplus_data[$k]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$surplus_data[$k]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
//待发金额
$surplus_data[$k]['wait_commission'] = substr(number_format($surplus_data[$k]['commission'] - ($surplus_data[$k]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$surplus_data[$k]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100)), 4, '.', ''),0,-2);
$data[$key]['wait_commission'] = $data[$key]['wait_commission'] + $surplus_data[$k]['wait_commission'];
}
if($data[$key]['type'] == 1) {
$data[$key]['wait_commission'] = 0;
}
}
if ($_REQUEST['export']) {

@ -360,7 +360,7 @@ class TimingController extends AdminController {
}
}
//参数 time 2020-10
//计算市场专员业绩公式 参数 time 2020-10
public function caculateMarketStream () {
echo date("Y-m-d H:i:s")."----------------------市场结算管理计算----------------------\n";
@ -369,9 +369,10 @@ class TimingController extends AdminController {
if ($_REQUEST['time']) {
$map['pay_time'] = $_REQUEST['time'];
}
$spend_map = [];
if($_REQUEST['time'] == 'all') {
$map = [];
$spend_map['pay_time'] = ['elt',strtotime(date('Y-m-t', strtotime('-1 month')))];
}
$data = M("auth_group")
@ -392,6 +393,7 @@ class TimingController extends AdminController {
->join("left join tab_promote on tab_spend.promote_id = tab_promote.id")
->join("left join tab_game game on game.id=tab_spend.game_id")
->where(['tab_spend.pay_status'=>1,'pay_way'=>['egt',1]])
->where($spend_map)
->group("tab_spend.id")
->select(false);
@ -519,4 +521,181 @@ class TimingController extends AdminController {
}
//
public function sendMarketBonus() {
echo date("Y-m-d H:i:s")."----------------------月初发放市场专员应发份额----------------------\n";
$map['pay_time'] = date("Y-m",strtotime('-1 month'));
if ($_REQUEST['pay_time']) {
$map['pay_time'] = $_REQUEST['pay_time'];
}
$all_data = M("settleup_marketorder","tab_")
->field("tab_settleup_marketorder.id,pay_time,promote_account,company_belong,tab_settleup_marketorder.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname,admin_id,
sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses")
->join("left join sys_auth_group_access access on admin_id=access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->join("left join sys_member member on access.uid=member.uid")
->where(['group_id'=>['in','11,12,21']])
->group("admin_id,pay_time")
->select();
$wait_amount = [];
foreach ($all_data as $key => $value) {
$sum_amount = $value['performance_revenue'] + $value['appraisal_bonuses'];
$market_percentage = json_decode($value['market_percentage'],true);
//业绩提成
$all_data[$key]['performance_commission'] =
number_format($value['company_profit']*($market_percentage['develop_commission_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_commission_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['performance_revenue'] ? ($all_data[$key]['performance_commission'] = 0):"";
//绩效考核奖金
$all_data[$key]['achievement_bonus'] =
number_format($value['company_profit']*($market_percentage['appraisal_bonuses_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_appraisal_bonuses_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['appraisal_bonuses'] ? ($all_data[$key]['achievement_bonus'] = 0):"";
//总提成
$all_data[$key]['commission'] = number_format($all_data[$key]['performance_commission']+$all_data[$key]['achievement_bonus'], 2, '.', '');
//应发金额
$all_data[$key]['extend_commission'] =
substr(number_format($all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
//待发金额
$all_data[$key]['wait_commission'] = substr(number_format($all_data[$key]['commission'] - ( $all_data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$all_data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100) ), 4, '.', ''),0,-2);
$wait_amount[$value['admin_id'].$value['pay_time']] = $all_data[$key]['wait_commission'];
}
$data = M("settleup_marketorder","tab_")
->field("tab_settleup_marketorder.id,pay_time,promote_account,company_belong,tab_settleup_marketorder.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(company_profit) company_profit,group_id,market_percentage,nickname,admin_id,
sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses")
->join("left join sys_auth_group_access access on admin_id=access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->join("left join sys_member member on access.uid=member.uid")
->where($map)
->group("admin_id,pay_time")
->select();
foreach ($data as $key => $value) {
if ($value['group_id'] == 21) {
$data[$key]['level'] = '初级';
} else if ($value['group_id'] == 11) {
$data[$key]['level'] = '中级';
} else if ($value['group_id'] == 12) {
$data[$key]['level'] = '高级';
}
$sum_amount = $value['performance_revenue'] + $value['appraisal_bonuses'];
$market_percentage = json_decode($value['market_percentage'],true);
//业绩提成
$data[$key]['performance_commission'] =
number_format($value['company_profit']*($market_percentage['develop_commission_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_commission_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['performance_revenue'] ? ($data[$key]['performance_commission'] = 0):"";
//绩效考核奖金
$data[$key]['achievement_bonus'] =
number_format($value['company_profit']*($market_percentage['appraisal_bonuses_ratio']/100) +
$value['company_profit']*($market_percentage['maintain_appraisal_bonuses_ratio']/100), 2, '.', '');
$sum_amount <$market_percentage['appraisal_bonuses'] ? ($data[$key]['achievement_bonus'] = 0):"";
//总提成
$data[$key]['commission'] = number_format($data[$key]['performance_commission']+$data[$key]['achievement_bonus'], 2, '.', '');
//应发金额
$data[$key]['extend_commission'] =
substr(number_format($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100), 4, '.', ''),0,-2);
//待发金额
$data[$key]['wait_commission'] = substr(number_format($data[$key]['commission'] - ($data[$key]['performance_commission'] * ($market_percentage['performance_monthly_ratio']/100)+
$data[$key]['achievement_bonus'] * ($market_percentage['month_bonus_ratio']/100)), 4, '.', ''),0,-2);
$month = date("m",strtotime($value['pay_time']));
$yes = date("Y",strtotime($value['pay_time']));
if ($market_percentage['time'] == 1) {
//跨级发放验证当前发放月份
$check_month = date("m",strtotime($_REQUEST['pay_time']));
if ($month == '07') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] +
$wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'] + $data[$key]['wait_commission'];
}
} elseif($month == '10') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'07'] +
$wait_amount[$value['admin_id'].$yes.'-'.'08'] + $wait_amount[$value['admin_id'].$yes.'-'.'09'] + $data[$key]['wait_commission'];
}
} elseif($month == '04') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] +
$wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'] + $data[$key]['wait_commission'];
}
} elseif($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'];
if ($_REQUEST['all']&&$check_month==$month) {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'10'] +
$wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'] + $data[$key]['wait_commission'];
}
}
} elseif($market_percentage['time'] == 2) {
if ($month == '07') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].$yes.'-'.'01'] + $wait_amount[$value['admin_id'].$yes.'-'.'02'] + $wait_amount[$value['admin_id'].$yes.'-'.'03'] +
$wait_amount[$value['admin_id'].$yes.'-'.'04'] + $wait_amount[$value['admin_id'].$yes.'-'.'05'] + $wait_amount[$value['admin_id'].$yes.'-'.'06'];
} elseif($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'].($yes-1).'-'.'07'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'08'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'09'] +
$wait_amount[$value['admin_id'].($yes-1).'-'.'10'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'11'] + $wait_amount[$value['admin_id'].($yes-1).'-'.'12'];
}
} elseif($market_percentage['time'] == 3) {
if ($month == '01') {
$data[$key]['extend_commission'] += $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '01'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '02'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '03'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '04'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '05'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '06'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '07'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '08'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '09'] +
$wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '10'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '11'] + $wait_amount[$value['admin_id'] . ($yes - 1) . '-' . '12'];
}
}
$insert['pay_time'] = $data[$key]['pay_time'];
$insert['admin_id'] = $data[$key]['admin_id'];
$insert['real_name'] = $data[$key]['real_name'];
$insert['nickname'] = $data[$key]['nickname'];
$insert['level'] = $data[$key]['level'];
$insert['pay_amount'] = $data[$key]['pay_amount'];
$insert['extend_commission'] = $data[$key]['extend_commission'];
$insert['wait_commission'] = $data[$key]['wait_commission'];
$insert['remark'] = "月初自动发放";
$insert['create_time'] = time();
echo "{$data[$key]['level']}市场专员:{$insert['real_name']}发放应发奖金及绩效:{$insert['extend_commission']}\n";
$is_hav = M("market_altogether","tab_")
->where(['pay_time'=>$data[$key]['pay_time'],'admin_id'=>$data[$key]['admin_id']])
->find();
if (!$is_hav) {
M("market_altogether","tab_")->add($insert);
} else {
M("market_altogether","tab_")
->where(['pay_time'=>$data[$key]['pay_time'],'admin_id'=>$data[$key]['admin_id']])
->save($insert);
}
}
echo date("Y-m-d H:i:s")."----------------------月初发放市场专员应发份额----------------------\n";
}
}

@ -83,8 +83,8 @@
<th >业绩提成</th>
<th >绩效考核奖金</th>
<th>总提成</th>
<th>当月应发金额</th>
<th>剩余金额</th>
<th>本月应发</th>
<th>本月未发</th>
<th>剩余金额发放状态</th>
<th>操作</th>
</tr>
@ -98,7 +98,7 @@
</tr>
</if>
<notemtpy name = "list_data">
<volist name="list_data" id="data">
<volist name="list_data" id="data" key="index">
<tr>
<td>{$data.pay_time|default='无'}</td>
<td>{$data.real_name|default='无'}</td>
@ -114,13 +114,28 @@
<td>{$data['extend_commission']|default='0.00'}</td>
<td>{$data['wait_commission']|default='0.00'}</td>
<td>{$data['is_send']|default='0.00'}</td>
<td>
<if condition="$data['is_send'] neq '已发放'">
<a data-time="{$data.pay_time}" data-admin_id="{$data.admin_id}" class="send"
url="{:U('sendBonus')}"><span class="button_icon button_icon1"></span>发放</a>
</if>
</td>
<if condition="$index eq 1">
<td>
<select id="time" class="select_gallery" style="width:100px;">
<option value="">请选择时间</option>
<volist name="list_data" id="s_data">
<if condition="$s_data['is_send_use'] eq 1">
<option value="{$s_data['pay_time']}" data-admin_id="{$s_data.admin_id}">{$s_data['pay_time']}</option>
</if>
</volist>
</select>
<a style="background: #3C95C8;font-size: 14px;font-weight: normal;color: #fff;cursor: pointer;border-radius: 3px;display: inline-block;text-align: center;border-bottom: none;width: 55px;height: 28px;line-height: 28px;text-indent:0"
url="{:U('sendBonus')}" class="send">发放</a>
</td>
<else/>
<td></td>
</if>
</tr>
</volist>
<tr>
<td></td>
@ -246,12 +261,13 @@
/* 状态搜索子菜单 */
/*发放提成*/
$('.send').click(function(){
var time = $(this).attr('data-time');
var admin_id = $(this).attr('data-admin_id');
var time = $("#time").val();
var admin_id = $("#time :selected").attr('data-admin_id');
layer.confirm('是否确认发放提成!', {
title:'发放提成?',
icon:0,
btn: ['发放','取消'] //按钮
btn: ['发放','离职发放','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
@ -270,6 +286,24 @@
}
}
});
}, function(){
$.ajax({
type: "POST",
url: "{:U('sendBonus')}",
dataType: 'json',
async: false,
data: {pay_time:time,admin_id:admin_id,all:1},
success:function(data){
if(data.status==1){
layer.msg(data.msg);
setTimeout(function(){
window.location.reload();
},1500);
} else {
layer.msg(data.msg);
}
}
});
}, function(){
layer.close();
});

@ -32,20 +32,20 @@
</style>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">提成汇总结算单</h3>
<p class="description_text">说明:此功是查看并管理推广员的功能</p>
<h3 class="page_title">提成数据汇总表</h3>
<!-- <p class="description_text">说明:此功是查看并管理推广员的功能</p>-->
</div>
<div class="cf top_nav_list">
<div class="fl button_list">
<div class="tools">
<empty name="show_status">
<a class=" " href="{:U('add?model='.$model['id'])}"><span class="button_icon button_icon1"></span>新增</a>
</empty>
</div>
</div>
<!-- <div class="fl button_list">-->
<!-- <div class="tools">-->
<!-- <empty name="show_status">-->
<!-- <a class=" " href="{:U('add?model='.$model['id'])}"><span class="button_icon button_icon1"></span>新增</a>-->
<!-- </empty>-->
<!-- </div>-->
<!-- </div>-->
<!-- 高级搜索 -->
<div class="jssearch fl cf search_list">
<div class="input-list search-title-box">

Loading…
Cancel
Save