Exemplo n.º 1
0
<?php

defined('_JEXEC') or die('Restricted access');
require_once JPATH_COMPONENT . DS . 'controller.php';
require_once JPATH_COMPONENT . DS . 'views' . DS . 'goods' . DS . 'view.html.php';
JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_goods' . DS . 'tables');
$controller = new GoodsController();
$controller->execute(JRequest::getVar('task'));
$controller->redirect();
?>
 
Exemplo n.º 2
0
 /**
  * 购买物品:
  * 检查购买等级,成就,任务,金钱,数量等限制
  * 打折,限量
  * 扣除玩家货币
  * 增加经验
  * 放入仓库?
  * @param $item
  * @return array
  */
 public function buyItem($tag, $num = 1, $usegem = false)
 {
     $stat['tag'] = $tag;
     $stat['num'] = $num;
     $stat['u'] = $this->_u;
     $stat['op'] = 'buy';
     $stat['tm'] = $_SERVER['REQUEST_TIME'];
     $item = ItemConfig::getItem($tag);
     $gemt = TT::GemTT();
     if (!$item || !isset($item['tag'])) {
         $ret['s'] = 'notfind';
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     if ($item['can_buy'] != 'true' && $item['can_buy'] != '1' && $item['group'] != 'g') {
         $ret['s'] = 'notbuy';
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     //TT::MONEY_STAT,TT::GEM_STAT
     $fds = array(TT::EXP_STAT);
     if ($item['buy_need_achive'] > 0) {
         $bna = TT::ACHIVEPRE_STAT . $item['buy_need_achive'];
         $fds[] = $bna;
     }
     if ($item['buy_need_task'] > 0) {
         $bnt = TT::TASKPRE_STAT . $item['buy_need_task'];
         $fds[] = $bnt;
     }
     $data =& $this->getdata($fds);
     //等级检查
     if ($item['buy_need_level'] > $this->getLevel($data[TT::EXP_STAT])) {
         $ret['s'] = 'level';
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     //成就
     if ($bna && !$data[$bna]) {
         $ret['s'] = 'achive';
         $ret['id'] = $item['buy_need_achiveid'];
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     //任务
     if ($bnt && !$data[$bnt]) {
         $ret['s'] = 'task';
         $ret['id'] = $item['buy_need_task'];
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     //总数限制
     $total_buy = $item['buy_totalnum'];
     $tusys = new TTUser(0);
     $statid = 'salenum_' . $item['tag'];
     if ($total_buy > 0) {
         $saled = $tusys->numch($statid, 0);
         $lnum = $total_buy - $saled;
         if ($lnum < 1) {
             $ret['s'] = 'buynumlimit';
             $ret['maxnum'] = $total_buy;
             $stat['s'] = $ret['s'];
             $gemt->putKeep(null, $stat);
             return $ret;
         }
     }
     //价格计算
     $disc = 1;
     if ($item['discount'] > 0 && $disc < 1) {
         //打折
         $disc = $item['discount'];
     }
     $currency = TT::MONEY_STAT;
     //		if( $usegem || $item['onlygem'] ){
     if ($usegem || $item['onlygem'] == 'true') {
         //前端把excel中此字段为空的加上false,但未及时通知后端,导致此处逻辑错误
         $currency = TT::GEM_STAT;
     }
     $cnum = floor($disc * $item[$currency] * $num);
     $rnum = $this->change($currency, -$cnum);
     if ($rnum < 0) {
         if ($currency == 'money') {
             require_once CONTROLLER_ROOT . '/GoodsController.php';
             $params['u'] = $this->_u;
             $check2 = GoodsController::checkout($params);
             //				$ret['params'] = $params;     //for debug
             //				$ret['checkresult'] = $check2;     //for debug
         }
         $rnum = $this->change($currency, -$cnum);
         if ($rnum < 0) {
             //钱不够
             $ret['s'] = $currency;
             $ret['num'] = $rnum + $cnum;
             //买物品失败,剩余金币或宝石
             $stat['s'] = $ret['s'];
             $gemt->putKeep(null, $stat);
             return $ret;
         }
     }
     $ret['s'] = 'OK';
     $stat[$currency] = $cnum;
     $stat['t'] = $currency;
     $stat['s'] = $ret['s'];
     $gemt->putKeep(null, $stat);
     $ret[$currency] = $rnum;
     $saled = $tusys->numch($statid, $num);
     if ($total_buy) {
         $ret['saled_num'] = $saled;
     }
     return $ret;
 }
Exemplo n.º 3
0
 /**
  * 移动
  * @param $params
  *  require u              --             user id
  *          d              --             item数组
  *                         id             --        type id(类型id)
  *                         pos            --        position information of items
  * @return 
  *                         s              --        OK ,or other fail
  *                                     notexsit ,不存在
  *				      gem
  */
 public function move($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     if ($tu->check_dup($params['_cid'], $ret)) {
         return $ret;
     }
     $index = 1;
     $ids = array();
     $pop = 0;
     $now = time();
     foreach ($params['d'] as $index => $row) {
         $item_obj = $tu->getbyid($row['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;
         }
         if ($item['type'] == 'ro' && $row['pos'] == 's') {
             //todo $tu 结算
             if ($item_obj['pos'] != 's') {
                 require_once 'GoodsController.php';
                 GoodsController::checkout($params);
                 $item_obj = $tu->getbyid($row['id']);
             }
             //*{//对货物尚未卖完的店面进行移动时要先单个结算,确定货物队列为空时才能移动
             if ($item_obj['_s'] == 'goods') {
                 $ret['error'] = 'notempty';
                 $ret['s'] = 'OK';
                 $ret['index'] = $index;
                 TTLog::record(array('m' => __METHOD__, 'tm' => $_SERVER['REQUEST_TIME'], 'u' => $uid, 'sp2' => 'movegoodsshop', 'shoptag' => $item_obj['tag'], 'sp1' => $item_obj['id']));
                 continue;
             }
         }
         if ($item['type'] != 'ro') {
             //改为不计算店面的人气
             if ($row['pos'] != 's' && $item_obj['pos'] == 's') {
                 $pop += $item['pop'];
                 if ($item['type'] == 'rs') {
                     //特殊店需从仓库摆出,结算时间为摆放时间
                     $row['ctime'] = $now;
                 }
             } else {
                 if ($row['pos'] == 's' && $item_obj['pos'] != 's') {
                     $pop -= $item['pop'];
                     if ($item['type'] == 'rs') {
                         //特殊店放入仓库结算时间需置零
                         unset($row['ctime']);
                     }
                 }
             }
         }
         foreach ($row as $k => $v) {
             $item_obj[$k] = $v;
         }
         $ret[$row['id']] = $item;
         $tu->puto($item_obj, '', false);
         //reduce a get op
     }
     if ($pop) {
         $popu = $tu->numch(TT::POPU, $pop);
     }
     if (!$ret['s']) {
         $ret['s'] = 'OK';
     }
     return $ret;
 }