예제 #1
0
if (isset($_GET['userId'])) {
    $userId = $_GET['userId'];
}
if (!UtilFunctions::checkUserSession($userId)) {
    $result->result = "401 : auth error";
    header("HTTP/1.1 401 Unauthorized");
    echo json_encode($result);
    exit(1);
}
if (!empty($userId)) {
    $user = GameUsers::getGameUserById($userId);
    if (!empty($user)) {
        $userId = $user->getUserId();
        if (!empty($userId)) {
            $user->dailyBonus = BonusUtils::getUserDailyBonus($user->userId);
            $user->items = ItemUtils::getUserItems($user->userId);
            $result->success = true;
            $result->result = new stdClass();
            $result->result->user = $user;
            unset($userId);
            unset($user);
        } else {
            $result->result = "User not found userId empty";
        }
    } else {
        $result->result = "User not found";
    }
} else {
    $result->result = "User Id empty";
}
echo json_encode($result);
예제 #2
0
} else {
    $log->logError(LanguageUtils::getText("LANG_API_USER_ID_EMPTY"));
    $result->result = LanguageUtils::getText("LANG_API_USER_ID_EMPTY");
}
if ($error) {
    $error = false;
    if (!empty($itemCode)) {
        $itemCode = str_replace("/", "", $itemCode);
        $item = GameItems::getGameItemByCode($itemCode);
        if (empty($item)) {
            $error = false;
            $log->logError(LanguageUtils::getText("LANG_API_ITEM_ID_EMPTY"));
            $result->result = LanguageUtils::getText("LANG_API_ITEM_ID_EMPTY");
        }
        $error = true;
    } else {
        $log->logError(LanguageUtils::getText("LANG_API_ITEM_ID_EMPTY"));
        $result->result = LanguageUtils::getText("LANG_API_ITEM_ID_EMPTY");
    }
    if ($error) {
        $log->logInfo("useItem : userId > " . $userId . " itemCode > " . $itemCode . " gameId > " . $gameId);
        $time = time();
        try {
            $result = ItemUtils::useItem($user, $item, $quantity, $toUserId, $gameId, $time);
        } catch (Exception $exc) {
            echo $exc->getMessage();
        }
    }
}
echo json_encode($result);
exit(1);
예제 #3
0
 private static function display($item)
 {
     $cols = [Item::delete_action($item["id"]), ItemUtils::type($item["type"]), $item['name'], $item['price'], ItemUtils::second_hand($item["second_hand"]), $item['description']];
     echo Utils::table_line(false, $cols);
 }
