_rspData(array( 'info' => array( 'goods_list1' => array(), 'goods_list2' => array(), ) )); return; } $goodsDtoList1 = array(); $goodsDtoList2 = array(); foreach ($goodsList as $goods) { } $this->_rspData(array( 'info' => array( 'goods_list1' => $goodsDtoList1, 'goods_list2' => $goodsDtoList2, ) )); } public function buyGoods() { } public function outsideBuy() { $itemId = getReqVal('item_id', 0); $itemNum = getReqVal('item_num', 0); $costItemId = getReqVal('item_id', 0); $itemMeta = mt\Item::get($itemId); if (!$itemMeta) { $this->_rspErr(1, 'item_id参数错误'); return; } if ($itemNum != 1) { $this->_rspErr(1, 'item_num参数必须等于1'); return; } $costItemMeta = mt\Item::get($costItemId); if (!$costItemMeta) { $this->_rspErr(1, 'item_id参数错误'); return; } $types = array(mt\Item::HERO_TYPE, mt\Item::HERO_SKIN_TYPE, mt\Item::GUN_SKIN_TYPE); if (!mt\Item::inTypes($itemMeta, $types)) { $this->_rspErr(1, 'item_id参数错误'); return; } { switch ($itemMeta['type']) { case mt\Item::HERO_TYPE: { $heroDb = Hero::find($itemMeta['id']); if (!$heroDb) { $this->_rspErr(4, '你已经拥有该英雄'); return; } } break; case mt\Item::HERO_SKIN_TYPE: { $heroSkinDb = HeroSkin::find($itemMeta['id']); if (!$heroSkinDb) { $this->_rspErr(4, '你已经拥有该皮肤'); return; } } break; case mt\Item::GUN_SKIN_TYPE: { $gunSkinDb = GunSkin::find($itemMeta['id']); if (!$gunSkinDb) { $this->_rspErr(4, '你已经拥有该皮肤'); return; } } break; default: { $this->_rspErr(1, 'item_id参数错误'); return; } break; } } $priceInfo = mt\Item::getPriceInfo($itemMeta); if (empty($priceInfo)) { $this->_rspErr(2, '配置表错误'); return; } $costItems = $this->getCostTimes($priceInfo, $costItemId); if (empty($costItems)) { $this->_rspErr(2, '配置表错误2'); return; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); $this->internalAddItem($itemMeta); $awardService = new services\AwardService(); $awardService->addItem($itemId, $itemNum); $this->rspData(array( 'award' => $awardService->toDto(), 'property_chg' => array( 'user_info' => User::info($this->_getOrmUserInfo()) ) )); } public function getOutsidePriceInfo() { $items = array(); { $types = array(mt\Item::HERO_TYPE, mt\Item::HERO_SKIN_TYPE, mt\Item::GUN_SKIN_TYPE); mt\Item::filter(function ($meta) use(&$items, &$types) { if (mt\Item::inTypes($meta, $types)) { array_push($items, $meta); } return true; }); } $priceList = array(); array_walk($items, function ($val) use(&$priceList) { array_push($priceList, mt\Item::getPriceInfo($val)); }); $this->_rspData(array( 'price_list' => $priceList )); } private function getCostItems($priceInfo, $costItemId) { $costGroup = null; array_walk($priceInfo['cost_list'], function ($val) use(&$costGroup, $costItemId) { if ($costGroup) { return; } if (count($val) > 0 && $val[0]['item_id'] == $costItemId) { $costGroup = $val; return; } }); if (!$costGroup) { return null; } $costItems = array(); array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) { if ($val['is_discount'] && $priceInfo['discount'] > 0 && $this->_getNowTime() >= $priceInfo['discount_begin_time'] && $this->_getNowTime() <= $priceInfo['discount_end_time'] ) { array_push($costItems, array( 'item_id' => $val['item_id'], 'item_num' => (int)($val['item_num'] * ($priceInfo['discount'] / 100)), )); } else { array_push($costItems, array( 'item_id' => $val['item_id'], 'item_num' => $val['item_num'], )); } }); return $costItems; } private function internalAddItem($itemMeta) { switch ($itemMeta['type']) { case mt\Item::HERO_TYPE: { Hero::addHero($itemMeta); } break; case mt\Item::HERO_SKIN_TYPE: { HeroSkin::addSkin($itemMeta); } break; case mt\Item::GUN_SKIN_TYPE: { GunSkin::addSkin($itemMeta); } break; default: { } break; } } private function updateBuyRecord($itemId, $itemNum) { } }