예제 #1
0
파일: Advert.php 프로젝트: uning/mall-back
 /**
  * 购买广告
  * @param $params
  *   require  u      --  玩家id
  *            tag    --  对应xml的id,广告种类
  *            num    --  一次购买的广告数量
  *            type   -- money or gem购买
  *            
  * @return 
  *            s      --  OK,other failed
  *            --  money,other failed
  *            --  gem,other failed
  *            --  level,
  *            --  conf, config error
  *            --  notexsit,未找到配置
  *            tag    --  
  *            num    --  一次购买的广告数量
  */
 public function buy($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     $adv_tag = $params['tag'];
     $num = $params['num'];
     if (!$num) {
         $num = 1;
     }
     $id = $tu->getoid('advert', TT::OTHER_GROUP);
     $config = AdvertConfig::getAdvert($adv_tag);
     if (!$config) {
         $ret['s'] = 'notexsit';
         return $ret;
     }
     $type = $config[$num];
     if (!$type) {
         $ret['s'] = 'notexsit';
         $ret['c'] = $config;
         return $ret;
     }
     $tgem = $tu->change($type[0], -$type[1]);
     if ($tgem < 1) {
         $ret['s'] = $type[0];
         return $ret;
     }
     $advbag = $tu->getbyid($id);
     $advbag['bag'][$adv_tag] += $num;
     $advbag['id'] = $id;
     $tu->puto($advbag, TT::ADVERT_GROUP, false);
     //		$ret['advbag'] = $advbag; //for debug
     $ret['s'] = 'OK';
     $ret['tag'] = $adv_tag;
     $ret['num'] = $num;
     $ret[$type[0]] = $tgem;
     return $ret;
 }
예제 #2
0
 /**
  * 买副驾驶
  * @param $params
  * require          u             --   user_id
  *                  tag           --   副驾驶tag
  *                  num           --   一次购买数量
  * @return
  *                  s             --   OK
  *                  tag           --   副驾驶tag
  *                  num           --   一次购买数量
  *                  copi          --   测试信息
  */
 public function buy_copolit($params)
 {
     $uid = $params['u'];
     $tag = $params['tag'];
     $num = $params['num'];
     $stat['tag'] = $tag;
     $stat['op'] = 'buy_copolit';
     $stat['num'] = $num;
     $stat['u'] = $uid;
     $stat['tm'] = $_SERVER['REQUEST_TIME'];
     $gemt = TT::GemTT();
     $tu = new TTUser($uid);
     $copi = self::$_config[$tag];
     if (!$copi) {
         $ret['s'] = 'copinotexsit';
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     //		$ret['copi'] = $copi;  // for debug
     $gem = $tu->change('gem', 0 - $copi['gem'][$num]);
     if ($gem < 0) {
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         $ret['s'] = 'gem';
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     $id = $tu->getoid('copilot', TT::OTHER_GROUP);
     $copilot = $tu->getbyid($id);
     $copilot['id'] = $id;
     $copilot['bag'][$tag] += $num;
     $tu->puto($copilot);
     $ret['s'] = 'OK';
     $ret['gem'] = $gem;
     $ret['tag'] = $tag;
     $ret['num'] = $num;
     $stat['gem'] = $copi['gem'][$num];
     $stat['t'] = 'gem';
     $stat['s'] = $ret['s'];
     $gemt->putKeep(null, $stat);
     return $ret;
 }
예제 #3
0
파일: test.php 프로젝트: uning/mall-back
        eval('print_r(  ' . $str . ');');
        record_time($st, $str);
        echo "\n";
    }
}
//Test::test_tt();
//testFeed();
/*
Test::testTTable();
exit;
Test::testTTUDB();
//Test::test_TTExtend();
exit;
*/
$u = 10;
$tu = new TTUser($u);
$f = 'gem';
$f = 'money';
$num = 1000;
$ret[] = $tu->change($f, -$num);
$ret[] = $tu->change($f, 100);
$ret[] = $tu->change($f, 100);
$ret[] = $tu->change($f, 100);
$ret[] = $tu->change($f, 0);
$ret[] = $tu->change($f, -100);
$ret[] = $tu->getf($f);
print_r($ret);
//*/
//Test::testTTDB();
exit;
//**
예제 #4
0
 /**
  * 扩大商厦
  * @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;
 }