106 lines
2.9 KiB
PHP
106 lines
2.9 KiB
PHP
<?php
|
|
|
|
require_once('mt/Shop.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Drop.php');
|
|
|
|
require_once('models/Hero.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
|
|
class ShopController extends BaseAuthedController {
|
|
|
|
public function info()
|
|
{
|
|
$shopId = getReqVal('sho_id', 0);
|
|
}
|
|
|
|
public function buyHero()
|
|
{
|
|
$heroId = getReqVal('hero_id', 0);
|
|
$buyType = getReqVal('buy_type', 0);
|
|
$heroMeta = mt\Hero::get($heroId);
|
|
if (!$heroMeta) {
|
|
$this->_rspErr(1, 'hero_id参数错误');
|
|
return;
|
|
}
|
|
if (empty($heroMeta['itemid'])) {
|
|
$this->_rspErr(2, 'hero.item_id配置错误');
|
|
return;
|
|
}
|
|
if (!in_array($buyType, array(0, 1))) {
|
|
$this->_rspErr(1, 'buy_type参数错误');
|
|
return;
|
|
}
|
|
$shopMeta = mt\Shop::get(mt\Shop::HERO_SHOP_ID);
|
|
if (!$shopMeta) {
|
|
$this->_rspErr(2, '配置表错误1');
|
|
return;
|
|
}
|
|
$goodsInfo = mt\Shop::getGoodsInfo($shopMeta, $heroMeta['itemid']);
|
|
if (empty($goodsInfo)) {
|
|
$this->_rspErr(2, '配置表错误2');
|
|
return;
|
|
}
|
|
if (Hero::find($heroId)) {
|
|
$this->_rspErr(3, '你已经有该英雄');
|
|
return;
|
|
}
|
|
$costItems = array(
|
|
'item_id' => $goodsInfo['costItemId'],
|
|
'item_num' => $goodsInfo['costItemNum'],
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, '道具不足');
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
Hero::addHero($heroMeta);
|
|
$awardService = new services\AwardService();
|
|
$heroDb = Hero::find($heroId);
|
|
if ($heroDb) {
|
|
$awardService->addHero(Hero::toDto($heroDb));
|
|
}
|
|
$this->rspData(array(
|
|
'award' => $awardService->toData()
|
|
));
|
|
}
|
|
|
|
public function outsideBuy()
|
|
{
|
|
$itemId = getReqVal('item_id', 0);
|
|
$itemNum = getReqVal('item_num', 0);
|
|
$costItemId = getReqVal('cost_item_id', 0);
|
|
}
|
|
|
|
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 (in_array($meta['type'], $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
|
|
));
|
|
}
|
|
|
|
}
|