144 lines
5.8 KiB
PHP
144 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
use phpcommon;
|
|
|
|
class OrderCtrl {
|
|
|
|
private function getRedis()
|
|
{
|
|
$redis_conf = getGlobalRedisConfig();
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => $redis_conf['host'],
|
|
'port' => $redis_conf['port'],
|
|
'passwd' => $redis_conf['passwd']
|
|
));
|
|
return $r;
|
|
}
|
|
|
|
private function getMysql($DNA)
|
|
{
|
|
$mysql_conf = getMysqlConfig($DNA);
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => 'paydb' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
private function getCpOrderIdDNA($cp_orderid)
|
|
{
|
|
if (strlen($cp_orderid) < 2) {
|
|
return 0;
|
|
}
|
|
$hex_str = substr($cp_orderid, strlen($cp_orderid) - 2);
|
|
return hexdec($hex_str);
|
|
}
|
|
|
|
private function getStrDNA($account_id)
|
|
{
|
|
return crc32($account_id) % 256;
|
|
}
|
|
|
|
public function genOrderId($account_id)
|
|
{
|
|
$hex_str = dechex($this->getStrDNA($account_id));
|
|
if (strlen($hex_str) < 2) {
|
|
$hex_str = '0' . $hex_str;
|
|
}
|
|
return uniqid('201020') . $hex_str;
|
|
}
|
|
|
|
public function getOrderByCpOrderId($cp_orderid)
|
|
{
|
|
$conn = $this->getMysql($this->getCpOrderIdDNA($cp_orderid));
|
|
$row = $conn->execQueryOne('SELECT * FROM orderinfo ' .
|
|
'WHERE orderid=:orderid;',
|
|
array(
|
|
':orderid' => $orderid
|
|
)
|
|
);
|
|
return $row;
|
|
}
|
|
|
|
public function addPreOrder($pre_order_info)
|
|
{
|
|
$pre_order_info['sp_orderid'] = '';
|
|
$pre_order_info['sp_amount'] = 0;
|
|
$pre_order_info['sp_confirm_time'] = 0;
|
|
$pre_order_info['sp_pay_result'] = 0;
|
|
return $this->internalAddOrder($pre_order_info);
|
|
}
|
|
|
|
private function internalAddOrder($order_info)
|
|
{
|
|
$gameid = phpcommon\extractGameId($order_info['account_id']);
|
|
$openid = phpcommon\extractOpenId($order_info['account_id']);
|
|
$conn = $this->getMysql($this->getStrDNA($order_info['account_id']));
|
|
$ret = $conn->execScript('INSERT INTO orderinfo(' .
|
|
' orderid, account_id, roleid, server_id, channel, ' .
|
|
' poly_sdk_channel, unified_channel, ' .
|
|
' gameid, openid, itemid, try_count, price, ipv4, status, ' .
|
|
' confirmtime, createtime, sp_orderid, sp_amount, ' .
|
|
' sp_confirm_time, sp_pay_result ' .
|
|
' ) ' .
|
|
'VALUES (:orderid, :account_id, :roleid, :server_id, :channel, ' .
|
|
' :poly_sdk_channel, :unified_channel, ' .
|
|
' :gameid, :openid, :itemid, :try_count, :price, :ipv4, :status, ' .
|
|
' :confirmtime, :createtime, :sp_orderid, :sp_amount, ' .
|
|
' :sp_confirm_time, :sp_pay_result ' .
|
|
' );',
|
|
array(
|
|
':orderid' => $order_info['orderid'],
|
|
':account_id' => $order_info['account_id'],
|
|
':roleid' => $order_info['roleid'],
|
|
':server_id' => $order_info['server_id'],
|
|
':channel' => $order_info['channel'],
|
|
':poly_sdk_channel' => $order_info['poly_sdk_channel'],
|
|
':unified_channel' => $order_info['unified_channel'],
|
|
':gameid' => $gameid,
|
|
':openid' => $openid,
|
|
':itemid' => $order_info['itemid'],
|
|
':try_count' => 0,
|
|
':price' => $order_info['price'],
|
|
':ipv4' => $order_info['ipv4'],
|
|
':status' => 0,
|
|
':confirmtime' => 0,
|
|
':createtime' => time(),
|
|
|
|
':sp_orderid' => $order_info['sp_orderid'],
|
|
':sp_amount' => $order_info['sp_amount'],
|
|
':sp_confirm_time' => $order_info['sp_confirm_time'],
|
|
':sp_pay_result' => $order_info['sp_pay_result'],
|
|
)
|
|
);
|
|
return $ret;
|
|
}
|
|
|
|
public function spPayConfirm($cp_orderid, $sp_orderid, $sp_amount)
|
|
{
|
|
$conn = $this->getMysql($this->getCpOrderIdDNA($cp_orderid));
|
|
$ret = $conn->execScript('UPDATE orderinfo SET ' .
|
|
' sp_orderid = :sp_orderid, ' .
|
|
' sp_amount = :sp_amount, ' .
|
|
' sp_confirm_time = :sp_confirm_time, ' .
|
|
' sp_pay_result = :sp_pay_result ' .
|
|
'WHERE orderid = :orderid;',
|
|
array(
|
|
':orderid' => $cp_orderid,
|
|
|
|
':sp_orderid' => $sp_orderid,
|
|
':sp_amount' => $sp_amount,
|
|
':sp_confirm_time' => time(),
|
|
':sp_pay_result' => 1,
|
|
)
|
|
);
|
|
return $ret;
|
|
}
|
|
|
|
}
|