@ -28,7 +28,9 @@ class StatementWarningSetController extends Controller {
'pc_statement'=>'下游内团',
'pu_statement'=>'下游外团',
'margin_ratio'=>'毛利率',
'profit_ratio'=>'利润率'
'profit_ratio'=>'利润率',
'cost'=>'费用',
'other_income'=>'其他收入'
];
private $statementWarningModel;
@ -66,19 +68,17 @@ class StatementWarningSetController extends Controller {
$count_date = date('Y',time()).'-'.(date('m',time()));
$this->configInit($count_date);
$preMonth = $this->getPreMonth();
$hasdb = $this->statementWarningModel->where([
'count_year'=>$this->year ,
'count_month'=>$this->month ,
'count_year'=>$preMonth[0] ,
'count_month'=>$preMonth[1] ,
"name"=>'wm_platm',
"type"=>1
])->find();
if(!$hasdb){
//第一次生成,同时上一次结扎
$year = date("Y",$this->beginThismonth-1);
$month = date("m",$this->beginThismonth-1);
$preMonth = $year."-".$month;
$params = "php ".SUBSITE_INDEX." StatementWarningSet/setFreeMonth/count_date/{$preMonth}";
$preCountMonth = $preMonth[0]."-".$preMonth[1];
$params = "php ".SUBSITE_INDEX." StatementWarningSet/setFreeMonth/count_date/{$preCountMonth}";
$time = time()+2*3600;
D("CmdTasks")->addScheduleTask("StatementWarningSet",$params,$time);
}
@ -130,13 +130,11 @@ class StatementWarningSetController extends Controller {
*/
private function setCompanyIsWm()
{
$year = date("Y",$this->beginThismonth-1);
$month = date("m",$this->beginThismonth-1);
$preMonth = $this->getPreMonth();
//cp
$preCpMonth = $this->statementWarningInfoModel->where([
'count_year'=>$year ,
'count_month'=>$month ,
'count_year'=>$preMonth[0] ,
'count_month'=>$preMonth[1] ,
'company_belong'=>9
])->getField('company_id,is_wm',true);
@ -157,8 +155,8 @@ class StatementWarningSetController extends Controller {
//下游
$preMonth = $this->statementWarningInfoModel->where([
'count_year'=>$year ,
'count_month'=>$month ,
'count_year'=>$preMonth[0] ,
'count_month'=>$preMonth[1] ,
'company_belong'=>['NEQ',9]
])->getField('company_id,is_wm',true);
@ -182,50 +180,24 @@ class StatementWarningSetController extends Controller {
*/
private function getAllWmAmount()
{
//获取官方渠道
$merchantIds = M("payment_merchant","tab_")->group('main_id')->where("main_id = 1")->getField("GROUP_CONCAT(id) ids");
$where = [
'partner_type'=>['in',[0,1]],
'merchant_id'=>['in',$merchantIds ],
'pay_status'=>1,
'payed_time'=>['between',[$this->beginThismonth,$this->endThismonth]],
];
$amout = $this->spendModel->where($where)->getField("sum(pay_amount) amount");
$sWWhere = [
"count_month"=>$this->month,
"count_year"=>$this->year,
"name"=>'wm_platm',
"type"=>1
];
$hasDb = $this->statementWarningModel->where($sWWhere)->find();
$saveData = array_merge(['money'=>$amout,'create_time'=>time()],$sWWhere);
if($hasDb){
$saveData['id'] = $hasDb['id'];
$this->statementWarningModel->save($saveData);
}else{
$this->statementWarningModel->add($saveData);
}
$amout = $this->spendModel->where($where)->where(['pay_way'=>['GT',0],])->getField("sum(pay_amount) amount");
$despost = M("deposit","tab_")->where($where)->getField("sum(pay_amount) amount");
$this->addStatementWarning(1,'wm_platm',$amout-0+$despost);
}
/**
* 添加默认信息
*/
private function setDefaultStatementWarning()
{
$Where = [
"count_month"=>$this->month,
"count_year"=>$this->year,
"name"=>'费用',
"type"=>3
];
$hasDb = $this->statementWarningModel->where($Where)->find();
$saveData = array_merge(['money'=>700000,'create_time'=>time()],$Where);
if(!$hasDb){
$this->statementWarningModel->add($saveData);
}
$Where['name'] = '其他收入';
$hasDb = $this->statementWarningModel->where($Where)->find();
$saveData = array_merge(['money'=>26000,'create_time'=>time()],$Where);
if(!$hasDb){
$this->statementWarningModel->add($saveData);
}
$this->addStatementWarning(3,'cost',700000,false);
$this->addStatementWarning(3,'other_income',26000,false);
}
/**
* 获取上游的结算金额
@ -238,21 +210,8 @@ class StatementWarningSetController extends Controller {
$company = $this->getCpCompanyInfo(array_keys($gamedata));
$cpStatementAmount = $this->addCpStatementWarningInfo($company,$gamedata);
}
$savedata = [
'type'=>2,
'name'=>'up_statement',
'count_month'=>$this->month,
'count_year'=>$this->year
];
$hasDb = $this->statementWarningModel->where($savedata)->find();
$savedata = array_merge(['money'=>$cpStatementAmount,'create_time'=>time()],$savedata);
if($hasDb){
$savedata['id'] = $hasDb['id'];
$this->statementWarningModel->save($savedata);
}else{
$this->statementWarningModel->add($savedata);
}
$this->addStatementWarning(2,'up_statement',$cpStatementAmount);
}
/**
* 获取月份游戏结算额
@ -323,20 +282,8 @@ class StatementWarningSetController extends Controller {
$company = $this->getPromoteCompanyGameSpend($company,0);
$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);
}
$this->addStatementWarning(2,'pc_statement',$pcStatementAmount);
}
private function getPromoteCompanyGameSpend($company,$companyBelong)
{
@ -416,17 +363,19 @@ class StatementWarningSetController extends Controller {
}
private function addStatementWarning($type,$name,$money)
private function addStatementWarning($type,$name,$money,$issave = true )
{
//汇总表差一个月
$preMonth = $this->getPreMonth();
$savedata = [
'type'=>$type,
'name'=>$name,
'count_month'=>$this->month ,
'count_year'=>$this->year
'count_year'=>$preMonth[0] ,
'count_month'=>$preMonth[1]
];
$hasDb = $this->statementWarningModel->where($savedata)->find();
$savedata = array_merge(['money'=>$money,'create_time'=>time()],$savedata);
if($hasDb){
if($hasDb & & $issave ){
$savedata['id'] = $hasDb['id'];
$this->statementWarningModel->save($savedata);
}else{
@ -485,6 +434,12 @@ class StatementWarningSetController extends Controller {
return 1;
}
private function getPreMonth()
{
return explode('-',date("Y-m",$this->beginThismonth-1));
}