...
This commit is contained in:
parent
472e75fa35
commit
e0cb798c94
@ -8,6 +8,7 @@ require_once('mt/Parameter.php');
|
||||
require_once('mt/Drop.php');
|
||||
require_once('mt/PayMethod.php');
|
||||
require_once('mt/Dailyselection.php');
|
||||
require_once('mt/ShopChest.php');
|
||||
|
||||
require_once('models/User.php');
|
||||
require_once('models/Hero.php');
|
||||
@ -40,6 +41,7 @@ use models\Chip;
|
||||
use mt\Shop;
|
||||
use mt\PayMethod;
|
||||
use mt\Dailyselection;
|
||||
use mt\ShopChest;
|
||||
use models\Transaction;
|
||||
use models\BcOrder;
|
||||
|
||||
@ -265,7 +267,7 @@ class ShopController extends BaseAuthedController
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
@ -406,7 +408,7 @@ class ShopController extends BaseAuthedController
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
// $awardService->addItem($row['goods_id'], $goods_num);
|
||||
@ -671,7 +673,7 @@ class ShopController extends BaseAuthedController
|
||||
return;
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1, 0);
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($itemId, $itemNum);
|
||||
ShopBuyRecord::add($itemId, $itemNum);
|
||||
@ -952,7 +954,7 @@ class ShopController extends BaseAuthedController
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
@ -992,7 +994,7 @@ class ShopController extends BaseAuthedController
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$this->addFreeBuyRecord($row);
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1);
|
||||
$this->_rspOk();
|
||||
} else {
|
||||
error_log("buy normal 1, need_price = ". $need_price . " goods_num = " . $goods_num);
|
||||
@ -1143,6 +1145,60 @@ class ShopController extends BaseAuthedController
|
||||
);
|
||||
}
|
||||
|
||||
public function buyBlindBox()
|
||||
{
|
||||
$account = $this->_getAccountId();
|
||||
|
||||
$id = getReqVal('id', 0);
|
||||
$num = getReqVal('num', 0);
|
||||
|
||||
if (!($num == 1 || $num == 10)) {
|
||||
$this->_rspErr(2, 'num is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$shop = mt\ShopGoods::get($id);
|
||||
if (!$shop) {
|
||||
$this->_rspErr(2, 'id is invalid');
|
||||
return;
|
||||
}
|
||||
$cost = $shop['price'] * $num;
|
||||
$recommend = $shop['recommend'];
|
||||
|
||||
$itemStore = mt\ShopChest::getRandomItemListByChestType($recommend);
|
||||
|
||||
$result = array();
|
||||
for ($i=0; $i<$num; $i++) {
|
||||
$record = array();
|
||||
foreach ($itemStore as $key => $value) {
|
||||
$item = $this->weighted_random($value);
|
||||
$itemMeta = mt\Item::get($item['item_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
if ($item['item_type'] == 2) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $item['num'], 1);
|
||||
} else {
|
||||
for ($j = 0; $j < $item['num']; $j++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$record[$key] = array( "item_id" => $item['item_id'], "num" => $item['num'] );
|
||||
}
|
||||
array_push($result, $record);
|
||||
}
|
||||
|
||||
error_log("buyBlindBox start " . json_encode(array(
|
||||
'account' => $account,
|
||||
'itemListStore' => $result,
|
||||
)
|
||||
));
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'reuslt' => $result,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function buyGoodsFree()
|
||||
{
|
||||
@ -1335,7 +1391,7 @@ class ShopController extends BaseAuthedController
|
||||
return;
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1, 0);
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($itemId, $itemNum);
|
||||
ShopBuyRecord::add($itemId, $itemNum);
|
||||
@ -1454,7 +1510,7 @@ class ShopController extends BaseAuthedController
|
||||
return $costItems;
|
||||
}
|
||||
|
||||
private function internalAddItem($propertyChgService, $itemMeta, $count)
|
||||
private function internalAddItem($propertyChgService, $itemMeta, $count, $sysAdd)
|
||||
{
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE: {
|
||||
@ -1488,9 +1544,11 @@ class ShopController extends BaseAuthedController
|
||||
$this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService);
|
||||
$propertyChgService->addUserChg();
|
||||
// 充值就尝试开启首充活动
|
||||
if ($sysAdd!=1) {
|
||||
if ($itemMeta['id'] == 10001) {
|
||||
$this->beginFirstTupop();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Bag::addItem($itemMeta['id'], $count);
|
||||
$propertyChgService->addBagChg();
|
||||
|
42
webapp/mt/ShopChest.php
Normal file
42
webapp/mt/ShopChest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace mt;
|
||||
|
||||
use phpcommon;
|
||||
|
||||
class ShopChest
|
||||
{
|
||||
|
||||
public static function getRandomItemListByChestType($chestType) {
|
||||
self::cacheRandomItemListByChestTypes();
|
||||
return getXVal(self::$itemListWithChestType, $chestType, null);
|
||||
}
|
||||
|
||||
protected static function cacheRandomItemListByChestTypes() {
|
||||
if (!self::$itemListWithChestType) {
|
||||
self::$itemListWithChestType = array();
|
||||
foreach (self::getMetaList() as $meta) {
|
||||
if (!getXVal(self::$itemListWithChestType, $meta['chest_type'], null)) {
|
||||
self::$itemListWithChestType[$meta['chest_type']] = array();
|
||||
}
|
||||
|
||||
if(!getXVal(self::$itemListWithChestType[$meta['chest_type']], $meta['item_type'], null)) {
|
||||
self::$itemListWithChestType[$meta['chest_type']][$meta['item_type']] = array();
|
||||
}
|
||||
|
||||
array_push(self::$itemListWithChestType[$meta['chest_type']][$meta['item_type']], $meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('Shopchest@Shopchest.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
protected static $itemListWithChestType;
|
||||
protected static $metaList;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user