_getMarketMysql(), 't_phase3_box', array( 'account' => $account, ) ); return $row; } /* 抽奖箱规则 箱子只能抽中其中一项奖励 名称 奖励 百分比 大约中奖人数 特奖 创世 NFT英雄 3% 6 头奖 枪械 NFT 5% 10 一等奖 芯片 NFT 7% 13 二等奖 25 CEC 20% 38 三等奖 20 CEC 30% 57 安慰奖 15 CEC 35% 67 */ public static function give($account) { $heros = array( 30100, 30200, 30300, 30400, 30500, 30600, 30700, 30800, 31000 ); $guns = array( 70001, 70002, 70003, 70004, 70005, 70006, 70007 ); $chips = array( 100001 ); $row = SqlHelper::ormSelectOne( myself()->_getMarketMysql(), 't_phase3_box', array( 'account' => $account, ) ); $randArr = array( 3, 5, 7, 20, 30, 35 ); { $space = 0; for ($i = 0; $i < count($randArr); ++$i) { $space += $randArr[$i]; $randArr[$i] = $space; } } if ($row && $row['state'] == self::INIT_STATE) { $rnd = rand(0, 99); $rewardIdx = -1; error_log(json_encode($randArr)); error_log('rand:' . $rnd); for ($i = 0; $i < count($randArr); ++$i) { if ($rnd <= $randArr[$i]) { $rewardIdx = $i; break; } } self::internalGive( $account, $row['token_id'], $rewardIdx, $heros, $guns, $chips); } } protected function internalGive($account, $tokenId, $rewardIdx, $heros, $guns, $chips) { $accountId = phpcommon\createAccountId(6516, 2006, $account); $itemId = 0; $tokenType = 0; $tags = ''; $cec = 0; switch ($rewardIdx) { case 0: { //特奖 创世 NFT英雄 3% 6 $rnd = rand(0, count($heros) - 1); $itemId = $heros[$rnd]; $tokenType = Nft::HERO_TYPE; $tags = Nft::GENESIS_TAG; } break; case 1: { //头奖 枪械 NFT 5% 10 $rnd = rand(0, count($guns) - 1); $itemId = $guns[$rnd]; $tokenType = Nft::EQUIP_TYPE; } break; case 2: { //一等奖 芯片 NFT 7% 13 $rnd = rand(0, count($chips) - 1); $itemId = $chips[$rnd]; $tokenType = Nft::CHIP_TYPE; } break; case 3: { //二等奖 25 CEC 20% 38 $cec = 25; } break; case 4: { //三等奖 20 CEC 30% 57 $cec = 20; } break; default: { //安慰奖 15 CEC 35% 67 $cec = 15; } break; } if (empty($itemId) && empty($cec)) { return; } if ($itemId) { $row = SqlHelper::ormSelectOne( myself()->_getMarketMysql(), 't_mint', array( 'bc_mint_tokenid' => $tokenId, ) ); if (!$row) { $uniKey = 'phase3box_' . $account; SqlHelper::insert( myself()->_getMarketMysql(), 't_mint', array( 'bc_mint_tokenid' => $tokenId, 'unikey' => $uniKey, 'account' => $account, 'game_id' => 2006, 'bc_mint_itemid' => $itemId, 'bc_mint_token_type' => $tokenType, 'bc_mint_tags' => $tags, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ) ); } } if ($cec > 0) { SqlHelper::upsert( myself()->_getMarketMysql(), 't_user_wallet_offline_temp', array( 'account_id' => $accountId, ), array( 'diamond' => function () use ($cec) { return 'diamond + ' . $cec; } ), array( 'account_id' => $accountId, 'diamond' => $cec, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ) ); } { SqlHelper::update( myself()->_getMarketMysql(), 't_phase3_box', array( 'account' => $account, ), array( 'item_id' => $itemId, 'cec' => $cec, 'state' => self::GIVE_STATE ) ); } } }