This commit is contained in:
aozhiwei 2020-10-20 11:39:16 +08:00
parent d262d4e992
commit 7864689ee6

View File

@ -17,27 +17,45 @@ class OrderCtrl {
return $r; return $r;
} }
private function getMysql() private function getMysql($DNA)
{ {
$mysql_conf = getMysqlConfig(); $mysql_conf = getMysqlConfig($DNA);
$conn = new phpcommon\Mysql(array( $conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'], 'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'], 'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'], 'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'], 'passwd' => $mysql_conf['passwd'],
'dbname' => 'paydb' 'dbname' => 'paydb' . $mysql_conf['instance_id']
)); ));
return $conn; return $conn;
} }
public function genOrderId($account_id) 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);
} }
public function getOrderByCpOrderId($orderid) private function getStrDNA($account_id)
{ {
$conn = $this->getMysql(); 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 ' . $row = $conn->execQueryOne('SELECT * FROM orderinfo ' .
'WHERE orderid=:orderid;', 'WHERE orderid=:orderid;',
array( array(
@ -47,24 +65,6 @@ class OrderCtrl {
return $row; return $row;
} }
public function getOrderBySpOrderId($channel, $sp_orderid)
{
$conn = $this->getMysql();
$row = $conn->execQueryOne('SELECT * FROM orderinfo ' .
'WHERE channel=:channel AND sp_orderid=:sp_orderid;',
array(
':channel' => $channel,
':sp_orderid' => $sp_orderid
)
);
return $row;
}
public function addOrder($order_info)
{
return $this->internalAddOrder($order_info);
}
public function addPreOrder($pre_order_info) public function addPreOrder($pre_order_info)
{ {
$pre_order_info['sp_orderid'] = ''; $pre_order_info['sp_orderid'] = '';
@ -78,7 +78,7 @@ class OrderCtrl {
{ {
$gameid = phpcommon\extractGameId($order_info['account_id']); $gameid = phpcommon\extractGameId($order_info['account_id']);
$openid = phpcommon\extractOpenId($order_info['account_id']); $openid = phpcommon\extractOpenId($order_info['account_id']);
$conn = $this->getMysql(); $conn = $this->getMysql($this->getStrDNA($order_info['account_id']));
$ret = $conn->execScript('INSERT INTO orderinfo(' . $ret = $conn->execScript('INSERT INTO orderinfo(' .
' orderid, account_id, roleid, server_id, channel, ' . ' orderid, account_id, roleid, server_id, channel, ' .
' poly_sdk_channel, unified_channel, ' . ' poly_sdk_channel, unified_channel, ' .
@ -119,9 +119,9 @@ class OrderCtrl {
return $ret; return $ret;
} }
public function spPayConfirm($orderid, $sp_orderid, $sp_amount) public function spPayConfirm($cp_orderid, $sp_orderid, $sp_amount)
{ {
$conn = $this->getMysql(); $conn = $this->getMysql($this->getCpOrderIdDNA($cp_orderid));
$ret = $conn->execScript('UPDATE orderinfo SET ' . $ret = $conn->execScript('UPDATE orderinfo SET ' .
' sp_orderid = :sp_orderid, ' . ' sp_orderid = :sp_orderid, ' .
' sp_amount = :sp_amount, ' . ' sp_amount = :sp_amount, ' .
@ -129,7 +129,7 @@ class OrderCtrl {
' sp_pay_result = :sp_pay_result ' . ' sp_pay_result = :sp_pay_result ' .
'WHERE orderid = :orderid;', 'WHERE orderid = :orderid;',
array( array(
':orderid' => $orderid, ':orderid' => $cp_orderid,
':sp_orderid' => $sp_orderid, ':sp_orderid' => $sp_orderid,
':sp_amount' => $sp_amount, ':sp_amount' => $sp_amount,