Commit a38496ed authored by rlgy's avatar rlgy

update

parent b73937b9
......@@ -10,6 +10,7 @@ namespace console\controllers;
use common\business\Chain33Business;
use common\business\CoinBusiness;
use h5\job\JugdeAwardJob;
use Yii;
use yii\console\Controller;
use common\models\psources\CoinGuessResult;
......@@ -70,6 +71,7 @@ class AwardController extends Controller
$guess_result->is_award = 0;
if ($guess_result->save()) {
//添加派奖任务到队列
Yii::$app->queue->push(new JugdeAwardJob());
Yii::info("竞猜开奖成功! [期数]: $stage", __CLASS__);
} else {
Yii::info("保存开奖记录失败! [期数]: $stage", __CLASS__);
......
......@@ -34,10 +34,10 @@ class AwardJob extends BaseObject implements JobInterface
*/
public function execute($queue)
{
$result = Chain33Business::transToken($this->from, $this->to, $this->amount, $this->note, $this->is_token,
$this->token);
$result = Chain33Business::transToken($this->from, $this->to, $this->amount, $this->note, $this->is_token, $this->token);
if (is_string($result)) {
//派奖记录到数据库中
Yii::info("派奖成功! 奖励[{$this->to}][$this->token][$this->amount]个", __CLASS__);
} else {
Yii::info("失败的派奖: [to]: {$this->to}, [amount]: {$this->amount}, [is_token] : {$this->is_token}, [token]: {$this->token}",
__CLASS__);
......
......@@ -36,26 +36,83 @@ class JugdeAwardJob extends BaseObject implements JobInterface
if ($guess_result) {
$config = Yii::$app->params['h5_activity']['ZWG_GUESS_NEWBEE'];
//获取区块间的所有交易(正常竞猜)
// $trans_normal = Chain33Business::getTxByAddrInRange($config['from_normal'], 2, 0, $guess_result->start_height, $guess_result->end_height);
$trans_normal = Chain33Business::getTxByAddrInRange('14o9MHrrLfpsXf7wu4H4YRwvy84fjd7uaj', 2, 0, 710900, 715345);
$trans_new = Chain33Business::getTxByAddrInRange($config['to'], 2, 0, $guess_result->start_height, $guess_result->end_height);
$trans = array_merge($trans_normal, $trans_new);
$txhashs = array_column($trans, 'hash');
$trans_info = Chain33Business::getTxByHashs($txhashs);
$trans_normal = Chain33Business::getTxByAddrInRange($config['to_normal'], 2, 0, $guess_result->start_height, $guess_result->end_height - 1);
$trans_new = Chain33Business::getTxByAddrInRange($config['to'], 2, 0, $guess_result->start_height, $guess_result->end_height - 1);
$trans = array_merge($trans_normal, $trans_new);
$txhashs = array_column($trans, 'hash');
$trans_info = Chain33Business::getTxByHashs($txhashs);
if ($trans_info['code'] == 0) {
$trans_info = $trans_info['result']['txs'];
if (is_array($trans_info)) {
$txs = [];
foreach ($trans_info as $k => $v) {
//收集数据
$temp = [];
$temp['amount'] = $v['amount'];
$temp['from'] = $v['fromAddr'];
$temp['to'] = $v['tx']['to'];
$temp['note'] = $v['tx']['payload']['Value']['Transfer']['note'] ?? '';
if ($temp['amount'] == intval($config['amount'] * 1e8) || $temp['amount'] == 2 * 1e8) {
$matchs = [];
if (preg_match('/^\d\d$/', $temp['note'], $matchs)) {
$temp['guess'] = $matchs[0];
$txs[] = $temp;
}
if (preg_match('/^(\d\d) (\w+)$/', $temp['note'], $matchs)) {
$temp['guess'] = $matchs[1];
$temp['from'] = $matchs[2];
$txs[] = $temp;
}
}
}
//为所有参与用户判断中奖情况
// $this->doAward($txs, $guess_result->result);
}
}
$loop = false;
$guess_result->is_award = 1;
if ($guess_result->save()) {
Yii::info("第{$guess_result->stage}期开奖成功", __CLASS__);
} else {
Yii::warning("第{$guess_result->stage}期开奖成功, 修改竞猜开奖情况失败", __CLASS__);
}
print "ok\n";
} else {
$loop = false;
}
} while ($loop);
return 0;
}
private function doAward($txs, $result)
{
foreach ($txs as $item) {
$flag = false;
if (preg_match('/^' . $result . '$/', $item['guess'])) {
$flag = true;
$amount = 1;
} else {
$guess = [];
$guess[] = intval($item['guess'] / 10);
$guess[] = intval($item['guess'] % 10);
$ans = [];
$ans[] = intval($result / 10);
$ans[] = intval($result % 10);
if (!empty(array_intersect($ans, $guess))) {
$flag = true;
$amount = 0.2;
}
}
if (!$flag) {
continue;
}
Yii::$app->queue->push(new AwardJob([
'from' => Yii::$app->params['h5_activity']['ZWG_GUESS_NEWBEE']['from'],
'to' => $item['from'],
'is_token' => true,
'token' => 'ZWGYBA',
'amount' => $amount * 1e8,
'note' => '竞猜奖励',
]));
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment