diff --git a/doc/Role.py b/doc/Role.py index 537d460..ff55d6b 100644 --- a/doc/Role.py +++ b/doc/Role.py @@ -95,14 +95,19 @@ class Role(object): ] }, { - 'desc': 'getNewHandReward', + 'desc': '获取新手奖励getNewHandReward', 'group': 'Role', 'url': 'webapp/index.php?c=Role&a=getNewHandReward', 'params': [ _common.ReqHead(), + ['type', 0, '类型1或2'], ], 'response': [ _common.RspHead(), + ['!item_list', _common.DropItemInfo, '掉落道具列表'], + ['coin_num', 0, '当前金币数'], + ['rmb_num', 0, '当前点券数量'], + ['!all_item_list', _common.RewardItemInfo, '实际奖励的道具列表'], ] }, { diff --git a/doc/_common.py b/doc/_common.py index 97b7644..d62377f 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -124,3 +124,21 @@ class RobotMetaInfo(object): ['name', 0, '机器人名字'], ['avatar_url', 0, '机器人头像'], ] + +class DropItemInfo(object): + + def __init__(self): + self.fields = [ + ['item_id', 0, '道具id'], + ['item_num', 0, '道具数量'], + ['time', 0, '时间'], + ] + +class RewardItemInfo(object): + + def __init__(self): + self.fields = [ + ['item_id', 0, '道具id'], + ['item_num', 0, '道具数量'], + ['time', 0, '时间'], + ] diff --git a/webapp/bootstrap/config_loader.php b/webapp/bootstrap/config_loader.php index 7879f72..bd3b22f 100644 --- a/webapp/bootstrap/config_loader.php +++ b/webapp/bootstrap/config_loader.php @@ -241,5 +241,19 @@ function getMetaTable($tblName) return $g_metatables[$tblName]; } +function splitStr1($string) +{ + return explode('|', $string); +} + +function splitStr2($string) +{ + $result = array(); + foreach (explode('|', $string) as $tmpStr) { + array_push($result, explode(':', $tmpStr)); + } + return $result; +} + checkMysqlConfig(); checkRedisConfig(); diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index 458fd55..1568568 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -215,7 +215,7 @@ class RoleController extends BaseAuthedController { $nowDaySeconds = $this->getNowDaySeconds(); if ($_REQUEST['items'] != '') { - $item_list = $this->getExplode($_REQUEST['items']); + $item_list = splitStr1($_REQUEST['items']); $addreward = new classes\AddReward(); $addreward->addReward((int)$item_list[0][0], (int)$item_list[0][1], $account_id, 0, 0); } @@ -378,73 +378,52 @@ class RoleController extends BaseAuthedController { public function getNewHandReward() { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT newhand, newhand2 FROM user WHERE accountid=:account_id;', - array( - ':account_id' => $account_id - )); - $type = 1; - if (isset($_REQUEST['type'])) { - $type = $_REQUEST['type']; + $userInfo = $this->getUserInfo(array( + 'newhand', + 'newhand2' + )); + if (!isset($_REQUEST['type']) || !in_array($_REQUEST['type'], array(1, 2))) { + $this->rspErr(1, '参数错误'); + return; } + $type = $_REQUEST['type']; $reward_id = 29001; if ($type == 1) { $reward_id = 29001; - if (!$row || $row['newhand'] != 1) { - phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件'); - return; - } - $ret = $conn->execScript('UPDATE user SET newhand=2, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':modify_time' => phpcommon\getNowTime(), - ':accountid' => $account_id - )); - if (!$ret) { - die(); + if ($userInfo['newhand'] != 1) { + $this->rspErr(ERR_USER_BASE + 2, '未达到领取条件'); return; } + $this->updateUserInfo(array( + 'newhand' => 2, + 'modify_time' => $this->getNowTime() + )); } else if ($type == 2) { $reward_id = 29002; - if (!$row || $row['newhand2'] != 1) { - phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件'); + if ($userInfo['newhand2'] != 1) { + $this->rspErr(ERR_USER_BASE + 2, '未达到领取条件'); return; } - $ret = $conn->execScript('UPDATE user SET newhand2=2, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':modify_time' => phpcommon\getNowTime(), - ':accountid' => $account_id - )); - if (!$ret) { - die(); - return; - } - } - - - $d = mt\Drop::getOldDrop($reward_id); - if (!$d) { - phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); - return; - } - $item_list = array(); - $all_item_list = array(); - $item_id_array = $this->getExplode($d['item_id']); - $item_num_array = $this->getExplode($d['num']); - for ($i = 0; $i < count($item_id_array); $i++) { - $item_id = $item_id_array[$i][0]; - $item_num = $item_num_array[$i][0]; - array_push($item_list, array( - 'item_id' => $item_id, - 'item_num' => $item_num, - 'time' => 0 + $this->updateUserInfo(array( + 'newhand2' => 2, + 'modify_time' => $this->getNowTime() )); } + + $dropMeta = mt\Drop::get($reward_id); + if (!$dropMeta) { + $this->rspErr(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $item_list = mt\Drop::getDropData(); + $all_item_list = array(); $addreward = new classes\AddReward(); foreach ($item_list as $item) { - $items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['time'], 0); + $items = $addreward->addReward($item['item_id'], + $item['item_num'], + $this->getAccountId(), + $item['time'], + 0); foreach($items as $i) { array_push($all_item_list, array( 'item_id' => $i['item_id'], @@ -453,14 +432,16 @@ class RoleController extends BaseAuthedController { )); } } - $coin_num = $addreward->getCoinNum($account_id); - $num = $addreward->getRmbNum($account_id); + $newUserInfo = $this->getUserInfo(array( + 'coin_num', + 'rmb_num' + )); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'item_list' => $item_list, - 'coin_num' => $coin_num, - 'rmb_nums' => $num, + 'coin_num' => $newUserInfo['coin_num'], + 'rmb_nums' => $newUserInfo['rmb_num'], 'all_item_list' => $all_item_list )); } @@ -854,7 +835,6 @@ class RoleController extends BaseAuthedController { $updateInfo ); } - $resultArr = array("type"=>$type,"itemID"=>$itemID,"heroSkinID"=>$heroSkinID); $this->sendDataToClient($code,"changeHIFrameHero",$resultArr); } @@ -875,7 +855,6 @@ class RoleController extends BaseAuthedController { if($code == 100) { $this->decItem($itemArr); - //error_log("改名测试======".$code); phpcommon\SqlHelper::update ($this->getSelfMysql(), diff --git a/webapp/controller/VoiceController.class.php b/webapp/controller/VoiceController.class.php index a89b11f..cd937b6 100644 --- a/webapp/controller/VoiceController.class.php +++ b/webapp/controller/VoiceController.class.php @@ -2,21 +2,19 @@ class VoiceController extends BaseAuthedController { - - public function upload() { $raw_data = file_get_contents('php://input'); $data = base64_encode($raw_data); $md5 = md5($data); $r = $this->getRedis($md5); - $r->set('game2004:voice:' . $md5, $data); - $r -> pexpire('game2004:voice:' . $md5, 1000 * 600); + $r->set('game2005:voice:' . $md5, $data); + $r -> pexpire('game2005:voice:' . $md5, 1000 * 600); $url = ''; if (SERVER_ENV == _ONLINE) { - $url = "https://game2004api.kingsome.cn/webapp/index.php?c=Voice&a=download&res_id=" . $md5; + $url = "https://game2005api.kingsome.cn/webapp/index.php?c=Voice&a=download&res_id=" . $md5; } else { - $url = "https://game2004api-test.kingsome.cn/webapp/index.php?c=Voice&a=download&res_id=" . $md5; + $url = "https://game2005api-test.kingsome.cn/webapp/index.php?c=Voice&a=download&res_id=" . $md5; } echo json_encode(array( 'errcode' => 0, @@ -28,10 +26,8 @@ class VoiceController extends BaseAuthedController { public function download() { $r = $this->getRedis($_REQUEST['res_id']); - $data = $r->get('game2004:voice:' . $_REQUEST['res_id']); + $data = $r->get('game2005:voice:' . $_REQUEST['res_id']); echo base64_decode($data); } } - - diff --git a/webapp/mt/Drop.php b/webapp/mt/Drop.php index 4f18614..a2bb08f 100644 --- a/webapp/mt/Drop.php +++ b/webapp/mt/Drop.php @@ -24,6 +24,23 @@ class Drop { ); } + public static function getDropData($meta) + { + $itemIds = splitStr1($meta['item_id']); + $itemNums = splitStr1($meta['num']); + $result = array(); + if (count($itemIds) == count($itemNums)) { + for ($i = 0; $i < count($itemIds); ++$i) { + array_push($result, array( + 'item_id' => $itemIds[$i], + 'item_num' => $itemNus[$i], + 'time' => 0 + )); + } + } + return $result; + } + protected static function getMetaList() { if (!self::$metaList) { diff --git a/webapp/mt/Robot.php b/webapp/mt/Robot.php new file mode 100644 index 0000000..cf75202 --- /dev/null +++ b/webapp/mt/Robot.php @@ -0,0 +1,46 @@ + $meta['id'], + 'name' => $meta['name'], + 'avatar_url' => $meta['avatar_url'], + ); + } + + public static function getSinMembers() + { + $members = array(); + foreach (self::getMetaList() as $meta) { + array_push($members, array( + 'name' => $meta['name'], + 'avatar_url' => $meta['avatar_url'], + )); + } + return $members; + } + + protected static function getMetaList() + { + if (!self::$metaList) { + self::$metaList = getMetaTable('robot@robot1.php'); + } + return self::$metaList; + } + + protected static $metaList; + +}