@ -803,6 +803,24 @@ class TimingController extends AdminController {
->where(['name'=>['in',"alipay,weixin,wei_xin,wei_xin_app,jubaobar,weixin_gf,jft,jft_wap,goldpig,ptb_pay,bind_pay,sqpay,heepay,yeepay"]])
->select();
//公司税费计算
$tax_radio = [];
$tax_data = M("tax_radio","tab_")
->field("tax_radio,time")
->order("time ASC")
->select();
foreach ($tax_data as $key => $value) {
$tax_radio[$key]['start'] = $value['time'];
$tax_radio[$key]['end'] = $tax_data[$key+1]['time'];
$tax_radio[$key]['tax_radio'] = $value['tax_radio'];
if (!$tax_data[$key+1]['time']) {
$tax_radio[$key]['end'] = 99999999999;
}
}
$pay_rate = [];
foreach ($paywayData as $key => $value) {
$pay_config = json_decode($value['config'],true);
@ -851,16 +869,9 @@ class TimingController extends AdminController {
->where(['develop_type'=>['egt',1]])
->select();
// dump($promote_data);die();
//
$tax_radio = 0;
$data = M("tool","tab_")
->field("config")
->where(['name'=>'tax_radio'])->find();
$data = json_decode($data['config'],true);
if (time() >= $data['timestart']) {
$tax_radio = $data['tax_radio'];
}
// dump($tax_radio);die();
foreach ($promote_data as $key => $value) {
@ -879,8 +890,16 @@ class TimingController extends AdminController {
$promote_data[$key]['promote_amount'] = $value['pay_amount'] * ($promote_radio * 0.01);
//渠道费用
$promote_data[$key]['channel_amount'] = $channel_fee[$value['pay_time'].$value['promote_id'].$value['game_name']];
$tax = 0;
//公司税费
$promote_data[$key]['company_tax'] = ($value['pay_amount']-$promote_data[$key]['cp_amount']- $promote_data[$key]['promote_amount'])*($tax_radio/100);
foreach($tax_radio as $k => $v) {
if (strtotime($value['pay_time'])>=$v['start'] & & strtotime($value['pay_time'])< $v['end']) {
$tax = $v['tax_radio'];
}
}
$promote_data[$key]['company_tax'] = ($value['pay_amount']-$promote_data[$key]['cp_amount']- $promote_data[$key]['promote_amount'])*($tax/100);
//毛利
$promote_data[$key]['company_profit'] = $value['pay_amount']-$promote_data[$key]['cp_amount']-$promote_data[$key]['promote_amount']-$promote_data[$key]['channel_amount']-$promote_data[$key]['company_tax'];
@ -909,16 +928,18 @@ class TimingController extends AdminController {
}
}
// var_dump($_REQUEST['time']);
$this->createMarketBonus($_REQUEST['time']);
echo date("Y-m-d H:i:s")."----------------------市场结算管理计算----------------------\n";
}
public function insertAllUserBonus($time) {
// $time = $_REQUEST['time'];
$data = M("member")
->field("access.uid admin_id,real_name,nickname,group_id level,0 pay_amount,0 extend_commission,0 wait_commission ")
->field("access.uid admin_id,real_name,nickname,group_id level")
->join("left join sys_auth_group_access access on sys_member.uid = access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->where(['group_id'=>['in','11,12,21']])
@ -926,7 +947,7 @@ class TimingController extends AdminController {
foreach ($data as $key => $value) {
$value['pay_time'] = $time;
$value['remark'] = '自动发放' ;
$value['remark'] = "" ;
$value['create_time'] = time();
$sign = M("market_altogether","tab_")
@ -934,322 +955,196 @@ class TimingController extends AdminController {
->find();
if (!$sign) {
M("market_altogether","tab_")->add($value);
} else {
M("market_altogether","tab_")
->where(['admin_id'=>$value['admin_id'],'pay_time'=>$time])
->save($value);
}
}
}
//
public function sendMarketBonus() {
echo date("Y-m-d H:i:s")."----------------------月初发放市场专员应发份额----------------------\n";
public function createMarketBonus($pay_time) {
$map['pay_time'] = date("Y-m",strtotime('-1 month'));
if ($pay_time& & $pay_time!='all') {
$map['pay_time'] = $pay_time;
}
if ($_REQUEST['pay_time']) {
$map['pay_time'] = $_REQUEST['pay_time'];
if (!$pay_time) {
$pay_time = date("Y-m",strtotime('-1 month'));
$map['pay_time'] = date("Y-m",strtotime('-1 month'));
}
if ($_REQUEST['pay_time'] == 'all') {
if ($pay_time == 'all') {
$end = date("Y-m",time());
$start = '2019-08';
} elseif($_REQUEST['pay_time']) {
$end = $_REQUEST['pay_time'];
$start = $_REQUEST['pay_time'];
} else {
$end = date("Y-m",strtotime('-1 month'));
$start = date("Y-m",strtotime('-1 month'));
$i = 0;
do {
$date = date('Y-m', strtotime($start . ' + ' . $i . ' month'));
$i++;
$this->insertAllUserBonus($date);
} while ($date < date ( ' Y-m ' , strtotime ( " { $ end } -1 month " ) ) ) ;
// $map['pay_time'] = [];
unset($map['pay_time']);
} else{
$this->insertAllUserBonus($pay_time);
}
$i = 0;
do {
$date = date('Y-m', strtotime($start . ' + ' . $i . ' month'));
echo "{$date}:\n";
$i++;
$map['pay_time'] = $date;
//所有管理员插入数据
$this->insertAllUserBonus($map['pay_time']);
$month = date("m",strtotime($date));
$yes = date("Y",strtotime($date));
$all_data = M("settleup_marketorder","tab_")
$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")
sum(if((develop_type = 1 or develop_type = 2), pay_amount, 0)) performance_revenue,sum(if(develop_type = 3, pay_amount, 0)) appraisal_bonuses,
sum(company_tax) company_tax, sum(cp_amount) cp_amount,sum(promote_amount) promote_amount")
->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'];
$check_month = date("m",strtotime($value['pay_time']));
$check_yes = date("Y",strtotime($value['pay_time']));
if ($market_percentage['time'] == 1) {
if ($month == '07'& & ($check_month=='01'||$check_month=='02'||$check_month=='03')) {
$where['season'][] = $value['pay_time'];
} elseif($month == '10'& & ($check_month=='04'||$check_month=='05'||$check_month=='06')) {
$where['season'][] = $value['pay_time'];
} elseif($month == '04'& & ($check_month=='10'||$check_month=='11'||$check_month=='12')& & $check_yes==($yes-1)) {
$where['season'][] = $value['pay_time'];
} elseif($month == '01'& & ($check_month=='07'||$check_month=='08'||$check_month=='09')& & $check_yes==($yes-1)) {
$where['season'][] = $value['pay_time'];
}
// var_dump($check_month);die();
} elseif($market_percentage['time'] == 2) {
if ($month == '07'& & ($check_month=='01'||$check_month=='02'||$check_month=='03'||$check_month=='04'||$check_month=='05'||$check_month=='06')) {
$where['half_year'][] = $value['pay_time'];
} elseif($month == '01'& & ($check_month=='07'||$check_month=='08'||$check_month=='09'||$check_month=='10'||$check_month=='11'||$check_month=='12')& & $check_yes==($yes-1)) {
$where['half_year'][] = $value['pay_time'];
}
} elseif($market_percentage['time'] == 3) {
if ($month == '01'& & ($check_month=='01'||$check_month=='02'||$check_month=='03'||$check_month=='04'||$check_month=='05'||$check_month=='06')& & $check_yes==($yes-1)) {
$where['year'][] = $value['pay_time'];
}
} else {
if ($check_month==($month-1)) {
$where['month'][] = $value['pay_time'];
}
}
}
// dump($wait_amount);die();
$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']));
$check_month = date("m",strtotime($date));
$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]['group_id'];
$insert['pay_amount'] = $data[$key]['pay_amount'];
$insert['extend_commission'] = $data[$key]['extend_commission'];
if ($month != $check_month) {
$insert['type'] = 2;
}
$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);
}
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);
$insert['pay_time'] = $value['pay_time'];
$insert['real_name'] = $value['real_name'];
$insert['admin_id'] = $value['admin_id'];
$insert['nickname'] = $value['nickname'];
$insert['level'] = $value['group_id'];
$insert['pay_amount'] = $value['pay_amount'];
$insert['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);
$insert['wait_commission'] = $all_data[$key]['wait_commission'];
$insert['remark'] = '';
$insert['create_time'] = time();
$insert['company_profit'] = $value['company_profit'];
$insert['company_tax'] = $value['company_tax'];
$insert['cp_amount'] = $value['cp_amount'];
$insert['promote_amount'] = $value['promote_amount'];
$insert['performance_revenue'] = $value['performance_revenue'];
$insert['appraisal_bonuses'] = $value['appraisal_bonuses'];
$insert['performance_commission'] = $all_data[$key]['performance_commission'];
$insert['achievement_bonus'] = $all_data[$key]['achievement_bonus'];
//待发业绩奖金
$insert['wait_performance_commission'] = number_format($all_data[$key]['performance_commission'] * (1-($market_percentage['performance_monthly_ratio']/100)), 2, '.', '');
//待发绩效奖金
$insert['wait_achievement_commission'] = number_format($all_data[$key]['achievement_bonus'] * (1-($market_percentage['month_bonus_ratio']/100)), 2, '.', '');
// $insert['wait_commission'] = ($insert['wait_performance_commission']+$insert['wait_achievement_commission']);
$is_hav = M("market_altogether","tab_")
->where(['admin_id'=>$value['admin_id'],'pay_time'=>$value['pay_time']])
->find();
if (!$is_hav) {
M("market_altogether","tab_")->add($insert);
} else {
M("market_altogether","tab_")
->where(['admin_id'=>$value['admin_id'],'pay_time'=>$value['pay_time']])
->save($insert);
}
//遍历统计数据
$data = M("market_altogether","tab_")
->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'=>$map['pay_time']])
->select();
foreach($data as $key => $value) {
// $sign = 0;
// if ($value['extend_commission']=='0.00') {
// $sign = 1;
// }
$market_percentage = json_decode($value['market_percentage'],true);
if ($market_percentage['time'] == 1) {
if ($month == '07'& & ($check_month=='01'||$check_month=='02'||$check_month=='03')) {
$where['season'][] = $value['pay_time'];
} elseif($month == '10'& & ($check_month=='04'||$check_month=='05'||$check_month=='06')) {
$where['season'][] = $value['pay_time'];
} elseif($month == '04'& & ($check_month=='01'||$check_month=='02'||$check_month=='03')) {
$where['season'][] = $value['pay_time'];
} elseif($month == '01'& & ($check_month=='07'||$check_month=='08'||$check_month=='09')& & $check_yes==($yes-1)) {
$where['season'][] = $value['pay_time'];
}
}
} elseif($market_percentage['time'] == 2) {
if ($month == '07'& & ($check_month=='01'||$check_month=='02'||$check_month=='03'||$check_month=='04'||$check_month=='05'||$check_month=='06')) {
$where['half_year'][] = $value['pay_time'];
} elseif($month == '01'& & ($check_month=='07'||$check_month=='08'||$check_month=='09'||$check_month=='10'||$check_month=='11'||$check_month=='12')& & $check_yes==($yes-1)) {
$where['half_year'][] = $value['pay_time'];
}
} elseif($market_percentage['time'] == 3) {
if ($month == '01'& & ($check_month=='01'||$check_month=='02'||$check_month=='03'||$check_month=='04'||$check_month=='05'||$check_month=='06')& & $check_yes==($yes-1)) {
$where['year'][] = $value['pay_time'];
}
} else {
if ($check_month==($month-1)) {
$where['month'][] = $value['pay_time'];
}
}
}
if ($market_percentage['time'] == 1) {
//跨级发放验证当前发放月份
if ($where['season']) {
M("market_altogether","tab_")
->where(['pay_time'=>['in',array_unique($where['season'])],'admin_id'=>$value['admin_id']])
->save(['type'=>2]);
}
public function sendMarketBonus(){
echo date("Y-m-d H:i:s")."----------------------月初发放市场专员应发份额----------------------\n";
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'];
} 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'];
} 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'];
} 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'];
}
} elseif($market_percentage['time'] == 2) {
$map['pay_time'] = date("Y-m",strtotime('-1 month'));
if ($where['half_year']) {
M("market_altogether","tab_")
->where(['pay_time'=>['in',array_unique($where['half_year'])],'admin_id'=>$value['admin_id']])
->save(['type'=>2]);
}
if ($_REQUEST['time']) {
$map['pay_time'] = $_REQUEST['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'] +
$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 ($_REQUEST['time'] == 'all') {
unset($map['pay_time']);
}
if ($where['year']) {
M("market_altogether","tab_" )
->where(['pay_time'=>['in',array_unique($where['year'])],'level'=>$value['admin_id']])
->save(['type'=>2] );
}
$data = M("market_altogether","tab_")
->where($map)
->select();
// dump($map);die();
foreach ($data as $key => $value) {
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 {
if ($where['month']) {
M("market_altogether","tab_")
->where(['pay_time'=>['in',array_unique($where['month'])],'admin_id'=>$value['admin_id']])
->save(['type'=>2]);
}
$data[$key]['extend_commission'] +=$wait_amount[$value['admin_id'] . date("Y-m",strtotime("last month",strtotime($date)))];
$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 =[];
if ($group_config['time'] == 1) {
// var_dump($month);die();
if ($month == '07') {
$where = [$yes.'-'.'01',$yes.'-'.'02',$yes.'-'.'03'];
} elseif($month == '10') {
$where = [$yes.'-'.'04',$yes.'-'.'05',$yes.'-'.'06'];
} elseif($month == '04') {
$where = [($yes-1).'-'.'10',($yes-1).'-'.'11',($yes-1).'-'.'12'];
} elseif($month == '01') {
$where = [($yes-1).'-'.'07',($yes-1).'-'.'08',($yes-1).'-'.'09'];
}
$update['extend_commission'] = $data[$key]['extend_commission'];
} 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'];
}
} else {
$where = [date("Y-m",strtotime("last month",strtotime($value['pay_time'])))];
}
echo "{$value['pay_time']}:{$value['real_name']}发放\n";
$save['status'] = 1;
$save['remark'] = '自动发放';
if ($where) {
$map['pay_time'] = ['in',$where];
$map['admin_id'] = $value['admin_id'];
// if ($sign) {
// M("market_altogether","tab_")
// ->where(['pay_time'=>$data[$key]['pay_time'],'admin_id'=>$data[$key]['admin_id']])
// ->save($update);
// }
M("market_altogether","tab_")
->where(['pay_time'=>$data[$key]['pay_time'],'admin_id'=>$data[$key]['admin_id']])
->save($update);
->where($map)
->save($save);
}
} while ($date < date ( ' Y-m ' , strtotime ( " { $ end } -1 month " ) ) ) ;
}
echo date("Y-m-d H:i:s")."----------------------月初发放市场专员应发份额 ----------------------\n";
echo date("Y-m-d H:i:s")."----------------------市场结算管理计算----------------------\n";
}