_rspData( array( 'goods_list' => $goodsList, ) ); } public function testBuyGoods() { if (SERVER_ENV != _ONLINE) { $this->internalBuyGoods(); } } public function buyGoodsS() { $this->internalBuyGoods(); } public function internalBuyGoods() { if (SERVER_ENV == _ONLINE) { myself()->_verifySwitch('hashrate.shop.buy'); } $goodsId = getReqVal('goods_id', 0); $goodsNum = intval(getReqVal('goods_num', 0)); if ($goodsNum < 1) { myself()->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); return; } $goodsMeta = mt\HashRateShop::find($goodsId); if (!$goodsMeta) { myself()->_rspErr(1, 'goods not found'); return; } if ($goodsMeta['is_close']) { myself()->_rspErr(1, 'no right to purchase'); return; } $itemMeta = mt\Item::get($goodsMeta['type']); if (!$itemMeta) { myself()->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); return; } $errCode = 0; $errMsg = ''; if (!HashRateShopService::buyLimitCheck($goodsMeta, $goodsNum, $errCode, $errMsg)) { myself()->_rspErr($errCode, $errMsg); return; } $propertyChgService = new services\PropertyChgService(); $awardService = new services\AwardService(); $price = $goodsMeta['pile_price']; if ($price < 1) { myself()->_rspErr(1, "config error"); return; } if ($price * $goodsNum > models\HashRate::getMyCurrentHashRate()) { myself()->_rspErr(2, "hashrate not enough"); return; } models\HashRate::decMyCurrentHashRate($price * $goodsNum); error_log(models\HashRate::getMyCurrentHashRate()); models\HashRateShopBuyRecord::add($goodsMeta['id'], $goodsNum, $goodsMeta['type']); for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($awardService, $propertyChgService, $itemMeta, $goodsMeta['item_num'] ); } $propertyChgService->addUserChg(); myself()->_callModelStatic('RookieTask','incTaskVal',\mt\RookieTask::HASH_RATE_BUYS_COND,$goodsNum); $this->_rspData( array( 'award' => $awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), ) ); } private function internalAddItem($awardService, $propertyChgService, $itemMeta, $count ) { myself()->_addItems( array( array( 'item_id' => $itemMeta['id'], 'item_num' => $count ) ), $awardService, $propertyChgService); } }