/** * 完成任务 * * @param $params * require u -- uid * tid -- 任务id * @return * s -- OK,正常 * notexsit,该任务不存在 * cantfinish,未接受该任务,不能完成 */ public function finish($params) { $uid = $params['u']; $fid = $params['fid']; $tid = $params['tid']; $tu = new TTUser($uid); $task_obj = $tu->getbyid($tid); if (!$task_obj) { $ret['s'] = 'notexsit'; return $ret; } if ($task_obj['s'] != '1') { $ret['s'] = 'cantfinish'; return $ret; } $task_obj['s'] = '2'; // $task_obj['at'] = time(); $id = $tu->puto($task_obj, TT::TASK_GROUP); $tu->putf(TT::TASK_STAT, '1'); $ret['id'] = $id; $ret['s'] = 'OK'; return $ret; }
/** * 使用广告 * @param $params * require u -- 玩家id * tag -- 某类广告id; * * @return * s -- OK,other failed * s -- nofind,没有该广告 * s -- error, */ public function set($params) { $uid = $params['u']; $adv_tag = $params['tag']; $adv = AdvertConfig::getAdvert($adv_tag); if (!$adv) { $ret['s'] = 'notexsit'; return $ret; } $tu = new TTUser($uid); //增加扣钱操作和加人气值 $id = $tu->getoid('advert', TT::OTHER_GROUP); $advbag = $tu->getbyid($id); if (!$advbag || $advbag['bag'][$adv_tag] < 1) { $ret['s'] = 'notexsit'; $ret['r'] = $advbag; return $ret; } $now = time(); $advbag['use'][$now] = $adv_tag; $advbag['bag'][$adv_tag] -= 1; $exp = $tu->getf(TT::EXP_STAT); $ua = UpgradeConfig::getUpgradeNeed($exp); $maxpopu = $ua['maxpopu'] + $adv['maxpopular']; if ($maxpopu > $tu->getf('max_popu')) { $tu->putf('maxpopu', $maxpopu); } //使用广告次数 $ret['s'] = 'OK'; $ret['t'] = $now; $ret['tag'] = $adv_tag; $tu->puto($advbag, TT::ADVERT_GROUP, false); return $ret; }
public function debug_get($params) { $now = time(); $uid = $params['u']; $tu = new TTUser($uid); $fids = $params['fids']; $infos = $tu->get('fr', false); if (!$fids) { $fids = $tu->getf(TT::FRIEND_STAT); if (!$fids) { $fids = "quest01,quest02,quest03,quest04,quest05,quest06,quest07,quest08,quest09"; } /* if($infos){ $ret['infos']=TTExtend::processlist($infos); $ret['s'] = 'OK'; return $ret; } */ } else { $tu->putf(TT::FRIEND_STAT, $fids); } $fl = explode(',', $fids); $rinfos = array(); $dup = array(); $now = time(); $dup['253382225'] = 1; //$fl[]='253382225'; $friend_count = 0; //记录好友个数 foreach ($fl as $pid) { if ($dup[$pid]) { continue; } $dup[$pid] = 1; $finfos = TTGenid::getbypid($pid); //by tingkun $id = $finfos['id']; if ($id) { $fdid = $tu->getdid($id, 'fr'); $fdata = json_decode($infos[$fdid], true); //if(!$fdata || $fdata['ut']<$now - 3600){ if (!$fdata || $fdata['ut'] < $now - 3600) { $ftu = new TTUser($finfos['id']); $acc = $ftu->getdata(); $acc['name'] = $finfos['name']; $acc['icon'] = $finfos['icon']; $acc['pid'] = $pid; $acc['ut'] = $now; $acc['id'] = $fdid; $acc['dbid'] = $id; $tu->puto($acc); $rinfos[] = $acc; } else { $rinfos[] = $fdata; } unset($infos[$fdid]); } else { $ret['notget'][] = $pid; } //$rids = array_keys($infos); //$tu->remove($rids); $friend_count++; } if ($friend_count > $tu->getf('friend_count')) { $tu->putf('friend_count', $friend_count); } //* $rinfos[] = array('name' => 'GM', 'icon' => 'http://hdn.xnimg.cn/photos/hdn121/20100807/1345/h_tiny_WtRB_190e0000358b2f75.jpg', 'pid' => '253382225', 'exp' => '10000', 'dbid' => 2, 'ht' => $now, 'help_car' => 1); //GM //*/ $ret['infos'] = $rinfos; $ret['fids'] = $fids; $ret['s'] = 'OK'; return $ret; }
$uid = $sess['id']; $tu = new TTUser($uid); $session_key = $sess['session_key']; if (!$pid) { die('no pid'); } if (!$session_key) { die('no session key'); } $ar['pid'] = $pid; require_once 'renren.php'; $ren = new Renren(); $ren->api_key = RenrenConfig::$api_key; $ren->secret = RenrenConfig::$secret; $renren->session_key = $session_key; $ren->init($session_key); $ret = $ren->api_client->friends_getAppFriends(); if ($ret && $ret[0] && $ret[0] > 0) { $fidstr = implode(',', $ret); $tu->putf(TT::FRIEND_STAT, $fidstr); echo "OK\n"; } else { echo "failed\n"; } print_r($ret); ?> </body> </html>
public function test_tt() { $tu = new TTUser(1); $tt = TT::get_tt('main', 1); $id = $tu->getdid(TT::SHOP_NUM); $str = '$tu->numch(TT::SHOP_NUM,$shop_num)'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $shop_num = 10; $str = '$tu->numch(TT::SHOP_NUM,$shop_num)'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $shop_num = -10; $str = '$tu->numch(TT::SHOP_NUM,$shop_num)'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $tu->putf('strint', '0000'); $str = '$tu->getf("strint")'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $shop_num = -10; $str = '$tu->numch("strint",$shop_num)'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $shop_num = 10; $str = '$tu->numch("strint",$shop_num)'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $tt->put("strint", 'a'); $str = '$tt->get("strint")'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $str = '$tt->numch("strint",100)'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; $str = '$tt->numch("strint",100)'; echo "{$str}="; record_time($st); eval('print_r( ' . $str . ');'); record_time($st, $str); echo "\n"; }
/** * 互相加为好友 */ public function add_friends($params) { $pids = $params['pids']; $ret['pids'] = $pids; $apids = explode(",", $pids); $length = count($apids); for ($i = 0; $i < $length; $i++) { $ui = TTGenid::getbypid($apids[$i]); $tu = new TTUser($ui['id']); $ret['bf'][$i] = $tu->getf(TT::FRIEND_STAT); $tu->putf(TT::FRIEND_STAT, $pids); $ret['af'][$i] = $tu->getf(TT::FRIEND_STAT); } /* $pids1 = $params['pids1']; $pids2 = $params['pids2']; $ret['pids1'] = $pids1; $ret['pids2'] = $pids2; $pid_array1 = explode(",",$pids1); $pid_array2 = explode(",",$pids2); $ret['array1'] = $pid_array1; $ret['array2'] = $pid_array2; foreach( $pid_array1 as $pid1 ){ $u1 = TTGenid::getbypid( $pid1 ); $tu1 = new TTUser( $u1['id'] ); } foreach( $pid_array2 as $pid2 ){ $u2 = TTGenid::getbypid( $pid2 ); $tu2 = new TTUser( $u2['id'] ); } $ret['bfids1'] = $tu1->getf( TT::FRIEND_STAT ); $ret['bfids2'] = $tu2->getf( TT::FRIEND_STAT ); // $tu1->putf( TT::FRIEND_STAT,$pid2 ); // $tu2->putf( TT::FRIEND_STAT,$pid1 ); $ret['afids1'] = $tu1->getf( TT::FRIEND_STAT ); $ret['afids2'] = $tu2->getf( TT::FRIEND_STAT ); */ return $ret; }
/** * 扩大商厦 * @param $params * require u -- 玩家id * @return * s -- OK */ public function enlarge_mall($params) { $level2money = array(0 => 0, 2 => 500, 5 => 1000, 9 => 10000, 13 => 10000, 17 => 30000, 21 => 30000, 25 => 50000, 29 => 80000, 33 => 100000, 37 => 200000, 41 => 300000, 45 => 500000, 54 => 800000, 66 => 1000000); $uid = $params['u']; $tu = new TTUser($uid); $user = $tu->getf(array(TT::EXP_STAT, TT::CAPACITY_STAT)); $capa = $user[TT::CAPACITY_STAT]; $cap = explode(",", $capa); // $ret['capa'] = $capa; // for debug // $ret['cap'] = $cap; // for debug $width = $cap[0]; $height = $cap[1]; // $ret['width'] = $width; // for debug // $ret['height'] = $height; // for debug $length = count(UpgradeConfig::$_upgrade); //必须先遍历找出最大值 $max_width = UpgradeConfig::$_upgrade[$length]['shopwidth']; $max_height = UpgradeConfig::$_upgrade[$length]['shopheight']; foreach (UpgradeConfig::$_upgrade as $upgrade) { if ($width > $upgrade['shopwidth'] || $height > $upgrade['shopheight']) { continue; } if ($width == $upgrade['shopwidth'] && $height == $upgrade['shopheight']) { if ($width == $max_width && $height == $max_height) { $need = $upgrade; break; } continue; } $need = $upgrade; break; } // $ret['need'] = $need; // for debug // $leftmoney = $tu->change( TT::MONEY_STAT,0-$level2money[$need['level']]); //有可能在之间的某个level调用此函数 $l = 0; foreach ($level2money as $level => $money) { if ($level < $need['level']) { $l = $level; continue; } break; } $leftmoney = $tu->change(TT::MONEY_STAT, 0 - $level2money[$l]); if ($leftmoney < 0) { $ret['s'] = 'money'; return $ret; } $tu->putf(TT::CAPACITY_STAT, $need['shopwidth'] . "," . $need['shopheight']); TTLog::record(array('m' => __METHOD__, 'tm' => $_SERVER['REQUEST_TIME'], 'u' => $uid, 'intp1' => $level2money[$l], 'sp1' => $need['shopwidth'] . "," . $need['shopheight'])); $ret['s'] = 'OK'; return $ret; }
$str = '$tn->numch("newdd")'; echo "{$str}="; eval('print_r( ' . $str . ');'); echo "\n"; } static function testGenId() { echo "test genid\n"; $data['pid'] = 'uning'; print_r($data = TTGenid::genid($data)); $data['newdatapid'] = 'uning1'; print_r(TTGenid::update($data)); print_r(TTGenid::genid($data)); $data['newdatapid'] = 'uning1 update iii'; $data['i newdatapid'] = 'uning1 update iii'; print_r(TTGenid::update($data)); print_r(TTGenid::genid(array('pid' => 'uning'))); } } Test::testTTUDB(); Test::test_TTExtend(); exit; $u = 20; $tu = new TTUser($u); $tu->putf($u, 'capacity', "5,3"); $ret['all'] = $tu->getf($u, 'capacity'); print_r($ret); print_r($tu->getf($u, array('capacity'))); //Test::testTTDB(); exit; //**