stage + 1; $start_height = $last->end_height; } else { //第一次计算开奖 $stage = intval($last_header['height'] / 50); $start_height = ($stage - 1) * 50; } $end_height = $start_height + 50; //判断区块是否超前了 if ($end_height > $last_header['height']) { return 0; } //获取中奖号码 $hash = Chain33Business::getBlockHashByHeight($end_height); if ($hash['code'] != 0) { Yii::info('获取区块hash失败: ' . $hash['msg'], __CLASS__); return 0; } $hash = $hash['result']['hash']; $hash = substr($hash, -2); if (!ctype_digit($hash)) { $hash = hexdec($hash) % 100; $hash = sprintf("%02d", $hash); } //保存开奖结果到数据库 $guess_result = new CoinGuessResult(); $guess_result->stage = $stage; $guess_result->start_height = $start_height; $guess_result->end_height = $end_height; $guess_result->result = $hash; $guess_result->is_award = 0; if ($guess_result->save()) { //添加派奖任务到队列 Yii::$app->queue->push(new JugdeAwardJob()); Yii::info("竞猜开奖成功! [期数]: $stage", __CLASS__); } else { Yii::info("保存开奖记录失败! [期数]: $stage", __CLASS__); } return 0; } }