Ejemplo n.º 1
0
 // GENERATE & QUERY & POST INVOICE
 $accountId = $result2->result->Id;
 $lStartDate = new DateTime($_POST['StartDate']);
 $formattedDate = date_format($lStartDate, 'Y-m-d\\TH:i:s');
 if ($accountId) {
     // && date('Y-m-d\TH:i:s') >= $formattedDate) {
     $invoiceDate = date('Y-m-d\\TH:i:s');
     $targetDate = date('Y-m-d\\TH:i:s');
     $result = generateInvoice($instance, $accountId, $invoiceDate, $targetDate);
     $success = $result->result->Success;
     $msg = $success ? $result->result->Id : $result->result->Errors->Code . " (" . $result->result->Errors->Message . ")";
     $CreateStatus = $CreateStatus . "Invoice Created.<br>";
     if ($success) {
         // QUERY Invoice
         $query = "SELECT Id, InvoiceNumber,Status FROM Invoice WHERE id = '" . $result->result->Id . "'";
         $records = queryAll($instance, $query);
         // $CreateStatus = $CreateStatus . "Invoice Queried ($query): " . $records[0]->InvoiceNumber ." ". $records[0]->Status . "<br>";
         // POST Invoice
         $result = postInvoice($instance, $result->result->Id);
         $success = $result->result->Success;
         $CreateStatus = $CreateStatus . "Invoice Posted :" . ($result->result->Success ? "Success <br>" : $result->result->Errors->Code . " (" . $result->result->Errors->Message . ")<br>");
         if ($success) {
             $CreateStatus = $CreateStatus . "In next section";
             // DO PAYMENT$success3 ? "Success"
             $PaymentSuccess = createAndApplyPayment($instance, $accountId, $CreateStatus);
             if ($PaymentSuccess) {
                 $Generalstatus = "Created Account and processed payment for " . $gFullName;
                 $_SESSION['MemberName'] = $Generalstatus;
                 header("Location: success.php" . $URLParms);
                 // ."?".$Generalstatus);
             } else {
Ejemplo n.º 2
0
function createAndApplyPayment($instance, $accountId)
{
    # QUERY PaymentMethod
    $query = "SELECT Id,Type FROM PaymentMethod WHERE AccountId = '" . $accountId . "'";
    $records = queryAll($instance, $query);
    $paymentMethodId = $records[0]->Id;
    print "\nPaymentMethod Queried ({$query}): " . $records[0]->Id . "  " . $records[0]->Type;
    # QUERY Invoice Balance
    $query = "select Id,Balance from Invoice where AccountId = '" . $accountId . "' and Balance>0";
    $records = queryAll($instance, $query);
    $amount = $records[0]->Balance;
    $invoiceId = $records[0]->Id;
    print "\nInvoice Balance Queried ({$query}): " . $records[0]->Id . "  " . $records[0]->Balance;
    $payment = new Zuora_Payment();
    $payment->AccountId = $accountId;
    $payment->Amount = $amount;
    $payment->EffectiveDate = date('Y-m-d\\TH:i:s');
    $payment->PaymentMethodId = $paymentMethodId;
    $payment->Type = 'Electronic';
    $payment->Status = 'Draft';
    $result = $instance->create(array($payment));
    $paymentId = $result->result->Id;
    $success1 = $result->result->Success;
    $msg = "Payment: " . ($success1 ? "Success" : $result->result->errors->Code . " (" . $result->result->errors->Message . ")");
    $invoicePayment = new Zuora_InvoicePayment();
    $invoicePayment->Amount = $amount;
    $invoicePayment->InvoiceId = $invoiceId;
    $invoicePayment->PaymentId = $paymentId;
    $result = $instance->create(array($invoicePayment));
    $success2 = $result->result->Success;
    $msg .= " -> InvoicePayment: " . ($success2 ? "Success" : $result->result->errors->Code . " (" . $result->result->errors->Message . ")");
    $payment = new Zuora_Payment();
    $payment->Id = $paymentId;
    $payment->Status = 'Processed';
    $result = $instance->update(array($payment));
    $success3 = $result->result->Success;
    $msg .= " -> Payment Processed:" . ($success3 ? "Success" : $result->result->errors->Code . " (" . $result->result->errors->Message . ")");
    print "\nCreate and Apply Payment: " . $msg;
}
Ejemplo n.º 3
0
if ($instance->login($username, $password)) {
    $productId = $_POST['Products'];
    $rateplanId = $_POST['RatePlans'];
    $chargeIds = $_POST['Charges'];
    $nowdate = date('Y-m-d\\TH:i:s', time());
    $products = queryAll($instance, "select Id ,Name from Product where EffectiveEndDate > '" . $nowdate . "' and EffectiveStartDate <'" . $nowdate . "'");
    if (count($products) == 1) {
        $productId = $products[0]->Id;
    }
    if (isset($productId) && strlen($productId) == 32) {
        $rateplans = queryAll($instance, "select Id,Name from ProductRatePlan where ProductId='" . $productId . "'");
        if (count($rateplans) == 1) {
            $rateplanId = $rateplans[0]->Id;
        }
        if (isset($rateplanId) && strlen($rateplanId) == 32) {
            $rateplancharges = queryAll($instance, "select Id, Name, AccountingCode, DefaultQuantity, Type, Model, ProductRatePlanId from ProductRatePlanCharge where ProductRatePlanId ='" . $rateplanId . "'");
            if ($chargeIds == null) {
                $chargeIds = array();
                foreach ($rateplancharges as $rc) {
                    $chargeIds[] = $rc->Id;
                }
            }
        }
    }
    if ($_POST['Submit']) {
        if (validate()) {
            subscribedata($instance, $chargeIds, $rateplancharges, $rateplanId);
        }
    }
} else {
    $status = "<b>Login Failed</b>";
Ejemplo n.º 4
0
<?php

header("Content-type: text/html; charset=utf-8");
session_start();
require_once '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'Config.php';
require_once '..' . DIRECTORY_SEPARATOR . 'includes' . PATH . 'service' . PATH . 'EmotionService.php';
$ac = $_GET['ac'];
switch ($ac) {
    case 'query_all':
        queryAll();
        //查询评论
        break;
}
function queryAll()
{
    $data = EmotionService::queryAllEmotion();
    echo json_encode($data);
}
Ejemplo n.º 5
0
$uid = '';
$pw = '';
$statString = '';
$status = "";
$enviroment = $_SESSION['enviroment'];
$endpoint = $_SESSION['endpoint'];
$uid = $_SESSION['uid'];
$pw = $_SESSION['pw'];
$config = new stdClass();
$config->wsdl = "../" . $wsdl;
$instance = Zuora_API::getInstance($config);
$instance->setQueryOptions($query_batch_size);
$instance->setLocation($endpoint);
$instance->login($uid, $pw);
$nowdate = date('Y-m-d\\TH:i:s', time());
$products = queryAll($instance, "select Id ,Name from Product where EffectiveEndDate > '" . $nowdate . "' and EffectiveStartDate <'" . $nowdate . "' and   name <>'Subscription Discount'  ");
if (count($products) > 0) {
    $productId = $products[0]->Id;
    //$status= "Got Some";
} else {
}
if (!empty($_POST['Submit'])) {
    /*		switch ($_POST['enviroment']) {
    		case 'Production':
    			$endpoint = 'https://www.zuora.com/apps/services/a/17.0';
    			break;
    		case 'Sandbox':
    			$endpoint = 'https://apisandbox.zuora.com/apps/services/a/17.0';
    			break;
    		default:
    			$endpoint = 'https://apisandbox.zuora.com/apps/services/a/17.0';
Ejemplo n.º 6
0
/**
@fn tableCRUD($ac, $tbl, $asAdmin?=false)

对象型接口的入口。
也可直接被调用,常与setParam一起使用, 提供一些定制的操作。

@param $asAdmin 默认根据用户身份自动选择"AC_"类; 如果为true, 则以超级管理员身份调用,即使用"AC0_"类。
设置$asAdmin=true好处是对于超级管理员权限来说,即使未定义"AC0_"类,默认也可以访问所有内容。

假如有Rating(订单评价)对象,不想通过对象型接口来查询,而是通过函数型接口来定制输出,接口设计为:

	queryRating(storeId, cond?) -> tbl(id, score, dscr, tm, orderDscr)

	查询店铺storeId的订单评价。

	应用逻辑:
	- 按时间tm倒排序

底层利用tableCRUD实现它,这样便于保留分页、参数cond/gres等特性:

	function api_queryRating()
	{
		$storeId = mparam("storeId");

		// 定死输出内容。
		setParam("res", "id, score, dscr, tm, orderDscr");

		// 相当于AccessControl框架中调用 addCond,用Obj.query接口的内部参数cond2以保证用户还可以使用cond参数。
		setParam("cond2", ["o.storeId=$storeId"]); 

		// 定死排序条件
		setParam("orderby", "tm DESC");

		$ret = tableCRUD("query", "Rating", true);
		return $ret;
	}

注意:
- 以上示例中的设计不可取,应使用标准对象接口来实现这个需求。

@see setParam
*/
function tableCRUD($ac1, $tbl, $asAdmin = false)
{
    $accessCtl = AccessControl::create($tbl, $asAdmin);
    $accessCtl->before($ac1);
    $tbl = $accessCtl->getTable();
    $ignoreAfter = false;
    if ($ac1 == "add") {
        $keys = '';
        $values = '';
        #			var_dump($_POST);
        $id = $accessCtl->genId();
        if ($id != 0) {
            $keys = "id";
            $values = (string) $id;
        }
        foreach ($_POST as $k => $v) {
            $k = htmlEscape($k);
            if ($k === "id") {
                continue;
            }
            // ignore non-field param
            if (substr($k, 0, 2) === "p_") {
                continue;
            }
            if ($v === "") {
                continue;
            }
            # TODO: check meta
            if (!preg_match('/^\\w+$/', $k)) {
                throw new MyException(E_PARAM, "bad key {$k}");
            }
            if ($keys !== '') {
                $keys .= ", ";
                $values .= ", ";
            }
            $keys .= $k;
            $values .= Q(htmlEscape($v));
        }
        if (strlen($keys) == 0) {
            throw new MyException(E_PARAM, "no field found to be added");
        }
        $sql = sprintf("INSERT INTO %s (%s) VALUES (%s)", $tbl, $keys, $values);
        #			var_dump($sql);
        $id = execOne($sql, true);
        $res = param("res");
        if (isset($res)) {
            setParam("id", $id);
            $ret = tableCRUD("get", $tbl);
        } else {
            $ret = $id;
        }
    } elseif ($ac1 == "set") {
        $id = mparam("id", $_GET);
        $kv = "";
        foreach ($_POST as $k => $v) {
            $k = htmlEscape($k);
            if ($k === 'id') {
                continue;
            }
            // ignore non-field param
            if (substr($k, 0, 2) === "p_") {
                continue;
            }
            # TODO: check meta
            if (!preg_match('/^\\w+$/', $k)) {
                throw new MyException(E_PARAM, "bad key {$k}");
            }
            if ($kv !== '') {
                $kv .= ", ";
            }
            // 空串或null置空;empty设置空字符串
            if ($v === "" || $v === "null") {
                $kv .= "{$k}=null";
            } else {
                if ($v === "empty") {
                    $kv .= "{$k}=''";
                } else {
                    if (startsWith($k, "flag_") || startsWith($k, "prop_")) {
                        $kv .= flag_getExpForSet($k, $v);
                    } else {
                        $kv .= "{$k}=" . Q(htmlEscape($v));
                    }
                }
            }
        }
        if (strlen($kv) == 0) {
            addLog("no field found to be set");
        } else {
            $sql = sprintf("UPDATE %s SET %s WHERE id=%d", $tbl, $kv, $id);
            $cnt = execOne($sql);
        }
        $ret = "OK";
    } elseif ($ac1 === "get" || $ac1 === "query") {
        $forGet = $ac1 === "get";
        $wantArray = param("wantArray/b");
        $sqlConf = $accessCtl->sqlConf;
        $enablePaging = true;
        if ($forGet || $wantArray) {
            $enablePaging = false;
        }
        if ($forGet) {
            $id = mparam("id");
            array_unshift($sqlConf["cond"], "t0.id={$id}");
        } else {
            $pagesz = param("_pagesz/i");
            $pagekey = param("_pagekey/i");
            // support jquery-easyui
            if (!isset($pagesz) && !isset($pagekey)) {
                $pagesz = param("rows/i");
                $pagekey = param("page/i");
                if (isset($pagekey)) {
                    $enableTotalCnt = true;
                    $enablePartialQuery = false;
                }
            }
            if ($pagesz == 0) {
                $pagesz = 20;
            }
            $maxPageSz = min($accessCtl->getMaxPageSz(), PAGE_SZ_LIMIT);
            if ($pagesz < 0 || $pagesz > $maxPageSz) {
                $pagesz = $maxPageSz;
            }
            if (isset($sqlConf["gres"])) {
                $enablePartialQuery = false;
            }
        }
        $orderSql = $sqlConf["orderby"];
        // setup cond for partialQuery
        if ($enablePaging) {
            if ($orderSql == null) {
                $orderSql = $accessCtl->getDefaultSort();
            }
            if (!isset($enableTotalCnt)) {
                $enableTotalCnt = false;
                if ($pagekey === 0) {
                    $enableTotalCnt = true;
                }
            }
            // 如果未指定orderby或只用了id(以后可放宽到唯一性字段), 则可以用partialQuery机制(性能更好更精准), _pagekey表示该字段的最后值;否则_pagekey表示下一页页码。
            if (!isset($enablePartialQuery)) {
                $enablePartialQuery = false;
                if (preg_match('/^(t0\\.)?id\\b/', $orderSql)) {
                    $enablePartialQuery = true;
                    if ($pagekey) {
                        if (preg_match('/\\bid DESC/i', $orderSql)) {
                            $partialQueryCond = "t0.id<{$pagekey}";
                        } else {
                            $partialQueryCond = "t0.id>{$pagekey}";
                        }
                        // setup res for partialQuery
                        if ($partialQueryCond) {
                            // 							if (isset($sqlConf["res"][0]) && !preg_match('/\bid\b/',$sqlConf["res"][0])) {
                            // 								array_unshift($sqlConf["res"], "t0.id");
                            // 							}
                            array_unshift($sqlConf["cond"], $partialQueryCond);
                        }
                    }
                }
            }
            if (!$pagekey) {
                $pagekey = 1;
            }
        }
        if (!isset($sqlConf["res"][0])) {
            $sqlConf["res"][0] = "t0.*";
        } else {
            if ($sqlConf["res"][0] === "") {
                array_shift($sqlConf["res"]);
            }
        }
        $resSql = join(",", $sqlConf["res"]);
        if ($resSql == "") {
            $resSql = "t0.id";
        }
        if (@$sqlConf["distinct"]) {
            $resSql = "DISTINCT {$resSql}";
        }
        $tblSql = "{$tbl} t0";
        if (count($sqlConf["join"]) > 0) {
            $tblSql .= "\n" . join("\n", $sqlConf["join"]);
        }
        $condSql = "";
        foreach ($sqlConf["cond"] as $cond) {
            if ($cond == null) {
                continue;
            }
            if (strlen($condSql) > 0) {
                $condSql .= " AND ";
            }
            if (stripos($cond, " and ") !== false || stripos($cond, " or ") !== false) {
                $condSql .= "({$cond})";
            } else {
                $condSql .= $cond;
            }
        }
        /*
        			foreach ($_POST as $k=>$v) {
        				# skip sys param which generally starts with "_"
        				if (substr($k, 0, 1) === "_")
        					continue;
        				# TODO: check meta
        				if (! preg_match('/^\w+$/', $k))
        					throw new MyException(E_PARAM, "bad key $k");
        
        				if ($condSql !== '') {
        					$condSql .= " AND ";
        				}
        				$condSql .= KVtoCond($k, $v);
        			}
        */
        $sql = "SELECT {$resSql} FROM {$tblSql}";
        if ($condSql) {
            flag_handleCond($condSql);
            $sql .= "\nWHERE {$condSql}";
        }
        if (isset($sqlConf["union"])) {
            $sql .= "\nUNION\n" . $sqlConf["union"];
        }
        if ($sqlConf["gres"]) {
            $sql .= "\nGROUP BY {$sqlConf['gres']}";
        }
        if ($orderSql) {
            $sql .= "\nORDER BY " . $orderSql;
        }
        if ($enablePaging) {
            if ($enableTotalCnt) {
                $cntSql = "SELECT COUNT(*) FROM {$tblSql}";
                if ($condSql) {
                    $cntSql .= "\nWHERE {$condSql}";
                }
                $totalCnt = queryOne($cntSql);
            }
            if ($enablePartialQuery) {
                $sql .= "\nLIMIT " . $pagesz;
            } else {
                $sql .= "\nLIMIT " . ($pagekey - 1) * $pagesz . "," . $pagesz;
            }
        } else {
            if ($pagesz) {
                $sql .= "\nLIMIT " . $pagesz;
            }
        }
        if ($forGet) {
            $ret = queryOne($sql, PDO::FETCH_ASSOC);
            if ($ret === false) {
                throw new MyException(E_PARAM, "not found `{$tbl}.id`=`{$id}`");
            }
            handleSubObj($sqlConf["subobj"], $id, $ret);
        } else {
            $ret = queryAll($sql, PDO::FETCH_ASSOC);
            if ($ret === false) {
                $ret = [];
            }
            if ($wantArray) {
                foreach ($ret as &$mainObj) {
                    $id1 = $mainObj["id"];
                    handleSubObj($sqlConf["subobj"], $id1, $mainObj);
                }
            } else {
                // Note: colCnt may be changed in after().
                $fixedColCnt = count($ret) == 0 ? 0 : count($ret[0]);
                $accessCtl->after($ret);
                $ignoreAfter = true;
                if ($enablePaging && $pagesz == count($ret)) {
                    // 还有下一页数据, 添加nextkey
                    if ($enablePartialQuery) {
                        $nextkey = $ret[count($ret) - 1]["id"];
                    } else {
                        $nextkey = $pagekey + 1;
                    }
                }
                $ret = objarr2table($ret, $fixedColCnt);
                if (isset($nextkey)) {
                    $ret["nextkey"] = $nextkey;
                }
                if (isset($totalCnt)) {
                    $ret["total"] = $totalCnt;
                }
                handleFormat($ret, $tbl);
            }
        }
    } elseif ($ac1 == "del") {
        $id = mparam("id");
        $sql = sprintf("DELETE FROM %s WHERE id=%d", $tbl, $id);
        $cnt = execOne($sql);
        if ($cnt != 1) {
            throw new MyException(E_PARAM, "not found id={$id}");
        }
        $ret = "OK";
    }
    if (!$ignoreAfter) {
        $accessCtl->after($ret);
    }
    return $ret;
}
Ejemplo n.º 7
0
function handleSearch($data, $queryAll)
{
    $uid = $data['userId'];
    $result = queryUid($uid);
    if (!$result) {
        $Response['status'] = 'error';
        $Response['message'] = '用户不存在';
        return $Response;
    }
    while ($row = mysql_fetch_array($result)) {
        //如果用户不是处于登录状态
        if (!$row['status']) {
            $Response['status'] = 'error';
            $Response['message'] = '用户未登录';
            return $Response;
        }
    }
    //是否查找全部人
    if (!$queryAll) {
        $result = queryName($data['keyword']);
    } else {
        $result = queryAll();
    }
    if (!$result) {
        $Response['status'] = 'failed';
        $Response['message'] = '未找到满足条件用户';
        $Response['count'] = 0;
        return $Response;
    }
    $Response['status'] = 'success';
    $Response['count'] = mysql_num_rows($result);
    $users = array();
    while ($row = mysql_fetch_array($result)) {
        $user['name'] = $row['name'];
        $user['phoneNumber'] = explode(' ', $row['phoneNumber']);
        $user['education'] = $row['education'];
        $user['eduDate'] = $row['eduDate'];
        $user['address'] = $row['address'];
        $user['email'] = $row['email'];
        $user['modifiedDate'] = $row['modifiedDate'];
        $user['headImage'] = $row['headImage'];
        $users[] = $user;
    }
    $Response['userData'] = $users;
    return $Response;
}
Ejemplo n.º 8
0
<?php

// run setenv to choose db
chdir(dirname(__FILE__));
require_once "../server/app.php";
$GLOBALS["dbConfirmFn"] = function ($connstr) {
    echo "=== connect to {$connstr} (enter to cont, ctrl-c to break) ";
    fgets(STDIN);
};
// example: update all names of users, e.g. "用户13712345678"->"用户137****5678"
$rows = queryAll("select id, name, phone from User");
global $DBH;
$DBH->beginTransaction();
$sth = $DBH->prepare("update User set name=? where id=?");
$n = 0;
foreach ($rows as $row) {
    $id = $row[0];
    $name = $row[1] ?: "User " . $row[2];
    $name1 = preg_replace('/\\d{3}\\K\\d{4}/', '****', $name);
    if ($name1 != $name) {
        echo "update `{$name}` to `{$name1}`\n";
        $sth->execute([$name1, $id]);
        ++$n;
    }
}
$DBH->commit();
echo "update {$n} records.\n";