| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Module\AppGame\Service;
- use App\Module\AppGame\Validations\BlockchainMinerValidation;
- use Uraus\App\RequestBlockchainMiner;
- class MinerService extends \App\Module\AppGame\UserService
- {
- public function calculate_miner_fee(RequestBlockchainMiner $blockchainMiner)
- {
- $va = BlockchainMinerValidation::makeByProrobuf($blockchainMiner);
- $va->validated();
- return $this->calculate_miner_fee2(
- $blockchainMiner->getAtype(),
- $blockchainMiner->getToAddress(),
- $blockchainMiner->getAmount()
- );
- }
- private function calculate_miner_fee2($atype, $to_address, $amount)
- {
- $feeTable = [
- 1 => [ 'amount' => '0.005', 'desc' => '普通交易矿工费' ],
- 2 => [ 'amount' => '0.008', 'desc' => '快速交易矿工费' ],
- 3 => [ 'amount' => '0.003', 'desc' => '慢速交易矿工费' ]
- ];
- // 开发环境固定返回类型1的费率
- if (!app()->isProduction()) {
- return $feeTable[1] ?? [ 'amount' => '0.005', 'desc' => '默认矿工费' ];
- }
- // 生产环境根据实际类型返回
- return $feeTable[$atype] ?? [
- 'amount' => '0.005',
- 'desc' => '未知交易类型矿工费'
- ];
- }
- }
|