优化预警平台

master
chenzhi 3 years ago
parent 80a020e352
commit d8c3fd969c

@ -28,7 +28,9 @@ class StatementWarningSetController extends Controller {
'pc_statement'=>'下游内团', 'pc_statement'=>'下游内团',
'pu_statement'=>'下游外团', 'pu_statement'=>'下游外团',
'margin_ratio'=>'毛利率', 'margin_ratio'=>'毛利率',
'profit_ratio'=>'利润率' 'profit_ratio'=>'利润率',
'cost'=>'费用',
'other_income'=>'其他收入'
]; ];
private $statementWarningModel; private $statementWarningModel;
@ -66,19 +68,17 @@ class StatementWarningSetController extends Controller {
$count_date = date('Y',time()).'-'.(date('m',time())); $count_date = date('Y',time()).'-'.(date('m',time()));
$this->configInit($count_date); $this->configInit($count_date);
$preMonth = $this->getPreMonth();
$hasdb = $this->statementWarningModel->where([ $hasdb = $this->statementWarningModel->where([
'count_year'=>$this->year, 'count_year'=>$preMonth[0],
'count_month'=>$this->month, 'count_month'=>$preMonth[1],
"name"=>'wm_platm', "name"=>'wm_platm',
"type"=>1 "type"=>1
])->find(); ])->find();
if(!$hasdb){ if(!$hasdb){
//第一次生成,同时上一次结扎 //第一次生成,同时上一次结扎
$year = date("Y",$this->beginThismonth-1); $preCountMonth = $preMonth[0]."-".$preMonth[1];
$month = date("m",$this->beginThismonth-1); $params = "php ".SUBSITE_INDEX." StatementWarningSet/setFreeMonth/count_date/{$preCountMonth}";
$preMonth = $year."-".$month;
$params = "php ".SUBSITE_INDEX." StatementWarningSet/setFreeMonth/count_date/{$preMonth}";
$time = time()+2*3600; $time = time()+2*3600;
D("CmdTasks")->addScheduleTask("StatementWarningSet",$params,$time); D("CmdTasks")->addScheduleTask("StatementWarningSet",$params,$time);
} }
@ -130,13 +130,11 @@ class StatementWarningSetController extends Controller {
*/ */
private function setCompanyIsWm() private function setCompanyIsWm()
{ {
$preMonth = $this->getPreMonth();
$year = date("Y",$this->beginThismonth-1);
$month = date("m",$this->beginThismonth-1);
//cp //cp
$preCpMonth = $this->statementWarningInfoModel->where([ $preCpMonth = $this->statementWarningInfoModel->where([
'count_year'=>$year, 'count_year'=>$preMonth[0],
'count_month'=>$month, 'count_month'=>$preMonth[1],
'company_belong'=>9 'company_belong'=>9
])->getField('company_id,is_wm',true); ])->getField('company_id,is_wm',true);
@ -157,8 +155,8 @@ class StatementWarningSetController extends Controller {
//下游 //下游
$preMonth = $this->statementWarningInfoModel->where([ $preMonth = $this->statementWarningInfoModel->where([
'count_year'=>$year, 'count_year'=>$preMonth[0],
'count_month'=>$month, 'count_month'=>$preMonth[1],
'company_belong'=>['NEQ',9] 'company_belong'=>['NEQ',9]
])->getField('company_id,is_wm',true); ])->getField('company_id,is_wm',true);
@ -188,44 +186,15 @@ class StatementWarningSetController extends Controller {
'payed_time'=>['between',[$this->beginThismonth,$this->endThismonth]], 'payed_time'=>['between',[$this->beginThismonth,$this->endThismonth]],
]; ];
$amout = $this->spendModel->where($where)->getField("sum(pay_amount) amount"); $amout = $this->spendModel->where($where)->getField("sum(pay_amount) amount");
$sWWhere = [ $this->addStatementWarning(1,'wm_platm',$amout);
"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);
}
} }
/** /**
* 添加默认信息 * 添加默认信息
*/ */
private function setDefaultStatementWarning() private function setDefaultStatementWarning()
{ {
$Where = [ $this->addStatementWarning(3,'cost',700000,false);
"count_month"=>$this->month, $this->addStatementWarning(3,'other_income',26000,false);
"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);
}
} }
/** /**
* 获取上游的结算金额 * 获取上游的结算金额
@ -416,17 +385,19 @@ class StatementWarningSetController extends Controller {
} }
private function addStatementWarning($type,$name,$money) private function addStatementWarning($type,$name,$money,$issave = true)
{ {
//汇总表差一个月
$preMonth = $this->getPreMonth();
$savedata = [ $savedata = [
'type'=>$type, 'type'=>$type,
'name'=>$name, 'name'=>$name,
'count_month'=>$this->month, 'count_year'=>$preMonth[0],
'count_year'=>$this->year 'count_month'=>$preMonth[1]
]; ];
$hasDb = $this->statementWarningModel->where($savedata)->find(); $hasDb = $this->statementWarningModel->where($savedata)->find();
$savedata = array_merge(['money'=>$money,'create_time'=>time()],$savedata); $savedata = array_merge(['money'=>$money,'create_time'=>time()],$savedata);
if($hasDb){ if($hasDb && $issave){
$savedata['id'] = $hasDb['id']; $savedata['id'] = $hasDb['id'];
$this->statementWarningModel->save($savedata); $this->statementWarningModel->save($savedata);
}else{ }else{
@ -485,6 +456,12 @@ class StatementWarningSetController extends Controller {
return 1; return 1;
} }
private function getPreMonth()
{
return explode('-',date("Y-m",$this->beginThismonth-1));
}

Loading…
Cancel
Save