/** * 捡钱并结算 * @param $params * require u -- 玩家id * sid -- shop id 不仅限于cinema * @return * s -- OK */ public function pick($params) { $uid = $params['u']; $sid = $params['sid']; $now = time(); $tu = new TTUser($uid); $shop_obj = $tu->getbyid($sid); // $ret['now'] = $now; //for debug // $ret['fnow'] = date( TM_FORMAT,$now ); //for debug // $ret['bshopobj'] = $shop_obj; //for debug // $ret['fbshopobj'] = date( TM_FORMAT,$shop_obj['ctime'] ); //for debug if (!$shop_obj) { $ret['s'] = 'notexist'; return $ret; } $item = ItemConfig::getItem($shop_obj['tag']); if (!$item) { $ret['s'] = 'itemnotexsit'; return $ret; } if ($now - $shop_obj['ctime'] < $item['mintime']) { //开业mintime后就可以收钱,但最多只能积累maxtime $ret['s'] = 'time'; return $ret; } $gap = $now - $shop_obj['ctime']; $factor = floor($gap / $item['mintime']); $money = $factor * $item['sellmoney']; $shop_obj['ctime'] += $factor * $item['mintime']; if ($gap > $item['maxtime']) { $money = floor($item['maxtime'] / $item['mintime']) * $item['sellmoney']; $shop_obj['ctime'] = $now; } $tu->chMoney($money); $tu->puto($shop_obj, TT::CINEMA_GROUP); // $ret['fashopobj'] = date( TM_FORMAT,$shop_obj['ctime'] ); //for debug // $ret['ashopobj'] = $shop_obj; //for debug TTLog::record(array('m' => __METHOD__, 'tm' => $_SERVER['REQUEST_TIME'], 'u' => $uid, 'intp1' => $money, 'sp1' => $shop_obj['ctime'])); $ret['money'] = $money; $ret['s'] = 'OK'; return $ret; }
/** * 捡钱并结算 * @param $params * require u -- 玩家id * sid -- shop id 不仅限于cinema * @return * s -- OK */ public function pick($params) { $uid = $params['u']; $sid = $params['sid']; $now = time(); $tu = new TTUser($uid); $shop_obj = $tu->getbyid($sid); // $ret['now'] = $now; //for debug // $ret['fnow'] = date( TM_FORMAT,$now ); //for debug // $ret['bshopobj'] = $shop_obj; //for debug // $ret['fbshopobj'] = date( TM_FORMAT,$shop_obj['ctime'] ); //for debug if (!$shop_obj) { $ret['s'] = 'notexist'; return $ret; } $item = ItemConfig::getItem($shop_obj['tag']); if (!$item) { $ret['s'] = 'itemnotexsit'; return $ret; } if ($shop_obj['tag'] == '60102') { //电影院 if ($now - $shop_obj['ctime'] < $item['selltime'] * 60) { //坐满30个才开映,再过2小时才放映结束 $ret['s'] = 'time'; return $ret; } $money = $item['sellmoney']; $shop_obj['ctime'] = $now; } elseif ($shop_obj['tag'] == '60103' || $shop_obj['tag'] == '60104') { //健身房和按摩店 if ($now - $shop_obj['ctime'] < $item['settletime']) { //开业时间需满足一定条件才可以收钱 $ret['s'] = 'time'; return $ret; } $money = $item['sellmoney']; $shop_obj['ctime'] = $now; } elseif ($shop_obj['tag'] == '60105' || $shop_obj['tag'] == '60106') { //月巴克和8-11便利店 if ($now - $shop_obj['ctime'] < 3600) { //开业1小时后就可以收钱,但最多只能积累6~9小时 $ret['s'] = 'time'; return $ret; } $gap = $now - $shop_obj['ctime']; $factor = floor($gap / 3600); $money = $factor * $item['sellmoney']; $shop_obj['ctime'] += $factor * 3600; if ($gap > $item['settletime']) { $money = floor($item['settletime'] / 3600) * $item['sellmoney']; // $shop_obj['ctime'] += floor( $gap/3600 ) * 3600; $shop_obj['ctime'] = $now; } } $tu->chMoney($money); $tu->puto($shop_obj, TT::CINEMA_GROUP); // $ret['fashopobj'] = date( TM_FORMAT,$shop_obj['ctime'] ); //for debug // $ret['ashopobj'] = $shop_obj; //for debug TTLog::record(array('m' => __METHOD__, 'tm' => $_SERVER['REQUEST_TIME'], 'u' => $uid, 'intp1' => $money, 'sp1' => $shop_obj['ctime'])); $ret['money'] = $money; $ret['s'] = 'OK'; return $ret; }
/** * 使用副驾驶 * @param $params * require u -- user_id * tag -- 副驾驶类别 * cid -- car id * @return * s -- OK * tag -- 副驾驶tag * car -- 测试信息 * copi -- 测试信息 */ public function apply_copolit($params) { $uid = $params['u']; $tag = $params['tag']; $cid = $params['cid']; $copi = self::$_config[$tag]; $stat['tag'] = $tag; $stat['op'] = 'apply_copolit'; $stat['num'] = $num; $stat['u'] = $uid; $stat['tm'] = $_SERVER['REQUEST_TIME']; $gemt = TT::GemTT(); if (!$copi) { $ret['s'] = 'copinotexist'; $stat['s'] = $ret['s']; $gemt->putKeep(null, $stat); return $ret; } $tu = new TTUser($uid); $id = $tu->getoid('copilot', TT::OTHER_GROUP); $copilot = $tu->getbyid($id); $car_obj = $tu->getbyid($cid); if (!$car_obj) { $ret['s'] = 'carnotexsit'; $stat['s'] = $ret['s']; $gemt->putKeep(null, $stat); return $ret; } if ($tag != 2006 && $car_obj['copolitTag']) { $ret['s'] = 'repeat'; $stat['s'] = $ret['s']; $gemt->putKeep(null, $stat); return $ret; } $goods = ItemConfig::getItem($car_obj['goodsTag']); if ($tag != 2006) { if ($copilot['bag'][$tag] < 1) { $ret['s'] = 'needbuy'; $stat['s'] = $ret['s']; $gemt->putKeep(null, $stat); return $ret; } $copilot['bag'][$tag] -= 1; $car_obj['copolitTag'] = $tag; } else { if ($goods['buytime'] >= 1800) { $car = ItemConfig::getItem($car_obj['tag']); $add_exp = $goods['exp'] * $car['goodsNumber']; //乘以载重箱,经验不包括好友帮助增加的箱数 if ($add_exp) { $tu->addExp($add_exp); } } unset($car_obj['addgoods']); unset($car_obj['accelerate']); unset($car_obj['t']); unset($car_obj['help']); unset($car_obj['goodsTag']); unset($car_obj['copolitTag']); } $copilot['id'] = $id; $now = time(); $tu->puto($copilot); if ($copi['addgoods']) { $car_obj['addgoods'] += $copi['addgoods']; } if ($copi['accelerate'] && $car_obj['t']) { if ($now - $car_obj['t'] + $copi['accelerate'] > $goods['buytime']) { $car_obj['t'] = $now - $goods['buytime']; } else { $car_obj['t'] -= $copi['accelerate']; } } $tu->puto($car_obj); $ret['s'] = 'OK'; $ret['tag'] = $tag; $stat['s'] = $ret['s']; $gemt->putKeep(null, $stat); return $ret; }
public function checkshop($params) { $uid = $params['u']; $sid = $params['sid']; $tu = new TTUser($uid); $shop_obj = $tu->getbyid($sid); if (!$shop_obj) { $ret['s'] = 'notexsit'; return $ret; } $goods_list = $shop_obj['goods']; $condata = array(); if (!$goods_list) { $ret['s'] = 'nogoods'; return $ret; } foreach ($goods_list as $goods_id => $stime) { $goods_obj = $tu->getbyid($goods_id); $condata[$stime] = $goods_obj; } $ret['condata'] = $condata; $popu = $params[TT::POPU]; $ret['bpopu'] = $popu; $ua = UpgradeConfig::getUpgradeNeed($params['exp']); $ret['ua'] = $ua; //算人气 $shops = $tu->get(TT::SHOP_GROUP); foreach ($shops as $shop) { $ret['shop_num_shop'][] = $shop; if ($shop['pos'] != 's') { $item = ItemConfig::getItem($shop['tag']); $shop_num += $item['gridWidth']; } } $ret['ashopnum'] = $shop_num; if (!$shop_num) { $ret['s'] = 'noshopexist'; return $ret; } $shop_popu = $shop_num * 15; //只算店面人气 $popu += $shop_popu; if ($popu > $ua['maxpopu']) { $popu = $ua['maxpopu']; } $ret['apopu'] = $popu; $aid = $tu->getoid('advert', TT::OTHER_GROUP); $adv = $tu->getbyid($aid); $used_advert = $adv['use']; // $ret['bbbbbadvert'] = $adv; $computetime = $params[TT::COMPUTE_PONIT]; // $ret['now'] = date( TM_FORMAT,$now ); // $ret['lastcomputetime'] = date( TM_FORMAT,$computetime ); $selloutids = array(); $income = 0; $special = 0; //特殊商店的收入 $sale_count = 0; //销售份数 $now = time(); $sconfig = ItemConfig::getItem($shop_obj['tag']); // $ret['sconfig'][$s] = $sconfig; ksort($condata); $curtime = 0; //可以售卖新商品时间 $cgoods = array(); foreach ($condata as $t => $g) { $gconfig = ItemConfig::getItem($g['tag']); $ctime = $g['ctime']; //上次结算时间 if ($curtime < $t) { $curtime = $t; } //上架时间 if ($curtime < $ctime) { $curtime = $ctime; } $g['ctime'] = $now; $ret['tloop'][$t] = date(TM_FORMAT, $curtime); $gaps = array(); if ($used_advert) { $tmp = self::getTimeRates($tu, $gaps, $used_advert, $curtime, $popu, $ua['maxpopu'], $now, $shop_num); // $ret['advertisement'][$s][$t] = $tmp; } else { $gaps = array(array($now - $curtime, $popu / ($shop_num * 15))); } $ret['gaps'][$t] = $gaps; // foreach($gaps as $gr){ foreach ($gaps as $k => $gr) { //测试信息需要该索引值 $stime = $gr[0]; if ($sconfig['gridWidth']) { $pertime = $gconfig['selltime'] / ($sconfig['gridWidth'] * $gr[1]); } if ($pertime) { $snum = floor($stime / $pertime); } $ret['pertime'][$t][$k] = $pertime; if ($snum >= $g['num']) { //卖完了 $asnum = $g['num']; } else { $asnum = $snum; } // $ret['asnum'][$s][$t][$k][$g['tag'] ] = $asnum; $ret['sell'][$g['tag']] += $asnum; $sale_count += $asnum; //记录销售份数,成就用 $income += $asnum * $gconfig['sellmoney']; //sellmoney是单份物品的卖价 $g['num'] -= $asnum; // $g['scount'] += $asnum; if ($g['num'] == 0) { //当前时间段卖光此箱货物,继续卖下一个货物 $cgoods[] = $g; $selloutids[] = $g['id']; unset($shop_obj['goods'][$g['id']]); break; //跳出时间段循环,继续卖同一商店下一个上架时间的货物(在同一商店,同一时间上架但售卖顺序不同的货物,已在上架时微调成不同上架时间) } } $tu->puto($shop_obj, TT::SHOP_GROUP); if ($g['num'] != 0) { $tu->puto($g, TT::GOODS_GROUP); //未卖完的商品需要保存回库,继续卖同一商店下一个上架时间的货物(在同一商店,一时间上架但售卖顺序不同的货物,已在上架时微调成不同上架时间) break; //跳出上架时间循环,但是继续店铺循环,终止同一店铺的货物队列中其他货物的结算 } } //删除使用过的广告队列 unset($adv['use']); if ($used_advert) { //如果是空数组 $adv['use'] = $used_advert; } $adv['id'] = $aid; $tu->puto($adv, TT::ADVERT_GROUP, false); //总销售份数 $now_sale_count = $tu->numch('total_count', $sale_count); //总销售额 $now_total_sale = $tu->numch('total_sale', $income); $ret['s'] = 'OK'; $ret['income'] = $income; $ret['money'] = $tu->numch('money', $income); $ret['t'] = $now; $tu->remove($selloutids); $tu->putf(TT::COMPUTE_PONIT, $now); return $ret; }
/** * update * @param $params * require u -- user * step -- 新手步数 * // v -- view * // d -- do * @return * s -- OK ,or other fail * money -- total money * exp -- total exp * award money exp items(物品对象数组) * d --新的manual对象 */ public function update($params) { $uid = $params['u']; //$da = $params['d']; $step = $params['step']; //$v = ;//$da['v']; $d = 1; //;$da['d']; $ret = array(); $conf = self::getAwardConf($step); if (!$v && !$d) { $ret['s'] = 'noaction'; return $ret; } if (!$conf) { $ret['s'] = 'noconf'; return $ret; } $tu = new TTUser($uid); $id = $tu->getoid('mannual', TT::OTHER_GROUP); $mano = $tu->getbyid($id); $mean_gap = 20; $now = time(); $mano['id'] = $id; $level = $tu->getLevel(); if ($level > $conf['maxlevel']) { $ret['s'] = 'level'; $ret['d'] = $mano; //return $ret; } if ($v && $mano[$step]['vtime'] > 0) { $ret['s'] = 'already'; $ret['d'] = $mano; return $ret; } if ($d && $mano[$step]['dtime'] > 0) { $ret['s'] = 'already'; $ret['d'] = $mano; return $ret; // } $award = array(); if ($v) { $mano[$step]['vtime'] = $now; $m = $conf['v_money']; if ($m > 0) { $ret['money'] = $tu->chMoney($m); $award['money'] = $m; } $m = $conf['v_gem']; if ($m > 0) { $ret['gem'] = $tu->chGem($m); $award['gem'] = $m; } $m = $conf['v_exp']; if ($m > 0) { $ret['exp'] = $tu->addExp($m); $award['exp'] = $m; } $items = $conf['v_items']; if ($items) { foreach ($items as $item) { $config = ItemConfig::getItem($item['tag']); $idp = $item['idp']; // $item['id']=$uid.$idp; unset($item['idp']); $item['pos'] = 's'; if ($config['group'] == 'g') { $item['num'] = $config['unitcout']; $tu->puto($item, TT::GOODS_GROUP); } else { $tu->puto($item, TT::ITEM_GROUP); } $award['items'][] = $item; } } $tu->puto($mano); $ret['award'] = $award; $ret['s'] = 'OK'; return $ret; } $mano[$step]['dtime'] = $now; $m = $conf['d_money']; if ($m > 0) { $ret['money'] = $tu->chMoney($m); $award['money'] = $m; } $m = $conf['d_gem']; if ($m > 0) { $ret['gem'] = $tu->chGem($m); $award['gem'] = $m; } $m = $conf['d_exp']; if ($m > 0) { $ret['exp'] = $tu->addExp($m); $award['exp'] = $m; } $items = $conf['d_items']; if ($items) { foreach ($items as $item) { $config = ItemConfig::getItem($item['tag']); $idp = $item['idp']; // $item['id']=$uid.$idp; unset($item['idp']); $item['pos'] = 's'; if ($config['group'] == 'g') { $item['num'] = $config['unitcout']; $tu->puto($item, TT::GOODS_GROUP); } else { $tu->puto($item, TT::ITEM_GROUP); } $award['items'][] = $item; } } $tu->puto($mano); TTLog::record(array('m' => __METHOD__, 'tm' => $_SERVER['REQUEST_TIME'], 'u' => $uid, 'intp1' => $step)); $ret['s'] = 'OK'; $ret['award'] = $award; return $ret; }
/** * 卖出 * @param $data (对应数据库的一条记录) * @param $num * @return */ public function saleItem(&$data, $num = 1) { $tag = $data['tag']; $stat['tag'] = $tag; $stat['num'] = $num; $stat['u'] = $this->_u; $stat['op'] = 'sale'; $stat['tm'] = $_SERVER['REQUEST_TIME']; $gemt = TT::GemTT(); $item = ItemConfig::getItem($tag); if (!$item || !isset($item['tag'])) { $ret['s'] = 'notfind'; $stat['s'] = $ret['s']; $gemt->putKeep(null, $stat); return $ret; } if ($item['onlygem'] == 'true') { //对用宝石购买的物品,按1:10000换成金币再3折 $num = $item['gem'] * 3000; } else { if ($item['group'] == 'g') { $num = $item['sellmoney'] * $item['unitcout'] * 0.3; } else { $num = $item['money'] * 0.3; } } $rnum = $this->numch(TT::MONEY_STAT, $num); $tusys = new TTUser(0); $statid = 'usalenum_' . $item['tag']; $saled = $tusys->numch($statid, $num); //记录系统回购每种商品总数 $ret['s'] = 'OK'; $ret['money'] = $rnum; $stat['money'] = $cnum; $stat['t'] = 'money'; $stat['s'] = $ret['s']; $gemt->putKeep(null, $stat); return $ret; }
/** 五,增加好友箱数: 说明: 货车出发之后,放进仓库之前,好友均可点击,点击会增加货物箱数。 按钮问题:好友帮助加箱数的按钮,在货车运货过程中和货车回来都有。而当货车回来,但是没有放进仓库时,只有到好友家才有按钮,自己的副驾驶功能消失。 限制: 每人每日可帮一个好友一次。 级别越高增加的箱数越多。 级别: 箱数: 1 1 20 2 40 3 被帮助者奖励: 礼物为一箱货物。 帮助者奖励: 获得所进货物经验(进货+取货的经验和)相等的经验。 * @param $params * require u -- user id * f -- friend id * cid -- car id * @return * s -- OK -- helped,已经拜访过 -- nofriend,不是朋友 award exp --奖励经验 money --奖励金钱 */ public function help_car($params) { $uid = $params['u']; $nid = $params['f']; $cid = $params['cid']; $tu = new TTUser($uid); $ftu = new TTUser($nid); $fdid = $tu->getdid($nid, 'fr'); $now = time(); $now_date = date('Ymd', $now); $fdata = $tu->getbyid($fdid); if (!$fdata) { $ret['s'] = 'nofriend'; return $ret; } $vt = $fdata['ht']; $vt_date = date('Ymd', $vt); if ($vt_date == $now_date && $fdata['help_car'] == '1') { $ret['s'] = 'helped'; return $ret; //for test } $car = $ftu->getbyid($cid); if (!$car) { $ret['s'] = 'nocar ' . $cid; return $ret; } $carconf = ItemConfig::getItem($car['tag']); $counts = count($car['help']); if ($counts > $carconf['gridWidth']) { $ret['help_time'] = $counts; $ret['gridW'] = $car['help']; $ret['s'] = 'max'; return $ret; } $goodsid = $car['goodsTag']; $gconfig = ItemConfig::getItem($goodsid); $add_exp = $gconfig['exp']; if (!$add_exp) { $ret['s'] = 'nogoods'; $ret['g'] = $gconfig; return $ret; } $level = $tu->getLevel(); $num = 1; if ($level > 39) { $num = 2; } if ($level > 69) { $num = 3; } //$mydata = TTGenid::getbyid($uid); $car['help'][$uid] = $num; $add_exp *= 4; $ret['exp'] = $tu->addExp($add_exp); $ret['award']['exp'] = $add_exp; $fdata['ht'] = $now; $fdata['help_car'] = 1; $tu->puto($fdata, 'fr', false); $ftu->puto($car, '', false); $ret['cid'] = $cid; $ret['s'] = 'OK'; $ret['t'] = $now; return $ret; }
/** * 收取礼物 * @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; }
public function resetNull() { //解决上架的货物中num字段为空或零的情况 $ret = array(); for ($i = 1; $i < 50000; $i++) { $uid = $i; $tu = new TTUser($uid); $goods = $tu->get(TT::GOODS_GROUP); if ($goods) { foreach ($goods as $index => $goods_obj) { $ret[$i]['bgoods'][$index] = $goods_obj; // for debug $item = ItemConfig::getItem($goods_obj['tag']); $ret[$i]['item'][$index] = $item; // for debug if (!$goods_obj['num']) { $goods_obj['num'] = $item['unitcout']; } $ret[$i]['agoods'][$index] = $goods_obj; // for debug // save new goods_obj } } } return $ret; }
/** * 结算卖货 with goods * @param $params * u - userid * sids - shop ids * @return * s - OK,noneed(短期内没有需要结算的商品),busy(太快) * income - 获得金币 * money - 总金币 * selloutids - 卖完删除的id * goods --数量有辩护的商品列表 */ public static function checkout($params) { $uid = $params['u']; $sids = $params['sids']; $now = time(); $tu = new ttuser($uid); //获取人气和宣传值 $goods = $tu->get(TT::GOODS_GROUP); foreach ($goods as $g) { $shopid = $g['pos']['y']; if (!$shopid || $shopid == 's') { continue; } $shop = $condata[$shopid]['shop']; if (!$condata[$shopid]['shop']) { $shop = $tu->getbyid($shopid); if (!$shop) { $shop = $tu->getbyid($shopid); //error log continue; } $condata[$shopid]['shop'] = $shop; $item = ItemConfig::getItem($shop['tag']); $condata[$shopid]['sconfig'] = $item; $total_width += $item['gridWidth']; } $stime = $g['stime']; //上架时间 $condata[$shopid]['goods'][$stime] = $g; } 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]; if ($popu < 0) { $popu = 0; } $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']; ksort($gs); $shop =& $vvv['shop']; $curtime = $shop['ctime']; //可以售卖新商品时间 $cgoods = array(); $shop_changed = false; $shop_empty = true; 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 = $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); // $g['ctime'] = $curtime; $shop_changed = true; $shop['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); $shop_empty = false; break; //跳出上架时间循环,但是继续店铺循环,终止同一店铺的货物队列中其他货物的结算 } } //foreach goods if ($shop_changed) { $shop['_s'] = 'goods'; if ($shop_empty) { $shop['_s'] = 'empty'; unset($shop['goods']); } $tu->puto($shop, TT::GOODS_GROUP, false); } } //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['total_width'] = $total_width; $ret['popu'] = $popu; $ret['maxpopu'] = $maxpopu; TTLog::record(array('m' => __METHOD__, 'u' => $uid, 'tm' => $_SERVER['REQUEST_TIME'], 'p' => json_encode($ret))); $tu->remove($selloutids); return $ret; }
/** 五,增加好友箱数: 说明: 货车出发之后,放进仓库之前,好友均可点击,点击会增加货物箱数。 按钮问题:好友帮助加箱数的按钮,在货车运货过程中和货车回来都有。而当货车回来,但是没有放进仓库时,只有到好友家才有按钮,自己的副驾驶功能消失。 限制: 每人每日可帮一个好友一次。 级别越高增加的箱数越多。 级别: 箱数: 1 1 40 2 70 3 被帮助者奖励: 礼物为一箱货物。 帮助者奖励: 获得所进货物经验(进货+取货的经验和)相等的经验。 * @param $params * require u -- user id * f -- friend id * cid -- car id * type -- 1 表示加货 * 2 表示保鲜 * @return * s -- OK -- helped,已经拜访过 -- nofriend,不是朋友 -- freshed 今天已经操作过了 -- alreadyfresh 可能已被别人保鲜了 -- notexpiration 货物未过期 award exp --奖励经验 money --奖励金钱 */ public function help_car($params) { $uid = $params['u']; $nid = $params['f']; $cid = $params['cid']; $type = $params['type']; //兼容在线的旧flash版本 if (!$type) { $type = 1; } $tu = new TTUser($uid); $ftu = new TTUser($nid); $fdid = $tu->getdid($nid, 'fr'); $now = time(); $now_date = date('Ymd', $now); $fdata = $tu->getbyid($fdid); if (!$fdata) { $ret['s'] = 'nofriend'; return $ret; } $car = $ftu->getbyid($cid); if (!$car) { $ret['s'] = 'nocar ' . $cid; return $ret; } $goodsid = $car['goodsTag']; $gconfig = ItemConfig::getItem($goodsid); $add_exp = $gconfig['exp']; if (!$add_exp) { $ret['s'] = 'nogoods'; $ret['g'] = $gconfig; return $ret; } $level = $tu->getLevel(); $vt = $fdata['ht']; $vt_date = date('Ymd', $vt); $fdata['ht'] = $now; if ($type == 1) { //加货 if ($vt_date == $now_date && $fdata['help_car'] == '1') { $ret['s'] = 'helped'; return $ret; } $carconf = ItemConfig::getItem($car['tag']); $counts = count($car['help']); if ($counts > $carconf['gridWidth']) { $ret['help_time'] = $counts; $ret['gridW'] = $car['help']; $ret['s'] = 'max'; return $ret; } $num = 1; if ($level > 39) { $num = 2; } if ($level > 69) { $num = 3; } $car['help'][$uid] = $num; $fdata['help_car'] = 1; } if ($type == 2) { //保鲜 if ($vt_date == $now_date && $fdata['fresh'] == '1') { $ret['s'] = 'freshed'; return $ret; } if ($car['fresh']) { $ret['s'] = 'alreadyfresh'; return $ret; } if ($now - $car['t'] <= 3 * $gconfig['buytime']) { //货物未过期 $ret['s'] = 'notexpiration'; return $ret; } $car['fresh'] = $nid; $car['fresh'] = $params['f']; $fdata['fresh'] = 1; } $add_exp *= 2; $ret['type'] = $type; $ret['exp'] = $tu->addExp($add_exp); $ret['award']['exp'] = $add_exp; $tu->puto($fdata, 'fr', false); $ftu->puto($car, '', false); $ret['cid'] = $cid; $ret['s'] = 'OK'; $ret['t'] = $now; $ret['car'] = $car; // for debug return $ret; }
$time1 = date(TM_FORMAT, $goods['stime']); echo "上架时间: {$time1} \n"; } if ($goods['ctime']) { $time2 = date(TM_FORMAT, $goods['ctime']); echo "结算时间: {$time2} \n"; } } } if ($shop_obj['pos'] != 's') { $shop = ItemConfig::getItem($shop_obj['tag']); if ($shop_obj['goods']) { foreach ($shop_obj['goods'] as $id) { $goods = $tu->getbyid($id); if ($goods) { $item = ItemConfig::getItem($goods['tag']); if ($item['gridWidth'] != $shop['gridWidth']) { echo "出现宽度与店铺宽度不一致的货物 : \n"; print_r($goods); } } } } else { echo "出现卖光货物但没有及时移动到仓库的店铺 : \n"; print_r($shop_obj); } $x = $shop_obj['pos']['x']; $y = $shop_obj['pos']['y']; for ($i = 0; $i < $shop['gridWidth']; $i++) { if (!$shop_pos[$x + $i][$y]) { $shop_pos[$x + $i][$y] = 1;
/** * 完成任务 * * @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; }
/** * 卖出 * @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; }
/** *update popula *$params * u -- uid * ids -- itemids with popu * popu -- itemids with popu **/ function update_popu($params) { $uid = $params['u']; $ids = $params['ids']; $tu = new ttuser($uid); $ret['oldpopu'] = $tu->getf(TT::POPU); $ret['s'] = 'OK'; if (!$ids) { $tu->putf(TT::POPU, 0); $ret['newpopu'] = $tu->getf(TT::POPU); return $ret; } $items = $tu->getbyids($ids); $popu = 0; foreach ($items as $o) { $conf = ItemConfig::getItem($o['tag']); $popu += $conf['pop']; } $tu->putf(TT::POPU, $popu); $ret['newpopu'] = $tu->getf(TT::POPU); TTLog::record(array('m' => __METHOD__, 'u' => $uid, 'tm' => $_SERVER['REQUEST_TIME'], 'intp1' => $popu)); return $ret; }