예제 #4
0
 public static function useItem($user, $item, $quantity, $toUserId = null, $gameId = null, $time = null)
 {
     if (empty($time)) {
         $time = time();
     }
     $result = new FunctionResult();
     $result->success = false;
     if (!empty($user)) {
         if (!empty($item)) {
             $userItemLog = new GameUserItemLog();
             $userItemLog->setItemId($item->id);
             $userItemLog->setGameId($gameId);
             $userItemLog->setTime($time);
             $userItemLog->setUserId($user->userId);
             $userItemLog->setCoin($item->coin);
             $userItemLog->setTo($toUserId);
             $userItemLog->setQuantity($quantity);
             $userItemLog->setType(GameUserItemLog::$CONSTANT_ITEM_LOG_TYPE_USED);
             $userItemLog->setUserLevel($user->userLevelNumber);
             $userItemLog->setUserCoin($user->coins);
             //$userItemLog->setUserSpentCoin(GameUserItemLog::$CONSTANT_ITEM_LOG_TYPE_BUY);
             try {
                 $userItemLog->insertIntoDatabase(DBUtils::getConnection());
             } catch (Exception $exc) {
                 error_log($exc->getMessage());
                 error_log($exc->getTraceAsString());
             }
             $userItem = ItemUtils::getUserItem($toUserId, $item->itemCode);
             if (empty($userItem)) {
                 $userItem = new GameUserItems();
                 $userItem->setId(-1);
                 $userItem->setUserId($toUserId);
                 $userItem->setItemCode($item->itemCode);
                 $userItem->setActive(1);
                 $userItem->setQuantity(0);
             }
             $userItem->setTime($time);
             if ($quantity < $userItem->quantity) {
                 $userItem->setQuantity($userItem->quantity - $quantity);
             } else {
                 $userItem->setQuantity(0);
             }
             try {
                 $userItem->updateInsertToDatabase(DBUtils::getConnection());
             } catch (Exception $exc) {
                 error_log($exc->getMessage());
                 error_log($exc->getTraceAsString());
             }
             $result->success = true;
             $result->data = new stdClass();
             $user->items = ItemUtils::getUserItems($user->userId);
             $result->data->user = $user;
             $result->data->item = $item;
             return $result;
         } else {
             $result->result = LanguageUtils::getText("LANG_API_TO_ITEM_EMPTY");
             return $result;
         }
     } else {
         $result->result = LanguageUtils::getText("LANG_API_USER_EMPTY");
         return $result;
     }
 }
 public static function buyProduct($user, $product, $requestId, $paymentId, $signedReq, $status, $currency, $amount, $quantity, $type, $time)
 {
     if (empty($time)) {
         $time = time();
     }
     $result = new FunctionResult();
     $result->success = false;
     if (!empty($user)) {
         if (!empty($product)) {
             if ($status == "completed") {
                 Queue::addUserCoinLog($user->userId, $product->coinCount, $product->coinCount, $time, GameUserXpLog::$CONSTANT_LOG_TYPE_BUY_PRODUCT, 1, null, $requestId . "_" . $product->id . "_" . $product->fbId . "_" . $product->coinCount . "_" . $product->coinCount, null);
                 Queue::addUserLeaderBoard($user->userId, $product->coinCount, $time);
                 $coin = $user->coins + $product->coinCount * $quantity;
                 $user->setCoins($coin);
                 $user->updateToDatabase(DBUtils::getConnection());
             }
             //if product campaign
             if ($product->type == GameFbProducts::$TYPE_CAMPAIGN && !empty($product->products)) {
                 try {
                     $products = json_decode($product->products);
                     if (!empty($products)) {
                         foreach ($products as $pro) {
                             if (!empty($pro) && !empty($pro->itemId)) {
                                 ItemUtils::buyCampaignItem($user, $pro->itemId, $pro->count, $time);
                             }
                         }
                     }
                 } catch (Exception $exc) {
                     error_log($exc->getMessage());
                     error_log($exc->getTraceAsString());
                 }
             }
             //if product campaign
             $userProductLog = new GameUserFbProductLog();
             $userProductLog->setAmount($amount);
             $userProductLog->setCoinCount($product->coinCount);
             $userProductLog->setCurrency($currency);
             $userProductLog->setPaymentId($paymentId);
             $userProductLog->setProdudctId($product->id);
             $userProductLog->setQuantity($quantity);
             $userProductLog->setRequestId($requestId);
             $userProductLog->setSignedReq($signedReq);
             $userProductLog->setStatus($status);
             $userProductLog->setTime($time);
             $userProductLog->setType($type);
             $userProductLog->setUserId($user->userId);
             $userProductLog->setUserLevel($user->userLevelNumber);
             $userProductLog->setUserCoin($user->coins);
             try {
                 $userProductLog->insertIntoDatabase(DBUtils::getConnection());
             } catch (Exception $exc) {
                 error_log($exc->getMessage());
                 error_log($exc->getTraceAsString());
             }
             $result->success = true;
             $result->data = new stdClass();
             $result->data->user = $user;
             return $result;
         } else {
             $result->result = LanguageUtils::getText("LANG_API_TO_ITEM_EMPTY");
             return $result;
         }
     } else {
         $result->result = LanguageUtils::getText("LANG_API_USER_EMPTY");
         return $result;
     }
 }
예제 #6
0
    $action = $_GET["action"];
    if ($action == "sort") {
        $tag = $_GET["tag"];
        $str = $tag . " " . $orderBy;
        $soldItemList = ItemUtils::getSoldItemList($start, $end, $str);
        if ($orderBy == "DESC") {
            $orderBy = "ASC";
        } else {
            $orderBy = "DESC";
        }
    }
} else {
    $str = "itemId " . $orderBy;
    $soldItemList = ItemUtils::getSoldItemList($start, $end, $str);
}
$total_item = ItemUtils::getSoldItemCount($start, $end);
$paymentList = FBProductUtils::getFBProductLogs($start, $end);
$totalPayment = FBProductUtils::getTotalPayment();
?>
<div class="container">
    Payments
    <hr> 
    <div class="row">
        <div class="offset4 span8" style="height: 40px ;margin-left: 228px;margin-bottom: 10px;">
            <table>
                <tr>
                <form action="payments.php" method="post">
                    <td> 
                    <div id="startDate" class="input-append date" >
                        <label style="float: left; height: 30px; color: #7ba29a; font-weight: bold; margin-top: 3px;" >Start Date :</label>
                        <input type="text" name="txtStartDate" value="<?php 
예제 #7
0
        $toUser = $user;
        $error = true;
    }
} else {
    $log->logError(LanguageUtils::getText("LANG_API_USER_ID_EMPTY"));
    $result->result = LanguageUtils::getText("LANG_API_USER_ID_EMPTY");
}
if ($error) {
    $error = false;
    if (!empty($itemId)) {
        $item = GameItems::getGameItemById($itemId);
        $error = true;
    } else {
        $log->logError(LanguageUtils::getText("LANG_API_ITEM_ID_EMPTY"));
        $result->result = LanguageUtils::getText("LANG_API_ITEM_ID_EMPTY");
    }
    if ($error) {
        $log->logInfo("buyItem : userId > " . $userId . " toUserId > " . $toUserId . " itemId > " . $itemId . " gameId > " . $gameId);
        $time = time();
        try {
            $result = ItemUtils::buyItem($user, $toUser, $item, $gameId, $time);
            if ($useItem == "1") {
                ItemUtils::useItem($user, $item, 1, $toUserId, $gameId, $time);
            }
        } catch (Exception $exc) {
            echo $exc->getMessage();
        }
    }
}
echo json_encode($result);
exit(1);