diff --git a/doc/AAMarket.py b/doc/AAMarket.py index 04cc40bf..c1cad481 100644 --- a/doc/AAMarket.py +++ b/doc/AAMarket.py @@ -300,8 +300,11 @@ class AAMarket(object): ], 'response': [ _common.RspHead(), + ['nickname', '', '昵称'], + ['email', '', 'email'], ['contribution_point', 0, '贡献点'], - ['gold', 0, '金币数'], + ['gold', '', '金币数'], + ['diamond', '', '钻石数'], ] }, { @@ -333,6 +336,23 @@ class AAMarket(object): ], '数据'], ] }, + { + 'method': 'GET', + 'name': '/api/activity/diamond/history/:account_address', + 'desc': '钻石-充值/消费记录', + 'group': '!AAMarket', + 'url': '/api/activity/diamond/history/:account_address', + 'params': [ + ], + 'response': [ + _common.RspHead(), + ['!rows', [ + ['type', 0, '0:充值 1:消费'], + ['date', 0, 'utc时间'], + ['amount', '', '数量'], + ], '数据'], + ] + }, { 'method': 'GET', 'name': '/api/chain/txhash/:net_id/:txhash', diff --git a/doc/README.php b/doc/README.php index b947f10e..dae61359 100644 --- a/doc/README.php +++ b/doc/README.php @@ -18,6 +18,7 @@ * @apiSuccessExample {json} Success-Response: * 2024/07/25 * c=Bag&a=useItemS + * 2024/08/01 * c=Bag&a=buyItemS * c=Avatar&a=buyAvatarS * c=Chip&a=upgradeQualityS diff --git a/sql/bcnftdb.sql b/sql/bcnftdb.sql index 8ad37293..3c031680 100644 --- a/sql/bcnftdb.sql +++ b/sql/bcnftdb.sql @@ -320,6 +320,7 @@ DROP TABLE IF EXISTS `t_recharge_order`; CREATE TABLE `t_recharge_order` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `order_id` varchar(255) COMMENT '订单号', + `short_order_id` varchar(60) COMMENT '短订单号-客户端显示用', `account_address` varchar(60) NOT NULL COMMENT '钱包地址', `currency_address` varchar(60) NOT NULL DEFAULT '' COMMENT '货币地址', `currency_name` varchar(60) NOT NULL DEFAULT '' COMMENT '货币名称', @@ -330,7 +331,8 @@ CREATE TABLE `t_recharge_order` ( `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), - UNIQUE KEY `order_id` (`order_id`) + UNIQUE KEY `order_id` (`order_id`), + UNIQUE KEY `short_order_id` (`short_order_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/webapp/controller/BigwheelController.class.php b/webapp/controller/BigwheelController.class.php index 37a06085..c59186f1 100644 --- a/webapp/controller/BigwheelController.class.php +++ b/webapp/controller/BigwheelController.class.php @@ -29,6 +29,13 @@ class BigwheelController extends BaseAuthedController { const MAX_DRAW_TIMES = 9; + public function _handlePre() + { + parent::_handlePre(); + $this->propertyChgService = new services\PropertyChgService(); + $this->awardService = new services\AwardService(); + } + public function info() { $key = $this->getMidDataKey(); @@ -74,22 +81,253 @@ class BigwheelController extends BaseAuthedController { myself()->_rspErr(3, 'config error'); return; } - } else if ($drawType == 1 || $drawType == 2) { + } else { $costItemNum = $priceInfo['price_single'] * $priceInfo['discount_single']; if (empty($costItemNum)) { myself()->_rspErr(3, 'config error'); return; } - } else { - myself()->_rspErr(2, 'type param error'); + } + $item1Hash = array(); + $item1Arr = array(); + $item2Hash = array(); + $item2Arr = array(); + mt\Bigwheel::traverseMeta( + function ($meta) use(&$data, &$item1Hash, &$item2Hash, &$item1Arr, &$item2Arr) { + $gridRef = null; + $this->getGridRefByGridId($data, $meta['id'], $gridRef); + if (empty($gridRef)) { + switch ($meta['Wheel_type']) { + case 1:{ + $item1Hash[$meta['id']] = $meta; + array_push($item1Arr, array( + 'weight' => 0, + 'meta' => $meta + )); + } + break; + case 2:{ + $item2Hash[$meta['id']] = $meta; + array_push($item2Arr, array( + 'weight' => 0, + 'meta' => $meta + )); + } + break; + } + } + return true; + }); + if (count($item1Hash) != count($item2Hash) || + count($item1Arr) != count($item2Arr) || + count($item1Arr) != count($item1Hash) || + count($item1Hash) < 1) { + myself()->_rspErr(1, 'The maximum number of lucky draws has been reached'); return; } + $randSpace1 = 0; + foreach ($item1Arr as &$item) { + $randSpace1 += $item['meta']['reWeight']; + $item['weight'] = $randSpace1; + } + $randSpace2 = 0; + foreach ($item2Arr as &$item) { + $randSpace2 += $item['meta']['reWeight']; + $item['weight'] = $randSpace2; + } + $rnd1 = rand(0, $randSpace1 - 1); + $rnd2 = rand(0, $randSpace2 - 1); + error_log(json_encode(array( + 'randSpace1' => $randSpace1, + 'randSpace2' => $randSpace2, + 'rnd1' => $rnd1, + 'rnd2' => $rnd2, + 'item1Arr' => $item1Arr, + 'item2Arr' => $item2Arr, + ))); + if ($randSpace1 <= 0 || + $randSpace2 <= 0) { + myself()->_rspErr(1, 'server internal error'); + return; + } + $item1 = null; + error_log(json_encode(array( + 'item2arr' => $item2Arr + ))); + { + foreach ($item1Arr as $itemTmp1) { + if ($rnd1 <= $itemTmp1['weight']) { + $item1 = $itemTmp1; + break; + } + } + } + $item2 = null; + { + error_log(json_encode(array( + 'item2arr' => $item2Arr + ))); + foreach ($item2Arr as $itemTmp2) { + error_log(json_encode(array( + 'rnd2' => $rnd2, + 'item' => $itemTmp2, + //'item2_weight' => $item['weight'], + ))); + if ($rnd2 <= $itemTmp2['weight']) { + $item2 = $itemTmp2; + break; + } + } + } + error_log(json_encode(array( + 'item1' => $item1, + 'item2' => $item2, + ))); + if (empty($item1) || empty($item2)) { + myself()->_rspErr(1, 'server internal error'); + return; + } + $lootMeta1 = myself()->_callMtStatic('LootConfig', 'find', $item1['meta']['content_loot']); + $lootMeta2 = myself()->_callMtStatic('LootConfig', 'find', $item2['meta']['content_loot']); + if (empty($lootMeta2) || empty($lootMeta2)) { + myself()->_rspErr(1, 'server internal error'); + return; + } + $drop1 = myself()->_callServiceStatic('LootService', 'dropOutItem', $item1['meta']['content_loot']); + $drop2 = myself()->_callServiceStatic('LootService', 'dropOutItem', $item2['meta']['content_loot']); + error_log(json_encode(array( + 'drop1' => $drop1, + 'drop2' => $drop2, + ))); + ++$data['drawed_times']; + $grid1 = array( + 'grid_id' => $item1['meta']['id'], + 'grid_state' => 1, + 'item_id' => $drop1[0]['item_id'], + 'item_num' => $drop1[0]['item_num'], + 'buy_price' => $priceInfo['price_buy'] * $priceInfo['discount_buy'], + 'draw_times' => $data['drawed_times'], + ); + $grid2 = array( + 'grid_id' => $item2['meta']['id'], + 'grid_state' => 1, + 'item_id' => $drop2[0]['item_id'], + 'item_num' => $drop2[0]['item_num'], + 'buy_price' => $priceInfo['price_buy'] * $priceInfo['discount_buy'], + 'draw_times' => $data['drawed_times'], + ); + $items = array(); + if ($drawType == 1) { + $grid2['grid_state'] = 2; + foreach ($drop1 as $itemTemp){ + array_push($items, $itemTemp); + } + } else if ($drawType == 2) { + $grid1['grid_state'] = 2; + foreach ($drop2 as $itemTemp){ + array_push($items, $itemTemp); + } + } else { + foreach ($drop1 as $itemTemp){ + array_push($items, $itemTemp); + } + foreach ($drop2 as $itemTemp){ + array_push($items, $itemTemp); + } + } + $hashItems = array(); + foreach ($items as $item){ + if (isset($hashItems[$item['item_id']])){ + $hashItems[$item['item_id']]['item_num'] += $item['item_num']; + }else{ + $hashItems[$item['item_id']] = $item; + } + } + array_push($data['grid_list'], $grid1); + array_push($data['grid_list'], $grid2); + + $costItems = array( + array( + 'item_id' => V_ITEM_DIAMOND, + 'item_num' => $costItemNum + ), + ); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + $this->propertyChgService->addUserChg(); + + myself()->_addItems($hashItems, $this->awardService, $this->propertyChgService); + myself()->_callModelStatic('MidData', 'setData', $key, json_encode($data)); + { + $priceInfo = $this->getPriceInfo($data['drawed_times']); + if (empty($priceInfo)) { + myself()->_rspErr(500, 'server internal error'); + return; + } + $info = array(); + $this->fillInfo($info, $data, $priceInfo); + myself()->_rspData(array( + 'award' => $this->awardService->toDto(), + 'property_chg' => $this->propertyChgService->toDto(), + 'info' => $info + )); + } } public function buyS() { $key = $this->getMidDataKey(); $data = $this->getAndCreateData($key); + $gridRef = null; + $gridId = getReqVal('grid_id', 0); + $this->getGridRefByGridId($data, $gridId, $gridRef); + error_log(json_encode($gridRef)); + if (empty($gridRef) || + $gridRef['grid_state'] != 2) { + myself()->_rspErr(1, 'cant buy'); + return; + } + $costItems = array( + array( + 'item_id' => V_ITEM_DIAMOND, + 'item_num' => $gridRef['buy_price'] + ), + ); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + $gridRef['grid_state'] = 1; + foreach ($data['grid_list'] as &$grid) { + if ($grid['grid_id'] == $gridId) { + $grid['grid_state'] = 1; + } + } + error_log(json_encode($gridRef)); + error_log(json_encode($data)); + myself()->_callModelStatic('MidData', 'setData', $key, json_encode($data)); + $this->awardService->addItem($gridRef['item_id'], $gridRef['item_num']); + $this->propertyChgService->addUserChg(); + + $priceInfo = $this->getPriceInfo($data['drawed_times']); + if (empty($priceInfo)) { + myself()->_rspErr(500, 'server internal error'); + return; + } + $info = array(); + $this->fillInfo($info, $data, $priceInfo); + + myself()->_rspData(array( + 'award' => $this->awardService->toDto(), + 'property_chg' => $this->propertyChgService->toDto(), + 'info' => $info + )); } private function getMidDataKey() @@ -100,9 +338,6 @@ class BigwheelController extends BaseAuthedController { private function getAndCreateData($key) { $data = myself()->_callModelStatic('MidData', 'getData', $key); - if (!empty($data)) { - $data = json_decode($data, true); - } if (empty($data)) { $data = array( 'drawed_times' => 0, @@ -132,7 +367,7 @@ class BigwheelController extends BaseAuthedController { 'buy_price' => 0, ); $gridRef = null; - $this->getGridRefByGridId($data, $meta['id'], $girdRef); + $this->getGridRefByGridId($data, $meta['id'], $gridRef); if (!empty($gridRef)) { $item = $gridRef; } @@ -153,7 +388,7 @@ class BigwheelController extends BaseAuthedController { private function getGridRefByGridId(&$data, $gridId, &$gridRefOut) { foreach ($data['grid_list'] as &$grid) { - if ($grid['grid_id'] == $girdId) { + if ($grid['grid_id'] == $gridId) { $gridRefOut = $grid; break; } @@ -178,7 +413,7 @@ class BigwheelController extends BaseAuthedController { if ($drawedTimes < 0) { return null; } - if ($drawedTimes > self::MAX_DRAW_TIMES) { + if ($drawedTimes >= self::MAX_DRAW_TIMES) { $drawedTimes = self::MAX_DRAW_TIMES - 1; } $priceInfo = array( diff --git a/webapp/controller/GMController.class.php b/webapp/controller/GMController.class.php index 5f1cdec3..cf77465c 100644 --- a/webapp/controller/GMController.class.php +++ b/webapp/controller/GMController.class.php @@ -62,6 +62,9 @@ class GMController extends BaseAuthedController { }, '.loot' => function () use($params) { $this->lootTest($params); + }, + '.clear_big_wheel' => function () use($params) { + $this->clearBigWheel($params); } ); $func = getXVal($cmdHash, $cmd); @@ -82,6 +85,7 @@ class GMController extends BaseAuthedController { .setsystime //设置服务器时间,示例:.setsystime 2021-12-08 00:00:00 .reset_mission //重置任务 .loot 索引ID 次数 //测试掉落系统数据,示例:.loot 1030 10 +.clear_big_wheel clear big wheel data END )); } @@ -282,4 +286,9 @@ END )); } + private function clearBigWheel($params){ + $key = myself()->_getModelConstant('MidData', 'BIG_WHEEL_TYPE'); + myself()->_callModelStatic('MidData', 'setData', $key, json_encode(array())); + myself()->_rspOk(); + } } diff --git a/webapp/models/MidData.php b/webapp/models/MidData.php index f94aed26..3960c9b6 100644 --- a/webapp/models/MidData.php +++ b/webapp/models/MidData.php @@ -7,7 +7,7 @@ use phpcommon\SqlHelper; class MidData extends BaseModel { - const BIG_WHEEL_TYPE = 'offer.reward.missions'; + const BIG_WHEEL_TYPE = 'big_wheel'; public static function getData($type) {