purchase type 2
This commit is contained in:
parent
e81e597b1b
commit
2d852ad3c8
@ -215,6 +215,124 @@ class RechargeController
|
||||
));
|
||||
}
|
||||
|
||||
public function purchaseNotify()
|
||||
{
|
||||
$params = array(
|
||||
'account_id' => $_REQUEST['account_id'],
|
||||
'goodsid' => $_REQUEST['goodsid'],
|
||||
'orderid' => $_REQUEST['orderid'],
|
||||
'amount' => $_REQUEST['amount'],,
|
||||
);
|
||||
$sign = phpcommon\md5Sign($params, 'NrN3zkVOzXF1vRzUc9eJM9ZKRO5eLooD', $_REQUEST['timestamp']);
|
||||
if ($sign != $_REQUEST['sign']) {
|
||||
error_log('game2004api payNotify sign error:' + json_encode($_REQUEST));
|
||||
echo json_encode(array(
|
||||
'errcode' => 1,
|
||||
'errmsg' => '签名校验失败'
|
||||
));
|
||||
die();
|
||||
}
|
||||
|
||||
$shopgoods = metatable\getShopGoodsById($_REQUEST['goodsid']);
|
||||
if (!$shopgoods) {
|
||||
error_log('game2004api payNotify goods error:' + json_encode($_REQUEST));
|
||||
echo json_encode(array(
|
||||
'errcode' => 2,
|
||||
'errmsg' => 'goods 未找到'
|
||||
));
|
||||
die();
|
||||
}
|
||||
|
||||
if (
|
||||
$shopgoods['type'] != 2 && //特惠礼包
|
||||
$shopgoods['type'] != 3 //月卡
|
||||
) {
|
||||
error_log('game2004api payNotify goods type error:' + json_encode($_REQUEST));
|
||||
echo json_encode(array(
|
||||
'errcode' => 3,
|
||||
'errmsg' => 'goods type error'
|
||||
));
|
||||
die();
|
||||
}
|
||||
|
||||
if ($shopgoods['type'] == 3) {
|
||||
|
||||
} else {
|
||||
$addreward = new classes\AddReward();
|
||||
$item_list = $addreward->addReward($shopgoods['item_id'], 1, $_REQUEST['account_id'], $_REQUEST['timestamp'], 0);
|
||||
foreach ($item_list as &$value) {
|
||||
$value['itemnum'] = (float)$value['itemnum'];
|
||||
}
|
||||
error_log(json_encode($item_list));
|
||||
$nowtime = time();
|
||||
$conn = $this->getMysql($_REQUEST['account_id']);
|
||||
|
||||
$this->insertNewOrder($conn, $nowtime, $item_list);
|
||||
|
||||
$this->updateUserTable($conn, $_REQUEST['amount']);
|
||||
$this->addToBuyHis($conn, $nowtime);
|
||||
}
|
||||
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => ''
|
||||
));
|
||||
}
|
||||
|
||||
private function insertNewOrder($conn, $nowtime, $item_list)
|
||||
{
|
||||
$ret = $conn->execScript('INSERT INTO orderinfo(accountid, orderid, goodsid, price, status, '.
|
||||
' confirmtime, create_time, modify_time, item_list)' .
|
||||
'VALUES(:accountid, :orderid, :goodsid, :price, :status,' .
|
||||
' :confirmtime, :create_time, :modify_time, :item_list);',
|
||||
array(
|
||||
':accountid' => $_REQUEST['account_id'],
|
||||
':orderid' => $_REQUEST['orderid'],
|
||||
':price' => $_REQUEST['amount'],
|
||||
':goodsid' => $_REQUEST['goodsid'],
|
||||
':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 updateUserTable($conn, $amount)
|
||||
{
|
||||
$ret = $conn->execScript('UPDATE user SET recharge_times_total=recharge_times_total + 1, ' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $_REQUEST['account_id'],
|
||||
));
|
||||
}
|
||||
|
||||
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 activityInfo()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
@ -250,8 +368,8 @@ class RechargeController
|
||||
'expire' => 0,
|
||||
'daily_time' => 0,
|
||||
),
|
||||
'daily_purchase' => array (),
|
||||
'total_recharge' => array (),
|
||||
'daily_purchase' => array(),
|
||||
'total_recharge' => array(),
|
||||
'total_consume' => array(),
|
||||
));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user