|
|
@@ -58,17 +58,17 @@ class CalcConsole extends BaseBusiness
|
|
|
//开始挂网 或者 已挂网 则直接返回
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
- if ($businessPeriod['IS_CLOSED']==0) {
|
|
|
- // 如果没有封期 则直接返回
|
|
|
- return true;
|
|
|
- }
|
|
|
+// if ($businessPeriod['IS_CLOSED']==0) {
|
|
|
+// // 如果没有封期 则直接返回
|
|
|
+// return true;
|
|
|
+// }
|
|
|
|
|
|
//用户选择是否自动执行
|
|
|
$autoExec = $businessPeriod['AUTO_EXEC'] > Period::MANUAL_EXEC_CALC;
|
|
|
$businessIsCalculated = $businessPeriod['IS_CALCULATED'] == Period::CALCULATE_FINISH;
|
|
|
$startExecTime = $businessPeriod['START_EXEC_TIME'] ?? 0;
|
|
|
$businessIsProcessing = $businessPeriod['IS_PROCESSING'] ?? 0;
|
|
|
+ $isPreparing = $businessPeriod['IS_PREPARING'];
|
|
|
|
|
|
echo $businessPeriod['IS_CALCING'];
|
|
|
//同步计算进度日志到业务系统
|
|
|
@@ -77,7 +77,7 @@ class CalcConsole extends BaseBusiness
|
|
|
\Yii::$app->db->createCommand()->update('AR_PERIOD', ['IS_CALCING' => 0], 'PERIOD_NUM=' . $period['PERIOD_NUM'])->execute();
|
|
|
}
|
|
|
|
|
|
- if (2 == $period['IS_PREPARE'] && 1 == $period['IS_PERFED'] && $autoExec && !$businessIsProcessing) {
|
|
|
+ if (2 == $period['IS_PREPARE'] && 1 == $period['IS_PERFED'] && ($autoExec || $isPreparing) && !$businessIsProcessing) {
|
|
|
//拉取期业绩
|
|
|
CalcRecord::record($period['PERIOD_NUM'], '【期业绩】第' . $period['PERIOD_NUM'] . '期的业绩数据已生成');
|
|
|
CalcRecord::record($period['PERIOD_NUM'], '【期业绩】开始获取第' . $period['PERIOD_NUM'] . '期的期业绩数据');
|
|
|
@@ -101,7 +101,7 @@ class CalcConsole extends BaseBusiness
|
|
|
return \Yii::$app->$db->createCommand()->update('AR_PERIOD', ['IS_PREPARE' => 3], 'PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM' => $period['PERIOD_NUM']])->execute();
|
|
|
}
|
|
|
|
|
|
- if (4 == $period['IS_PREPARE'] && 1 == $period['IS_CALCULATED'] && $autoExec && !$businessIsProcessing && !$businessIsCalculated) {
|
|
|
+ if (4 == $period['IS_PREPARE'] && 1 == $period['IS_CALCULATED'] && ($autoExec || $isPreparing) && !$businessIsProcessing && !$businessIsCalculated) {
|
|
|
CalcRecord::record($period['PERIOD_NUM'], '【奖金计算】第' . $period['PERIOD_NUM'] . '期的奖金已计算完成');
|
|
|
CalcRecord::record($period['PERIOD_NUM'], '【奖金计算】开始拉取第' . $period['PERIOD_NUM'] . '期的奖金数据');
|
|
|
|
|
|
@@ -123,6 +123,8 @@ class CalcConsole extends BaseBusiness
|
|
|
CalcOperation::closeOperation($businessPeriod['CALC_ID']);
|
|
|
//拉取计算系统的进度日志
|
|
|
self::syncLogRecord($period['PERIOD_NUM'], $db, $startExecTime);
|
|
|
+ //设置计算进行中标识
|
|
|
+ Period::updatePeriodIsPreparing($period['PERIOD_NUM'], Period::NOT_PREPARING);
|
|
|
//设置redis开关
|
|
|
Yii::$app->cache->set('isCalcing', 0);
|
|
|
} else {
|
|
|
@@ -131,6 +133,10 @@ class CalcConsole extends BaseBusiness
|
|
|
\Yii::$app->$db->createCommand()->update('AR_PERIOD', ['CALC_ID' => ''], 'PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM' => $period['PERIOD_NUM']])->execute();
|
|
|
CalcOperation::closeOperation($businessPeriod['CALC_ID']);
|
|
|
CalcRecord::record($period['PERIOD_NUM'], '【奖金计算】第' . $period['PERIOD_NUM'] . '期的奖金数据获取失败,原因:' . $res['msg']);
|
|
|
+ //设置计算进行中标识
|
|
|
+ Period::updatePeriodIsPreparing($period['PERIOD_NUM'], Period::NOT_PREPARING);
|
|
|
+ //设置redis开关
|
|
|
+ Yii::$app->cache->set('isCalcing', 0);
|
|
|
return $res;
|
|
|
}
|
|
|
return true;
|
|
|
@@ -139,114 +145,48 @@ class CalcConsole extends BaseBusiness
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public static function autoPrePerf(){ // 自动预结算
|
|
|
+ public static function autoPrePerf(){ // 定时计算
|
|
|
$nowTs = time();
|
|
|
$currentPeriod = Period::find()->where('START_TIME< :NOW_TIME',['NOW_TIME'=>$nowTs])->where('END_TIME>= :NOW_TIME',['NOW_TIME'=>$nowTs-6])->asArray()->one();
|
|
|
$periodNum = $currentPeriod['PERIOD_NUM'];
|
|
|
if (
|
|
|
Period::isPreparing($periodNum)
|
|
|
- || $currentPeriod['IS_MONTH'] == 0
|
|
|
+// || $currentPeriod['IS_MONTH'] == 0
|
|
|
) {
|
|
|
return;
|
|
|
}
|
|
|
- if($nowTs+86400>$currentPeriod['END_TIME'] ){
|
|
|
- $nowMin = date("i", $nowTs);
|
|
|
- $nowSec = date("s", $nowTs);
|
|
|
- if(($nowMin!=0 || $nowSec >= 5 ) || Period::isPreparing($periodNum)){ // 当不是整点小时,当计算中,不计算
|
|
|
- return;
|
|
|
- }
|
|
|
- print_r($periodNum."该预结算".$nowMin.PHP_EOL.$nowSec);
|
|
|
- //设置计算进行中标识
|
|
|
- Period::updatePeriodIsPreparing($periodNum, Period::IS_PREPARING);
|
|
|
- //设置自动计算标识
|
|
|
- Period::updatePeriodIsAutoExec($periodNum, Period::MANUAL_EXEC_CALC);
|
|
|
- //记录开始计算的时间
|
|
|
- $calc_id = uniqid('calc_');
|
|
|
- CalcOperation::record($calc_id, $periodNum);
|
|
|
- Period::updateAll(['START_EXEC_TIME' => time(), 'CALC_ID' => $calc_id], ['PERIOD_NUM' => $periodNum]);
|
|
|
- $formModel = new PeriodForm();
|
|
|
- $formModel->scenario = 'autoPerf';
|
|
|
-
|
|
|
- if($formModel->load(['periodNum'=>$periodNum], '') && $formModel->autoPrePerf()) {
|
|
|
- echo('自动计算已开始,请等待'.PHP_EOL);
|
|
|
- //设置redis开关
|
|
|
- Yii::$app->cache->set('isPreparing', 1, 3600);
|
|
|
- CalcRecord::record($periodNum, '【定时计算】第' . $periodNum . '期,定时计算开始');
|
|
|
- } else {
|
|
|
- echo('自动计算未开始'.PHP_EOL);
|
|
|
- CalcRecord::record($periodNum, '【定时计算】第' . $periodNum . '期,定时计算未开始');
|
|
|
- }
|
|
|
- return;
|
|
|
- }else{
|
|
|
+
|
|
|
+ $nowDate = date("d", $nowTs);
|
|
|
+ $nowMin = date("i", $nowTs);
|
|
|
+ $nowSec = date("s", $nowTs);
|
|
|
+ if($nowDate >1 && $nowDate <= 15 || (($nowMin!=0 || $nowSec >= 5 ) || Period::isPreparing($periodNum)) ){ // 当不是整点小时,当计算中,不计算
|
|
|
return;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- public static function listenAutoPerfPeriod() // 拉取预结算的结果
|
|
|
- {
|
|
|
- // 先检查redis的开关
|
|
|
- $preparingSwitch = Yii::$app->cache->get('isPreparing') ? 1 : 0;
|
|
|
- if(!$preparingSwitch){
|
|
|
- return true;
|
|
|
- }
|
|
|
- $db = self::CALC_DB_NAME;
|
|
|
- $allPeriod = \Yii::$app->$db->createCommand("SELECT * FROM AR_PERIOD order by PERIOD_NUM desc")->queryAll();
|
|
|
- $period = [];
|
|
|
- foreach ($allPeriod as $v) {
|
|
|
- if ($v['IS_PREPARE'] > 0) {
|
|
|
- $period = $v;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (empty($period)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- $businessPeriod = Period::find()->where(['PERIOD_NUM' => $period['PERIOD_NUM']])->asArray()->one();
|
|
|
+ print_r($periodNum."该预结算".$nowMin.PHP_EOL.$nowSec);
|
|
|
|
|
|
- if(!$period['CALC_ID'] || $period['CALC_ID'] != $businessPeriod['CALC_ID']) { // 如果计算ID不符,则退出
|
|
|
- return true;
|
|
|
- }
|
|
|
+ //设置计算进行中标识
|
|
|
+ Period::updatePeriodIsPreparing($periodNum, Period::IS_PREPARING);
|
|
|
+ //设置自动计算标识
|
|
|
+ Period::updatePeriodIsAutoExec($periodNum, Period::AUTO_EXEC_CALC);
|
|
|
+ //记录开始计算的时间
|
|
|
+ $calc_id = uniqid('calc_');
|
|
|
+ CalcOperation::record($calc_id, $periodNum);
|
|
|
+ Period::updateAll(['START_EXEC_TIME' => time(), 'CALC_ID' => $calc_id], ['PERIOD_NUM' => $periodNum]);
|
|
|
+ $formModel = new PeriodForm();
|
|
|
+ $formModel->scenario = 'autoPerf';
|
|
|
|
|
|
- $startExecTime = $businessPeriod['START_EXEC_TIME'] ?? 0;
|
|
|
- if (
|
|
|
- $businessPeriod['SEND_STARTED_AT'] > 0 || $businessPeriod['IS_SENT'] > 0 // 已挂网
|
|
|
- || 1 != $businessPeriod['IS_PREPARING'] // 未在预计算中
|
|
|
- || $period['PERFED_AT'] < $businessPeriod['START_EXEC_TIME'] // 计算服务中的计算时间,早于业务系统开始计算时间,说明是旧的,不拉取
|
|
|
- ){
|
|
|
- return false;
|
|
|
+ if($formModel->load(['periodNum'=>$periodNum], '') && $formModel->autoPrePerf()) {
|
|
|
+ echo('自动计算已开始,请等待'.PHP_EOL);
|
|
|
+ //设置redis开关
|
|
|
+ Yii::$app->cache->set('isCalcing', 1, 3600);
|
|
|
+ CalcRecord::record($periodNum, '【定时计算】第' . $periodNum . '期,定时计算开始');
|
|
|
+ } else {
|
|
|
+ echo('自动计算未开始'.PHP_EOL);
|
|
|
+ CalcRecord::record($periodNum, '【定时计算】第' . $periodNum . '期,定时计算未开始');
|
|
|
}
|
|
|
- if (
|
|
|
- 2 == $period['IS_PREPARE']
|
|
|
- && 1 == $period['IS_PERFED']
|
|
|
- ) {
|
|
|
- //拉取期业绩
|
|
|
- CalcRecord::record($period['PERIOD_NUM'], '【期业绩】第' . $period['PERIOD_NUM'] . '期的预计算业绩数据已生成');
|
|
|
- CalcRecord::record($period['PERIOD_NUM'], '【期业绩】开始获取第' . $period['PERIOD_NUM'] . '期的预计算期业绩数据');
|
|
|
+ return;
|
|
|
|
|
|
- Period::updatePeriodIsPreparing($period['PERIOD_NUM'], Period::IS_PREPARING);
|
|
|
- $res = (new PullPerfDataFromCalc($period['PERIOD_NUM']))->start();
|
|
|
- if (200 == $res['code']) {
|
|
|
-// Period::updatePeriodIsProcessing($period['PERIOD_NUM'], Period::NOT_PROCESSING);
|
|
|
- //设置预计算标识
|
|
|
- Period::updatePeriodIsPreparing($period['PERIOD_NUM'], Period::NOT_PREPARING);
|
|
|
- CalcRecord::record($period['PERIOD_NUM'], '【期业绩】第' . $period['PERIOD_NUM'] . '期的预计算期业绩数据已获取');
|
|
|
- \Yii::$app->$db->createCommand()->update('AR_PERIOD', ['CALC_ID' => ''], 'PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM' => $period['PERIOD_NUM']])->execute();
|
|
|
- CalcOperation::closeOperation($businessPeriod['CALC_ID']);
|
|
|
- self::syncLogRecord($period['PERIOD_NUM'], $db, $startExecTime);
|
|
|
- Yii::$app->cache->set('isPreparing', 0);
|
|
|
- return $res;
|
|
|
- } else {
|
|
|
- //结束计算状态
|
|
|
-// Period::updatePeriodIsProcessing($period['PERIOD_NUM'], Period::NOT_PROCESSING);
|
|
|
- //设置预计算标识
|
|
|
- Period::updatePeriodIsPreparing($period['PERIOD_NUM'], Period::NOT_PREPARING);
|
|
|
- \Yii::$app->$db->createCommand()->update('AR_PERIOD', ['CALC_ID' => ''], 'PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM' => $period['PERIOD_NUM']])->execute();
|
|
|
- CalcOperation::closeOperation($businessPeriod['CALC_ID']);
|
|
|
- CalcRecord::record($period['PERIOD_NUM'], '【期业绩】第' . $period['PERIOD_NUM'] . '期的预计算期业绩数据获取失败,原因:' . $res['msg']);
|
|
|
- return $res;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
/**
|