143 lines
5.9 KiB
PHP
143 lines
5.9 KiB
PHP
<?php
|
|
|
|
require 'classes/AddReward.php';
|
|
|
|
class PayNotifyController{
|
|
|
|
protected function getMysql($account_id)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($account_id));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
private function insertNewOrder($conn, $nowtime, $item_list)
|
|
{
|
|
$ret = $conn->execScript('INSERT INTO orderinfo(accountid, orderid, itemid, coin, status, '.
|
|
' confirmtime, create_time, modify_time, item_list)' .
|
|
'VALUES(:accountid, :orderid, :itemid, :coin, :status,' .
|
|
' :confirmtime, :create_time, :modify_time, :item_list);',
|
|
array(
|
|
':accountid' => $_REQUEST['account_id'],
|
|
':orderid' => $_REQUEST['orderid'],
|
|
':coin' => $_REQUEST['amount'],
|
|
':itemid' => $_REQUEST['itemid'],
|
|
':status' => 1,
|
|
':confirmtime' => $nowtime,
|
|
':create_time' => $nowtime,
|
|
':modify_time' => $nowtime,
|
|
':item_list' => json_encode($item_list)
|
|
));
|
|
if (!$ret) {
|
|
echo json_encode(array(
|
|
'errcode' => 2,
|
|
'errmsg'=> '服务器内部错误'
|
|
));
|
|
die();
|
|
}
|
|
}
|
|
|
|
private function updateOrder($conn, $item_list)
|
|
{
|
|
$ret = $conn->execScript('UPDATE orderinfo SET status=1, item_list=:item_list WHERE orderid=:orderid'.
|
|
array(
|
|
':orderid' => $_REQUEST['orderid'],
|
|
':item_list' => json_encode($item_list)
|
|
));
|
|
if (!$ret) {
|
|
echo json_encode(array(
|
|
'errcode' => 2,
|
|
'errmsg'=> '服务器内部错误'
|
|
));
|
|
die();
|
|
}
|
|
}
|
|
|
|
private function updateUserTable($conn, $amount)
|
|
{
|
|
$ret = $conn->execScript('UPDATE user SET recharge_times_total=recharge_times_total + 1, ' .
|
|
' sum_coin=sum_coin + :amount WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $_REQUEST['account_id'],
|
|
':amount' => $amount
|
|
));
|
|
}
|
|
|
|
private function addToBuyHis($conn, $nowtime)
|
|
{
|
|
$dayseconds = phpcommon\getdayseconds($nowtime);
|
|
$conn->execScript('INSERT INTO buy_his(accountid, itemid, sum_times, today_times, ' .
|
|
' last_buy_time, create_time, modify_time)' .
|
|
'VALUES(:accountid, :itemid, 1, 1, ' .
|
|
' :last_buy_time, :create_time, :modify_time)' .
|
|
'ON DUPLICATE KEY UPDATE sum_times=sum_times + 1, ' .
|
|
' modify_time=:modify_time, last_buy_time=:last_buy_time,' .
|
|
' today_times=' .
|
|
" CASE WHEN last_buy_time < $dayseconds THEN 1 ELSE today_times + 1 END;",
|
|
array(
|
|
':accountid' => $_REQUEST['account_id'],
|
|
':itemid' => $_REQUEST['itemid'],
|
|
':last_buy_time' => $nowtime,
|
|
':create_time' => $nowtime,
|
|
':modify_time' => $nowtime,
|
|
));
|
|
}
|
|
|
|
public function payNotify()
|
|
{
|
|
$params = array(
|
|
'account_id' => $_REQUEST['account_id'],
|
|
'orderid' => $_REQUEST['orderid'],
|
|
'itemid' => $_REQUEST['itemid'],
|
|
'itemnum' => $_REQUEST['itemnum'],
|
|
'amount' => $_REQUEST['amount']
|
|
);
|
|
$sign = phpcommon\md5Sign($params, 'fc38349c5d084e920925e614c420be9f', $_REQUEST['timestamp']);
|
|
if ($sign != $_REQUEST['sign']) {
|
|
error_log('game2004api payNotify sign error:' + json_encode($_REQUEST));
|
|
echo json_encode(array(
|
|
'errcode' => 1,
|
|
'errmsg'=> '签名校验失败'
|
|
));
|
|
die();
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
$item_list = $addreward->addReward($_REQUEST['itemid'], $_REQUEST['itemnum'], $_REQUEST['account_id']);
|
|
foreach ($item_list as &$value) {
|
|
$value['itemnum'] = (float)$value['itemnum'];
|
|
}
|
|
error_log(json_encode($item_list));
|
|
$nowtime = time();
|
|
$conn = $this->getMysql($_REQUEST['account_id']);
|
|
$row = $conn->execQueryOne('SELECT orderid, status FROM orderinfo WHERE orderid=:orderid;',
|
|
array(
|
|
':orderid' => $_REQUEST['orderid']
|
|
));
|
|
if (!$row) {
|
|
$this->insertNewOrder($conn, $nowtime, $item_list);
|
|
} else {
|
|
if ($row['status'] == 1) {
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> ''
|
|
));
|
|
die();
|
|
}
|
|
$this->updateOrder($conn, $item_list);
|
|
}
|
|
$this->updateUserTable($conn, $_REQUEST['amount']);
|
|
$this->addToBuyHis($conn, $nowtime);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> ''
|
|
));
|
|
}
|
|
|
|
}
|