From e0cb798c943fb840de1ae9bca958e1ab765b1e0f Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 28 Jun 2023 17:17:57 +0800 Subject: [PATCH 1/5] ... --- webapp/controller/ShopController.class.php | 76 +++++++++++++++++++--- webapp/mt/ShopChest.php | 42 ++++++++++++ 2 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 webapp/mt/ShopChest.php diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index c432082e..c052d061 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -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,8 +1544,10 @@ class ShopController extends BaseAuthedController $this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService); $propertyChgService->addUserChg(); // 充值就尝试开启首充活动 - if ($itemMeta['id'] == 10001) { - $this->beginFirstTupop(); + if ($sysAdd!=1) { + if ($itemMeta['id'] == 10001) { + $this->beginFirstTupop(); + } } } else { Bag::addItem($itemMeta['id'], $count); diff --git a/webapp/mt/ShopChest.php b/webapp/mt/ShopChest.php new file mode 100644 index 00000000..6c3f604c --- /dev/null +++ b/webapp/mt/ShopChest.php @@ -0,0 +1,42 @@ + Date: Wed, 28 Jun 2023 17:22:52 +0800 Subject: [PATCH 2/5] ... --- doc/Shop.py | 15 +++++++++++++++ doc/_common.py | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/doc/Shop.py b/doc/Shop.py index 76974439..e7cc26bc 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -217,5 +217,20 @@ class Shop(object): _common.RspHead(), ['block_chain', _common.ShopTrans(), '链上购买订单信息'] ] + }, + { + 'name': 'buyBlindBox', + 'desc': '购买盲盒(宝箱)', + 'group': 'Shop', + 'url': 'webapp/index.php?c=Shop&a=buyBlindBox', + 'params': [ + _common.ReqHead(), + ['id', 0, '商品唯一id,参见shopGoods表'], + ['num', 0, '购买数量 1:单个 10:十连抽'], + ], + 'response': [ + _common.RspHead(), + ['!result', [_common.BlindBoxResult()], '盲盒结果列表'], + ] } ] diff --git a/doc/_common.py b/doc/_common.py index a11cba34..6b031de1 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1218,4 +1218,12 @@ class ShopTrans(object): ['!params', [''], 'params'], ['item_id', 0, 'item_id'], ['item_num', 0, 'item_num'], + ] + +class BlindBoxResult(object): + + def __init__(self): + self.fields = [ + ['item_id', 0, 'item_id'], + ['num', 0, 'num'], ] \ No newline at end of file From ab4bcf3ad2f72c572d42b3daa64de560e8953644 Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 28 Jun 2023 17:26:00 +0800 Subject: [PATCH 3/5] ... --- doc/_common.py | 2 +- webapp/controller/ShopController.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/_common.py b/doc/_common.py index 6b031de1..f686f202 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1225,5 +1225,5 @@ class BlindBoxResult(object): def __init__(self): self.fields = [ ['item_id', 0, 'item_id'], - ['num', 0, 'num'], + ['item_num', 0, 'item_num'], ] \ No newline at end of file diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index c052d061..763fd6be 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -1182,7 +1182,7 @@ class ShopController extends BaseAuthedController } } - $record[$key] = array( "item_id" => $item['item_id'], "num" => $item['num'] ); + $record[$key] = array( "item_id" => $item['item_id'], "item_num" => $item['num'] ); } array_push($result, $record); } From 0b5a86dd329590cd86f3ca5d70882e9b7589a9d3 Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 28 Jun 2023 17:34:22 +0800 Subject: [PATCH 4/5] ... --- webapp/controller/ShopController.class.php | 128 ++++++++++----------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 763fd6be..429b66d9 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -997,19 +997,19 @@ class ShopController extends BaseAuthedController $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1); $this->_rspOk(); } else { - error_log("buy normal 1, need_price = ". $need_price . " goods_num = " . $goods_num); + error_log("buy normal 1, need_price = " . $need_price . " goods_num = " . $goods_num); $price = $this->normalizeWeb3Price($goods_num * $need_price); error_log("buy normal 2, price = " . $price); $item_id = $row['goods_id']; $item_count = $goods_num; - + $response = services\BlockChainService::gameItemMallBuy( Transaction::BUY_GOODS_ACTION_TYPE, $price, $item_id, $item_count ); - + BcOrder::upsert($response['trans_id'], array( 'item_id' => $item_id, 'item_num' => $item_count, @@ -1020,11 +1020,11 @@ class ShopController extends BaseAuthedController 'id' => $id, )), )); - + $response['item_id'] = $item_id; $response['item_num'] = $item_count; $this->_rspData( - array( + array( "block_chain" => $response ) ); @@ -1098,15 +1098,16 @@ class ShopController extends BaseAuthedController $price = $this->normalizeWeb3Price($goods['price'] * $count); $item_id = $goods['goods_id']; $item_count = $goods['goods_num'] * $count; - error_log("buyGoodsDS start " . json_encode(array( - 'idx' => $idx, - 'grid' => $grid, - 'count' => $count, - 'goodPrice' => $goods['price'], - 'price' => $price, - 'item_id' => $item_id, - 'item_count' => $item_count, - ) + error_log("buyGoodsDS start " . json_encode( + array( + 'idx' => $idx, + 'grid' => $grid, + 'count' => $count, + 'goodPrice' => $goods['price'], + 'price' => $price, + 'item_id' => $item_id, + 'item_count' => $item_count, + ) )); $response = services\BlockChainService::gameItemMallBuy( Transaction::BUY_GOODS_ACTION_TYPE, @@ -1127,12 +1128,13 @@ class ShopController extends BaseAuthedController )), )); - error_log("buyGoodsDS start " . json_encode(array( - 'idx' => $idx, - 'grid' => $grid, - 'count' => $count, - 'block_chain' => $response, - ) + error_log("buyGoodsDS start " . json_encode( + array( + 'idx' => $idx, + 'grid' => $grid, + 'count' => $count, + 'block_chain' => $response, + ) )); $this->_rspData( @@ -1168,7 +1170,7 @@ class ShopController extends BaseAuthedController $itemStore = mt\ShopChest::getRandomItemListByChestType($recommend); $result = array(); - for ($i=0; $i<$num; $i++) { + for ($i = 0; $i < $num; $i++) { $record = array(); foreach ($itemStore as $key => $value) { $item = $this->weighted_random($value); @@ -1181,16 +1183,16 @@ class ShopController extends BaseAuthedController $this->internalAddItem($propertyChgService, $itemMeta, 1, 1); } } - - $record[$key] = array( "item_id" => $item['item_id'], "item_num" => $item['num'] ); + $record[$key] = array("item_id" => $item['item_id'], "item_num" => $item['num']); + array_push($result, $record[$key]); } - array_push($result, $record); } - error_log("buyBlindBox start " . json_encode(array( - 'account' => $account, - 'itemListStore' => $result, - ) + error_log("buyBlindBox start " . json_encode( + array( + 'account' => $account, + 'itemListStore' => $result, + ) )); $this->_rspData( @@ -1544,7 +1546,7 @@ class ShopController extends BaseAuthedController $this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService); $propertyChgService->addUserChg(); // 充值就尝试开启首充活动 - if ($sysAdd!=1) { + if ($sysAdd != 1) { if ($itemMeta['id'] == 10001) { $this->beginFirstTupop(); } @@ -1645,50 +1647,48 @@ class ShopController extends BaseAuthedController return phpcommon\bnToStr($ret_price); } - private function countFreeBuyTimes($goods) { + private function countFreeBuyTimes($goods) + { $conn = myself()->_getMysql(''); $account = myself()->_getAccountId(); - - switch($goods['free_type']) - { - case 1: - { - $dayTime = myself()->_getNowDaySeconds(); - $sql = 'SELECT COUNT(*) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?'; - $row = $conn->execQueryOne($sql, array($account, $goods['id'], $goods['goods_id'], $dayTime)); - return $row['cnt']; - } - break; + + switch ($goods['free_type']) { + case 1: { + $dayTime = myself()->_getNowDaySeconds(); + $sql = 'SELECT COUNT(*) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?'; + $row = $conn->execQueryOne($sql, array($account, $goods['id'], $goods['goods_id'], $dayTime)); + return $row['cnt']; + } + break; } return 0; } - private function addFreeBuyRecord($goods) { + private function addFreeBuyRecord($goods) + { $conn = myself()->_getMysql(''); $account = myself()->_getAccountId(); - - switch($goods['free_type']) - { - case 1: - { - $dayTime = myself()->_getNowTime(); - SqlHelper::insert( - $conn, - 't_shop_free_record', - array( - 'account_id' => $account, - 'shop_id' => $goods['shop_id'], - 'id' => $goods['id'], - 'goods_id' => $goods['goods_id'], - 'goods_num' => $goods['goods_num'], - 'free_type' => $goods['free_type'], - 'free_num' => $goods['free_num'], - 'createtime' => $dayTime, - ) - ); - } - break; + + switch ($goods['free_type']) { + case 1: { + $dayTime = myself()->_getNowTime(); + SqlHelper::insert( + $conn, + 't_shop_free_record', + array( + 'account_id' => $account, + 'shop_id' => $goods['shop_id'], + 'id' => $goods['id'], + 'goods_id' => $goods['goods_id'], + 'goods_num' => $goods['goods_num'], + 'free_type' => $goods['free_type'], + 'free_num' => $goods['free_num'], + 'createtime' => $dayTime, + ) + ); + } + break; } } } From ad420b180ee7f77a474cbd15a28dbe70165664f6 Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 28 Jun 2023 17:56:42 +0800 Subject: [PATCH 5/5] ... --- webapp/controller/ShopController.class.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 429b66d9..b6b85992 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -1164,10 +1164,27 @@ class ShopController extends BaseAuthedController $this->_rspErr(2, 'id is invalid'); return; } + $isFreeBuy = false; + if (!empty($shop['free_type'])) { + $count = $this->countFreeBuyTimes($shop); + if ($count < $shop['free_num']) { + $isFreeBuy = true; + } + } $cost = $shop['price'] * $num; + if ($isFreeBuy) { + $cost = 0; + } + $recommend = $shop['recommend']; $itemStore = mt\ShopChest::getRandomItemListByChestType($recommend); + if ($isFreeBuy) { + if ($num != 1) { + $this->_rspErr(2, 'num is invalid'); + return; + } + } $result = array(); for ($i = 0; $i < $num; $i++) { @@ -1186,6 +1203,9 @@ class ShopController extends BaseAuthedController $record[$key] = array("item_id" => $item['item_id'], "item_num" => $item['num']); array_push($result, $record[$key]); } + if ($isFreeBuy && $num == 1) { + $this->addFreeBuyRecord($shop); + } } error_log("buyBlindBox start " . json_encode(