예제 #1
0
 /**
  * 卖出卡车
  * @param $params
  * require  u         --  user_id
  * require  d         --  car id array
  * @return
  * s   -- OK
  * a   -- user account
  */
 public function sale($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     foreach ($params['d'] as $index => $id) {
         $car_obj = $tu->getbyid($id);
         if (!$car_obj) {
             $ret['s'] = 'notexist';
             $ret['index'] = $index;
             return $ret;
         }
         $sale_ret = $tu->saleItem($car_obj);
         if ($sale_ret['s'] != 'OK') {
             $sale_ret['index'] = $index;
             return $sale_ret;
         }
     }
     $tu->remove($params['d']);
     $ret['s'] = 'OK';
     return $ret;
 }
예제 #2
0
파일: Gift.php 프로젝트: uning/mall-back
 /**
  * 收取礼物
  * @param $params
  *  require         u        -- user id
  *                  gids      -- gift ids
  * @return 
  *  s       -- OK ,or other fail
  *  id2id   -- 新旧ids映射
  */
 public function accept($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     $gifts = $params['gids'];
     foreach ($gifts as $gid) {
         $d = $tu->getbyid($gid);
         $oid = $d['id'];
         if ($d) {
             $tag = $d['gtag'];
             if ($tag) {
                 $d['tag'] = $tag;
             } else {
                 $tag = $d['tag'];
             }
             $conf = ItemConfig::getItem($tag);
             if (!$conf) {
                 continue;
             }
             $g = $conf['group'];
             if (!$g) {
                 $g = TT::ITEM_GROUP;
             }
             $id = $tu->getdid(null, $g);
             $id2id[$gid] = $id;
             $d['id'] = $id;
             unset($d['msg']);
             $d['pos'] = 's';
             $tu->puto($d);
         } else {
             $id2id[$gid] = null;
         }
         $rids[] = $oid;
     }
     $tu->remove($rids);
     $ret['s'] = 'OK';
     $ret['id2id'] = $id2id;
     TTLog::record(array('m' => __METHOD__, 'tm' => $_SERVER['REQUEST_TIME'], 'u' => $uid, 'intp1' => $d['fid'], 'sp1' => $tag));
     return $ret;
 }
예제 #3
0
파일: Task.php 프로젝트: uning/mall-back
 /**
  * 领取任务奖励
  *   
  * @param $params
  *  require   u                 --    uid
  *            tid               --    任务id
  * @return 
  *            s                 --   OK,正常
  *                                    notexsit,该任务不存在
  *                                    cantgetaward,未完成的任务,不能领取奖励
  *            tid               --    task id
  */
 public function get_award($params)
 {
     $uid = $params['u'];
     $tid = $params['tid'];
     //判断用户是否正在任务中
     $tu = new TTUser($uid);
     $task_obj = $tu->getbyid($tid);
     //        $ret['task_obj'] = $task_obj;
     if (!$task_obj) {
         $ret['s'] = 'notexsit';
         return $ret;
     }
     if ($task_obj['s'] != '2') {
         $ret['s'] = 'cantgetaward';
         return $ret;
     }
     //两种奖励,分别根据$task_obj['ac'] (分享的奖励) 结算
     $today_start = strtotime(date('Y-m-d', time()));
     if ($task_obj['ct'] < $today_start) {
         //如果是昨天的任务,领取奖励后此条记录删除
         $tu->remove($tid);
     } else {
         $task_obj['s'] = '4';
         $tu->puto($task_obj, TT::TASK_GROUP);
     }
     $ret['id'] = $tid;
     $ret['s'] = 'OK';
     return $ret;
 }
예제 #4
0
파일: Tool.php 프로젝트: uning/mall-back
 /**
  * 处理仍有货物的商店被放进仓库的坏数据,同时清除店面和商品
  * @param $params
  *  require u              --             user id
  * @return 
  *          s              --        OK ,or other fail
  */
 public function cleanShopInStoreWithGoods($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     $goods = $tu->get(TT::GOODS_GROUP);
     $shops = $tu->get(TT::SHOP_GROUP);
     $ret = array();
     foreach ($shops as $shop) {
         if ($shop['pos'] == 's') {
             $rgids = array();
             $count = 0;
             foreach ($goods as $good) {
                 if ($good['pos']['y'] == $shop['id']) {
                     $rgids[] = $good['id'];
                     $count++;
                     $ret['deletegoods'][][] = $good;
                 }
             }
             if ($count) {
                 //如果有货则删除
                 $tu->remove($shop['id']);
             }
             $tu->remove($rgids);
             $ret['deleteshops'][] = $shop;
         }
     }
     $ret['s'] = 'OK';
     return $ret;
 }
예제 #5
0
 /**
  * 结算卖货
  * @param $params use shop
  *   u   - userid
  *   sids  - shop ids
  * @return 
  *   s  - OK,noneed(短期内没有需要结算的商品),busy(太快)
  *   income  - 获得金币
  *   money   - 总金币
  *   selloutids - 卖完删除的id
  *   goods   --数量有辩护的商品列表
  */
 public static function shop_checkout($params)
 {
     $uid = $params['u'];
     $sids = $params['sids'];
     $now = $params['now'];
     if (!$now) {
         $now = time();
     }
     $tu = new TTUser($uid);
     //获取人气和宣传值
     $shops = $tu->get(TT::SHOP_GROUP);
     foreach ($shops as $shop) {
         if ($shop['pos'] != 's') {
             $item = ItemConfig::getItem($shop['tag']);
             @asort($shop['goods']);
             $gids = @array_keys($shop['goods']);
             if ($gids) {
                 $gs = $tu->getbyids($gids);
                 if ($gs['g']) {
                     $condata[$shop['id']]['sconfig'] = $item;
                     $condata[$shop['id']]['shop'] = $shop;
                     $condata[$shop['id']]['goods'] =& $gs['g'];
                     $total_width += $item['gridWidth'];
                 } else {
                     unset($shop['goods']);
                     //=array();
                     $tu->puto($shop);
                 }
             }
         }
     }
     if (!$condata || !$total_width) {
         $ret['s'] = 'OK';
         $ret['msg'] = 'nogoods';
         return $ret;
     }
     $params = $tu->getf(array(TT::POPU, TT::EXP_STAT));
     $popu = $params[TT::POPU];
     $ua = UpgradeConfig::getUpgradeNeed($params['exp']);
     $maxpopu = $ua['maxpopu'];
     $aid = $tu->getoid('advert', TT::OTHER_GROUP);
     $adv = $tu->getbyid($aid);
     $used_advert = $adv['use'];
     if (!$used_advert) {
         $used_advert = array();
     }
     //处理广告
     foreach ($used_advert as $k => $v) {
         $adv = AdvertConfig::getAdvert($tag);
         if ($start + $adv['allTime'] < $now) {
             continue;
         }
         $savead[$k] = $v;
     }
     if ($savead) {
         $adv['use'] = $savead;
         $tu->puto($adv);
     } else {
         if ($used_advert) {
             unset($adv['use']);
             $tu->puto($adv);
         }
     }
     $selloutids = array();
     $income = 0;
     $sale_count = 0;
     //销售份数
     $popu += 15 * $total_width;
     foreach ($condata as $s => $vvv) {
         $sconfig =& $vvv['sconfig'];
         $gs =& $vvv['goods'];
         $shop =& $vvv['shop'];
         $curtime = $shop['ctime'];
         //可以售卖新商品时间
         $cgoods = array();
         $shop_changed = false;
         foreach ($gs as $t => $g) {
             $gconfig = ItemConfig::getItem($g['tag']);
             if (!$gconfig) {
                 continue;
             }
             $ctime = $g['ctime'];
             //上次结算时间
             if ($curtime < $t) {
                 $curtime = $t;
             }
             //上架时间
             if ($curtime < $ctime) {
                 $curtime = $ctime;
             }
             if ($curtime < $g['stime']) {
                 $curtime = $g['stime'];
             }
             $gaps = self::getTimeRates($used_advert, $curtime, $now, $popu, $maxpopu, $total_width);
             foreach ($gaps as $k => $gr) {
                 //测试信息需要该索引值
                 //$snum = floor( $gr[0]/$gconfig['selltime']*$gr[1] );
                 $pertime = $gr[0] / $gconfig['selltime'] * $gr[1] * $sconfig['gridWidth'];
                 $snum = floor($gr[0] / $pertime);
                 if ($snum >= $g['num']) {
                     //卖完了
                     $asnum = $g['num'];
                 } else {
                     $asnum = $snum;
                 }
                 if ($asnum == 0) {
                     break;
                 }
                 $ret['sell'][$g['tag']] += $asnum;
                 $sale_count += $asnum;
                 //记录销售份数,成就用
                 $income += $asnum * $gconfig['sellmoney'];
                 //sellmoney是单份物品的卖价
                 $g['num'] -= $asnum;
                 $curtime += floor($asnum * $pertime);
                 //
                 $shop_changed = true;
                 $shop['ctime'] = $curtime;
                 $g['ctime'] = $curtime;
                 if ($g['num'] == 0) {
                     //当前时间段卖光此箱货物,继续卖下一个货物
                     $cgoods[] = $g;
                     $selloutids[] = $g['id'];
                     unset($shop['goods'][$g['id']]);
                     break;
                     //跳出时间段循环,继续卖同一商店下一个上架时间的货物(在同一商店,同一时间上架但售卖顺序不同的货物,已在上架时微调成不同上架时间)
                 }
             }
             //foreach group
             if ($g['num'] != 0) {
                 $tu->puto($g, TT::GOODS_GROUP);
                 break;
                 //跳出上架时间循环,但是继续店铺循环,终止同一店铺的货物队列中其他货物的结算
             }
         }
         //foreach goods
         if ($shop_changed) {
             $tu->puto($shop);
         }
     }
     //foreach shop
     //总销售份数
     $now_sale_count = $tu->numch('total_count', $sale_count);
     //总销售额
     $now_total_sale = $tu->numch('total_sale', $income);
     //记录玩家每一种物品卖出量
     if ($ret['sell']) {
         foreach ($ret['sell'] as $gid => $num) {
             $tu->numch("sale_goods_{$gid}", $num);
         }
     }
     $ret['s'] = 'OK';
     $ret['income'] = $income;
     $ret['money'] = $tu->chMoney($income);
     $ret['t'] = $now;
     $ret['rids'] = $selloutids;
     $ret['u'] = $uid;
     TTLog::record(array('m' => __METHOD__, 'u' => $uid, 'tm' => $_SERVER['REQUEST_TIME'], 'p' => json_encode($ret)));
     $tu->remove($selloutids);
     return $ret;
 }
