优化下游个人结算

master
chenzhi 3 years ago
parent c56c763d16
commit d53fb89622

@ -73,7 +73,8 @@ class StatementWarningSetController extends Controller {
// $this->getAllWmAmount();
// $this->cpStatement();
$this->pcStatement();
// $this->pcStatement();
$this->puStatement();
echo "{$this->year}-{$this->month}生成成功".PHP_EOL;
@ -253,7 +254,7 @@ class StatementWarningSetController extends Controller {
'company_belong'=>0
])->getField("id company_id,company_name,develop_type",true);
$company = $this->getPcGameSpend($company);
$company = $this->getPromoteCompanyGameSpend($company);
$pcStatementAmount = $this->addStatementWarningInfo($company,0);
$savedata = [
'type'=>2,
@ -270,7 +271,7 @@ class StatementWarningSetController extends Controller {
$this->statementWarningModel->add($savedata);
}
}
private function getPcGameSpend($company)
private function getPromoteCompanyGameSpend($company)
{
$where = [
'tab_spend.is_check'=>1,
@ -285,6 +286,7 @@ class StatementWarningSetController extends Controller {
->where($where)
->group('tab_promote.company_id,relation_game_name')
->select();
if(!$items) return $company;
$CompanyGameRatio = D("CompanyGameRatio");
$games = M("Game",'tab_')->where(['relation_game_name' => ['in',array_column($items,'relation_game_name')]])->getField("relation_game_name,relation_game_id");
@ -302,11 +304,75 @@ class StatementWarningSetController extends Controller {
}
return $company;
}
private function puStatement()
{
//获取公司
$company = M('promote_company','tab_')->where([
'id'=>["NOT IN",$this->inSideCompanyIds],
'company_type'=>1,
'company_belong'=>['in',[1,2]]
])->getField("id company_id,company_name,develop_type",true);
if(!$company) {
$this->addStatementWarning(2,'pu_statement',0);
return;
};
$company = $this->getPuSpecialStatement( $this->getPromoteCompanyGameSpend($company) );
foreach ($company as $key => $value) {
if(!array_key_exists('statement_money',$value) ) {
unset($company[$key]);
};
}
$puStatementAmount = $this->addStatementWarningInfo($company,0);
$this->addStatementWarning(2,'pu_statement',$puStatementAmount);
}
private function getPuSpecialStatement($company)
{
$where = [
"company_belong"=>["NOT IN",[0,9]],
"company_id"=>["IN",array_keys($company)],
"withdraw_type"=>3,
"_string"=>"statement_begin_time >= {$this->beginThismonth} and statement_end_time <= {$this->endThismonth}"
];
$res = M("company_statement", "tab_")->where($where)->group('company_id')->getField("company_id,sum(statement_money) statement_money");
if($res){
foreach ($res as $key => $value) {
if(array_key_exists('statement_money',$company[$key])){
$company[$key]['statement_money'] += ($value-0);
}else{
$company[$key]['statement_money'] = ($value-0);
}
}
}
return $company;
}
private function addStatementWarning($type,$name,$money)
{
$savedata = [
'type'=>$type,
'name'=>$name,
'count_month'=>$this->month,
'count_year'=>$this->year
];
$hasDb = $this->statementWarningModel->where($savedata)->find();
$savedata = array_merge(['money'=>$money,'create_time'=>time()],$savedata);
if($hasDb){
$savedata['id'] = $hasDb['id'];
$this->statementWarningModel->save($savedata);
}else{
$this->statementWarningModel->add($savedata);
}
}
private function addStatementWarningInfo($company,$companyBelong)
{
$statementAmount = 0;
foreach ($company as $key => $value) {
$statementMoney = $value['statement_money']-0;
$statementMoney = array_key_exists('statement_money',$value) ? ($value['statement_money']-0) : 0;
$statementAmount += $statementMoney;
$company[$key]['is_wm'] = $this->getCompanyIsWm($key,$companyBelong);
$company[$key]['company_belong'] = $companyBelong;

Loading…
Cancel
Save