diff --git a/doc/Bag.py b/doc/Bag.py index 0610f7d..c807b67 100644 --- a/doc/Bag.py +++ b/doc/Bag.py @@ -28,9 +28,9 @@ class Bag(object): _common.ReqHead(), ['item_id', 0, '道具id'], ['item_num', 0, '道具数量'], - ['param1', 0, '参数1(当使用的是改名卡时param1=新的角色名)'], - ['param2', 0, '参数2(当使用的是改名卡时param2=签名)'], - ['param3', 0, '参数3'], + ['param1', '', '参数1(当使用的是改名卡时param1=新的角色名)'], + ['param2', '', '参数2(当使用的是改名卡时param2=签名)'], + ['param3', '', '参数3'], ], 'response': [ _common.RspHead(), diff --git a/webapp/controller/BagController.class.php b/webapp/controller/BagController.class.php index 6b360d9..c0778d8 100644 --- a/webapp/controller/BagController.class.php +++ b/webapp/controller/BagController.class.php @@ -5,6 +5,8 @@ require_once('mt/Item.php'); require_once('models/Bag.php'); +require_once('services/NameService.php'); + use phpcommon\SqlHelper; use models\Bag; @@ -25,14 +27,83 @@ class BagController extends BaseAuthedController { ); $this->_rspData(array( 'item_list' => $itemList, - #'time' => date('Y-m-d H:i:s', -662716800), - #'datetime' => strtotime('1949-01-01 00:00:00') )); } public function useItem() { + $itemId = getReqVal('item_id', 0); + $itemNum = getReqVal('item_num', 0); + $param1 = getReqVal('param1', ''); + $param2 = getReqVal('param2', ''); + $param3 = getReqVal('param3', ''); + if ($itemNum < 0) { + $this->_rspErr(1, 'item_num必须大于0'); + return; + } + $itemDb = Bag::find($itemId); + if (isset($itemDb) || $itemDb['item_num'] <= 0) { + $this->_rspErr(1, '道具不足'); + return; + } + $itemMeta = mt\Item::get($itemId); + if (!$itemMeta) { + $this->_rspErr(2, '配置表错误'); + return; + } + if ($itemMeta['type'] != mt\Item::FUNC_TYPE) { + $this->_rspErr(3, '该道具为不可使用道具'); + return; + } + switch ($itemMeta['sub_type']) { + case mt\Item::FUNC_RENAME_CARD_SUBTYPE: + { + $this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); + } + break; + default: + { + $this->_rspErr(4, '该道具功能暂未实现'); + return; + } + break; + } + } + + private function renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3) + { + if (mb_strlen($param1) < 3) { + $this->_rspErr(5, '参数错误名字长度不得小于3'); + return; + } + if (mb_strlen($param1) > 7) { + $this->_rspErr(5, '参数错误名字长度不得大于7'); + return; + } + $nameService = new services\NameService(); + if (!$nameService->verifyNameSign($param1, $param2)){ + $this->_rspErr(5, '参数错误名,签名校验失败'); + return; + } + if (!$nameService->nameUsed($param1)){ + $this->_rspErr(6, '名字已被占用'); + return; + } + $ret = $nameService->useName($param1); + if (!$ret) { + $this->_rspErr(10, '服务器内部错误'); + return; + } + $this->_updateUserInfo(array( + 'name' => $name + )); + $this->_decItems(array( + array( + 'item_id' => $itemMeta['id'], + 'item_num' => 1 + ) + )); } } diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 3e7e330..0c84d0f 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -70,6 +70,8 @@ class Item { const FUNC_TYPE = 9; const MATERIAL_TYPE = 10; + const FUNC_RENAME_CARD_SUBTYPE = 1; + const DAILY_BUY_LIMIT = 1; const WEEKLY_BUY_LIMIT = 2; const TOTAL_BUY_LIMIT = 3; diff --git a/webapp/services/NameService.php b/webapp/services/NameService.php new file mode 100644 index 0000000..9a5c5fb --- /dev/null +++ b/webapp/services/NameService.php @@ -0,0 +1,51 @@ +_getMysql($name); + $row = SqlHelper::ormSelectOne + ($conn, + 't_used_name', + array( + 'name_base64' => $nameBase64, + 'key' => '2005' + ) + ); + return !empty($row); + } + + public function useName($name) + { + $nameBase64 = base64_encode($name); + $conn = myself()->_getMysql($name); + SqlHelper::insert + ($conn, + 't_used_name', + array( + 'name' => $name, + 'name_base64' => $nameBase64, + 'key' => '2005', + 'account_id' => myself()->_getAccountId(), + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + return true; + } + +}