예제 #6
0
 /**
  * 完成任务
  *   
  * @param $params
  *  require   u       --  uid
  *            tag     --  任务id
  *            rids     -- 消耗物品ids(只能是空闲物品)
  *            minus  (money=>11,gem=>122)
  * @return 
  *            s       --  OK,正常
  *            award    --  和新手等一致
  *                        finished,该任务不存在
  */
 public function finish($params)
 {
     $uid = $params['u'];
     $tag = $params['tag'];
     //判断用户是否正在任务中
     $tu = new TTUser($uid);
     $tid = $tu->getoid($tag, 'to');
     $to = $tu->getbyid($tid);
     if (!$to) {
         //	$ret['s']='no';
         //	return $ret;
         $to['id'] = $tid;
     }
     if ($to['s'] == 'finished') {
         $ret['s'] = 'finished';
         return $ret;
     }
     $conf = self::getConf($tag);
     $d = $conf['award'];
     if ($d) {
         foreach ($d as $k => $v) {
             $tu->numch($k, $v);
             $award[$k] = $v;
         }
     }
     $d = $params['minus'];
     if ($d) {
         foreach ($d as $k => $v) {
             $tu->numch($k, -$v);
         }
     }
     $items = $conf['items'];
     if ($items) {
         foreach ($items as $item) {
             $num = $item['num'];
             unset($item['num']);
             $iconf = ItemConfig::getItem($item['tag']);
             $g = $iconf['group'];
             if (!$g) {
                 $g = 'o';
             }
             if (!$num) {
                 $num = 1;
             }
             for ($i = 0; $i < $num; $i++) {
                 $item['pos'] = 's';
                 $item['id'] = $tu->getoid(null, $g);
                 $tu->puto($item);
                 $award['items'][] = $item;
             }
         }
     }
     $rids = $params['rids'];
     if ($rids) {
         $tu->remove($rids);
     }
     $ret['award'] = $award;
     $to['id'] = $tid;
     $to['s'] = 'finished';
     $to['ut'] = time();
     $tu->puto($to);
     $ret['s'] = 'OK';
     return $ret;
 }
