优化子站生成数据

master
chenzhi 4 years ago
parent 7d650a9595
commit c285a88c8d

@ -119,8 +119,6 @@ return array(
"sys_auth_group",
"tab_index_chart",
"tab_company_statement",
"tab_company_lack_statement_info",
"tab_company_statement_info",
"tab_company_statement_pool",
"tab_financial_summary",
"tab_pay_statement_info",

@ -523,264 +523,6 @@ class SubCompanyStatementSetController extends Controller {
}
return [$begintime,$endtime];
}
//获取推广公司推广金额
public function getPromoteCompanySpend(&$pcList,$idarr,$begintime,$endtime){
$res = [];
$all_res = [];
$cp_res = [];
$cp_all_res = [];
//获取推广员
if(count($idarr) == 0){return $res;}
$Promote = M("Promote","tab_");
$Spend = M("Spend","tab_");
$spenMap = [
"s.pay_status"=>1,
"s.payed_time"=>['between', [$begintime,$endtime]],
"s.is_check"=>1
];
D("Spend")->addSubsiteWhere($spenMap);
$cpMap = [
"s.pay_status"=>1,
"s.payed_time"=>['between', [$begintime,$endtime]]
];
D("Spend")->addSubsiteWhere($cpMap);
$cpAllMap =[
"s.pay_status"=>1,
"s.payed_time"=>['elt',$endtime]
];
D("Spend")->addSubsiteWhere($cpAllMap);
for ($i=0; $i <count($idarr); $i++) {
$company_id = $idarr[$i];
$pres = $Promote->field("group_concat(id) ids,count(id) count")->where("company_id = '{$company_id}'")->group("company_id")->find();
if($pres['count'] ==0 ){continue;}
$spenMap['s.promote_id']=["in",$pres['ids']];
//获取支付记录
$list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($spenMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
$allSpendMap = $spenMap;
unset($allSpendMap["s.payed_time"]);
$allspend_list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($allSpendMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
foreach($allspend_list as $k=>$v){
try {
$all_res[$company_id]["pay_amount"] += $v['pay_amount'];
} catch (\Throwable $th) {
$all_res[$company_id]["pay_amount"] = $v['pay_amount'];
}
if(isset($all_res[$company_id][$v['relation_game_id']])){
//
$all_res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
}else{
unset($v['game_id']);
$all_res[$company_id][$v['relation_game_id']]= $v;
}
}
if(empty($list)){continue;}
foreach($list as $k=>$v){
try {
$res[$company_id]["pay_amount"] += $v['pay_amount'];
} catch (\Throwable $th) {
$res[$company_id]["pay_amount"] = $v['pay_amount'];
}
if(isset($res[$company_id][$v['relation_game_id']])){
//
$res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
$res[$company_id][$v['relation_game_id']]['ratio_pay_amount'] += $v['pay_amount'];
}else{
unset($v['game_id']);
$v['ratio_pay_amount'] = $v['pay_amount'];
$res[$company_id][$v['relation_game_id']]= $v;
}
}
$game_ids = implode(",",array_unique(array_column($list,"relation_game_id")));
$game_ids = $this->getModuleRatioGame($company_id,$game_ids,$begintime,$endtime);
$sameGame = $this->getTheSameGame($game_ids);
if(!empty($sameGame)){
foreach ($sameGame as $k => $v) {
$temp = 0;
for ($j=0; $j < count($v); $j++) {
// $turnover_where = [
// "relation_game_id"=>$v[$j],
// "company_id"=>$company_id,
// "_string"=>"begin_time <={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})"
// ];
// $turnover_type = D("CompanyGameRatio")->field("turnover_type")->where($turnover_where)->find()['turnover_type'];
$turnover_type = $this->getTurnoverType($v[$j],$company_id,$begintime,$endtime);
if ($turnover_type == 2) {
$res[$company_id][$v[$j]]['ratio_pay_amount'] = $all_res[$company_id][$v[$j]]['pay_amount'];
$temp += $all_res[$company_id][$v[$j]]['pay_amount'];
} elseif($turnover_type == 3){
if (empty($cp_res[$company_id])) {
$cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
// if ($company_id == 5) {
// dump($cpMap);
// }
foreach($cpSpendList as $ck=>$cv){
try {
$cp_res[$company_id]["pay_amount"] += $cv['pay_amount'];
} catch (\Throwable $th) {
$cp_res[$company_id]["pay_amount"] = $cv['pay_amount'];
}
if(isset($cp_res[$company_id][$cv['relation_game_id']])){
//
$cp_res[$company_id][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
}else{
unset($cv['game_id']);
$cp_res[$company_id][$cv['relation_game_id']]= $cv;
}
}
}
$res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_res[$company_id][$v[$j]]['pay_amount'];
$temp += $cp_res[$company_id][$v[$j]]['pay_amount'];
} elseif($turnover_type == 4){
if (empty($cp_all_res[$company_id])) {
$cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
foreach ($cpAllSpendList as $ck => $cv) {
try {
$cp_all_res[$company_id]["pay_amount"] += $cv['pay_amount'];
} catch (\Throwable $th) {
$cp_all_res[$company_id]["pay_amount"] = $cv['pay_amount'];
}
if (isset($cp_all_res[$company_id][$cv['relation_game_id']])) {
//
$cp_all_res[$company_id][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
} else {
unset($cv['game_id']);
$cp_all_res[$company_id][$cv['relation_game_id']] = $cv;
}
}
}
$res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_all_res[$company_id][$v[$j]]['pay_amount'];
$temp += $cp_all_res[$company_id][$v[$j]]['pay_amount'];
} else {
// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount'];
$temp += $res[$company_id][$v[$j]]['pay_amount'];
}
}
$sameGame[$k] = $temp;
}
foreach ($sameGame as $k => $v) {
$res[$company_id][$k]['all_pay_amount'] = $v;
// $game[$k]['pay_amount']= $v;
}
}
}
foreach($res as $key=>$value){
foreach ($value as $k => $v){
if ($k!='pay_amount') {
$turnover_type = $this->getTurnoverType($k,$key,$begintime,$endtime);
if ($turnover_type == 2) {
$res[$key][$k]['ratio_pay_amount'] = $all_res[$key][$k]['pay_amount'];
} elseif($turnover_type == 3){
if (empty($cp_res[$key])) {
// if ($key == 5) {
// dump(2);
// dump($cpMap);
// dump($cp_res);
// }
$cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
foreach($cpSpendList as $ck=>$cv){
try {
$cp_res[$key]["pay_amount"] += $cv['pay_amount'];
} catch (\Throwable $th) {
$cp_res[$key]["pay_amount"] = $cv['pay_amount'];
}
if(isset($cp_res[$key][$cv['relation_game_id']])){
//
$cp_res[$key][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
}else{
unset($cv['game_id']);
$cp_res[$key][$cv['relation_game_id']]= $cv;
}
}
}
$res[$key][$k]['ratio_pay_amount'] = $cp_res[$key][$k]['pay_amount'];
} elseif($turnover_type == 4){
if (empty($cp_all_res[$key])) {
$cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
foreach ($cpAllSpendList as $ck => $cv) {
try {
$cp_all_res[$key]["pay_amount"] += $cv['pay_amount'];
} catch (\Throwable $th) {
$cp_all_res[$key]["pay_amount"] = $cv['pay_amount'];
}
if (isset($cp_all_res[$key][$cv['relation_game_id']])) {
//
$cp_all_res[$key][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
} else {
unset($cv['game_id']);
$cp_all_res[$key][$cv['relation_game_id']] = $cv;
}
}
}
$res[$key][$k]['ratio_pay_amount'] = $cp_all_res[$key][$k]['pay_amount'];
}
}
}
}
foreach($res as $k=>$v){
$pcList[$k]["pay_amount"] = $v['pay_amount'];
unset($v['pay_amount']);
$pcList[$k]['game_list'] = $v;
$pcList[$k]['game_ids'] = implode(",",array_keys($pcList[$k]['game_list']));
}
}
/**
* 返回结算流水类型
*/

Loading…
Cancel
Save