public function dealTask($task) { $currentUsedNum = $task['usedNum']; $trueUsedNum = Bll_HzBidPlan::countBucketChoicePlan($task['blockId'], $task['priceId']); printf('正在处理 队列id %s, blockId %s, priceId %s 结果是: userNum: %s, 实际: %s, 状态:%s' . PHP_EOL, $task['id'], $task['blockId'], $task['priceId'], $currentUsedNum, $trueUsedNum, $currentUsedNum == $trueUsedNum ? 'success' : 'error'); if ($currentUsedNum == $trueUsedNum) { return true; } $result = Model_Choice_HzBidBucket::updateBucket(array('id' => $task['id']), array('usedNum' => $trueUsedNum)); printf('更新usedNum结果: %s' . PHP_EOL, $result ? '更新成功' : '更新失败'); return true; }
/** * 更新坑位信息,重新计算 * * @param int $blockId * @param int $priceId * @return bool */ private static function updateBucket($blockId, $priceId) { $bucketCount = Bll_HzBidPlan::countBucketChoicePlan($blockId, $priceId); $bucketInfo = Bll_Choice_HzBidBucket::getBucketInfo($blockId, $priceId); if (empty($bucketInfo)) { $bucketInfo = Bll_Choice_HzBidBucket::init_bucket_info($blockId, $priceId); } if ($bucketInfo['usedNum'] == $bucketCount) { return true; } $condition = array('blockId' => $blockId, 'priceId' => $priceId); return 1 == Model_Choice_HzBidBucket::updateBucket($condition, array('usedNum' => min($bucketCount, $bucketInfo['totalNum']))); }