예제 #7
0
 /**
  * 卖出
  * @param $params
  *  require u  -- user id
  *  require d  -- item_id 数组
  *     
  * @return 
  *  s   -- OK ,or other fail
  *                                     notexsit ,不存在配置
  *                                     notsale ,不能购买的物品
  *                                     level,等级未到 
  *                                     achive, 所需成就buy_need_achiveid 未达成 
  *                                     task,所需任务未达成
  *                                     buynumlimit,限量版已经卖完
  *                                     money,
  *				      gem
  */
 public function sale($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     if ($tu->check_dup($params['_cid'], $ret)) {
         return $ret;
     }
     foreach ($params['d'] as $index => $id) {
         $item_obj = $tu->getbyid($id);
         if (!$item_obj) {
             $ret['s'] = 'notexsit';
             $ret['index'] = $index;
             return $ret;
         }
         $item = ItemConfig::getItem($item_obj['tag']);
         if (!$item) {
             $ret['s'] = 'notexsit';
             $ret['index'] = $index;
             return $ret;
         }
         $sale_ret = $tu->saleItem($item_obj);
         if ($sale_ret['s'] != 'OK') {
             $sale_ret['index'] = $index;
             return $sale_ret;
         }
         if ($item_obj['pos'] != 's') {
             $pop -= $item['pop'];
         }
     }
     if ($pop) {
         $tu->numch(TT::POPU, $pop);
     }
     $tu->remove($params['d']);
     $ret['s'] = 'OK';
     return $ret;
 }
예제 #8
0
파일: test.php 프로젝트: uning/mallb
    if ($usage) {
        echo "{$usage} use time {$cost} us\n";
    }
    $start = $end;
}
function dodebug($str)
{
    echo "{$str}=";
    eval('echo  ' . $str . ';');
    echo "\n";
}
record_time($st);
//require_once('TTt.php');
require_once 'renren_config.php';
$tu = new TTUser(1);
$tu->remove('1:ho:60102');
$tu->remove('22:ho:60102');
$tu->remove('22:o:4c8ddfebda000');
exit;
echo $tu->getf('money') . "\n";
$tu->chMoney(100);
echo $tu->getf('money') . "\n";
exit;
$ltt = TT::LinkTT();
$lid = 'dfdf';
$data = array('lid' => $lid);
$id = $ltt->put($data);
print_r($ltt->get($id));
print_r($ltt->getbyuidx('lid', $lid));
print_r($ltt->getbyuidx('lid', '9A18326D4627EF4F0B0A43A638C6E96'));
return;