Example #1
0
require_once 'model.php';
error_reporting(0);
if ($_REQUEST['do'] == "processForm") {
    $portfolio = new Portfolio();
    $message = $portfolio->buildFromPost();
    if ($message == "") {
        $message = "Successfully aded portfolio!";
        include 'html/green_messagebox.php';
        $portfolio->persist();
    } else {
        include 'html/red_messagebox.php';
    }
}
if ($_REQUEST['do'] == 'closeTrade') {
    $trade_id = $_POST['trade_id'];
    $trade = new Trade($trade_id);
    $message = $trade->closeTrade();
    if ($message == "") {
        $trade->persist();
        $message = "Successfully closed trade.";
        include 'html/green_messagebox.php';
    } else {
        include 'html/red_messagebox.php';
    }
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Portfolios - Kyle Stock Tracker</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="images/ktrader.css" type="text/css" />
Example #2
0
 private function datalist_trade($xml)
 {
     if (!$this->bind_check($xml)) {
         return;
     }
     $uid = $this->user_profile->id;
     $from = $xml->FromUserName;
     $to = $xml->ToUserName;
     $url = _url('user/trade/datalist');
     if (ENV == 'dev') {
         $url = preg_replace('/^https/', 'http', $url);
     }
     $trade = Trade::get_list_by_uid($uid, 0, 3);
     $ret_text = '';
     if (!$trade || $trade['total'] == 0) {
         $ret_text = '很遗憾,您在懒投资平台暂无资金流水。';
     } else {
         foreach ($trade['items'] as $key => $trade) {
             $ret_text .= "交易时间: {$trade->time}\n";
             $ret_text .= "交易类型: " . $trade->type_text() . "\n";
             $ret_text .= "交易金额: " . number_format($trade->amount / 100.0, 2) . "元\n\n";
         }
         $ret_text .= '点全文可查看账单明细';
     }
     $news_arr = array(array('title' => '资金流水', 'desc' => $ret_text, 'link' => $url));
     $this->wx_reply->imm_reply_news($to, $from, $news_arr);
 }
Example #3
0
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2048 $
 */
define('CURSCRIPT', 'list');
require "../libraries/common.inc.php";
require "../share.inc.php";
uses("trade", "industry", "area", "tradefield", "form");
require CACHE_PATH . 'cache_trusttype.php';
require CACHE_PATH . 'cache_country.php';
require CACHE_PATH . 'cache_membergroup.php';
$area = new Areas();
$offer = new Tradefields();
$trade = new Trades();
$trade_controller = new Trade();
$form = new Forms();
$industry = new Industries();
$conditions = array();
$industry_id = $area_id = 0;
$conditions[] = "t.status=1";
if (isset($_GET['navid'])) {
    setvar("nav_id", intval($_GET['navid']));
}
uses("tag");
$tag = new Tags();
$viewhelper->setTitle(L('offer', 'tpl'));
$viewhelper->setPosition(L('offer', 'tpl'), "offer/");
if (isset($_GET['typeid'])) {
    $type_id = intval($_GET['typeid']);
    $conditions[] = "t.type_id='" . $type_id . "'";
Example #4
0
 function detail()
 {
     global $viewhelper, $G, $pb_user;
     $positions = $titles = array();
     uses("trade", "member", "company", "tradefield", "form", "industry", "area", "meta");
     $offer = new Tradefields();
     $area = new Areas();
     $meta = new Metas();
     $industry = new Industries();
     $company = new Companies();
     $trade = new Trade();
     $trade_model = new Trades();
     $member = new Members();
     //$typeoption = new Typeoption();
     $form = new Forms();
     setvar("Genders", cache_read("typeoption", 'gender'));
     setvar("PhoneTypes", cache_read("typeoption", 'phone_type'));
     $viewhelper->setTitle(L("offer", "tpl"));
     $viewhelper->setPosition(L("offer", "tpl"), "index.php?do=offer");
     if (isset($_GET['title'])) {
         $title = trim($_GET['title']);
         $res = $trade_model->findByTitle($title);
         $id = $res['id'];
     }
     if (isset($_GET['id'])) {
         $id = intval($_GET['id']);
     }
     if (!empty($id)) {
         $trade->setInfoById($id);
         $info = $trade->info;
         if (empty($info['id'])) {
             flash("data_not_exists", '', 0);
         }
         $info['title_clear'] = $info['title'];
         $info['title'] .= ($G['setting']['offer_expire_method'] == 1 || $G['setting']['offer_expire_method'] == 3) && $info['expdate'] < $offer->timestamp ? "[" . L("has_expired", "tpl") . "]" : '';
         $info['title'] .= !empty($info['if_urgent']) ? "[" . L("urgent_buy", "tpl") . "]" : '';
         if ($info['expdate'] < $offer->timestamp && $G['setting']['offer_expire_method'] == 2) {
             flash("has_been_expired", URL, 0, $info['title_clear'] . " ");
         }
     } else {
         flash("data_not_exists", '', 0);
     }
     if ($info['status'] != 1) {
         flash("under_checking", null, 0, $info['title_clear'] . " ");
     }
     $trade_types = $trade->getTradeTypes();
     $viewhelper->setTitle($trade_types[$info['type_id']]);
     $viewhelper->setPosition($trade_types[$info['type_id']], "index.php?do=offer&action=lists&typeid=" . $info['type_id']);
     $trade_model->clicked($id);
     if ($info['require_point'] > 0) {
         //check member points
         if (empty($pb_user)) {
             flash("please_login_first", URL . "logging.php");
         }
         $point = $member->field("points", "id='" . $pb_user['pb_userid'] . "'");
         if ($point < $info['require_point']) {
             flash("not_enough_points", URL, 0, $info['require_point']);
         }
     }
     $form_vars = array();
     if (isset($info['formattribute_ids'])) {
         $form_vars = $form->getAttributes(explode(",", $info['formattribute_ids']));
     }
     setvar("ObjectParams", $form_vars);
     $info['pubdate'] = df($info['pubdate']);
     $info['expdate'] = df($info['expdate']);
     $info['image'] = pb_get_attachmenturl($info['picture']);
     $login_check = 1;
     if ($info['type_id'] == 1) {
         $login_check = $G['setting']['buy_logincheck'];
     } elseif ($info['type_id'] == 2) {
         $login_check = $G['setting']['sell_logincheck'];
     }
     if (!empty($info['member_id'])) {
         $member_info = $member->getInfoById($info['member_id']);
         $info['link_people'] = $member_info['last_name'];
         $info['space_name'] = $member_info['space_name'];
         $info['tel'] = $member_info['tel'];
         $info['address'] = $member_info['address'];
         $info['zipcode'] = $member_info['zipcode'];
         $info['fax'] = $member_info['fax'];
         $info['site_url'] = $member_info['site_url'];
         setvar("MEMBER", $member_info);
     }
     if (!empty($info['company_id'])) {
         $company_info = $company->getInfoById($info['company_id']);
         if (!empty($company_info)) {
             $info['companyname'] = $company_info['name'];
             $info['link_people'] = $company_info['link_man'];
             $info['address'] = $company_info['address'];
             $info['zipcode'] = $company_info['zipcode'];
             $info['site_url'] = pb_hidestr($company_info['site_url']);
             $info['tel'] = pb_hidestr($company_info['tel']);
             $info['fax'] = pb_hidestr($company_info['fax']);
         }
         setvar("COMPANY", $company_info);
     }
     setvar("LoginCheck", $login_check);
     $info['title'] = strip_tags($info['title']);
     $info['industry_names'] = $industry->disSubNames($info['industry_id'], null, true, "offer");
     $info['area_names'] = $area->disSubNames($info['area_id'], null, true, "offer");
     //delete the pre num.2011.9.1
     //		$info['tel'] = preg_replace('/\((.+?)\)/i', '', pb_hidestr($info['tel']));
     //		$info['fax'] = preg_replace('/\((.+?)\)/i', '', pb_hidestr($info['fax']));
     $info = pb_lang_split_recursive($info);
     setvar("item", $info);
     $meta_info = $meta->getSEOById($id, 'trade', false);
     empty($meta_info['title']) ? $viewhelper->setTitle($info['title'], $info['picture']) : $viewhelper->setTitle($meta_info['title']);
     empty($meta_info['description']) ? $viewhelper->setMetaDescription($info['content']) : $viewhelper->setMetaDescription($meta_info['description']);
     $viewhelper->setPosition($info['title_clear']);
     if (isset($meta_info['keyword'])) {
         $viewhelper->setMetaKeyword($meta_info['keyword']);
     }
     setvar("forward", $this->url(array("module" => "offer", "id" => $id)));
     render("offer/detail");
 }
Example #5
0
require "../libraries/common.inc.php";
require "room.share.php";
require PHPB2B_ROOT . 'libraries/page.class.php';
check_permission("offer");
$tpl_file = "offer";
$page = new Pages();
uses("trade", "tradefield", "product", "tag", "attachment", "form", "typeoption", "point", "industry", "area");
$attachment = new Attachment("pic");
$area = new Areas();
$industry = new Industries();
$form = new Forms();
$point = new Points();
$tradefield = new Tradefields();
$tag = new Tags();
$trade = new Trades();
$trade_controller = new Trade();
$typeoption = new Typeoption();
$conditions = array();
$conditions[] = "member_id = " . $the_memberid;
setvar("TradeTypes", $trade_controller->getTradeTypes());
setvar("TradeNames", $trade_controller->getTradeTypeNames());
$tmp_personalinfo = $memberinfo;
setvar("MemberInfo", $tmp_personalinfo);
$expires = $trade_controller->getOfferExpires();
setvar("TradeTypes", $trade_controller->getTradeTypes());
setvar("PhoneTypes", $typeoption->get_cache_type("phone_type"));
setvar("ImTypes", $typeoption->get_cache_type("im_type"));
setvar("OfferExpires", $expires);
setvar("Countries", $countries = cache_read("country"));
if (isset($company_id)) {
    setvar("CompanyId", $company_id);
Example #6
0
/**
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2116 $
 */
function smarty_block_offer($params, $content, &$smarty, &$repeat)
{
    global $_PB_CACHE;
    $conditions[] = "t.status='1'";
    $param_count = count($smarty->_tag_stack);
    if (empty($params['name'])) {
        $params['name'] = "offer";
    }
    if (!class_exists("Trades")) {
        uses("trade");
        $trade = new Trades();
        $trade_controller = new Trade();
    } else {
        $trade = new Trades();
        $trade_controller = new Trade();
    }
    if ($_PB_CACHE['setting']['offer_expire_method']) {
        switch ($_PB_CACHE['setting']['offer_expire_method']) {
            case "2":
                $conditions[] = "t.expire_time>" . $trade->timestamp;
                break;
            case "3":
                $conditions[] = "t.expire_time>" . $trade->timestamp;
                break;
            default:
                break;
        }
    }
    if (isset($params['type'])) {
        $type = explode(",", $params['type']);
        $type = array_unique($type);
        foreach ($type as $val) {
            switch ($val) {
                case 'image':
                    $conditions[] = "t.picture!=''";
                    break;
                case 'urgent':
                    $conditions[] = "t.if_urgent='1'";
                    break;
                case 'company':
                    $conditions[] = "t.company_id>0";
                    break;
                case 'commend':
                    $conditions[] = "t.if_commend>0";
                    break;
                default:
                    break;
            }
        }
    }
    if (isset($params['industryid'])) {
        if (isset($params['depth'])) {
            $depth = intval($params['depth']);
            if ($depth) {
                if (class_exists("Industries")) {
                    $industry = new Industries();
                    $industry_controller = new Industry();
                } else {
                    uses("industry");
                    $industry = new Industries();
                    $industry_controller = new Industry();
                }
                $ids_s = $industry->getConditionIds($params['industryid']);
                if (is_array($ids_s)) {
                    $ids_s = array_filter($ids_s);
                    $conditions['industry'] = "t.industry_id IN (" . implode(",", $ids_s) . ")";
                } else {
                    $conditions['industry'] = "t.industry_id='" . $ids_s . "'";
                }
            }
        } else {
            $conditions[] = "t.industry_id = '" . $params['industryid'] . "'";
        }
    }
    if (isset($params['areaid'])) {
        if (isset($params['depth'])) {
            $depth = intval($params['depth']);
            if ($depth) {
                global $industry;
                $ids_s = $industry->getConditionIds($params['areaid']);
                if (is_array($ids_s)) {
                    $ids_s = array_filter($ids_s);
                    $conditions['area'] = "t.area_id IN (" . implode(",", $ids_s) . ")";
                } else {
                    $conditions['area'] = "t.area_id='" . $ids_s . "'";
                }
            }
        } else {
            $conditions['area'] = "t.area_id = '" . $params['areaid'] . "'";
        }
    }
    if (!empty($_GET['industryid'])) {
        $conditions['industry'] = "t.industry_id=" . intval($_GET['industryid']);
    }
    if (!empty($_GET['areaid'])) {
        $conditions['area'] = "t.area_id=" . intval($_GET['areaid']);
    }
    if (isset($params['exclude'])) {
        $conditions[] = $trade->getExcludeIds($params['exclude']);
    }
    if (isset($params['include'])) {
        $conditions[] = $trade->getIncludeIds($params['include']);
    }
    if (isset($params['country_id'])) {
        $conditions[] = "t.country_id='" . $params['country_id'] . "'";
    }
    if (isset($params['expday'])) {
        $conditions[] = "t.expire_time<'" . ($params['expday'] * 86400 + $trade->timestamp) . "'";
    }
    if (isset($params['subday'])) {
        $conditions[] = "t.submit_time>'" . ($trade->timestamp - $params['expireday'] * 86400) . "'";
    }
    if (isset($params['typeid'])) {
        if (!empty($params['typeid'])) {
            if (strpos($params['typeid'], ",") > 0) {
                $tmp_ids = explode(",", $params['typeid']);
                $conditions[] = "t.type_id in ('" . implode("','", $tmp_ids) . "')";
            } else {
                $conditions[] = "t.type_id='" . $params['typeid'] . "'";
            }
        }
    }
    if (isset($params['urgent'])) {
        $conditions[] = "t.if_urgent='1'";
    }
    if (!empty($params['memberid'])) {
        $conditions[] = "t.member_id='" . $params['memberid'] . "'";
    }
    if (!empty($params['companyid'])) {
        $conditions[] = "t.company_id='" . $params['companyid'] . "'";
    }
    if (isset($params['cash'])) {
        $conditions[] = "t.require_point>0";
    }
    $trade->setCondition($conditions);
    $orderby = null;
    $orderby = isset($params['orderby']) ? " ORDER BY " . trim($params['orderby']) . " " : " ORDER BY modified DESC";
    $limit = $offset = 0;
    if (isset($params['row'])) {
        $limit = $params['row'];
    }
    if (isset($params['start'])) {
        $offset = $params['start'];
    }
    if (isset($_GET['pos'])) {
        $offset = intval($_GET['pos']);
    }
    $trade->setLimitOffset($offset, $limit);
    $mysql_limit = $trade->getLimitOffset();
    if (isset($params['limit'])) {
        $mysql_limit = " " . trim($params['limit']);
    }
    if (!$params['recursive']) {
        $sql = "SELECT *,title as name,title as fulltitle,content as fullcontent FROM {$trade->table_prefix}trades t " . $trade->getCondition() . "{$orderby}" . $mysql_limit;
    } else {
        $sql = "SELECT *,content as fullcontent FROM {$trade->table_prefix}trades t " . $trade->getCondition() . " ORDER BY t.display_order ASC,t.id DESC" . $mysql_limit;
    }
    $offer_typenames = $trade_controller->getTradeTypes();
    if (empty($smarty->blockvars[$param_count])) {
        $smarty->blockvars[$param_count] = $trade->GetArray($sql);
        if (!$smarty->blockvars[$param_count]) {
            return $repeat = false;
        }
    }
    if (!function_exists("smarty_function_the_url")) {
        require "function.the_url.php";
    }
    if (list($key, $item) = each($smarty->blockvars[$param_count])) {
        $repeat = true;
        $item['rownum'] = $key;
        $item['iteration'] = ++$key;
        $url = smarty_function_the_url(array("id" => $item['id'], "typeid" => $item['type_id'], "module" => "offer"));
        $item['url'] = $url;
        $item['title'] = strip_tags($item['title']);
        $item['content'] = strip_tags($item['content']);
        if (isset($params['titlelen'])) {
            $item['title'] = mb_substr($item['title'], 0, $params['titlelen']);
        }
        if (isset($params['infolen'])) {
            $item['content'] = mb_substr($item['content'], 0, $params['infolen']);
        }
        if (isset($params['titlestart'])) {
            $item['title'] = $params['titlestart'] . $item['title'];
        }
        $item['pubdate'] = df($item['submit_time']);
        $item['typeid'] = $item['type_id'];
        $item['typename'] = $offer_typenames[$item['type_id']];
        $item['src'] = $item['thumb'] = URL . "attachment/" . $item['picture'] . ".small.jpg";
        $item['link'] = '<a title="' . $item['fulltitle'] . '" href="' . $url . '">' . $item['title'] . '</a>';
        $item['style'] = parse_highlight($item['highlight']);
        $smarty->assign($params['name'], $item);
    } else {
        $repeat = false;
        reset($smarty->blockvars[$param_count]);
    }
    if (!is_null($content)) {
        print $content;
    }
    if (!$repeat) {
        $smarty->blockvars[$param_count] = array();
    }
}
Example #7
0
    if ($notify->query_data['return_code'] == 'SUCCESS') {
        //$data['id'] = $orderId = substr($notify->query_data['out_trade_no'], 14);
        $data['id'] = $orderId = $notify->query_data['out_trade_no'];
        $data['pay_type'] = Config::ORDER_PAY_TYPE;
        $data['pay_status'] = Config::ORDER_PAY_FAILED_CODE;
        if ($notify->query_data['result_code'] == 'SUCCESS') {
            $data['pay_status'] = Config::ORDER_PAY_SUCCESS_CODE;
        }
        //$data['pay_discount'] = Config::ORDER_PAY_DISCOUNT;
        // 微信会轮训回调通知接口,更新订单支付状态前需要先查询订单是否已经更改
        $order_info = Order::get_order_by_id($data['id']);
        if ((int) $order_info['pay_status'] !== Config::ORDER_PAY_WAITTINT_CODE) {
            return;
        }
        if ($notify->request_data['attach'] !== PAY_ENV) {
            return;
        }
        $update_result = Order::update_order_status($data, $orderId);
        if ($update_result === true) {
            // 如果订单支付状态更新成功,则记录支付流水
            $update_suborder = Order::update_suborder_status($data['pay_status'], $orderId);
            $add_result = Trade::add_trade_bill($notify->request_data, $data);
        } else {
            throw new Exception('order pay status update failed');
        }
    } else {
        Log::DEBUG(sprintf('callback error|file:%s|line:%s|require_data:%s', __FILE__, __LINE__, json_encode($notify->request_data)));
    }
} catch (Exception $e) {
    Log::ERROR(sprintf('run exceptin:%s|file:%s|line:%s', $e->getMessage(), $e->getFile(), $e->getLine()));
}
Example #8
0
<?php

/**
 * PHPB2B :  Opensource B2B Script (http://www.phpb2b.com/)
 * Copyright (C) 2007-2010, Ualink. All Rights Reserved.
 * 
 * Licensed under The Languages Packages Licenses.
 * Support : phpb2b@hotmail.com
 * 
 * @version $Revision: 1393 $
 */
require "../libraries/common.inc.php";
require "room.share.php";
uses("trade");
$trade = new Trade();
$trade_model = new Trades();
if (isset($_POST['del'])) {
    pb_submit_check('id');
    $ids = implode(",", $_POST['id']);
    $ids = "(" . $ids . ")";
    $sql = "DELETE FROM {$tb_prefix}favorites WHERE id IN " . $ids . " AND member_id=" . $_SESSION['MemberID'];
    $res = $pdb->Execute($sql);
    if (!$res) {
        flash("action_failed");
    }
}
if (isset($_POST['do']) && isset($_POST['id'])) {
    if ($trade_model->checkExist($_POST['id'])) {
        $sql = "INSERT INTO {$tb_prefix}favorites (target_id,member_id,type_id,created,modified) VALUE (" . $_POST['id'] . "," . $_SESSION['MemberID'] . ",1," . $time_stamp . "," . $time_stamp . ")";
        $result = $pdb->Execute($sql);
    }
 public function doSell()
 {
     if (Auth::guest()) {
         echo json_encode(array('status' => 'error', 'message' => Lang::get('messages.login_to_buy')));
         exit;
     }
     $logFile = 'trades.log';
     Log::useDailyFiles(storage_path() . '/logs/trades/' . $logFile);
     Log::info('------------------------- Do Sell -----------------------------');
     $user = Confide::user();
     $price_sell = sprintf('%.8f', $_POST['price']);
     $amount_sell = sprintf('%.8f', $_POST['amount']);
     $total_sell = $price_sell * $amount_sell;
     //sprintf('%.8f',$price_sell*$amount_sell);
     $market_id = $_POST['market_id'];
     //Session::get('market_id');
     //get info market
     $market_default = Market::find($market_id);
     if (!isset($market_default->active) || $market_default->active == 0) {
         echo json_encode(array('status' => 'error', 'message' => Lang::get('messages.market_not_active')));
         exit;
     }
     $wallet_from = $market_default->wallet_from;
     $wallet_to = $market_default->wallet_to;
     $wallet = new Wallet();
     $from = $wallet->getType($wallet_from);
     $to = $wallet->getType($wallet_to);
     //cleck limit trade
     $limit_trade = WalletLimitTrade::where('wallet_id', $wallet_from)->first();
     if ($limit_trade) {
         $limit_trade = $limit_trade->toArray();
     } else {
         $limit_trade = array('min_amount' => 0.0001, 'max_amount' => 1000);
     }
     if (sprintf('%.8f', $_POST['amount']) < $limit_trade['min_amount'] || sprintf('%.8f', $_POST['amount']) > $limit_trade['max_amount']) {
         echo json_encode(array('status' => 'error', 'message' => Lang::get('messages.message_limit_trade')));
         exit;
     }
     //set default return value
     $status = 'error';
     $message = Lang::get('messages.error_contact_admin');
     $balance = new Balance();
     $message_socket = array();
     $message_socket['market_id'] = $market_id;
     //sub $total_buy money
     if ($balance->takeMoney($amount_sell, $wallet_from, $user->id)) {
         $orders_sell = new Order();
         $orders_sell->price = $price_sell;
         $orders_sell->status = 'active';
         $orders_sell->from_value = $amount_sell;
         $orders_sell->to_value = $total_sell;
         $orders_sell->market_id = $market_id;
         $orders_sell->user_id = $user->id;
         $orders_sell->type = 'sell';
         $amount_real = 0;
         $amount_rest = 0;
         $total_rest = 0;
         //get list order sell matching
         $orders = new Order();
         $buy_orders_matching = $orders->getBuyOrdersMatching($market_id, $price_sell);
         $buy_orders_matching = $buy_orders_matching->toArray();
         Log::info('buy_orders_matching: market_id: ' . $market_id . ' -- Price: ' . $price_sell, $buy_orders_matching);
         if (count($buy_orders_matching) > 0) {
             //fee_buy, fee_sell
             $fee_trade = new FeeTrade();
             $fee = $fee_trade->getFeeTrade($market_id);
             $per_fee_buy = $fee['fee_buy'];
             $per_fee_sell = $fee['fee_sell'];
             $message = '';
             foreach ($buy_orders_matching as $buy_order) {
                 $amount_rest = 0;
                 $total_rest = 0;
                 $amount_sold = 0;
                 if ($amount_sell > 0) {
                     $amount_real = $amount_sell;
                     $trade_history = new Trade();
                     Log::info("\n" . '---*****-----SELL : amount_sell: ' . $amount_sell . ' -- Price: ' . $price_sell);
                     $buy_matching = $buy_order;
                     //$buy_orders_matching[0];
                     $price_buy = $buy_matching['price'];
                     $amount_buy = $buy_matching['from_value'];
                     $total_buy = $buy_matching['to_value'];
                     $user_buy = $buy_matching['user_id'];
                     $class_price = str_replace(".", "-", $price_buy);
                     $class_price = str_replace(",", "-", $price_buy);
                     if ($amount_buy == $amount_sell) {
                         $total_sell = $amount_sell * $price_buy;
                         //sprintf('%.8f',$amount_sell*$price_buy);//really total sell;
                         $fee_buy = $total_buy * $per_fee_buy / 100;
                         $fee_sell = $total_sell * $per_fee_sell / 100;
                         if ($balance->takeMoney($fee_buy, $wallet_to, $user->id)) {
                             //tru phi nguoi mua
                             //add coin for seller/buyer
                             $balance->addMoney($amount_buy, $wallet_from, $user_buy);
                             $balance->addMoney($total_sell - $fee_sell, $wallet_to, $user->id);
                             Order::where('id', $buy_matching['id'])->update(array('status' => 'filled'));
                             $status = 'success';
                             //$message .= "\n".Lang::get('messages.filled').' : Fee buy: '.sprintf('%.8f',$fee_buy).' - Fee Sell: '.sprintf('%.8f',$fee_sell).' - Total buy: '.(sprintf('%.8f',$amount_buy)) . ' - Total sell: '.sprintf('%.8f',($total_sell-$fee_sell));
                             $message .= '<p>' . Lang::get('messages.filled') . ' Sold ' . $amount_buy . ' ' . $from . ' at price ' . $price_buy . ' Fee sell: ' . $fee_sell . ' ' . $to . ' - Received: ' . ($total_sell - $fee_sell) . ' ' . $to . '</p>';
                             Log::info('amount_buy = amount_sell Update sell orders: ', array('status' => 'filled'));
                             $orders_sell->status = 'filled';
                             //add history
                             $trade_id = $trade_history->addTradeHistory(array('seller_id' => $user->id, 'buyer_id' => $user_buy, 'amount' => $amount_buy, 'price' => $price_buy, 'market_id' => $market_id, 'type' => 'sell', 'fee_buy' => $fee_buy, 'fee_sell' => $fee_sell));
                             $message_socket['message_socket'][$class_price]['order_b'] = array('action' => "delete", 'id' => $buy_matching['id'], 'price' => $price_buy);
                             $message_socket['message_socket'][$buy_matching['id']]['history_trade'] = array('id' => $trade_id, 'seller_id' => $user->id, 'buyer_id' => $user_buy, 'amount' => $amount_buy, 'price' => $price_buy, 'market_id' => $market_id, 'type' => 'sell', "created_at" => date("Y-m-d H:i:s"), "order_id" => $buy_matching['id']);
                         } else {
                             $message .= Lang::get('messages.balance_not_enought_for_fee');
                         }
                     } elseif ($amount_buy > $amount_sell) {
                         $total_sell = $amount_sell * $price_buy;
                         //really total sell;
                         $fee_buy = $total_sell * $per_fee_buy / 100;
                         $fee_sell = $total_sell * $per_fee_sell / 100;
                         if ($balance->takeMoney($fee_buy, $wallet_to, $user->id)) {
                             //tru phi nguoi mua
                             if (isset($message_socket['message_socket'][$class_price]['order_s']['amount'])) {
                                 $amount_sold = $message_socket['message_socket'][$class_price]['order_b']['amount'] + $amount_sell;
                             } else {
                                 $amount_sold = $amount_sell;
                             }
                             //add coin for seller/buyer
                             $balance->addMoney($amount_sell, $wallet_from, $user_buy);
                             $balance->addMoney($total_sell - $fee_sell, $wallet_to, $user->id);
                             $amount_rest = sprintf('%.8f', $amount_buy - $amount_sell);
                             $total_rest = $amount_rest * $price_buy;
                             //sprintf('%.8f',$amount_rest * $price_buy);
                             Order::where('id', $buy_matching['id'])->update(array('status' => 'partly filled', 'from_value' => $amount_rest, 'to_value' => $total_rest));
                             Log::info('amount_buy > amount_sell Update sell orders: ', array('status' => 'partly filled', 'from_value' => $amount_rest, 'to_value' => $total_rest));
                             $status = 'success';
                             //$message .= "\n".Lang::get('messages.partly_filled').' : Fee buy: '.sprintf('%.8f',$fee_buy).' - Fee Sell: '.sprintf('%.8f',$fee_sell).' - Total buy: '.(sprintf('%.8f',$amount_sell)) . ' - Total sell: '.sprintf('%.8f',($total_sell-$fee_sell));
                             $message .= '<p>' . Lang::get('messages.filled') . ' Sold ' . $amount_sell . ' ' . $from . ' at price ' . $price_buy . ' Fee sell: ' . $fee_sell . ' ' . $to . ' - Received: ' . ($total_sell - $fee_sell) . ' ' . $to . '</p>';
                             $orders_sell->status = 'filled';
                             $trade_id = $trade_history->addTradeHistory(array('seller_id' => $user->id, 'buyer_id' => $user_buy, 'amount' => $amount_sell, 'price' => $price_buy, 'market_id' => $market_id, 'type' => 'sell', 'fee_buy' => $fee_buy, 'fee_sell' => $fee_sell));
                             //call socket
                             $message_socket['message_socket'][$class_price]['order_b'] = array("action" => "update", "id" => $buy_matching['id'], "amount" => $amount_sold, "price" => $price_buy, "total" => $amount_sold * $price_buy);
                             $message_socket['message_socket'][$buy_matching['id']]['history_trade'] = array('id' => $trade_id, 'seller_id' => $user->id, 'buyer_id' => $user_buy, 'amount' => $amount_sell, 'price' => $price_buy, 'market_id' => $market_id, 'type' => 'sell', "created_at" => date("Y-m-d H:i:s"), "order_id" => $buy_matching['id']);
                         } else {
                             $message .= Lang::get('messages.balance_not_enought_for_fee');
                         }
                     } else {
                         $total_sell = $amount_buy * $price_buy;
                         //sprintf('%.8f',$amount_buy*$price_buy);//really total sell;
                         $fee_buy = $total_sell * $per_fee_buy / 100;
                         $fee_sell = $total_sell * $per_fee_sell / 100;
                         if ($balance->takeMoney($fee_buy, $wallet_to, $user->id)) {
                             //tru phi nguoi mua
                             //add coin for seller/buyer
                             $balance->addMoney($amount_buy, $wallet_from, $user_buy);
                             $balance->addMoney($total_sell - $fee_sell, $wallet_to, $user->id);
                             $amount_rest = sprintf('%.8f', $amount_sell - $amount_buy);
                             $total_rest = $amount_rest * $price_sell;
                             //sprintf('%.8f',$amount_rest * $price_sell);
                             Order::where('id', $buy_matching['id'])->update(array('status' => 'filled'));
                             $status = 'success';
                             //$message .= "\n".Lang::get('messages.partly_filled').' : Fee buy: '.sprintf('%.8f',$fee_buy).' - Fee Sell: '.sprintf('%.8f',$fee_sell).' - Total buy: '.(sprintf('%.8f',$amount_buy)) . ' - Total sell: '.sprintf('%.8f',($total_sell-$fee_sell));
                             $message .= '<p>' . Lang::get('messages.partly_filled') . ' Sold ' . $amount_buy . ' ' . $from . ' at price ' . $price_buy . ' Fee sell: ' . $fee_sell . ' ' . $to . ' - Received: ' . ($total_sell - $fee_sell) . ' ' . $to . '</p>';
                             Log::info('amount_buy < amount_sell Update sell orders: ', array('status' => 'filled'));
                             $orders_sell->status = 'partly filled';
                             $orders_sell->from_value = $amount_rest;
                             $orders_sell->to_value = $total_rest;
                             $trade_id = $trade_history->addTradeHistory(array('seller_id' => $user->id, 'buyer_id' => $user_buy, 'amount' => $amount_buy, 'price' => $price_buy, 'market_id' => $market_id, 'type' => 'sell', 'fee_buy' => $fee_buy, 'fee_sell' => $fee_sell));
                             $amount_real = $amount_buy;
                             //call socket
                             $message_socket['message_socket'][$class_price]['order_b'] = array("action" => "delete", "id" => $buy_matching['id'], 'price' => $price_buy);
                             $message_socket['message_socket'][$buy_matching['id']]['history_trade'] = array('id' => $trade_id, 'seller_id' => $user->id, 'buyer_id' => $user_buy, 'amount' => $amount_buy, 'price' => $price_buy, 'market_id' => $market_id, 'type' => 'sell', "created_at" => date("Y-m-d H:i:s"), "order_id" => $buy_matching['id']);
                         } else {
                             $message .= Lang::get('messages.balance_not_enought_for_fee');
                         }
                     }
                     //refund money
                     /*if($price_buy > $price_sell){
                     			Log::info('-------Refund: ');
                     			$total_refunds = ($amount_real*$price_buy) - ($amount_real*$price_sell);
                     			$balance->addMoney($total_refunds,$from,$user->id);
                     		}*/
                     //update amount
                     $amount_sell = sprintf('%.8f', $amount_sell - $amount_real);
                 }
             }
             Log::info('-------amount_sell final: ' . $amount_sell);
             if ($amount_sell > 0) {
                 $orders_sell->save();
                 $message_socket['message_socket'][$orders_sell['id']]['order_s'] = array('action' => "insert", "amount" => $amount_sell, "price" => $price_sell, "total" => $total_rest, "type" => "sell");
                 $message_socket['message_socket'][$orders_sell['id']]['order_s']['id'] = $orders_sell->id;
                 $message_socket['message_socket'][$orders_sell['id']]['order_s']['created_at'] = $orders_sell->created_at;
             }
             $trade = new Trade();
             $message_socket['data_price'] = $trade->getBlockPrice($market_id);
             $balance = new Balance();
             $message_socket['data_price']['balance_coinmain'] = sprintf('%.8f', $balance->getBalance($wallet_from, 0));
             $message_socket['data_price']['balance_coinsecond'] = sprintf('%.8f', $balance->getBalance($wallet_to, 0));
             $message_socket['change_price']['total_volume'] = $trade->getVolume($market_id);
             $message_socket['change_price']['cur_price'] = $price_buy;
         } else {
             $orders_sell->save();
             $status = 'success';
             $message = Lang::get('messages.order_created');
             $message_socket['message_socket'][$orders_sell['id']]['order_s'] = array('action' => "insert", "id" => $orders_sell->id, "amount" => $orders_sell->from_value, "price" => $orders_sell->price, "total" => $orders_sell->to_value, 'type' => 'sell', 'created_at' => $orders_sell->created_at);
         }
         $this->triggerPusherTicket($market_id);
     } else {
         $message = Lang::get("messages.not_enough_purchase", array('type' => strtoupper($from)));
     }
     echo json_encode(array('status' => $status, 'message' => $message, "message_socket" => $message_socket));
     exit;
 }
Example #10
0
/**
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2181 $
 */
function smarty_function_the_url($params)
{
    $do = null;
    extract($params);
    global $subdomain_support, $topleveldomain_support, $rewrite_able, $rewrite_compatible;
    $return = "##";
    if (!empty($module)) {
        switch ($module) {
            case "producttype":
                if ($rewrite_able) {
                    $return = URL . "space/" . $userid . "/product/list-" . $typeid . "-" . intval($page) . ".html";
                } else {
                    $return = URL . "space/?userid=" . $userid . "&do=product&typeid=" . $typeid . "&page=" . $page;
                }
                break;
            case "space":
                if (!class_exists('Space')) {
                    uses("space");
                }
                $space_controller = new Space();
                $return = $space_controller->rewrite($userid, $id, $do);
                break;
            case "offer":
                if (!class_exists('Trade')) {
                    uses("trade");
                }
                $trade_controller = new Trade();
                if ($rewrite_able) {
                    $return = "offer/" . $trade_controller->getModulenameById($typeid) . "/detail/" . $id . ".html";
                } else {
                    $return = "offer/detail.php?id=" . $id;
                }
                break;
            case "list":
                $extra_param = array();
                if (!empty($extra)) {
                    if (strpos($extra, "|") > 0) {
                        $tmp = explode("|", $extra);
                        foreach ($tmp as $k => $v) {
                            $tmp_p = explode(",", $v);
                            $extra_param[$tmp_p[0]] = $tmp_p[1];
                        }
                    } else {
                        $tmp = explode(",", $extra);
                        $extra_param[$tmp[0]] = $tmp[1];
                    }
                }
                $param = http_build_query($extra_param + $_GET);
                $return = $GLOBALS['php_self'] . "?" . $param;
                break;
            case "special":
                if ($rewrite_able) {
                    if ($type == "topic") {
                        //name first alias_name
                        $return = "topic/" . $name . "/";
                    } else {
                        $return = "topic/" . $type . "/" . $id . "/?do=" . $do;
                    }
                } else {
                    if ($type == "topic") {
                        //name first alias_name
                        $return = "special/?type=" . $type . "&name=" . $name;
                    } else {
                        $return = "special/?type=" . $type . "&do=" . $do . "&id=" . $id;
                    }
                }
                break;
            case "page":
                if ($rewrite_able) {
                    $return = "page/" . urlencode($title) . "/";
                } else {
                    $return = "page.php?title=" . urlencode($title);
                }
                break;
            case "search":
                if ($rewrite_able) {
                    if (!isset($pos)) {
                        $pos = 0;
                    }
                    if (!isset($params['pos']) && !isset($params['typeid'])) {
                        $return = empty($do) ? "search/" : "search/" . $do . "/";
                    } else {
                        $return = $do . "-list-" . $pos . "-" . intval($typeid) . "-" . intval($areaid) . "-" . intval($industryid) . ".html";
                    }
                } else {
                    $return = "search/?do=" . $do . "&pos=" . $pos;
                    if (!empty($q)) {
                        $return .= "&q=" . $q;
                    }
                    if (!empty($typeid)) {
                        $return .= "&typeid=" . intval($typeid);
                    }
                    if (!empty($areaid)) {
                        $return .= "&areaid=" . $areaid;
                    }
                    if (!empty($industryid)) {
                        $return .= "&industryid=" . $industryid;
                    }
                    if (!empty($type)) {
                        $return .= "&type=" . $type;
                    }
                }
                break;
            case "wap":
                if ($do) {
                    if ($rewrite_able) {
                        $return = "wap-" . $do . "/";
                    } else {
                        $return = "?do=" . $do;
                    }
                } else {
                    $return = URL . "wap/";
                }
                break;
            case "tag":
                if ($rewrite_able) {
                    $return = "tag/" . $do . "-" . $q . "/";
                } else {
                    $return = smarty_function_the_url(array("do" => $do, "q" => $q, "module" => "search"));
                }
                break;
            default:
                if (!empty($id)) {
                    if ($rewrite_able) {
                        $return = URL . $module . "/detail/" . $id . ".html";
                    } else {
                        $return = URL . $module . "/detail.php?id=" . $id;
                    }
                }
                break;
        }
    }
    return $return;
}
Example #11
0
 public function getChart()
 {
     $market_id = $_POST['market_id'];
     $timeSpan = $_POST['timeSpan'];
     $trade = new Trade();
     $datachart = $trade->getDatasChart($market_id, $timeSpan);
     echo $datachart;
     exit;
 }
Example #12
0
 public function viewprofile($page = '', $filter = '')
 {
     $user = Confide::user();
     $user_id = $user->id;
     $data = array();
     $data['user_id'] = $user_id;
     $data['user'] = $user;
     if ($user_id > 0) {
         $profile = User::leftJoin('users_roles', 'users.id', '=', 'users_roles.user_id')->join('roles', 'roles.id', '=', 'users_roles.role_id')->select('users.*', 'roles.name as rolename')->where('users.id', '=', $user_id)->get();
         if ($profile) {
             $data['profile'] = $profile->first()->toArray();
         }
     }
     $data['page'] = $page;
     $data['filter'] = $filter;
     $balance = new Balance();
     $order = new Order();
     $market = new Market();
     $wallet = new Wallet();
     $setting = new Setting();
     $data['disable_points'] = $setting->getSetting('disable_points', 0);
     switch ($page) {
         case 'balances':
             $wallets = Wallet::orderBy('name')->get()->toArray();
             foreach ($wallets as $key => $value) {
                 $wallet_id = $value['id'];
                 //get balance
                 $balance_amount = $balance->getBalance($wallet_id);
                 $wallets[$key]['balance'] = sprintf('%.8f', $balance_amount);
                 //get PENDING DEPOSITS
                 $deposit_pendding = Deposit::where('user_id', '=', $user_id)->where('wallet_id', '=', $wallet_id)->where('paid', '=', 0)->sum('amount');
                 $wallets[$key]['deposit_pendding'] = sprintf('%.8f', $deposit_pendding);
                 //get PENDING WITHDRAWALS
                 $withdraw_pendding = Withdraw::where('user_id', '=', $user_id)->where('wallet_id', '=', $wallet_id)->where('status', '=', 0)->sum('amount');
                 $wallets[$key]['withdraw_pendding'] = sprintf('%.8f', $withdraw_pendding);
                 //get HELD FOR ORDERS
                 //giao dich ban se giam tien cua wallet hien tai, doi voi btc/ltc (dong tien trao doi) thi giao dich mua se giam tien no
                 //vi vay can xac dinh dau la btc/ltc, bang cach dua vao market, wallet_to trong market chinh la dong tien chinh de trao doi
                 $wallets_to = Market::select("market.wallet_to")->distinct()->get();
                 $wal_to = array();
                 foreach ($wallets_to as $value) {
                     $wal_to[] = $value->wallet_to;
                 }
                 //$wallets_to = array_column($market, 'wallet_to');
                 $status_active = $order->getStatusActive();
                 /*if(in_array($wallet_id,$wal_to)){
                       $held_order = Order::leftJoin('market', 'orders.market_id', '=', 'market.id')
                                   ->where('market.wallet_to','=',$wallet_id)
                                   ->where('orders.user_id','=',$user_id)
                                   ->whereIn('status', $status_active)
                                   ->sum('to_value');
                   }else{*/
                 $held_order = Order::leftJoin('market', 'orders.market_id', '=', 'market.id')->where('market.wallet_from', '=', $wallet_id)->where('orders.user_id', '=', $user_id)->where('type', '=', 'sell')->whereIn('status', $status_active)->sum('from_value');
                 //}
                 $wallets[$key]['held_order'] = sprintf('%.8f', $held_order);
             }
             //echo "<pre>ggg?: "; print_r($wallets); echo "</pre>";
             $data['balances'] = $wallets;
             break;
         case 'orders':
             $record_per_page = 15;
             if (empty($_GET['pager_page'])) {
                 $pager_page = 1;
             } else {
                 $pager_page = $_GET['pager_page'];
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to` from orders a left join market b on a.market_id=b.id where a.user_id='" . $user_id . "' ";
             if ($filter != '') {
                 $data['current_coin'] = $wallet->getType($filter);
                 $select .= " AND (b.wallet_to='" . $filter . "' OR b.wallet_from='" . $filter . "') ";
             }
             if (isset($_GET['do_filter'])) {
                 if (!empty($_GET['market'])) {
                     $select .= " AND a.market_id='" . $_GET['market'] . "'";
                 }
                 if ($_GET['status'] != '') {
                     $select .= " AND a.status='" . $_GET['status'] . "'";
                 }
                 if ($_GET['type'] != '') {
                     $select .= " AND a.type='" . $_GET['type'] . "'";
                 }
             }
             $select_count = $select;
             $total_records = DB::select($select_count);
             $data['total_pages'] = ceil(count($total_records) / $record_per_page);
             $select .= " order by `created_at` desc limit " . $offset_start . "," . $record_per_page;
             $ordershistory = DB::select($select);
             //echo "<pre>ordershistory: "; print_r($ordershistory); echo "</pre>";
             //echo "<pre>".dd(DB::getQueryLog())."</pre>";
             $data['ordershistories'] = $ordershistory;
             $markets = Market::get();
             $market_wallet = array();
             foreach ($markets as $value) {
                 $market_wallet[$value->id] = $market->getWalletType($value->id);
             }
             $data['markets'] = $market_wallet;
             break;
         case 'trade-history':
             $record_per_page = 15;
             if (empty($_GET['pager_page'])) {
                 $pager_page = 1;
             } else {
                 $pager_page = $_GET['pager_page'];
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to` from trade_history a left join market b on a.market_id=b.id where (a.seller_id='" . $user_id . "' OR a.buyer_id ='" . $user_id . "') ";
             if ($filter != '') {
                 $data['current_coin'] = $wallet->getType($filter);
                 $select .= " AND (b.wallet_to='" . $filter . "' OR b.wallet_from='" . $filter . "') ";
             }
             if (isset($_GET['do_filter'])) {
                 if (!empty($_GET['market'])) {
                     $select .= " AND a.market_id='" . $_GET['market'] . "'";
                 }
                 if (!empty($_GET['type'])) {
                     $select .= " AND a.type='" . $_GET['type'] . "'";
                 }
             }
             $select_count = $select;
             $total_records = DB::select($select_count);
             //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit;
             $data['total_pages'] = ceil(count($total_records) / $record_per_page);
             $select .= " order by `created_at` desc limit " . $offset_start . "," . $record_per_page;
             $trades = DB::select($select);
             $data['tradehistories'] = $trades;
             $markets = Market::get();
             $market_wallet = array();
             foreach ($markets as $value) {
                 $market_wallet[$value->id] = $market->getWalletType($value->id);
             }
             $data['markets'] = $market_wallet;
             break;
         case 'deposits':
             $deposits = Deposit::leftJoin('wallets', 'deposits.wallet_id', '=', 'wallets.id')->select('deposits.*', 'wallets.name', 'wallets.type')->where('user_id', '=', $user_id);
             if ($filter != '') {
                 $data['current_coin'] = $wallet->getType($filter);
                 $deposits = $deposits->where('deposits.wallet_id', '=', $filter);
             }
             if (isset($_POST['do_filter'])) {
                 if (isset($_POST['wallet']) && $_POST['wallet'] != '') {
                     $deposits = $deposits->where('wallet_id', '=', $_POST['wallet']);
                 }
                 if ($_POST['status'] != '') {
                     $deposits = $deposits->where('paid', '=', $_POST['status']);
                 }
             }
             $deposits = $deposits->orderBy('created_at', 'desc')->get();
             //echo "<pre>_POST: "; print_r($_POST); echo "</pre>";
             //echo "<pre>"; echo dd(DB::getQueryLog()); echo "</pre>";
             $data['deposits'] = $deposits;
             $wallets = Wallet::select('id', 'type', 'name')->get();
             $data['wallets'] = $wallets;
             break;
         case 'withdrawals':
             $withdrawals = Withdraw::leftJoin('wallets', 'withdraws.wallet_id', '=', 'wallets.id')->select('withdraws.*', 'wallets.name', 'wallets.type')->where('user_id', '=', $user_id);
             if ($filter != '') {
                 $data['current_coin'] = $wallet->getType($filter);
                 $withdrawals = $withdrawals->where('withdraws.wallet_id', '=', $filter);
             }
             if (isset($_POST['do_filter'])) {
                 if ($_POST['wallet'] != '') {
                     $withdrawals = $withdrawals->where('wallet_id', '=', $_POST['wallet']);
                 }
                 if ($_POST['status'] != '') {
                     $withdrawals = $withdrawals->where('status', '=', $_POST['status']);
                 }
             }
             $withdrawals = $withdrawals->orderBy('created_at', 'desc')->get();
             //echo "<pre>_POST: "; print_r($_POST); echo "</pre>";
             //echo "<pre>"; echo dd(DB::getQueryLog()); echo "</pre>";
             $data['withdrawals'] = $withdrawals;
             $wallets = Wallet::select('id', 'type', 'name')->get();
             $data['wallets'] = $wallets;
             break;
         case 'viewtranferin':
             $record_per_page = 15;
             if (empty($_GET['pager_page'])) {
                 $pager_page = 1;
             } else {
                 $pager_page = $_GET['pager_page'];
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             //$offset_end = ($pager_page*$record_per_page)-1;
             $select = "select a.*, b.type, b.name , c.username from transfer_history a left join wallets b on a.wallet_id=b.id left join users c on a.receiver=c.id where a.receiver='" . $user_id . "'";
             $select_count = "select count(*) as total from transfer_history a where a.receiver='" . $user_id . "'";
             if ($filter != '') {
                 $data['current_coin'] = $wallet->getType($filter);
                 $select .= " AND a.wallet_id='" . $filter . "'";
             }
             $where = '';
             if (isset($_GET['do_filter'])) {
                 if ($where == '') {
                     if (!empty($_GET['wallet'])) {
                         $where = $where . " AND a.wallet_id='" . $_GET['wallet'] . "'";
                     }
                 }
             }
             $select_count = $select_count . " " . $where . " order by `created_at` desc";
             $total_records = DB::select($select_count);
             //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit;
             $data['total_pages'] = ceil($total_records[0]->total / $record_per_page);
             $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page;
             $transferins = DB::select($select);
             $data['transferins'] = $transferins;
             $wallets_temp = Wallet::get();
             $wallets = array();
             foreach ($wallets_temp as $wallet) {
                 $wallets[$wallet->id] = $wallet;
             }
             $data['wallets'] = $wallets;
             break;
         case 'viewtranferout':
             $record_per_page = 2;
             if (empty($_GET['pager_page'])) {
                 $pager_page = 1;
             } else {
                 $pager_page = $_GET['pager_page'];
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             //$offset_end = ($pager_page*$record_per_page)-1;
             $select = "select a.*, b.type, b.name , c.username from transfer_history a left join wallets b on a.wallet_id=b.id left join users c on a.sender=c.id where a.sender='" . $user_id . "'";
             $select_count = "select count(*) as total from transfer_history a where a.sender='" . $user_id . "'";
             if ($filter != '') {
                 $data['current_coin'] = $wallet->getType($filter);
                 $select .= " AND a.wallet_id='" . $filter . "'";
             }
             $where = '';
             if (isset($_GET['do_filter'])) {
                 if ($where == '') {
                     if (!empty($_GET['wallet'])) {
                         $where = $where . " AND a.wallet_id='" . $_GET['wallet'] . "'";
                     }
                 }
             }
             $select_count = $select_count . " " . $where . " order by `created_at` desc";
             $total_records = DB::select($select_count);
             //echo "<pre>total_records: "; print_r($total_records); echo "</pre>";
             $data['total_pages'] = ceil($total_records[0]->total / $record_per_page);
             $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page;
             $transferouts = DB::select($select);
             $data['transferouts'] = $transferouts;
             $wallets_temp = Wallet::get();
             $wallets = array();
             foreach ($wallets_temp as $wallet) {
                 $wallets[$wallet->id] = $wallet;
             }
             $data['wallets'] = $wallets;
             break;
         case 'dashboard':
             $total_trades = Trade::where('seller_id', $user_id)->orwhere('buyer_id', $user_id)->get()->toArray();
             $data['total_trades'] = count($total_trades);
             $order = new Order();
             $total_openordes = Order::where('user_id', $user_id)->whereIn('status', $order->getStatusActive())->get()->toArray();
             $data['total_openordes'] = count($total_openordes);
             $twentyfourhours = date('Y-m-d H:i:s', strtotime('-24 hour'));
             $deposit_twentyfourhours = Deposit::where('user_id', $user_id)->where('created_at', ">=", $twentyfourhours)->get()->toArray();
             $data['deposit_twentyfourhours'] = count($deposit_twentyfourhours);
             $withdraw_twentyfourhours = Withdraw::where('user_id', $user_id)->where('created_at', ">=", $twentyfourhours)->get()->toArray();
             $data['withdraw_twentyfourhours'] = count($withdraw_twentyfourhours);
             $deposit_pendings = Deposit::where('user_id', $user_id)->where('paid', 0)->get()->toArray();
             $data['deposit_pendings'] = count($deposit_pendings);
             $total_referred = User::where('referral', $user->username)->get()->toArray();
             $data['total_referred'] = count($total_referred);
             //echo "<pre>total_referred: "; print_r($total_referred); echo "</pre>";
             break;
         case "ecoinstraderpoint":
             $setting = new Setting();
             $data['point_per_btc'] = $setting->getSetting('point_per_btc', 1);
             $data['percent_point_reward_trade'] = $setting->getSetting('percent_point_reward_trade', 0);
             $data['percent_point_reward_referred_trade'] = $setting->getSetting('percent_point_reward_referred_trade', 0);
             break;
         case "verify":
             $userinfo = UserInformation::where('user_id', $user_id)->first();
             //echo "<pre>userinfo: "; print_r($userinfo); echo "</pre>";
             $data['userinfo'] = $userinfo;
             break;
     }
     return View::make('user.profile', $data);
 }
Example #13
0
define('CURSCRIPT', 'post');
require "../libraries/common.inc.php";
require "../share.inc.php";
require LIB_PATH . "validation.class.php";
$validate = new Validation();
if (session_id() == '') {
    require_once LIB_PATH . "session_php.class.php";
    $session = new PbSessions();
}
uses("trade", "member", "tradefield", "tag", "typeoption");
$tag = new Tags();
$offer = new Tradefields();
$typeoption = new Typeoption();
$member = new Members();
$trade = new Trades();
$trade_controller = new Trade();
$tradefield = new Tradefields();
$expires = $trade_controller->getOfferExpires();
setvar("Genders", $typeoption->get_cache_type("gender", null, array("0", "-1")));
setvar("PhoneTypes", $typeoption->get_cache_type("phone_type"));
setvar("ImTypes", $typeoption->get_cache_type("im_type"));
$if_visit_post = $_PB_CACHE['setting']['vis_post'];
if (!$if_visit_post) {
    $smarty->flash('visitor_forbid', URL, 0);
}
capt_check("capt_post_free");
if (isset($_POST['visit_post'])) {
    pb_submit_check('visit_post');
    $trade->setParams();
    $tradefield->setParams();
    $if_title_exists = $trade->findByTitle($trade->params['data']['trade']['title']);
Example #14
0
 function formatResult($result)
 {
     global $_PB_CACHE, $form;
     if (class_exists("Trade")) {
         $trade_controller = new Trade();
     } else {
         uses("trade");
         $trade_controller = new Trade();
     }
     if (!empty($result)) {
         if (empty($_PB_CACHE['trusttype'])) {
             require CACHE_PATH . 'cache_trusttype.php';
         }
         $result_count = count($result);
         for ($i = 0; $i < $result_count; $i++) {
             if (empty($result[$i]['userid'])) {
                 $result[$i]['userid'] = $result[$i]['username'];
             }
             if (!empty($result[$i]['formattribute_ids'])) {
                 $tmp_arr = $form->getAttribute(explode(",", $result[$i]['formattribute_ids']));
                 if (!empty($tmp_arr)) {
                     foreach ($tmp_arr as $key => $val) {
                         $result[$i][$key] = $val;
                     }
                 }
             }
             $result[$i]['im'] = $this->formatIM($result[$i]['cache_contacts']);
             $result[$i]['pubdate'] = @date("Y-m-d", $result[$i]['submit_time']);
             $result[$i]['content'] = strip_tags($result[$i]['content']);
             $result[$i]['url'] = $trade_controller->rewrite($result[$i]['id'], $result[$i]['type_id']);
             if (!empty($result[$i]['membergroup_id'])) {
                 $result[$i]['gradeimg'] = 'images/group/' . $_PB_CACHE['membergroup'][$result[$i]['membergroup_id']]['avatar'];
                 $result[$i]['gradename'] = $_PB_CACHE['membergroup'][$result[$i]['membergroup_id']]['name'];
             }
             $result[$i]['image'] = pb_get_attachmenturl($result[$i]['picture'], '', 'middle');
             $trusttype_images = null;
             if (!empty($result[$i]['trusttype_ids'])) {
                 $tmp_trusttype = explode(",", $result[$i]['trusttype_ids']);
                 foreach ($tmp_trusttype as $val) {
                     $trusttype_images .= '<img src="' . $_PB_CACHE['trusttype'][$val]['avatar'] . '" alt="' . $_PB_CACHE['trusttype'][$val]['name'] . '" />';
                 }
             }
             $result[$i]['trusttype'] = $trusttype_images;
         }
         return $result;
     } else {
         return null;
     }
 }
Example #15
0
File: Trade.php Project: xJakub/LCE
<?php

/**
 * Created by PhpStorm.
 * User: Jakub
 * Date: 27/11/2015
 * Time: 23:10
 */
class Trade extends Model
{
    public $tradeid;
    public $player1id;
    public $team1id;
    public $player2id;
    public $team2id;
    public $week;
}
Trade::init('trades', 'tradeid');
Example #16
0
 public function getChange($market_id)
 {
     $data_trade = Trade::where('market_id', $market_id)->orderby('created_at', 'desc')->take(2)->get()->toArray();
     $curr_price = isset($data_trade[0]['price']) ? $data_trade[0]['price'] : 0;
     $pre_price = isset($data_trade[1]['price']) ? $data_trade[1]['price'] : 0;
     $change = $pre_price != 0 ? sprintf('%.2f', ($curr_price - $pre_price) / $pre_price * 100) : 100;
     $select = "SELECT SUM( amount * price ) AS total FROM trade_history Where `market_id`='" . $market_id . "' GROUP BY market_id";
     $total_btc = DB::select($select);
     if (isset($total_btc[0])) {
         $total_volume = $total_btc[0]->total;
     } else {
         $total_volume = 0;
     }
     return array('curr_price' => $curr_price, 'pre_price' => $pre_price, 'change' => $change, 'total_volume' => $total_volume);
 }
Example #17
0
/**
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2048 $
 */
define('CURSCRIPT', 'detail');
require "../libraries/common.inc.php";
require "../share.inc.php";
$positions = $titles = array();
uses("trade", "member", "company", "tradefield", "form", "typeoption", "industry", "area");
$offer = new Tradefields();
$area = new Areas();
$industry = new Industries();
$company = new Companies();
$trade = new Trade();
$trade_model = new Trades();
$member = new Members();
$typeoption = new Typeoption();
$form = new Forms();
setvar("Genders", $typeoption->get_cache_type('gender'));
setvar("PhoneTypes", $typeoption->get_cache_type('phone_type'));
$viewhelper->setTitle(L("offer", "tpl"));
$viewhelper->setPosition(L("offer", "tpl"), "offer/");
if (isset($_GET['title'])) {
    $title = rawurldecode(trim($_GET['title']));
    $res = $trade_model->findByTitle($title);
    $id = $res['id'];
}
if (isset($_GET['id'])) {
    $id = intval($_GET['id']);
Example #18
0
        AddMoney($Amount + $Fees, $owner, $from_id);
    }
    mysql_query("DELETE FROM trades WHERE `Id`='{$ids}'");
}
//--------------------------------------
if (isset($_POST["Amount"])) {
    if ($_POST["price1"] > 0 && $_POST["Amount"] > 0) {
        $PricePer = mysql_real_escape_string($_POST["price1"]);
        $Amount = mysql_real_escape_string($_POST["Amount"]);
        $Fees = file_get_contents("http://dev3.openex.pw/system/calculatefees2.php?P=" . $Amount);
        $Total = $Fees + $Amount;
        echo $Total;
        $user_id = $loggedInUser->user_id;
        if (TakeMoney($Total, $user_id, $id) == true) {
            AddMoney($Fees, -1, $id);
            $New_Trade = new Trade();
            $New_Trade->trade_to = $Currency_1a;
            $New_Trade->trade_from = $name;
            $New_Trade->trade_amount = $Amount;
            $New_Trade->trade_value = $PricePer;
            $New_Trade->trade_owner = $user_id;
            $New_Trade->trade_type = $name;
            $New_Trade->trade_fees = $Fees;
            $New_Trade->trade_total = $Total;
            $New_Trade->trade_type = $name;
            $New_Trade->standard = $Amount;
            $New_Trade->GetEquivalentTrade();
            $New_Trade->ExecuteTrade();
            //mysql_query("INSERT INTO trades (`To`,`From`,`Amount`,`Value`,`User_ID`,`Type`,`Fee`,`Total`)VALUES ('$Currency_1a','$name','$Amount','$PricePer','$user_id','$name','$Fees','$Total');");
        } else {
            echo "<p class='notify-red' id='notify'>You cannot afford that!</p>";
Example #19
0
<?php

/**
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2075 $
 */
require "../libraries/common.inc.php";
require "room.share.php";
uses("trade", "product");
check_permission("offer");
$product = new Products();
$trade = new Trades();
$trade_controller = new Trade();
$trade_type_names = $trade_controller->getTradeTypes();
$conditions = "member_id = " . $the_memberid;
$amount = $pdb->GetArray("select Trade.type_id as TradeTypeId,count(Trade.id) as CountTrade from " . $trade->getTable(true) . " where " . $conditions . " group by Trade.type_id");
if (is_array($amount)) {
    $stats = array();
    foreach ($amount as $val) {
        $stats[$val['TradeTypeId']] = array("Amount" => $val['CountTrade'], "name" => $trade_type_names[$val['TradeTypeId']]);
    }
}
setvar("UserTradeStat", $stats);
setvar("ProductAmount", $product->findCount(null, $conditions, "Product.id"));
template("stat");
Example #20
0
<?php

/**
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2075 $
 */
require "../libraries/common.inc.php";
require "room.share.php";
require CACHE_PATH . "cache_typeoption.php";
uses("membergroup", "trade");
$membergroup = new Membergroups();
$trade = new Trade();
setvar("MenuHide", "display:none;");
if (!empty($memberinfo)) {
    $service_info = false;
    $membergroup_id = $memberinfo['membergroup_id'];
    if (empty($memberinfo['service_end_date']) or empty($memberinfo['service_start_date'])) {
        $service_info = false;
    } else {
        $total_days = $memberinfo['service_end_date'] - $memberinfo['service_start_date'];
        if ($total_days <= 0) {
            $total_days = 1;
            $service_interation = 1;
        } else {
            $service_interation = intval(($time_stamp - $memberinfo['service_start_date']) / $total_days * 100);
        }
        setvar("service_days", $service_interation > 100 ? 100 : $service_interation);
        $service_info = true;
    }
Example #21
0
 function Add($params = '')
 {
     $result = false;
     if (!empty($this->params['expire_days'])) {
         $trade_controller = Trade::getInstance();
         if (array_key_exists($this->params['expire_days'], $trade_controller->getOfferExpires())) {
             $this->params['data']['trade']['expire_time'] = $this->timestamp + 24 * 3600 * $_POST['expire_days'];
             $this->params['data']['trade']['expire_days'] = $_POST['expire_days'];
         } else {
             $this->params['data']['trade']['expire_time'] = $this->timestamp + 24 * 3600 * 10;
             $this->params['data']['trade']['expire_days'] = 10;
         }
     }
     $this->params['data']['trade']['submit_time'] = $this->params['data']['trade']['created'] = $this->params['data']['trade']['modified'] = $this->timestamp;
     $this->params['data']['trade']['ip_addr'] = pb_get_client_ip('str');
     if (isset($this->params['data']['trade']['title'])) {
         $trade_info = $this->params['data']['trade'];
         $result = $this->save($trade_info);
         $key = $this->table_name . "_id";
         //$last_tradeid = $this->$key;
         $last_tradeid = $this->dbstuff->Insert_ID();
         $_this = Tradefields::getInstance();
         $_this->params['data']['tradefield']['trade_id'] = $last_tradeid;
         $tradefield_info = $_this->params['data']['tradefield'] + $this->params['data']['tradefield'];
         $_this->primaryKey = "trade_id";
         $_this->save($tradefield_info);
     }
     return $result;
 }
Example #22
0
<?php

/**
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2048 $
 */
if (!defined('IN_PHPB2B')) {
    exit('Not A Valid Entry Point');
}
uses("trade", "tradefield");
$trade = new Trades();
$trade_controller = new Trade();
$conditions = array();
$conditions[] = "Trade.status=1";
if (!empty($member->info['id'])) {
    $conditions[] = "Trade.member_id='" . $member->info['id'] . "'";
}
if (!empty($company->info['id'])) {
    $conditions[] = "Trade.company_id='" . $company->info['id'] . "'";
}
$amount = $trade->findCount(null, $conditions, "Trade.id");
setvar("TradeTypes", $tradetypes = $trade_controller->getTradeTypes());
setvar("TradeNames", $tradenames = $trade_controller->getTradeTypeNames());
setvar("paging", array('total' => $amount));
$space->render("offer");
 public function deleteMarket()
 {
     $market_id = Input::get('market_id');
     $market = Market::find($market_id);
     if (isset($market->id)) {
         FeeTrade::where('market_id', $market_id)->delete();
         Order::where('market_id', $market_id)->delete();
         Trade::where('market_id', $market_id)->delete();
         Market::where('id', $market_id)->delete();
         $message = Lang::get('admin_messages.delete_success');
         if (Input::get('isAjax')) {
             echo json_encode(array('status' => 'success', 'message' => $message));
             exit;
         } else {
             return Redirect::to('admin/manage/markets')->with('success', $message);
         }
     } else {
         $message = Lang::get('admin_messages.market_not_exist');
         if (Input::get('isAjax')) {
             echo json_encode(array('status' => 'error', 'message' => $message));
             exit;
         } else {
             return Redirect::to('admin/manage/markets')->with('error', $message);
         }
     }
 }