|
|
|
@ -502,7 +502,7 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//设定开始结束时间
|
|
|
|
|
public function setBeginAndEndTime($type,$stime){
|
|
|
|
|
protected function setBeginAndEndTime($type,$stime){
|
|
|
|
|
if($type == 0){
|
|
|
|
|
$begintime = mktime(0,0,0,date('m',$stime),date('d',$stime)-7,date('Y',$stime));
|
|
|
|
|
$endtime = mktime(0,0,0,date('m',$stime),date('d',$stime),date('Y',$stime))-1;
|
|
|
|
@ -526,7 +526,7 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
/**
|
|
|
|
|
* 返回结算流水类型
|
|
|
|
|
*/
|
|
|
|
|
public function getTurnoverType($relation_game_id = 0, $company_id = 0, $begin_time = 0, $end_time = 0){
|
|
|
|
|
protected function getTurnoverType($relation_game_id = 0, $company_id = 0, $begin_time = 0, $end_time = 0){
|
|
|
|
|
$company_belong = M("promote_company","tab_")->field("company_belong")->where(['id'=>$company_id])->find();
|
|
|
|
|
|
|
|
|
|
if (!$company_belong) {
|
|
|
|
@ -581,6 +581,8 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
//获取推广公司推广金额
|
|
|
|
|
protected function getPuPromoteSpend(&$pcList,$idarr,$begintime,$endtime){
|
|
|
|
|
$res = [];
|
|
|
|
|
$statement_begin_time = date("Y.m.d",$begintime);
|
|
|
|
|
$statement_end_time = date("Y.m.d",$endtime);
|
|
|
|
|
//获取推广员
|
|
|
|
|
if(count($idarr) == 0){return $res;}
|
|
|
|
|
$Promote = M("Promote","tab_");
|
|
|
|
@ -591,19 +593,6 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
"s.is_check"=>1
|
|
|
|
|
];
|
|
|
|
|
D("Spend")->addSubsiteWhere($spenMap,"s");
|
|
|
|
|
$cpallgame = [];
|
|
|
|
|
$cpgame = [];
|
|
|
|
|
$cpMap = [
|
|
|
|
|
"s.pay_status"=>1,
|
|
|
|
|
"s.payed_time"=>['between', [$begintime,$endtime]]
|
|
|
|
|
];
|
|
|
|
|
D("Spend")->addSubsiteWhere($cpMap,"s");
|
|
|
|
|
$cpAllMap = [
|
|
|
|
|
"s.pay_status"=>1,
|
|
|
|
|
"s.payed_time"=>['elt',$endtime]
|
|
|
|
|
];
|
|
|
|
|
D("Spend")->addSubsiteWhere($cpAllMap,"s");
|
|
|
|
|
|
|
|
|
|
for ($i=0; $i <count($idarr); $i++) {
|
|
|
|
|
$company_id = $idarr[$i];
|
|
|
|
|
|
|
|
|
@ -618,44 +607,21 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
//获取支付记录
|
|
|
|
|
$list = $Spend
|
|
|
|
|
->alias('s')
|
|
|
|
|
->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id")
|
|
|
|
|
->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,g.game_type_name")
|
|
|
|
|
->where($spenMap)
|
|
|
|
|
->group('p_id,game_id')
|
|
|
|
|
->join("tab_promote promote ON s.promote_id = promote.id","left")
|
|
|
|
|
->group('game_id')
|
|
|
|
|
->join("left join tab_game g on s.game_id = g.id")
|
|
|
|
|
->select();
|
|
|
|
|
|
|
|
|
|
$all_spendMap = $spenMap;
|
|
|
|
|
unset($all_spendMap['s.payed_time']);
|
|
|
|
|
|
|
|
|
|
$all_list = $Spend
|
|
|
|
|
->alias('s')
|
|
|
|
|
->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id")
|
|
|
|
|
->where($all_spendMap)
|
|
|
|
|
->group('p_id,game_id')
|
|
|
|
|
->join("tab_promote promote ON s.promote_id = promote.id","left")
|
|
|
|
|
->join("left join tab_game g on s.game_id = g.id")
|
|
|
|
|
->select();
|
|
|
|
|
|
|
|
|
|
if(empty($list)){continue;}
|
|
|
|
|
if(empty($list)){unset($pcList[$company_id]);continue;}
|
|
|
|
|
$game = [];
|
|
|
|
|
foreach($list as $k=>$v){
|
|
|
|
|
if(isset($game[$v['relation_game_id']])){
|
|
|
|
|
$game[$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
|
|
|
|
|
}else{
|
|
|
|
|
$game[$v['relation_game_id']]['pay_amount'] = $v['pay_amount'];
|
|
|
|
|
$game[$v['relation_game_id']] = $v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$allgame = [];
|
|
|
|
|
foreach($all_list as $k=>$v){
|
|
|
|
|
if(isset($allgame[$v['relation_game_id']])){
|
|
|
|
|
$allgame[$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
|
|
|
|
|
}else{
|
|
|
|
|
$allgame[$v['relation_game_id']]['pay_amount'] = $v['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//同cp,同一个原包名的共享总流水分成
|
|
|
|
|
$game_ids = implode(",",array_keys($game));
|
|
|
|
|
$game_ids = $this->getModuleRatioGame($company_id,$game_ids,$begintime,$endtime);
|
|
|
|
@ -665,45 +631,7 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
foreach ($sameGame as $k => $v) {
|
|
|
|
|
$temp = 0;
|
|
|
|
|
for ($j=0; $j < count($v); $j++) {
|
|
|
|
|
$turnover_type = $this->getTurnoverType($v[$j],$company_id,$begintime,$endtime);
|
|
|
|
|
if ($turnover_type == 2) {
|
|
|
|
|
$temp += $allgame[$v[$j]]['pay_amount'];
|
|
|
|
|
} elseif($turnover_type == 3) {
|
|
|
|
|
|
|
|
|
|
if (empty($cpgame)) {
|
|
|
|
|
$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){
|
|
|
|
|
if(isset($cpgame[$cv['relation_game_id']])){
|
|
|
|
|
$cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
|
|
|
|
|
}else{
|
|
|
|
|
$cpgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$temp += $cpgame[$v[$j]]['pay_amount'];
|
|
|
|
|
} elseif($turnover_type == 4) {
|
|
|
|
|
|
|
|
|
|
if (empty($cpallgame)) {
|
|
|
|
|
$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){
|
|
|
|
|
if(isset($cpallgame[$cv['relation_game_id']])){
|
|
|
|
|
$cpallgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
|
|
|
|
|
}else{
|
|
|
|
|
$cpallgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$temp += $cpallgame[$v[$j]]['pay_amount'];
|
|
|
|
|
} else {
|
|
|
|
|
$temp += $game[$v[$j]]['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$sameGame[$k] = $temp;
|
|
|
|
|
}
|
|
|
|
@ -711,78 +639,26 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
$game[$k]['pay_amount']= $v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$pcList[$company_id]['game_ids'] = implode(",",array_keys($game));
|
|
|
|
|
|
|
|
|
|
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'];
|
|
|
|
|
}
|
|
|
|
|
$p_account = $promote_a[$v['p_id']];
|
|
|
|
|
|
|
|
|
|
if(isset($res[$company_id][$p_account][$v['relation_game_id']])){
|
|
|
|
|
//
|
|
|
|
|
$res[$company_id][$p_account][$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
|
|
|
|
|
}else{
|
|
|
|
|
unset($v['game_id']);
|
|
|
|
|
$res[$company_id][$p_account][$v['relation_game_id']]= $v;
|
|
|
|
|
|
|
|
|
|
$turnover_type = $this->getTurnoverType($v['relation_game_id'],$company_id,$begintime,$endtime);
|
|
|
|
|
|
|
|
|
|
if ($turnover_type == 2) {
|
|
|
|
|
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $allgame[$v['relation_game_id']]['pay_amount'];
|
|
|
|
|
} elseif($turnover_type == 3) {
|
|
|
|
|
|
|
|
|
|
if (empty($cpgame)) {
|
|
|
|
|
$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){
|
|
|
|
|
if(isset($cpgame[$cv['relation_game_id']])){
|
|
|
|
|
$cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
|
|
|
|
|
}else{
|
|
|
|
|
$cpgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpgame[$v['relation_game_id']]['pay_amount'];
|
|
|
|
|
} elseif($turnover_type == 4) {
|
|
|
|
|
|
|
|
|
|
if (empty($cpallgame)) {
|
|
|
|
|
$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){
|
|
|
|
|
if(isset($cpallgame[$cv['relation_game_id']])){
|
|
|
|
|
$cpallgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount'];
|
|
|
|
|
}else{
|
|
|
|
|
$cpallgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpallgame[$v['relation_game_id']]['pay_amount'];
|
|
|
|
|
} else {
|
|
|
|
|
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
$res[$company_id][$p_account][$v['relation_game_id']]['game_type_name'] = $this->getGameTypeName($v['relation_game_id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// if($company_id == 23) dd($game);
|
|
|
|
|
//计算比例
|
|
|
|
|
$pay_amount = 0;
|
|
|
|
|
$sum_money = 0;
|
|
|
|
|
$statementInfo = [];
|
|
|
|
|
foreach ($game as $k => $v) {
|
|
|
|
|
$company_belong = $pcList[$company_id]['company_belong'];
|
|
|
|
|
$gameOther =$this->getPuGameRatio($company_id,$company_belong,$k,$v['pay_amount'],$begintime,$endtime);
|
|
|
|
|
$v['ratio'] = $gameOther[0];
|
|
|
|
|
$v['sum_money'] = $gameOther[1];
|
|
|
|
|
$v['statement_begin_time'] = $statement_begin_time;
|
|
|
|
|
$v['statement_end_time'] = $statement_end_time;
|
|
|
|
|
$statementInfo[] = $v;
|
|
|
|
|
|
|
|
|
|
foreach($res as $k=>$v){
|
|
|
|
|
$pcList[$k]["pay_amount"] = $v['pay_amount'];
|
|
|
|
|
unset($v['pay_amount']);
|
|
|
|
|
foreach($v as $ke=>$va){
|
|
|
|
|
$tmp = [
|
|
|
|
|
"account"=>$ke,
|
|
|
|
|
'game_list'=>$va
|
|
|
|
|
];
|
|
|
|
|
$pcList[$k]['list'][] = $tmp;
|
|
|
|
|
$pay_amount += $v['pay_amount'];
|
|
|
|
|
$sum_money += $v['sum_money'];
|
|
|
|
|
}
|
|
|
|
|
$pcList[$company_id]['statement_info'] = $statementInfo;
|
|
|
|
|
$pcList[$company_id]['pay_amount'] = $pay_amount;
|
|
|
|
|
$pcList[$company_id]['sum_money'] = $sum_money;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public function promoteUserPool($type,$stime,$recount = false){
|
|
|
|
@ -790,48 +666,14 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
$begintime = $t[0];
|
|
|
|
|
$endtime = $t[1];
|
|
|
|
|
|
|
|
|
|
$user = [
|
|
|
|
|
"pay_amount"=>0,
|
|
|
|
|
"statement_money"=>0,
|
|
|
|
|
"lack_statement_money"=>0,
|
|
|
|
|
"withdraw_type"=>$type,
|
|
|
|
|
"platform_amount"=>0,
|
|
|
|
|
"create_lack_ids"=>[],
|
|
|
|
|
"del_lack_ids"=>[],
|
|
|
|
|
$statementInfo = $this->doPromoteUserPool($user,1,$stime,$recount);
|
|
|
|
|
if($recount){
|
|
|
|
|
SM("user_statement","sub_")->where([
|
|
|
|
|
"statement_begin_time"=>$begintime,
|
|
|
|
|
"statement_end_time"=>$endtime,
|
|
|
|
|
"fine"=>0,
|
|
|
|
|
"reward"=>0,
|
|
|
|
|
"verify_status"=>0,
|
|
|
|
|
"company_type"=>2,
|
|
|
|
|
"verify_log"=>json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]),
|
|
|
|
|
"op_time"=>time(),
|
|
|
|
|
"statement_num"=>"PL_".date('Ymd').date('His').sp_random_num(3)
|
|
|
|
|
];
|
|
|
|
|
// $users = $user = $basedata;
|
|
|
|
|
// $users['is_payment'] = 1;
|
|
|
|
|
// $users['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3);
|
|
|
|
|
|
|
|
|
|
// $user['is_payment'] = 2;
|
|
|
|
|
// $user['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($type == 0){//周结
|
|
|
|
|
$this->doPromoteUserPool($user,0,$stime,$recount);
|
|
|
|
|
}else if($type == 1){
|
|
|
|
|
$users['withdraw_type'] = 1;
|
|
|
|
|
$user['withdraw_type'] = 1;
|
|
|
|
|
//月结&补点
|
|
|
|
|
$this->doPromoteUserPool($user,1,$stime,$recount);
|
|
|
|
|
}else{
|
|
|
|
|
$users['withdraw_type'] = 2;
|
|
|
|
|
$user['withdraw_type'] = 2;
|
|
|
|
|
$this->doPromoteUserPool($user,2,$stime,$recount);
|
|
|
|
|
"statement_end_time"=>$endtime
|
|
|
|
|
])->delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->savePromotateUserPool($user);
|
|
|
|
|
|
|
|
|
|
SM("user_statement","sub_")->add($statementInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -868,7 +710,7 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
"company_type"=>2
|
|
|
|
|
];
|
|
|
|
|
$tmpp = M("PromoteCompany","tab_")
|
|
|
|
|
->field("id,uid,company_name partner,settlement_contact link_man,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,taxation_rate,company_belong,company_type,ali_user,ali_account,has_server_fee,server_fee,has_ratio,turnover_ratio")
|
|
|
|
|
->field("id,company_name partner,company_belong,company_type")
|
|
|
|
|
->where($pu_map)
|
|
|
|
|
->select();
|
|
|
|
|
if(count($tmpp)<1){return;}
|
|
|
|
@ -876,374 +718,29 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
$pc =[];
|
|
|
|
|
$Promote = M("Promote","tab_");
|
|
|
|
|
foreach ($tmpp as $v) {
|
|
|
|
|
$p_map = [
|
|
|
|
|
"company_id"=>$v['id'],
|
|
|
|
|
"withdraw_done"=>1
|
|
|
|
|
];
|
|
|
|
|
if($v['has_ratio']){
|
|
|
|
|
$v['turnover_ratio'] = json_decode($v['turnover_ratio'],true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pc[$v['id']]=$v;
|
|
|
|
|
$pc[$v['id']]['is_payment']=$pcList[$v['id']]['is_payment'];
|
|
|
|
|
}
|
|
|
|
|
unset($tmpp);
|
|
|
|
|
|
|
|
|
|
$this->getPuPromoteSpend($pc,array_unique(array_keys($pc)),$begintime,$endtime);
|
|
|
|
|
dump($pc);die();
|
|
|
|
|
|
|
|
|
|
$StatementDb = SM("CompanyStatement","tab_");
|
|
|
|
|
$statement_begin_time = date("Y.m.d",$begintime);
|
|
|
|
|
$statement_end_time = date("Y.m.d",$endtime);
|
|
|
|
|
// $RewardRecord = M("RewardRecord","tab_");
|
|
|
|
|
$LackStatement = SM("company_lack_statement_info","tab_");
|
|
|
|
|
$StatementInfo = SM("company_statement_info","tab_");
|
|
|
|
|
|
|
|
|
|
foreach($pc as $k=>&$v){
|
|
|
|
|
$fax_ratio = $v['taxation_rate'];
|
|
|
|
|
$RewardRecordRes = $this->getPromoteUserRewardRecord($v['id'],$begintime,$endtime);
|
|
|
|
|
if($v['has_ratio'] == 1){
|
|
|
|
|
$company_ratio = $this->getCompanyRatio($v['pay_amount'],$pc[$k]['turnover_ratio']);
|
|
|
|
|
}else{
|
|
|
|
|
$company_ratio = 0;
|
|
|
|
|
}
|
|
|
|
|
//获取其他信息
|
|
|
|
|
$v = $this->getCompanyOtherInfo($v,$k);
|
|
|
|
|
$countdata = &$user;
|
|
|
|
|
$v['statement_money'] = 0;
|
|
|
|
|
$v['pay_amount'] = 0;
|
|
|
|
|
if($type < 2 && $RewardRecordRes){
|
|
|
|
|
$v['fine'] = $RewardRecordRes['fine'];
|
|
|
|
|
$v['reward'] = $RewardRecordRes['reward'];
|
|
|
|
|
$v['statement_money'] -= $v['fine'];
|
|
|
|
|
$v['statement_money'] += $v['reward'];
|
|
|
|
|
}else{
|
|
|
|
|
$v['fine'] = 0;
|
|
|
|
|
$v['reward'] = 0;
|
|
|
|
|
}
|
|
|
|
|
$v['platform_amount'] = 0;
|
|
|
|
|
if(!isset($v['list'])){continue;}
|
|
|
|
|
$company_belong = $pc[$v['id']]['company_belong'];
|
|
|
|
|
//服务器费用
|
|
|
|
|
if ($type < 2) {
|
|
|
|
|
if ($v['has_server_fee'] == 1 && $v['server_fee'] > 0) {
|
|
|
|
|
$v['statement_info'][] = [
|
|
|
|
|
"game_name"=>"服务器费用",
|
|
|
|
|
"sum_money"=>-$v['server_fee'],
|
|
|
|
|
"pay_amount"=>-$v['server_fee'],
|
|
|
|
|
'statement_type'=>1,
|
|
|
|
|
"statement_begin_time"=>$statement_begin_time,
|
|
|
|
|
"statement_end_time"=>$statement_end_time
|
|
|
|
|
];
|
|
|
|
|
$v['pay_amount'] -= $v['server_fee'];
|
|
|
|
|
$v['statement_money'] -= $v['server_fee'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$promoteCompanyGameRatio = D("CompanyGameRatio")->getPromoteCompanyGameRatio($v['id'],$v['game_ids'],$begintime,$endtime,$company_belong);
|
|
|
|
|
|
|
|
|
|
$handleed_data = [];
|
|
|
|
|
|
|
|
|
|
foreach($v['list'] as $ke=>$va){
|
|
|
|
|
$templist = $va['game_list'];
|
|
|
|
|
$va['game_list'] = [];
|
|
|
|
|
foreach($templist as $p_id => $p_info){
|
|
|
|
|
|
|
|
|
|
$ratioCount = count($promoteCompanyGameRatio[$p_info['relation_game_id']]);
|
|
|
|
|
$isMoreRatio = $ratioCount > 1 ? true : false;
|
|
|
|
|
|
|
|
|
|
if(!$isMoreRatio){
|
|
|
|
|
$tmp_game_ratio = $promoteCompanyGameRatio[$p_info['relation_game_id']][0];
|
|
|
|
|
if($type == 1){
|
|
|
|
|
$tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio += $company_ratio;
|
|
|
|
|
}elseif($type == 0){
|
|
|
|
|
// $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
// $tratio = $tmp_game_ratio['ratio'];
|
|
|
|
|
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
|
|
|
|
|
|
|
|
|
|
// if ($v['id'] == 5) {
|
|
|
|
|
// dump($p_info['all_pay_amount']);
|
|
|
|
|
// dump($turnover_type);
|
|
|
|
|
// dump($tmp_game_ratio);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if ($turnover_type == 2||$turnover_type == 4) {
|
|
|
|
|
$tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
} else {
|
|
|
|
|
$tratio = $tmp_game_ratio['ratio'];
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
|
|
|
|
|
if ($turnover_type == 2||$turnover_type == 4) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//补点
|
|
|
|
|
$tratio1 =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio2 =$tmp_game_ratio['ratio'];
|
|
|
|
|
$tratio = $tratio1-$tratio2+$company_ratio;
|
|
|
|
|
if($tratio <= 0){ continue;}
|
|
|
|
|
}
|
|
|
|
|
$tratio -= 0;
|
|
|
|
|
if($type == 2){
|
|
|
|
|
$p_info['increment_ratio']=$tratio;
|
|
|
|
|
}else{
|
|
|
|
|
$p_info['ratio']=$tratio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$p_info['pay_amount'] = $this->getRelationGameIdPromoteSpend($p_info["p_id"],$p_info['relation_game_id'],$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']);
|
|
|
|
|
|
|
|
|
|
$p_info['pay_amount'] = number_format($p_info['pay_amount'],2,'.','');
|
|
|
|
|
|
|
|
|
|
$v['platform_amount'] += $p_info['pay_amount'];
|
|
|
|
|
$p_info['sum_money']=round($p_info['pay_amount']*$tratio/100,2); //个人等于 结算金额*比例
|
|
|
|
|
$v['pay_amount'] += $p_info['sum_money'];
|
|
|
|
|
$v['statement_money'] += $p_info['sum_money'];
|
|
|
|
|
$p_info['fax_ratio']=$fax_ratio;
|
|
|
|
|
$p_info['statement_begin_time']=$statement_begin_time;
|
|
|
|
|
$p_info['statement_end_time']=$statement_end_time;
|
|
|
|
|
|
|
|
|
|
$RewardRecordRes = $this->getPromoteUserGameRewardRecord($v['id'],$statement_begin_time,$statement_end_time);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0')
|
|
|
|
|
|| ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0')
|
|
|
|
|
) {
|
|
|
|
|
$p_info['fine'] = 0;
|
|
|
|
|
$p_info['reward'] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$p_info['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0;
|
|
|
|
|
$p_info['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0;
|
|
|
|
|
$handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine'];
|
|
|
|
|
$handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward'];
|
|
|
|
|
}
|
|
|
|
|
// if ($p_info['relation_game_id'] == 191 && $v['id'] == 334) {
|
|
|
|
|
// dump($RewardRecordRes);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$p_info['statement_type']=0;
|
|
|
|
|
|
|
|
|
|
if ($p_info['pay_amount'] !='0') {
|
|
|
|
|
$va['game_list'][] = $p_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
for ($i=0; $i < $ratioCount; $i++) {
|
|
|
|
|
$temp_game = [];
|
|
|
|
|
$tmp_game_ratio = $promoteCompanyGameRatio[$p_info['relation_game_id']][$i];
|
|
|
|
|
if($type == 1){
|
|
|
|
|
$tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio += $company_ratio;
|
|
|
|
|
}elseif($type == 0){
|
|
|
|
|
|
|
|
|
|
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
|
|
|
|
|
// if ($v['id'] == 5) {
|
|
|
|
|
// dump($p_info['all_pay_amount']);
|
|
|
|
|
// dump($turnover_type);
|
|
|
|
|
// dump($tmp_game_ratio);
|
|
|
|
|
// }
|
|
|
|
|
if ($turnover_type == 2 || $turnover_type == 4) {
|
|
|
|
|
$tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
} else {
|
|
|
|
|
$tratio = $tmp_game_ratio['ratio'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
|
|
|
|
|
if ($turnover_type == 2 || $turnover_type == 4) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//补点
|
|
|
|
|
$tratio1 =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio2 =$tmp_game_ratio['ratio'];
|
|
|
|
|
$tratio = $tratio1-$tratio2+$company_ratio;
|
|
|
|
|
if($tratio <= 0){ continue;}
|
|
|
|
|
}
|
|
|
|
|
$tratio -= 0;
|
|
|
|
|
if($type == 2){
|
|
|
|
|
$temp_game['increment_ratio']=$tratio;
|
|
|
|
|
}else{
|
|
|
|
|
$temp_game['ratio']=$tratio;
|
|
|
|
|
}
|
|
|
|
|
$temp_game['pay_amount'] = $this->getRelationGameIdPromoteSpend($p_info["p_id"],$p_info['relation_game_id'],$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']);
|
|
|
|
|
$temp_game['pay_amount'] -=0;
|
|
|
|
|
$temp_game['pay_amount'] = number_format($temp_game['pay_amount'],2,'.','');
|
|
|
|
|
|
|
|
|
|
$v['platform_amount'] += $temp_game['pay_amount'];
|
|
|
|
|
$temp_game['sum_money']=round($temp_game['pay_amount']*$tratio/100,2); //个人等于 结算金额*比例
|
|
|
|
|
$v['pay_amount'] += $temp_game['sum_money'];
|
|
|
|
|
$v['statement_money'] += $temp_game['sum_money'];
|
|
|
|
|
|
|
|
|
|
$temp_game['fax_ratio']=$fax_ratio-0;
|
|
|
|
|
$temp_game['statement_begin_time']=date("Y.m.d",$tmp_game_ratio['begintime']);
|
|
|
|
|
$temp_game['statement_end_time']=date("Y.m.d",$tmp_game_ratio['endtime']);
|
|
|
|
|
$temp_game['statement_type']=0;
|
|
|
|
|
|
|
|
|
|
$RewardRecordRes = $this->getPromoteUserGameRewardRecord($v['id'],$temp_game['statement_begin_time'],$temp_game['statement_end_time']);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
($handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] || $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] == '0')
|
|
|
|
|
|| ($handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] || $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] == '0')
|
|
|
|
|
) {
|
|
|
|
|
$temp_game['fine'] = 0;
|
|
|
|
|
$temp_game['reward'] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$temp_game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0;
|
|
|
|
|
$temp_game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0;
|
|
|
|
|
$handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] = (string)$RewardRecordRes['fine'];
|
|
|
|
|
$handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] = (string)$RewardRecordRes['reward'];
|
|
|
|
|
}
|
|
|
|
|
// if ($p_info['relation_game_id'] == 191 && $v['id'] == 334) {
|
|
|
|
|
// dump($RewardRecordRes);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
$temp_game['statement_type']=0;
|
|
|
|
|
|
|
|
|
|
$temp_game['relation_game_id']=$p_info["relation_game_id"];
|
|
|
|
|
$temp_game['game_name']=$p_info["game_name"];
|
|
|
|
|
$temp_game['game_type_name']=$p_info["game_type_name"];
|
|
|
|
|
$temp_game['all_pay_amount']=$p_info["all_pay_amount"];
|
|
|
|
|
|
|
|
|
|
if ($temp_game['pay_amount'] != '0') {
|
|
|
|
|
$va['game_list'][] = $temp_game;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$v['statement_info'][] = $va;
|
|
|
|
|
}
|
|
|
|
|
$company_info = [
|
|
|
|
|
'account'=>$v['account'],
|
|
|
|
|
"company_relation_str"=>$v['company_relation_str'],
|
|
|
|
|
"company_belong_str"=>$v['company_belong_str'],
|
|
|
|
|
"company_type_str"=>$v['company_type_str'],
|
|
|
|
|
"nickname"=>$v['nickname'],
|
|
|
|
|
"payee_name"=>$v['payee_name'],
|
|
|
|
|
"bank_account"=>$v['bank_account'],
|
|
|
|
|
"opening_bank"=>$v['opening_bank'],
|
|
|
|
|
"ali_user"=>$v['ali_user'],
|
|
|
|
|
"ali_account"=>$v['ali_account']
|
|
|
|
|
];
|
|
|
|
|
if($v['platform_amount'] < 300){
|
|
|
|
|
$lackcompany =[
|
|
|
|
|
"company_id"=>$k,
|
|
|
|
|
"company_type"=>2,
|
|
|
|
|
"company_name"=>$v['partner'],
|
|
|
|
|
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
|
|
|
|
|
"statement_money"=>$v['statement_money'],
|
|
|
|
|
"pay_amount"=>$v['pay_amount'],
|
|
|
|
|
"platform_amount"=>$v['platform_amount'],
|
|
|
|
|
"fine"=>$v['fine'],
|
|
|
|
|
"reward"=>$v['reward'],
|
|
|
|
|
"statement_begin_time"=>$begintime,
|
|
|
|
|
"statement_end_time"=>$endtime,
|
|
|
|
|
|
|
|
|
|
"statement_pool_num"=>$countdata['statement_num'],//母单
|
|
|
|
|
|
|
|
|
|
"is_payment"=>$v['is_payment'],
|
|
|
|
|
"statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$is_continue = false;
|
|
|
|
|
$statement_data = $v['statement_info'];
|
|
|
|
|
foreach ($statement_data as $skey => $sval) {
|
|
|
|
|
if ($sval['game_list']) {
|
|
|
|
|
$is_continue = true;
|
|
|
|
|
}
|
|
|
|
|
// dump($sval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$is_continue) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//无需补点不统计其他金额
|
|
|
|
|
if($type == 2 && $v['statement_money'] == 0){
|
|
|
|
|
continue ;
|
|
|
|
|
}
|
|
|
|
|
//聚合未结算数据
|
|
|
|
|
$lsres = $LackStatement->where("company_id='{$k}' and is_pool = 0")->select();
|
|
|
|
|
$del_lack_ids = [];
|
|
|
|
|
if(count($lsres) > 0){
|
|
|
|
|
//进行聚合
|
|
|
|
|
foreach($lsres as $key=>$val){
|
|
|
|
|
|
|
|
|
|
$del_lack_ids[] = $val['id'];
|
|
|
|
|
$v['statement_money'] += $val['statement_money'];
|
|
|
|
|
$v['pay_amount'] += $val['pay_amount'];
|
|
|
|
|
$v['fine'] += $val['fine'];
|
|
|
|
|
$v['reward'] += $val['reward'];
|
|
|
|
|
$v['platform_amount'] += $val['platform_amount'];
|
|
|
|
|
$t_statement_info = json_decode($val['statement_info'],true);
|
|
|
|
|
$statement_info = [];
|
|
|
|
|
foreach($t_statement_info as $p=>$info){
|
|
|
|
|
$statement_info[$info['account']] = $info['game_list'];
|
|
|
|
|
}
|
|
|
|
|
foreach($v['statement_info'] as $p=>$info){
|
|
|
|
|
if(isset($statement_info[$info['account']])){
|
|
|
|
|
$v['statement_info'][$p]['game_list'] = array_merge($statement_info[$info['account']],$v['statement_info'][$p]['game_list']);
|
|
|
|
|
unset($statement_info[$info['account']]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!empty($statement_info)){
|
|
|
|
|
foreach($statement_info as $p=>$info){
|
|
|
|
|
$v['statement_info'][] = ["account"=>$p,"game_list"=>$info];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if($v['platform_amount'] == 0 && $v['statement_money'] == 0){
|
|
|
|
|
continue ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($v['platform_amount'] < 300){
|
|
|
|
|
//存未满
|
|
|
|
|
// if($lackcompany['pay_amount'] != 0){
|
|
|
|
|
$lask_id = $LackStatement->add($lackcompany);
|
|
|
|
|
$countdata['create_lack_ids'][] =$lask_id;
|
|
|
|
|
$countdata['lack_statement_money'] +=$lackcompany['statement_money'];
|
|
|
|
|
$countdata['lack_platform_amount'] +=$lackcompany['platform_amount'];
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
// if($v['pay_amount'] != 0){
|
|
|
|
|
//存成功配置单号
|
|
|
|
|
$company =[
|
|
|
|
|
"pool_id"=>0,
|
|
|
|
|
"company_id"=>$k,
|
|
|
|
|
"company_type"=>2,
|
|
|
|
|
"company_name"=>$v['partner'],
|
|
|
|
|
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
|
|
|
|
|
"statement_money"=>$v['statement_money'],
|
|
|
|
|
"pay_amount"=>$v['pay_amount'],
|
|
|
|
|
"platform_amount"=>$v['platform_amount'],
|
|
|
|
|
"fine"=>$v['fine'],
|
|
|
|
|
"reward"=>$v['reward'],
|
|
|
|
|
$StatementDb = SM("user_statement","sub_");
|
|
|
|
|
$res = [
|
|
|
|
|
"statement_begin_time"=>$begintime,
|
|
|
|
|
"statement_end_time"=>$endtime,
|
|
|
|
|
"statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE),
|
|
|
|
|
"statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5)
|
|
|
|
|
"statement_money"=>0,
|
|
|
|
|
"pay_amount"=>0,
|
|
|
|
|
"op_time"=>time(),
|
|
|
|
|
"remark"=>''
|
|
|
|
|
];
|
|
|
|
|
if($v['is_payment'] == 1){
|
|
|
|
|
$company['verify_status'] = 0;
|
|
|
|
|
}else{
|
|
|
|
|
$company['verify_status'] = 2;
|
|
|
|
|
}
|
|
|
|
|
$companyid = $StatementInfo->add($company);
|
|
|
|
|
$countdata['info_ids'][] =$companyid;
|
|
|
|
|
$countdata['del_lack_ids'] =array_merge($countdata['del_lack_ids'],$del_lack_ids);
|
|
|
|
|
$countdata['statement_money'] +=$v['statement_money'];
|
|
|
|
|
$countdata['pay_amount'] +=$v['pay_amount'];
|
|
|
|
|
$countdata['platform_amount'] +=$v['platform_amount'];
|
|
|
|
|
$countdata['fine'] +=$v['fine'];
|
|
|
|
|
$countdata['reward'] +=$v['reward'];
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
$statementInfo = [];
|
|
|
|
|
foreach($pc as $k=>$v){
|
|
|
|
|
$res['pay_amount'] += $v['pay_amount'];
|
|
|
|
|
$res['statement_money'] += $v['sum_money'];
|
|
|
|
|
unset($v['pay_amount'],$v['sum_money']);
|
|
|
|
|
$statementInfo[] = $v;
|
|
|
|
|
}
|
|
|
|
|
$res['statement_info'] = json_encode($statementInfo,JSON_UNESCAPED_UNICODE);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 保存信息汇总信息
|
|
|
|
@ -1632,6 +1129,47 @@ class SubCompanyStatementSetController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
return $senddata;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取下游个人游戏分成比例,不计其他,只计算最后一条
|
|
|
|
|
*/
|
|
|
|
|
protected function getPuGameRatio($company_id,$company_belong,$relation_game_ids,$pay_amount,$begin_time,$end_time){
|
|
|
|
|
$flag = false;
|
|
|
|
|
$ratio = 0;
|
|
|
|
|
$turnover_ratio = '';
|
|
|
|
|
$where = [
|
|
|
|
|
"relation_game_id"=>$relation_game_ids,
|
|
|
|
|
"company_id"=>$company_id,
|
|
|
|
|
"_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})"
|
|
|
|
|
];
|
|
|
|
|
$dbres = M("CompanyGameRatio","tab_")->where($where)->order('begin_time desc')->find();
|
|
|
|
|
!empty($dbres) && $flag = true;
|
|
|
|
|
if(!$flag){
|
|
|
|
|
$where = [
|
|
|
|
|
"relation_game_id"=>$relation_game_ids,
|
|
|
|
|
"company_belong"=>$company_belong,
|
|
|
|
|
"_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})"
|
|
|
|
|
];
|
|
|
|
|
$dbres = M("CompanyGameRatio","tab_")->where($where)->order('begin_time desc')->find();
|
|
|
|
|
!empty($dbres) && $flag = true;
|
|
|
|
|
}
|
|
|
|
|
if(!$flag){
|
|
|
|
|
$where = [
|
|
|
|
|
"relation_game_id"=>$relation_game_ids,
|
|
|
|
|
"company_belong"=>$company_belong,
|
|
|
|
|
"_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})"
|
|
|
|
|
];
|
|
|
|
|
$dbres = M("GameRatioMould","tab_")->where($where)->order('begin_time desc')->find();
|
|
|
|
|
!empty($dbres) && $flag = true;
|
|
|
|
|
}
|
|
|
|
|
if($flag){
|
|
|
|
|
$ratio = $dbres['ratio'];
|
|
|
|
|
$turnover_ratio = $dbres['turnover_ratio'];
|
|
|
|
|
}
|
|
|
|
|
$ratio = $this->getTurnoverRatio($pay_amount,$ratio,$turnover_ratio);
|
|
|
|
|
$sum_money = round($pay_amount * $ratio / 100,2);
|
|
|
|
|
return [$ratio,$sum_money];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重算接口
|
|
|
|
|