Example #1
0
 /**
  * 根据ID 获取价格段信息
  *
  * @param $id
  * @return array
  */
 public static function get_price_by_id($id)
 {
     try {
         $priceInfo = Model_House_EsfPrice::data_access('')->filter('id', $id)->get_row();
     } catch (Exception $e) {
         return array();
     }
     if (is_null($priceInfo)) {
         return array();
     }
     return $priceInfo;
 }
 public function dealTask($task)
 {
     $currentUsedNum = $task['usedNum'];
     //获取价格信息
     $priceIntervalInfo = Model_House_EsfPrice::data_access()->filter('id', $task['priceId'])->find_only();
     if (empty($priceIntervalInfo)) {
         printf("价格段priceId:" . $task['priceId'] . "获取失败" . PHP_EOL);
         return false;
     }
     //获取实际计划数目
     $trueUsedNum = Model_Plan_EsfAjkPropSpread::data_access()->filter("areacode", $task['typeCode'])->filter("smallprice", $priceIntervalInfo->minPrice)->filter("bigprice", $priceIntervalInfo->maxPrice)->filter("bidVersion", Model_Plan_EsfAjkPropSpread::CHOICEVERSION)->filter("model", Model_Plan_EsfAjkPropSpread::BLOCK_CHOICE)->filter_by_op('status', 'in', array(Model_Plan_EsfAjkPropSpread::ONLINE, Model_Plan_EsfAjkPropSpread::ONQUEUE))->count();
     printf('正在处理 队列id %s, areaCode %s, priceId %s 结果是: userNum: %s, 实际: %s, 状态:%s' . PHP_EOL, $task['id'], $task['typeCode'], $task['priceId'], $currentUsedNum, $trueUsedNum, $currentUsedNum == $trueUsedNum ? 'success' : 'error');
     if ($currentUsedNum == $trueUsedNum) {
         return true;
     }
     $result = Model_Choice_EsfBlockBidBucket::updateUsedNum($task['id'], $trueUsedNum, $task['usedNum']);
     printf('更新usedNum结果: %s' . PHP_EOL, $result ? '更新成功' : '更新失败');
     return true;
 }
 public function run()
 {
     //根据游标获取一定数量的坑位信息
     $bucketInfos = Model_Choice_EsfBidBucket::getBucketInfoById($this->cursor, 0, $this->limit);
     //无需要处理的数据
     if (empty($bucketInfos)) {
         $this->setShStopFlag();
         $this->setCursor(0);
         $this->logQuit("无需要处理的数据.");
     }
     //检验具体的坑位信息
     foreach ($bucketInfos as $bucketInfo) {
         //获取价格信息
         $priceIntervalInfo = Model_House_EsfPrice::data_access()->filter('id', $bucketInfo->priceId)->find_only();
         if (empty($priceIntervalInfo)) {
             $this->addLogger(sprintf("坑位信息%d,价格段id:%d获取失败", $bucketInfo->id, $bucketInfo->priceId));
             continue;
         }
         //获取实际计划数目
         $planNum = Model_Plan_EsfAjkPropSpread::data_access()->filter("commId", $bucketInfo->communityId)->filter("smallprice", $priceIntervalInfo->minPrice)->filter("bigprice", $priceIntervalInfo->maxPrice)->filter("bidVersion", Model_Plan_EsfAjkPropSpread::CHOICEVERSION)->filter("model", Model_Plan_EsfAjkPropSpread::COMM_CHOICE)->filter_by_op('status', 'in', array(Model_Plan_EsfAjkPropSpread::ONLINE, Model_Plan_EsfAjkPropSpread::ONQUEUE))->count();
         if ($planNum == $bucketInfo->usedNum) {
             if (isset($this->exceptionBucket[$bucketInfo->id])) {
                 //移除已经正常的坑位标记
                 unset($this->exceptionBucket[$bucketInfo->id]);
                 $this->addLogger(sprintf("坑位信息%d,坑位恢复到正常%d", $bucketInfo->id, $planNum));
             } else {
                 $this->addLogger(sprintf("坑位信息%d正常", $bucketInfo->id));
             }
             //更新游标
             $this->setCursor($bucketInfo->id);
             //更新异常文件
             $this->exceptionBucketFile->coverLog(json_encode($this->exceptionBucket));
             continue;
         }
         //坑位异常处理
         if (isset($this->exceptionBucket[$bucketInfo->id])) {
             //坑位已异常
             if ($this->exceptionBucket[$bucketInfo->id]["occur"] <= $this->repairOccurNum) {
                 //达到警告线,需要修复数据
                 //已实际计划数为依据更新
                 if (Model_Choice_EsfBidBucket::updateUsedNum($bucketInfo->id, $planNum, $bucketInfo->usedNum)) {
                     unset($this->exceptionBucket[$bucketInfo->id]);
                     $this->addLogger(sprintf("坑位信息%d,更新坑位信息成功, SQL:%s", $bucketInfo->id, Model_Choice_EsfBidBucket::$lastSql));
                 } else {
                     $this->addLogger(sprintf("坑位信息%d,更新坑位信息失败, SQL:%s", $bucketInfo->id, Model_Choice_EsfBidBucket::$lastSql));
                     continue;
                 }
             } else {
                 //未达到警告线,继续标记
                 //记录历史信息
                 if (isset($this->exceptionBucket[$bucketInfo->id]['history'])) {
                     $history = $this->exceptionBucket[$bucketInfo->id]['history'];
                 } else {
                     $history = array();
                 }
                 $history[] = $this->exceptionBucket[$bucketInfo->id];
                 //继续标记
                 $this->exceptionBucket[$bucketInfo->id] = array('planNum' => $planNum, 'usedNum' => $bucketInfo->usedNum, 'occur' => $this->exceptionBucket[$bucketInfo->id]["occur"] + 1);
                 $this->exceptionBucket[$bucketInfo->id]['history'] = $history;
                 //记录日志
                 $this->addLogger(sprintf("坑位信息%d,出现异常%s", $bucketInfo->id, json_encode($this->exceptionBucket[$bucketInfo->id])));
             }
         } else {
             $this->exceptionBucket[$bucketInfo->id] = array('planNum' => $planNum, 'usedNum' => $bucketInfo->usedNum, 'occur' => 1);
             $this->addLogger(sprintf("坑位信息%d,出现异常%s", $bucketInfo->id, json_encode($this->exceptionBucket[$bucketInfo->id])));
         }
         //更新异常文件
         $this->exceptionBucketFile->coverLog(json_encode($this->exceptionBucket));
         //更新游标
         $this->setCursor($bucketInfo->id);
     }
 }