root пре 3 година
родитељ
комит
b5de60aa94

+ 3 - 10
common/components/SwooleAsyncTimer.php

@@ -9,19 +9,11 @@ namespace common\components;
 
 use anlity\swooleAsyncTimer\SocketInterface;
 use anlity\swooleAsyncTimer\SwooleAsyncTimerComponent;
-use backendApi\modules\v1\models\Admin;
-use common\components\Redis;
-use common\helpers\bonus\AutoClosePeriod;
 use common\helpers\Cache;
-use common\helpers\Date;
-use common\helpers\Tool;
-use common\libs\logging\system\ApiSystem;
 use common\libs\logging\system\AsyncSystem;
 use common\libs\taskQueue\Queue;
-use common\libs\taskQueue\TaskFunc;
-use common\models\UserInfo;
 use Yii;
-use anlity\swooleAsyncTimer\SwooleAsyncTimerController;
+use common\helpers\bonus\CalcServeBonusCalc;
 use common\helpers\bonus\CalcServePerfCalc;
 use yii\base\Exception;
 use yii\helpers\Json;
@@ -47,7 +39,8 @@ class SwooleAsyncTimer extends SwooleAsyncTimerComponent implements SocketInterf
      * @throws \yii\db\Exception
      */
     public function timerCallback($timerId, $server){
-        CalcServePerfCalc::instance()->calcStep(); 
+        CalcServePerfCalc::instance()->calcStep(); // 累计业绩
+        CalcServeBonusCalc::instance()->calcStep();  // 计算奖金
         // 自动执行任务队列中的任务
         Queue::instance()->consumeTask();
 

+ 20 - 1
common/helpers/bonus/CalcServeBonusCalc.php

@@ -50,6 +50,7 @@ class CalcServeBonusCalc extends BaseObject {
     private $_calcMonth;
     private $_calcYearMonth;
     private $_calcMonthPeriodNumCount = 0;
+    private $_isPerpare;
     //pv
     private $_pvRatio;
     private $_calcZone = ['openTravel', 'openCar', 'openHouse'];
@@ -110,7 +111,7 @@ class CalcServeBonusCalc extends BaseObject {
      * @param null $handleUserId
      * @return bool
      */
-    public function calcStep($periodNum, $handleUserId = null) {
+    public function calcStep($periodNum=null, $handleUserId = null) {
         try {
             $this->_errors = [];
             $this->setPeriodNum($periodNum);
@@ -118,6 +119,14 @@ class CalcServeBonusCalc extends BaseObject {
             $t1 = microtime(true);
             // 初始化结算任务
             $this->initCalcTask();
+            // 判断是否能开始进行计算奖金
+            $checkStart = $this->checkStart();
+            if (!$checkStart) {
+                return false;
+            } else {
+                // 更新状态为,奖金计算中
+                Period::updateCalcProcess(4, $this->_periodNum);
+            }
             $t2 = microtime(true);
             ServeProcess::recordProcess($t1, $t2, $this->_periodNum, '奖金计算初始化配置', 'bonus');
             // 设置结算状态
@@ -260,12 +269,22 @@ class CalcServeBonusCalc extends BaseObject {
         $this->_starCrownLevelConfig = Cache::getStarCrownLevelConfig();
         $this->_decRoleConfig = CalcCache::getDecRoleConfig($this->_periodNum);
         $this->_periodId = $periodDataArr['ID'];
+        $this->_isPerpare = $periodDataArr['ID'];
         $this->_isCalcMonth = $periodObj->isCalcMonth($this->_periodNum);
         $this->_calcYear = $periodObj->getYear($this->_periodNum);
         $this->_calcMonth = $periodObj->getMonth($this->_periodNum);
         $this->_calcYearMonth = $periodObj->getYearMonth($this->_periodNum);
     }
 
+    // 校验是否能开始进行计算
+    public function checkStart() {
+        if ($this->_isPerpare == 3) {
+            return true;
+        }
+
+        return false;
+    }
+
     /**
      * 设置结算状态
      * @param $type

+ 0 - 57
common/helpers/bonus/CalcServePerfCalc.php

@@ -74,63 +74,6 @@ class CalcServePerfCalc {
      */
     public function calcStep($periodNum = null) {
         try {
-//             // $userId="317189059070005248";
-//             $userId="376748282036228096";
-//             $sql = "SELECT t2.USER_ID
-//         FROM
-//             (
-//                 SELECT 
-//                 @r AS _id,
-//                 (SELECT @r := PARENT_UID FROM AR_USER_NETWORK_NEW WHERE USER_ID = _id) AS PARENT_UID,
-//                 @l := @l + 1 AS lvl
-//                 FROM
-//                 (SELECT @r := '".$userId."', @l := 0) vars, AR_USER_NETWORK_NEW AS h
-//                 WHERE @r <> 0 
-//             ) t1
-//         JOIN AR_USER_NETWORK_NEW t2
-//         ON t1._id = t2.USER_ID AND t1._id != '".$userId."';";
-//         $parentUidsArr = \Yii::$app->db->createCommand($sql)->queryAll();
-//         if (empty($parentUidsArr)) {
-//             return [];
-//         }
-//         $allUserIds = array_column($parentUidsArr, 'USER_ID');
-        
-//         $allUserIds = array_reverse($allUserIds);
-//         $allkey = array_values($allUserIds);
-//         $allvalue = array_keys($allUserIds);
-//         $resourceData = array_combine($allkey, $allvalue);
-//         // echo '<pre>';var_dump($resourceData);
-//         if(empty($allUserIds)) return [];
-//         $topDeep = count($allUserIds);
-//         $pageParentUids = array_slice($allUserIds, 0, 100);
-//         $parentList = [];
-//         foreach ($pageParentUids as $parentUid) {
-//             $nowKey = $resourceData[$parentUid];
-//                 $nearSon = $nowKey+1;
-//                 if ($nearSon == $topDeep) {
-//                     $locationInfoUid = $userId;
-//                 } else {
-//                     $locationInfoUid = $allUserIds[$nearSon];
-//                 }
-            
-//             $parentNetInfo = UserNetwork::find()
-//             ->select(['RELATIVE_LOCATION', 'PARENT_UID'])
-//             ->where('USER_ID=:USER_ID', ['USER_ID'=>$locationInfoUid])
-//             ->asArray()
-//             ->one();
-//             $location = $parentNetInfo['RELATIVE_LOCATION'];
-//             $parentList[] = [
-//                 'USER_ID' => $userId,
-//                 'TOP_DEEP' => $topDeep,
-//                 'PARENT_UID' => $parentUid,
-//                 'LOCATION' => $location,
-//             ];
-//         }
-//         echo '<pre>';var_dump($parentList);exit;
-//         unset($allUserIds);
-
-//  return '1111';exit;
-            //////////////////////////////////////////////////////////////////////////////////////
             $requestTime = date('Y-m-d H:i:s', time());
             if (empty($periodNum)) {
                 echo('触发时间:【'.$requestTime.'】'.'定时器执行累计业绩计算 ,内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);