新增内团结算

master
chenzhi 3 years ago
parent 1030077095
commit c56c763d16

@ -5,7 +5,7 @@ use Think\Controller;
/**
* 财务结算预警
* TODO:当前业务下未计算上游奖罚
* TODO:当前业务下不用计算奖罚
* @author cz
*
*/
@ -24,7 +24,8 @@ class StatementWarningSetController extends Controller {
private $promoteCompanyIsWm;
private $statementWarningKey=[
'wm_platm'=>'万盟平台',
'up_statement'=>'上游'
'up_statement'=>'上游',
'pc_statement'=>'下游内团'
];
private $statementWarningModel;
@ -70,8 +71,9 @@ class StatementWarningSetController extends Controller {
$this->getInsideCompanyid();
$this->setCompanyIsWm();
$this->getAllWmAmount();
$this->cpStatement();
// $this->getAllWmAmount();
// $this->cpStatement();
$this->pcStatement();
echo "{$this->year}-{$this->month}生成成功".PHP_EOL;
@ -227,18 +229,87 @@ class StatementWarningSetController extends Controller {
*/
private function addCpStatementWarningInfo($company,$gamedata)
{
$cpStatementAmount = 0;
// $cpStatementAmount = 0;
foreach ($company as $key => $value) {
$statementMoney = 0;
$gameids = explode(",",$value['game_ids']);
foreach ($gameids as $gameid) {
$statementMoney += ($gamedata[$gameid]-0);
}
$cpStatementAmount += $statementMoney;
unset($company[$key]['game_ids']);
$company[$key]['statement_money'] = $statementMoney;
$company[$key]['is_wm'] = $this->getCompanyIsWm($key,9);
$company[$key]['company_belong'] = 9;
unset($company[$key]['game_ids']);
}
return $this->addStatementWarningInfo($company,9);
}
/**
* 获取内团的结算金额
*/
private function pcStatement()
{
//获取内团公司
$company = M('promote_company','tab_')->where([
'id'=>["NOT IN",$this->inSideCompanyIds],
'company_belong'=>0
])->getField("id company_id,company_name,develop_type",true);
$company = $this->getPcGameSpend($company);
$pcStatementAmount = $this->addStatementWarningInfo($company,0);
$savedata = [
'type'=>2,
'name'=>'pc_statement',
'count_month'=>$this->month,
'count_year'=>$this->year
];
$hasDb = $this->statementWarningModel->where($savedata)->find();
$savedata = array_merge(['money'=>$pcStatementAmount,'create_time'=>time()],$savedata);
if($hasDb){
$savedata['id'] = $hasDb['id'];
$this->statementWarningModel->save($savedata);
}else{
$this->statementWarningModel->add($savedata);
}
}
private function getPcGameSpend($company)
{
$where = [
'tab_spend.is_check'=>1,
'tab_spend.pay_status'=>1,
'tab_spend.is_refund'=>0,
'tab_spend.payed_time'=>['between', [$this->beginThismonth,$this->endThismonth]],
"tab_promote.company_id"=>["IN",array_keys($company)],
];
$items = M('spend', 'tab_')
->field(["substring_index(game_name, '(', 1) relation_game_name",'tab_promote.company_id', 'sum(pay_amount) amount'])
->join('left join tab_promote on tab_spend.promote_id=tab_promote.id')
->where($where)
->group('tab_promote.company_id,relation_game_name')
->select();
$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");
foreach ($items as $key => $val) {
$relationGameId = $games[$val['relation_game_name']];
$radio = end($CompanyGameRatio->getGameRadio($val['company_id'],$relationGameId,0,$this->beginThismonth,$this->endThismonth));
$radio = $CompanyGameRatio->getTurnoverRatio($val['amount'],$radio['ratio'],$radio['turnover_ratio']);
$statementMoney =round($val['amount']*$radio/100,2);
if(isset($company[$val['company_id']]['statement_money'])){
$company[$val['company_id']]['statement_money'] += ( $statementMoney - 0);
}else{
$company[$val['company_id']]['statement_money'] = ( $statementMoney - 0);
}
}
return $company;
}
private function addStatementWarningInfo($company,$companyBelong)
{
$statementAmount = 0;
foreach ($company as $key => $value) {
$statementMoney = $value['statement_money']-0;
$statementAmount += $statementMoney;
$company[$key]['is_wm'] = $this->getCompanyIsWm($key,$companyBelong);
$company[$key]['company_belong'] = $companyBelong;
$company[$key]['count_month'] = $this->month;
$company[$key]['count_year'] = $this->year;
$company[$key]['create_time'] = time();
@ -252,7 +323,7 @@ class StatementWarningSetController extends Controller {
$id = $this->statementWarningInfoModel->where([
'count_year'=>$this->year,
'count_month'=>$this->month,
'company_belong'=>9,
'company_belong'=>$companyBelong,
'company_id'=>$key
])->getField("id");
if($id){
@ -262,9 +333,11 @@ class StatementWarningSetController extends Controller {
$this->statementWarningInfoModel->add($company[$key]);
}
}
return $cpStatementAmount;
return $statementAmount;
}
private function getCompanyIsWm($companyid,$company_belong)
{
if($company_belong == 9){

@ -112,7 +112,7 @@ class CompanyGameRatioModel extends Model
}
protected function getGameRadio($company_id,$game_id,$company_belong,$begintime,$endtime)
public function getGameRadio($company_id,$game_id,$company_belong,$begintime,$endtime)
{
$map = [
"company_id"=>$company_id,
@ -285,4 +285,26 @@ class CompanyGameRatioModel extends Model
];
}
}
public function getTurnoverRatio($amount,$ratio,$turnover_ratio)
{
if(empty($turnover_ratio)){
return $ratio;
}
if(!is_array($turnover_ratio)){
$turnover_ratio = json_decode($turnover_ratio,true);
}
foreach($turnover_ratio as $k=>$v){
if($v['instanceof'] == 1){
if($amount >= $v['turnover']){
$ratio = $v['ratio'];
}
}else{
if($amount > $v['turnover']){
$ratio = $v['ratio'];
}
}
}
return $ratio;
}
}
Loading…
Cancel
Save